Post by glolar » Thu Oct 10, 2019 6:40 am

Hello,

By default, products in the cart seem to be sorted by date added (The date_added field in the product table). I need the products in the cart to be sorted by model (the model field in the product table).

For the life of me, I cannot find the code that is setting the default to "date_added". If someone has the solution to this, it would be greatly appreciated!

Larry
Last edited by glolar on Fri Feb 04, 2022 6:19 am, edited 1 time in total.

Increase Your Child's I.Q.
iPad Wallpapers
Turtle & Tortoise Screen Savers


User avatar
Active Member

Posts

Joined
Thu Jul 29, 2010 12:35 pm
Location - San Diego, CA

Post by thekrotek » Thu Oct 10, 2019 2:20 pm

Try to add this before "return $product_data;" in getProducts() function of system/library/cart/cart.php file:

usort($product_data, function ($a, $b) { return strcmp($a['model'], $b['model']); });

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 glolar » Fri Oct 11, 2019 12:55 am

thekrotek, that seems to have solved the issue.

I was trying to add changes to /store/catalog/controller/checkout/cart.php, and not the cart.php in /store/system/library/cart.

Cannot thank you enough!

Increase Your Child's I.Q.
iPad Wallpapers
Turtle & Tortoise Screen Savers


User avatar
Active Member

Posts

Joined
Thu Jul 29, 2010 12:35 pm
Location - San Diego, CA

Post by glolar » Fri Oct 11, 2019 1:05 am

thekrotek,

Since you have been so helpful here, (and many times in the past), could I ask you a quick question? Do you know what determines which products are in the "Bestsellers" list ... Is it the products that have sold the most quantity, or is it based on total dollar amount sold for each product? I would like to look at the code that determines this, so if you know which file to look in, that would be extremely helpful.

Thanks again, thekrotek!

Larry

Increase Your Child's I.Q.
iPad Wallpapers
Turtle & Tortoise Screen Savers


User avatar
Active Member

Posts

Joined
Thu Jul 29, 2010 12:35 pm
Location - San Diego, CA

Post by thekrotek » Fri Oct 11, 2019 4:41 am

The first one - most purchased. The total sum of all product quantities from all orders with this product.

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 glolar » Fri Oct 11, 2019 4:45 am

thekrotek,

Yeah, I found the code with the query to fetch the bestsellers. I modified it to only include products ordered in the last 120 days.

Thanks again for all the help!

Larry

Increase Your Child's I.Q.
iPad Wallpapers
Turtle & Tortoise Screen Savers


User avatar
Active Member

Posts

Joined
Thu Jul 29, 2010 12:35 pm
Location - San Diego, CA

Post by dansjigs » Sat Apr 18, 2020 1:48 am

glolar wrote:
Fri Oct 11, 2019 4:45 am
thekrotek,

Yeah, I found the code with the query to fetch the bestsellers. I modified it to only include products ordered in the last 120 days.

Thanks again for all the help!

Larry
Larry,

Is this something you are willing to share. Also would be interested in limiting to certain product groups.

Thanks, Dan

New member

Posts

Joined
Sat Jun 24, 2017 7:56 am

Post by glolar » Fri Feb 04, 2022 6:17 am

dansjigs wrote:
Sat Apr 18, 2020 1:48 am
glolar wrote:
Fri Oct 11, 2019 4:45 am
thekrotek,

Yeah, I found the code with the query to fetch the bestsellers. I modified it to only include products ordered in the last 120 days.

Thanks again for all the help!

Larry
Larry,

Is this something you are willing to share. Also would be interested in limiting to certain product groups.

Thanks, Dan
Dan, so sorry ... I am only seeing your question two years later! Here is what I did:

In file store/catalog/model/catalog/product.php

Change this:

Code: Select all

$query = $this->db->query("SELECT op.product_id, SUM(op.quantity) AS total FROM " . DB_PREFIX . "order_product op LEFT JOIN `" . DB_PREFIX . "order` o ON (op.order_id = o.order_id) LEFT JOIN `" . DB_PREFIX . "product` p ON (op.product_id = p.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) WHERE o.order_status_id > '0' AND p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' GROUP BY op.product_id ORDER BY total DESC LIMIT " . (int)$limit);
to this:

Code: Select all

$query = $this->db->query("SELECT op.product_id, SUM(op.quantity) AS total FROM " . DB_PREFIX . "order_product op LEFT JOIN `" . DB_PREFIX . "order` o ON (op.order_id = o.order_id) LEFT JOIN `" . DB_PREFIX . "product` p ON (op.product_id = p.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) WHERE o.order_status_id > '0' AND p.status = '1' AND p.date_available <= NOW() AND o.date_added >= date(NOW() - interval 120 day) AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' GROUP BY op.product_id ORDER BY total DESC LIMIT " . (int)$limit);
I added:

Code: Select all

AND o.date_added >= date(NOW() - interval 120 day)
to restrict products added to bestsellers list to only those products sold in the last 120 days. Change the 120 to whatever you need. I previously made this to the code for version 3.0.2.0 of OpenCart. I just now made this change for OpenCart version 3.0.3.8.

Sorry again that I am just seeing your question.

User avatar
Active Member

Posts

Joined
Thu Jul 29, 2010 12:35 pm
Location - San Diego, CA
Who is online

Users browsing this forum: moreduff and 265 guests