Post by Keejos » Tue Jan 10, 2017 3:55 am

Hi,

Tried to search for help on this but couldn't find it, forgive me if its been asked before.
I'm looking for a way to let the shopping cart display the items sorted by item name (A-Z).

I run a photography webshop, where clients get to choose from in between 50-100 different pictures after a shoot. Right now it sorts by 'date+time added', instead of by item name. As a result, shopping cart looks like:

Photo_001
Photo_016
Photo_003
Photo_008
Photo_002

Would it at ALL be possible to change this to sort by name? Ideally I would like to have clients be able to pick their own type of sort order as they please (by clicking column names), but for now let's focus on getting the items in shopping cart sorted A-Z by item name.

Thank you so so much!

Newbie

Posts

Joined
Sun Jan 08, 2017 5:55 am


Post by opencartmart » Tue Jan 10, 2017 8:20 pm

What is your OC version exactly?

XForm - Opencart Form Builder

Xshippingpro - An advanced Shipping Module


Active Member

Posts

Joined
Wed Oct 02, 2013 3:59 am
Location - Dhaka, Bangladesh


Post by Keejos » Thu Jan 12, 2017 4:54 am

It's 2.3.0.2 :)

Newbie

Posts

Joined
Sun Jan 08, 2017 5:55 am

Post by opencartmart » Thu Jan 12, 2017 9:45 pm

In the file system/library/cart/cart.php, find the function getProducts() and add following lines of code just before the last line i.e. return $product_data;

Code: Select all

              $name_order = array();
		foreach ($product_data as $key => $value) {
			$name_order[$key] = $value['name'];
		}
	    $name_order = array_map('strtolower', $name_order);
	    array_multisort($name_order, SORT_ASC, $product_data);

XForm - Opencart Form Builder

Xshippingpro - An advanced Shipping Module


Active Member

Posts

Joined
Wed Oct 02, 2013 3:59 am
Location - Dhaka, Bangladesh
Who is online

Users browsing this forum: Google [Bot] and 28 guests