Post by k2tec » Fri Jan 13, 2023 9:22 pm

In the old versions of opencart he sorted the moment of placing the product in the shopping cart. In version 3.x it sorts by id. How can I get this back in such a way that he will see the moment of putting the items in the shopping cart as the sorting order.
So not by model or product ID
Last edited by k2tec on Tue Jan 17, 2023 2:47 am, edited 2 times in total.

User avatar
Active Member

Posts

Joined
Mon Apr 12, 2010 8:06 pm

Post by thekrotek » Sun Jan 15, 2023 6:17 pm

It doesn't really sort it by anything. But you can add ORDER BY date_added to getProducts() function in system/library/cart/cart.php file.

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 k2tec » Sun Jan 15, 2023 8:34 pm

Hi thekrotek,
THanks for your reply. The order by date won't help I have read that post.
In all the old shops 1.4. and 2.0.1 the products are sort by putting them in to the basket. Maybe the sessions setting are different in the old shops.

User avatar
Active Member

Posts

Joined
Mon Apr 12, 2010 8:06 pm

Post by ADD Creative » Sun Jan 15, 2023 8:52 pm

OpenCart before 2.1 saved the cart in the session. For 2.1 and above the cart is stored in the database, so the order is defined by the database and the query. Why do you think adding ORDER BY date_added to the queries won't work?

www.add-creative.co.uk


Guru Member

Posts

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

Post by k2tec » Sun Jan 15, 2023 11:20 pm

Thanks for the reply, I will look at it tomorrow. But it is not the moment of ordering.
Suppose I want to assemble a chimney from 4 products and then I also order 10 parts for electricity. Now they all get mixed up and is a bit more complicated with orderpick with big orders

User avatar
Active Member

Posts

Joined
Mon Apr 12, 2010 8:06 pm

Post by paulfeakins » Mon Jan 16, 2023 6:18 pm

There might be a table you can sort by e.g. the ID of oc_cart.

UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk


User avatar
Guru Member
Online

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - London Gatwick, United Kingdom

Post by ADD Creative » Mon Jan 16, 2023 6:53 pm

Are you looking to change the order of the products in the cart or are you actually looking to change the order of the products on the order?

If it's the latter this may help.
viewtopic.php?f=202&p=846766

www.add-creative.co.uk


Guru Member

Posts

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

Post by k2tec » Mon Jan 16, 2023 10:29 pm

Thanks all for the replies. I tried this one

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 this

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 ");
Places everything beautiful in the cart and even in the checkout it is the right sorting, but in the written sales order in admin the sort order is not right any more.

User avatar
Active Member

Posts

Joined
Mon Apr 12, 2010 8:06 pm

Post by ADD Creative » Mon Jan 16, 2023 10:50 pm

Have a look in the oc_order_product table for an order made after you changed. Are the products in the correct order?

If they are you may be able, in getOrderProducts(), to sort by the order_product_id comum which auto increments.

www.add-creative.co.uk


Guru Member

Posts

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

Post by k2tec » Tue Jan 17, 2023 1:58 am

That did the job ADD Creative
Thanks all for your help.
This is what I changed in admin>model> sale>order.php

Code: Select all

public function getOrderProducts($order_id) {
		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_product WHERE order_id = '" . (int)$order_id . "'");

		return $query->rows;
	}
into

Code: Select all

public function getOrderProducts($order_id) {
		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_product WHERE order_id = '" . (int)$order_id . "' ORDER BY order_product_id");

		return $query->rows;
	}
In the system/library/cart/cart.php

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()) . "'");
into

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 ");
This makes it a lot easier for order picking

User avatar
Active Member

Posts

Joined
Mon Apr 12, 2010 8:06 pm
Who is online

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