Post by daveydave » Wed Aug 03, 2022 8:07 pm

Hello there!

I'm running OpenCart 3.0.2.0

I need to change the order on the email confirmation (and in the cart, I was presume) to the order in which items were added to the cart.

I found this thread:

viewtopic.php?t=214245 where TheKrotek suggests this to change the order to the model no:
Try to add this before "return $product_data;" in getProducts() function of system/library/cart/cart.php file:

Code: Select all

usort($product_data, function ($a, $b) { return strcmp($a['model'], $b['model']); });
but I'm not even sure if OpenCart keeps the order that items were added to the cart or how it expresses it.

Is this possibe?
Last edited by daveydave on Wed Aug 10, 2022 3:03 pm, edited 1 time in total.

New member

Posts

Joined
Fri Aug 28, 2015 10:26 pm

Post by ADD Creative » Thu Aug 04, 2022 12:11 am

OpenCart does not store any order in the oc_order_product table. You could may be able, in getOrderProducts(), to sort by the order_product_id comum which auto increments. As long as they were inserted in the correct order, in addOrder(), they should then be selected in the same order.

www.add-creative.co.uk


Expert Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by daveydave » Fri Aug 05, 2022 3:08 pm

Thanks.

I'll give that a try and post the code here if I can get it working.

New member

Posts

Joined
Fri Aug 28, 2015 10:26 pm

Post by daveydave » Fri Aug 05, 2022 5:33 pm

I've modified the code in catalog/model/checkout/order.php as below

Code: Select all

		
		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_product WHERE order_id = '" . (int)$order_id . "'ORDER By order_product_id ASC"); 
It appears that the order_product_id field does not reflect the order that products were added to the cart.

Will keep looking. If anyone else has any suggestions that dont need me to make large modifications to how the cart works, I would welcome them!

New member

Posts

Joined
Fri Aug 28, 2015 10:26 pm

Post by ADD Creative » Fri Aug 05, 2022 11:09 pm

I would look at your oc_cart table in the database to check the products are in the correct order there. If so you could modify the system/library/cart/cart.php getProducts query to sort by cart_id or date_added.

www.add-creative.co.uk


Expert Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by daveydave » Tue Aug 09, 2022 5:03 pm

Thanks for that ADD Creative.

On line 35 in system/library/cart/cart.php , I changed the code from

Code: Select all

$cart_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "cart WHERE api_id = '" . (isset($this->session->data['api_id']) ? (int)$this->session->data['api_id'] : 0) . "' AND customer_id = '" . (int)$this->customer->getId() . "' AND session_id = '" . $this->db->escape($this->session->getId()) . "'");
to

Code: Select all

		$cart_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "cart WHERE api_id = '" . (isset($this->session->data['api_id']) ? (int)$this->session->data['api_id'] : 0) . "' AND customer_id = '" . (int)$this->customer->getId() . "' AND session_id = '" . $this->db->escape($this->session->getId()) . "' ORDER BY cart_id ");
Now we know the order products were added to the cart. This is useful for us as it helps us spot the effectiveness of our 'related products' and 'suggested products' at checkout.

Thanks!

New member

Posts

Joined
Fri Aug 28, 2015 10:26 pm
Who is online

Users browsing this forum: DesignCart and 102 guests