Sort product listing by multiple columns?

  • Posts: 146
  • Thank you received: 4
  • Hikashop Business
9 years 7 months ago #229615

-- HikaShop version -- : 2.6.1
-- Joomla version -- : 3.4.8
-- PHP version -- : 5.6.16

I have a product set that uses multiple custom fields ('A0','B0','K0',etc.). My customer would like to have a table display listing which is sorted by A0, then by B0, then by K0. Even though such a DB query is simple, the Administrative interface only allows a single value to be selected from a popup list. Is there a HikaShop approved method to sort product listings by multiple field values?

(I am a php developer and can modify code as needed.)

Please Log in or Create an account to join the conversation.

  • Posts: 84328
  • Thank you received: 13718
  • MODERATOR
9 years 7 months ago #229628

Hi,

There is no option for that.
The only solution is to directly modify the code generating the MySQL query.
You can find the line:

$order = ' ORDER BY '.$pageInfo->filter->order->value.' '.$pageInfo->filter->order->dir;
in the file components/com_hikashop/views/product/view.html.php if you want to do that.

The following user(s) said Thank You: icomex

Please Log in or Create an account to join the conversation.

  • Posts: 146
  • Thank you received: 4
  • Hikashop Business
9 years 7 months ago #229721

Found it. I added

if(!empty($pageInfo->filter->order->value) && ($pageInfo->filter->order->value=='b.ao')){
    $order = ' ORDER BY b.ao, b.bo, b.ko, b.k1 '.$pageInfo->filter->order->dir; 
}

It works beautifully. I'm assume that on updates, this may disappear, so I'm adding it to my production notes.

I'd like to submit a suggestion for a method to supply multiple field choices for sorting product lists in a future HikaShop version which will endure updates.

Thanks.

Please Log in or Create an account to join the conversation.

  • Posts: 84328
  • Thank you received: 13718
  • MODERATOR
9 years 7 months ago #229746

Yes, you'll loose your change when you update.

If you want a solution that endure updates it's possible too.
Create a HikaShop plugin and implement the function onBeforeProductListingLoad( & $filters, & $order, & $this, & $select, & $select2, & $a, & $b, & $on) in it. There, just set the $order variable like you want.
We have a developer documentation available here if necessary:
www.hikashop.com/support/documentation/6...r-documentation.html

Please Log in or Create an account to join the conversation.

Time to create page: 0.057 seconds
Powered by Kunena Forum