Post by SXGuy » Mon Dec 04, 2017 8:32 pm

I need to arrange the data for the order_products table by product sort order.

So the table not only groups by order id, but each product id is arranged by product sort order also.

Whats the best way to do this?

Active Member

Posts

Joined
Sun Nov 08, 2009 2:07 am

Post by paulfeakins » Mon Dec 04, 2017 9:07 pm

Try this (assuming your table prefix is oc_):

Code: Select all

SELECT * FROM `oc_order_product` op 
LEFT JOIN `oc_product`p on p.product_id = op.product_id 
ORDER BY sort_order

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


User avatar
Guru Member

Posts

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

Post by SXGuy » Mon Dec 04, 2017 11:06 pm

Thanx. That would work to display in order however I wish to insert the sort_order to the table so I can pull the data by sort order in other extensions.

Active Member

Posts

Joined
Sun Nov 08, 2009 2:07 am

Post by straightlight » Mon Dec 04, 2017 11:13 pm

An array_multisort function would need to be applied for your request along with the added sort orders. Although, no OC version posted, no location in the platform where you'd like those appearing sort ordering list to show from your first post.

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 SXGuy » Mon Dec 04, 2017 11:36 pm

Version is 2.3.0.2.

In specific location to apply it to at this stage other than perhaps admin order details and invoices.
a rough idea would be enough for now.
Last edited by SXGuy on Mon Dec 04, 2017 11:42 pm, edited 1 time in total.

Active Member

Posts

Joined
Sun Nov 08, 2009 2:07 am

Post by straightlight » Mon Dec 04, 2017 11:42 pm

Is it by the database sort order you'd like to have it or by your own defined sort order like the modules already provides? As for the specific locations, please specify those locations since there are quite a few in Opencart.

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 SXGuy » Mon Dec 04, 2017 11:47 pm

Just by product sort order. The sort order you define in admin products.

I need the sort order info included in the order_product table when data is inserted.

Just a rough idea where to add the data in terms of which modal file and whether product sort order is available to add in that modal file of if it needs to be defined first.

Retrieving customers ordered products in order of Sort order is not really the issue since I'm sure I could just include order by sort_order in the sql query to anywhere that calls that data.

Active Member

Posts

Joined
Sun Nov 08, 2009 2:07 am

Post by straightlight » Mon Dec 04, 2017 11:51 pm

Just a rough idea where to add the data in terms of which modal file and whether product sort order is available to add in that modal file of if it needs to be defined first.
Any screenshots you could provide regarding the modal file you are referring about?

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 straightlight » Tue Dec 05, 2017 12:14 am

There's an extension that might provide what you need (if not, pretty close): https://www.opencart.com/index.php?rout ... n_id=14279 . Although, it would need to be compatible with your OC version.

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 SXGuy » Tue Dec 05, 2017 12:53 am

Guys, thanks for your help but ive found a work around.

For anyone thats insterested in system\library\cart\cart.php

I added ORDER BY p.sort_order to the end of

Code: Select all

$product_query = $this->db->query
This assigned the correct sort order to the cart for any product added, which in turn also adds each product to the order_product table in the correct order.

Since the order_prodct table assigns an order_prodct_id incrementally by each product, i was able to use this as a method of sorting the results.

So on for example the admin order view page, each product is displayed in the correct sort order by changing

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;
	}
and replacing with

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 ASC");

		return $query->rows;
	}
Same can be done for order invoices, etc etc.

Easiest solution all round i think.

Active Member

Posts

Joined
Sun Nov 08, 2009 2:07 am

Post by straightlight » Tue Dec 05, 2017 2:00 am

Well, when it's well-explained yes ... based on your first post until the last one, none was indicated that you'd want to address the cart library specifically nor anything about the cart itself ...

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 SXGuy » Tue Dec 05, 2017 3:07 pm

Unfortunately modifying the cart library was just a way of achieving what I wanted. I didn't discuss it because it wasn't something I thought I had to do to get what I wanted to work.

To be fair I did ask a simple question relating to the order_products table. Nothing else would have mattered.

Active Member

Posts

Joined
Sun Nov 08, 2009 2:07 am

Post by straightlight » Tue Dec 05, 2017 9:14 pm

To be fair I did ask a simple question relating to the order_products table. Nothing else would have mattered.
This simple question was incomplete since, again, there were no indication found elsewhere on the topic that your issue needed to affect the cart page but simply the order_products which I am sure you'll understand that this database table name not only reflects one location in the platform which is why you were asked previously on this topic for specific areas.

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
Who is online

Users browsing this forum: No registered users and 392 guests