Page 1 of 2

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

Posted: Tue Oct 05, 2021 8:08 am
by loop
Hi All
I have the system/override folder, but it seems nothing happends, whenn i put it there

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

Posted: Tue Oct 05, 2021 9:40 am
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.

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

Posted: Tue Oct 05, 2021 1:09 pm
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?

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

Posted: Tue Oct 05, 2021 2:09 pm
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.

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

Posted: Tue Oct 05, 2021 3:35 pm
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

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

Posted: Wed Oct 06, 2021 6:15 pm
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

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

Posted: Wed Oct 06, 2021 6:36 pm
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,
      ];
    }

  }

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

Posted: Wed Oct 06, 2021 7:41 pm
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,
     ],
  ]);

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

Posted: Thu Oct 07, 2021 2:06 am
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.

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

Posted: Thu Oct 07, 2021 11:37 am
by Omar_one
Thank you @ecartz I get it
thank you for you help