Post by Seraph77 » Wed Nov 22, 2017 8:32 pm

Im trying to make the latest products display by date available instead of date added...replacing date added with 'ORDER BY p.date_available DESC LIMIT' but it's having no effect. Is that code wrong or do I need to change something else?

OC3.0.2.0

Code: Select all

	public function getLatestProducts($limit) {
		$product_data = $this->cache->get('product.latest.' . (int)$this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id') . '.' . $this->config->get('config_customer_group_id') . '.' . (int)$limit);

		if (!$product_data) {
			$query = $this->db->query("SELECT p.product_id FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) WHERE p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' ORDER BY p.date_added DESC LIMIT " . (int)$limit);

			foreach ($query->rows as $result) {
				$product_data[$result['product_id']] = $this->getProduct($result['product_id']);
			}

			$this->cache->set('product.latest.' . (int)$this->config->get('config_language_id') . '.' . (int)$this->config->get('config_store_id') . '.' . $this->config->get('config_customer_group_id') . '.' . (int)$limit, $product_data);
Last edited by Seraph77 on Thu Nov 23, 2017 5:47 pm, edited 1 time in total.

New member

Posts

Joined
Mon Aug 14, 2017 3:23 am

Post by straightlight » Wed Nov 22, 2017 9:20 pm

ORDER BY p.date_added
It mentions date_added in the query, not date_available.

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 Seraph77 » Wed Nov 22, 2017 9:28 pm

I replaced Date Added with 'ORDER BY p.date_available DESC LIMIT' but it had no effect. Cleared cache. Is there something else needed?

New member

Posts

Joined
Mon Aug 14, 2017 3:23 am

Post by straightlight » Wed Nov 22, 2017 9:51 pm

$query = $this->db->query("SELECT p.product_id FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) WHERE p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' ORDER BY p.date_added DESC LIMIT " . (int)$limit);
Where has this been replaced into?

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 Seraph77 » Wed Nov 22, 2017 10:14 pm

Like this:

Code: Select all

$query = $this->db->query("SELECT p.product_id FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (p.product_id = p2s.product_id) WHERE p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "'ORDER BY p.date_available DESC LIMIT " . (int)$limit);

New member

Posts

Joined
Mon Aug 14, 2017 3:23 am

Post by straightlight » Thu Nov 23, 2017 9:27 am

More like this:

Code: Select all

$query = $this->db->query("SELECT p.product_id FROM " . DB_PREFIX . "product p LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) LEFT JOIN " . DB_PREFIX . "product_to_store p2s ON (pd.product_id = p2s.product_id) WHERE p.status = '1' AND p.date_available <= NOW() AND p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY p.date_available DESC LIMIT " . (int)$limit);

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 Seraph77 » Thu Nov 23, 2017 5:44 pm

Thanks again Straightlight.
It's nice to have easier control over the latest list by simply changing the available date in the admin. That helps a lot. Cheers.

New member

Posts

Joined
Mon Aug 14, 2017 3:23 am
Who is online

Users browsing this forum: No registered users and 417 guests