[Skip to main content](#vessel-content)

#   Cart sorting by product code

##

- **[GunnarB](/forum/user/36435-gunnarb "View GunnarB's Profile")**
- [![GunnarB's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/36435-gunnarb "View GunnarB's Profile") Topic Author
- [ Offline](/forum/user/36435-gunnarb)

Less More

- Posts: 21
- Thank you received: 0
-
-

11 years 8 months ago [\#194720](#194720) by [GunnarB](/forum/user/36435-gunnarb "View GunnarB's Profile")  *[Cart sorting by product code](/forum/27-checkout/875669-cart-sorting-by-product-code#194720 "-- HikaShop version -- : 2.4.0 -- Joomla version -- : 3.4.0  For us it would make sense to order the cart items by product&#95;code. Is this option implemented?  If not I'd appreciate a hint for php change.")* was created by *[GunnarB](/forum/user/36435-gunnarb "View GunnarB's Profile")*

-- HikaShop version -- : 2.4.0
-- Joomla version -- : 3.4.0

For us it would make sense to order the cart items by product_code. Is this option implemented?

If not I'd appreciate a hint for php change.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI3LWNoZWNrb3V0Lzg3NTY2OS1jYXJ0LXNvcnRpbmctYnktcHJvZHVjdC1jb2RlP3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86587
- Thank you received: 14326
-
-

11 years 8 months ago -  11 years 8 months ago [\#194756](#194756) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Cart sorting by product code](/forum/27-checkout/875669-cart-sorting-by-product-code#194756 "-- HikaShop version -- : 2.4.0 -- Joomla version -- : 3.4.0  For us it would make sense to order the cart items by product&#95;code. Is this option implemented?  If not I'd appreciate a hint for php change.")*

Hi,

There is no options for that, but it's potentially possible with some code change. But on which page do you want that ?
The cart module ? The cart on the checkout ? The order details page in the backend ? the invoice in the backend ? the order details page on the frontend ? the invoice on the frontend ? The email notifications ?

Last edit: 11 years 8 months ago by [nicolas](/forum/user/63-nicolas "View nicolas's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI3LWNoZWNrb3V0Lzg3NTY2OS1jYXJ0LXNvcnRpbmctYnktcHJvZHVjdC1jb2RlP3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[GunnarB](/forum/user/36435-gunnarb "View GunnarB's Profile")**
- [![GunnarB's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/36435-gunnarb "View GunnarB's Profile") Topic Author
- [ Offline](/forum/user/36435-gunnarb)

Less More

- Posts: 21
- Thank you received: 0
-
-

11 years 8 months ago [\#194822](#194822) by [GunnarB](/forum/user/36435-gunnarb "View GunnarB's Profile")  Replied by *[GunnarB](/forum/user/36435-gunnarb "View GunnarB's Profile")* on topic *[Cart sorting by product code](/forum/27-checkout/875669-cart-sorting-by-product-code#194822 "-- HikaShop version -- : 2.4.0 -- Joomla version -- : 3.4.0  For us it would make sense to order the cart items by product&#95;code. Is this option implemented?  If not I'd appreciate a hint for php change.")*

Yes, to be consistent on all mentioned lists: Priority would be cart module and checkout, than email. Than the others.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI3LWNoZWNrb3V0Lzg3NTY2OS1jYXJ0LXNvcnRpbmctYnktcHJvZHVjdC1jb2RlP3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86587
- Thank you received: 14326
-
-

11 years 8 months ago [\#194824](#194824) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Cart sorting by product code](/forum/27-checkout/875669-cart-sorting-by-product-code#194824 "-- HikaShop version -- : 2.4.0 -- Joomla version -- : 3.4.0  For us it would make sense to order the cart items by product&#95;code. Is this option implemented?  If not I'd appreciate a hint for php change.")*

For the cart, you can change the line: Code:

$query='SELECT a.*,b.*,c.* FROM '.hikashop_table('cart').' AS a LEFT JOIN '.hikashop_table('cart_product').' AS b ON a.cart_id = b.cart_id LEFT JOIN '.hikashop_table('product').' AS c ON b.product_id=c.product_id WHERE '.implode(' AND ',$filters).' ORDER BY b.cart_product_modified ASC';

in the file administrator/components/com_hikashop/classes/cart.php to something like this: Code:

$query='SELECT a.*,b.*,c.* FROM '.hikashop_table('cart').' AS a LEFT JOIN '.hikashop_table('cart_product').' AS b ON a.cart_id = b.cart_id LEFT JOIN '.hikashop_table('product').' AS c ON b.product_id=c.product_id WHERE '.implode(' AND ',$filters).' ORDER BY b.cart_product_code ASC';

For the orders, it's the line:
$query = 'SELECT a.* FROM '.hikashop_table('order_product').' AS a WHERE a.order_id = '.(int)$order-&gt;order_id;
of the file administrator/components/com_hikashop/classes/order.php that you want to change to something like this:
$query = 'SELECT a.* FROM '.hikashop_table('order_product').' AS a WHERE a.order_id = '.(int)$order-&gt;order_id.' ORDER BY order_product_code ASC';

Please note that we cannot guarantee the proper functioning of HikaShop with these modifications and you might have some surprises as the system wasn't designed to work like that. Note also that you'll loose your changes when you update HikaShop.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI3LWNoZWNrb3V0Lzg3NTY2OS1jYXJ0LXNvcnRpbmctYnktcHJvZHVjdC1jb2RlP3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[GunnarB](/forum/user/36435-gunnarb "View GunnarB's Profile")**
- [![GunnarB's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/36435-gunnarb "View GunnarB's Profile") Topic Author
- [ Offline](/forum/user/36435-gunnarb)

Less More

- Posts: 21
- Thank you received: 0
-
-

11 years 8 months ago [\#194857](#194857) by [GunnarB](/forum/user/36435-gunnarb "View GunnarB's Profile")  Replied by *[GunnarB](/forum/user/36435-gunnarb "View GunnarB's Profile")* on topic *[Cart sorting by product code](/forum/27-checkout/875669-cart-sorting-by-product-code#194857 "-- HikaShop version -- : 2.4.0 -- Joomla version -- : 3.4.0  For us it would make sense to order the cart items by product&#95;code. Is this option implemented?  If not I'd appreciate a hint for php change.")*

Hi Nicolas,

I tried it, but this solution does not work, the table hikashop_cart_product does not carry the field cart_product_code.

I found a different solution:
I copied components\com_hikashop\views\product\tmpl\cart.php into my template folder templates\favourite\html\com_hikashop\product so it will also work after an update.

Then I added at the beginning of the file (line 11) Code:

function cmp_product_code($a, $b) { return strcmp($a-&gt;product_code, $b-&gt;product_code); }

Then in around line 400 Code:

usort($this-&gt;rows, "cmp_product_code"); // added sort foreach($this-&gt;rows as $i =&gt; $row){ // original code

This works for the cart. I was thinking to maybe modify the table hikashop_cart_product, add a new field cart_product_order and insert the product_code there (or any other field to sort by).

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI3LWNoZWNrb3V0Lzg3NTY2OS1jYXJ0LXNvcnRpbmctYnktcHJvZHVjdC1jb2RlP3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[Jerome](/forum/user/80-jerome "View Jerome's Profile")**
- [![Jerome's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar80.png)](/forum/user/80-jerome "View Jerome's Profile")
- [ Offline](/forum/user/80-jerome)
- HikaShop core developer

Less More

- Posts: 26402
- Thank you received: 4081
-
- [](http://obsi.dev)
-

11 years 8 months ago [\#194874](#194874) by [Jerome](/forum/user/80-jerome "View Jerome's Profile")  Replied by *[Jerome](/forum/user/80-jerome "View Jerome's Profile")* on topic *[Cart sorting by product code](/forum/27-checkout/875669-cart-sorting-by-product-code#194874 "-- HikaShop version -- : 2.4.0 -- Joomla version -- : 3.4.0  For us it would make sense to order the cart items by product&#95;code. Is this option implemented?  If not I'd appreciate a hint for php change.")*

Hi,

I think that Nicolas wanted to write Code:

ORDER BY c.product_code ASC

Because the product_code value is in the product table.

Regards,

---

Jerome - Obsidev.com
HikaMarket &amp; HikaSerial developer / HikaShop core dev team.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI3LWNoZWNrb3V0Lzg3NTY2OS1jYXJ0LXNvcnRpbmctYnktcHJvZHVjdC1jb2RlP3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

Board Categories HikaShop Install &amp; Update Product &amp; Category Display Content Creation Sales and Orders Orders management Reports &amp; Statistics Customers Checkout Payment Methods Shipping Methods Import &amp; Export (CSV, XLS…) Specific Features Affilation Taxes Wishlist Vote Carousel &amp; Slider Mass Actions Filters &amp; Search Discount &amp; Coupon Feature Request Integrations Showcase General Talk about HikaShop Development HikaShop 3.0 Beta Translation Commercial Jobs HikaShop Components HikaMarket Market: Feature requests Market: How to? Market: Bug Report HikaSerial General talk about HikaSerial Serial: Bug Report Serial: How to? Support en Français de HikaSerial (French Support) HikaSubscription HikaAuction Auction: Feature requests Auction: How to? Auction: Bug report Hikashop around the world Support en Français (French Support) Russian FAQ. Курс выживания с Hikashop. Частые вопросы и о Расширения Hikashop Наши сайты на Hikashop 日本語版サポート(Japanese Support) Thai German Archives Bug Report How to?

[](/forum/topics/feed/mode-topics?format=feed&type=rss)

Time to create page: 0.049 seconds

[Powered by](/forum/credits) [Kunena Forum](https://www.kunena.org)
