How to overwrite /includes/system/segments/sortable_product_columns.php?

Open to all! Ask other shopowners for help.
loop
Contributor
Posts: 253
Joined: Thu Mar 25, 2021 12:26 pm
Phoenix Version:
Has thanked: 7 times
Been thanked: 3 times

How to overwrite /includes/system/segments/sortable_product_columns.php?

Post by loop »

Hi All
I have the system/override folder, but it seems nothing happends, whenn i put it there


Join The Code Co-op to get access to your library in the Code Co-op Forum
ecartz
Core Team
Posts: 3084
Joined: Tue Nov 05, 2019 6:02 pm
Phoenix Version:
Has thanked: 4 times
Been thanked: 208 times

Re: How to overwrite /includes/system/segments/sortable_product_columns.php?

Post by ecartz »

It isn't a class or template, so it can't be overridden.

Just override the thing that calls it and call something else. Or use the hook to customize the behavior, which could go as far as throwing out the previous result and starting over.
loop
Contributor
Posts: 253
Joined: Thu Mar 25, 2021 12:26 pm
Phoenix Version:
Has thanked: 7 times
Been thanked: 3 times

Re: How to overwrite /includes/system/segments/sortable_product_columns.php?

Post by loop »

oh i see...

i just wanted to add a "different" sort method:
like this (but different sort order)
'PRODUCT_LIST_ORDERED' => " ORDER BY p.products_ordered%s, pd.products_name",

...what would you suggest ist the best approach? copy the file and link it new from product_listing.php or is there a better way?
ecartz
Core Team
Posts: 3084
Joined: Tue Nov 05, 2019 6:02 pm
Phoenix Version:
Has thanked: 4 times
Been thanked: 208 times

Re: How to overwrite /includes/system/segments/sortable_product_columns.php?

Post by ecartz »

You can just make a hook and add values to the $column_specifications array.

Code: Select all

class hook_shop_filter_whatever {

  public function listen_filterStart($parameters) {
    $parameters['column_specifications']['PRODUCT_LIST_WHATEVER'] = // whatever
Replace the whatevers with stuff that makes sense.
loop
Contributor
Posts: 253
Joined: Thu Mar 25, 2021 12:26 pm
Phoenix Version:
Has thanked: 7 times
Been thanked: 3 times

Re: How to overwrite /includes/system/segments/sortable_product_columns.php?

Post by loop »

Hi ecartz

that sounds pretty amazing!
Maybe i did something wrong, as it won't eject the hook.
i placed here a file: "includes\hooks\shop\system\sortableProductColumns.php"

Code: Select all

class hook_shop_system_sortableProductColumns{
    public function listen_filterStart($parameters) {
        $parameters['column_specifications']['PRODUCT_LIST_BESTSELLER'] = " ORDER BY test";
    }
}
can you help me where i missunderstood your solution? Is it not in the "system" hook? (i don't know exactly where's the difference of siteWide and system hooks)
thank you for your help
Omar_one
Senior Contributor
Posts: 677
Joined: Fri Oct 25, 2019 5:06 pm
Phoenix Version: v1.0.8.16
Has thanked: 100 times
Been thanked: 56 times

Re: How to overwrite /includes/system/segments/sortable_product_columns.php?

Post by Omar_one »

@ecartz
I am trying to do the something
after creating the hook I get error

Code: Select all

Warning: Illegal string offset 'sortable' in \templates\override\includes\components\product_listing.php on line 45
Warning: Illegal string offset 'heading' in \templates\override\includes\components\product_listing.php on line 46
and I added the new sort method to sortable_product_columns.php , nothing change the error still
ecartz
Core Team
Posts: 3084
Joined: Tue Nov 05, 2019 6:02 pm
Phoenix Version:
Has thanked: 4 times
Been thanked: 208 times

Re: How to overwrite /includes/system/segments/sortable_product_columns.php?

Post by ecartz »

loop wrote: Tue Oct 05, 2021 3:35 pm

Code: Select all

class hook_shop_system_sortableProductColumns{
    public function listen_filterStart($parameters) {
        $parameters['column_specifications']['PRODUCT_LIST_BESTSELLER'] = " ORDER BY test";
    }
}
It has to look like the other entries:

Code: Select all

  class hook_shop_filter_sortableProductColumns{

    public function listen_filterStart($parameters) {
      $parameters['column_specifications']['PRODUCT_LIST_BESTSELLER'] = [
        'order_by' => " ORDER BY test",
        'heading' => TABLE_HEADING_BESTSELLER,
        'sortable' => false,
      ];
    }

  }
Omar_one
Senior Contributor
Posts: 677
Joined: Fri Oct 25, 2019 5:06 pm
Phoenix Version: v1.0.8.16
Has thanked: 100 times
Been thanked: 56 times

Re: How to overwrite /includes/system/segments/sortable_product_columns.php?

Post by Omar_one »

it's working after adding this to sortable_product_columns.php file

Code: Select all

'PRODUCT_LIST_BESTSELLER' => [
      'order_by' => " ORDER BY test",
      'heading' => TABLE_HEADING_BESTSELLER,
      'sortable' => true,
    ],


I tried to create another hook to customize the behavior but it was not working

Code: Select all

  public function listen_injectApplicationTop() {	  
$column_specifications = array_filter([
'PRODUCT_LIST_BESTSELLER' => [
      'order_by' => " ORDER BY test",
      'heading' => TABLE_HEADING_BESTSELLER,
      'sortable' => true,
     ],
  ]);
ecartz
Core Team
Posts: 3084
Joined: Tue Nov 05, 2019 6:02 pm
Phoenix Version:
Has thanked: 4 times
Been thanked: 208 times

Re: How to overwrite /includes/system/segments/sortable_product_columns.php?

Post by ecartz »

Omar_one wrote: Wed Oct 06, 2021 7:41 pm I tried to create another hook to customize the behavior but it was not working

Code: Select all

  public function listen_injectApplicationTop() {	  
$column_specifications = array_filter([
'PRODUCT_LIST_BESTSELLER' => [
      'order_by' => " ORDER BY test",
      'heading' => TABLE_HEADING_BESTSELLER,
      'sortable' => true,
     ],
  ]);
1. You don't want to put it in an injectApplicationTop listener. You want it in filterStart, as that happens after the column specification is created but before it is used.
2. I would make it a filter hook, not system. If not filter, then a specific page.
3. It needs to look like the way that I wrote it previously. The way that you have it written won't do anything, even in the correct place.
Omar_one
Senior Contributor
Posts: 677
Joined: Fri Oct 25, 2019 5:06 pm
Phoenix Version: v1.0.8.16
Has thanked: 100 times
Been thanked: 56 times

Re: How to overwrite /includes/system/segments/sortable_product_columns.php?

Post by Omar_one »

Thank you @ecartz I get it
thank you for you help


Join The Code Co-op to get access to your library in the Code Co-op Forum
Post Reply