Post by karinar0 » Mon Jan 08, 2018 11:14 pm

Hi,

I would like to sort cart alphabetically.

It's showing according to the order added.

Newbie

Posts

Joined
Tue Nov 14, 2017 1:07 am

Post by straightlight » Tue Jan 09, 2018 8:05 am

No OC version posted. More information is needed.

The most generated errors being found on Opencart forum originates from contributed programming. The increased counters are caused by posted redundancies of the same solutions that were already provided prior.

F. Rules:

- viewtopic.php?f=176&t=200480
- viewtopic.php?f=176&t=200804


Regards,
Straightlight


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by karinar0 » Tue Jan 09, 2018 10:27 am

Sorry! Version 2.3.0.2

Newbie

Posts

Joined
Tue Nov 14, 2017 1:07 am

Post by thekrotek » Tue Jan 09, 2018 2:07 pm

You can sort the resulting array of cart products with this:

Code: Select all

array_multisort(array_column($products, 'price'), SORT_ASC, $products);

Professional OpenCart extensions, support and custom work.
Contact me via email or Skype by support@thekrotek.com


User avatar
Active Member

Posts

Joined
Sun Jul 03, 2016 12:24 am


Post by karinar0 » Tue Jan 09, 2018 10:38 pm

I'm still not able to sort, I tried to add the line you provided at the end of file cart.php and it's not working. Could you please advise me where to add them?

Newbie

Posts

Joined
Tue Nov 14, 2017 1:07 am

Post by webcorvo » Sat Jan 13, 2018 8:22 am

Hi,
Edit file cart.tpl in catalog/view/theme/default/template/checkout/cart.tpl

Find :

Code: Select all

<?php foreach ($products as $product) { ?>  
And before add:

Code: Select all

array_multisort(array_column($products, 'name'), SORT_ASC, $products);
Should stay like this:

Code: Select all

<?php 
array_multisort(array_column($products, 'name'), SORT_ASC, $products);
foreach ($products as $product) { ?>

Opencart Developer - For custom work and support contact @ webcorvo@gmail.com


User avatar
Active Member

Posts

Joined
Mon Mar 20, 2017 11:42 pm
Location - Lisbon, Portugal

Post by karinar0 » Tue Jan 16, 2018 12:53 am

Perfeito! Agora funcionou! Mto obrigada!

Newbie

Posts

Joined
Tue Nov 14, 2017 1:07 am

Post by karinar0 » Wed Jan 31, 2018 12:07 am

Worked perfectly!

@webcorvo do you know how to do the same on order_shiping.tpl ?

Newbie

Posts

Joined
Tue Nov 14, 2017 1:07 am

Post by karinar0 » Wed Jan 31, 2018 12:40 am

Got the solution

Code: Select all

array_multisort(array_column($order['product'], 'name'), SORT_ASC, $order['product']);
        foreach ($order['product'] as $product) { ?> 
Thx!

Newbie

Posts

Joined
Tue Nov 14, 2017 1:07 am
Who is online

Users browsing this forum: No registered users and 17 guests