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.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


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
Expert 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

Post by erwtje » Sun Mar 31, 2019 7:31 am

To sort the items based on SKU on the dispatch note / packing slip, I modified the following code in admin/view/template/sale/order_shipping.tpl

Code: Select all

<?php foreach ($orders as $order) { ?>
  <div style="page-break-after: always;">
    <h1><?php echo $text_picklist; ?> #<?php echo $order['order_id']; ?></h1>
    <?php array_multisort(array_column($order['product'], 'sku'), SORT_ASC, $order['product']); ?> <!-- this line is added -->
Thanks for getting me started!

Newbie

Posts

Joined
Sun Mar 31, 2019 6:08 am

Post by scentswatch » Fri Jul 05, 2019 6:45 pm

webcorvo wrote:
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) { ?>
I tried using this solution to my cart and it worked perfectly. But why is it when I use the same in my Order Invoice, I get an error: Call to undefined function array_column() ???

Newbie

Posts

Joined
Fri Jul 05, 2019 6:35 pm

Post by OSWorX » Fri Jul 05, 2019 10:50 pm

scentswatch wrote:
Fri Jul 05, 2019 6:45 pm
I tried using this solution to my cart and it worked perfectly. But why is it when I use the same in my Order Invoice, I get an error: Call to undefined function array_column() ???
1. which OpenCart is used
2. which template is used
3. do we know what your your Order Invoice is

Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.


User avatar
Guru Member

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria
Who is online

Users browsing this forum: dcortex and 413 guests