Post by bonyta2442 » Sat Dec 29, 2018 7:33 pm

Hi all. OC 2.0.1.1
I have totalProduct count activated because I need it for other mod. So to speed up loading I have cached the totalProducts results like this:

Code: Select all

$cacheid='product.gettotalproducts.'.md5($sql); 
$total=$this->cache->get($cacheid);
if ($total === false ) {
       $query = $this->db->query($sql);
       $total = $query->row['total'];
       $this->cache->set($cacheid,$total);
}
Now I have slow YMM Filter results loading.
Can Someone help how to cache also this results?

Code: Select all

protected $ymm_cache;
	protected $ymm_where;

	public function __construct($registry) 
	{
		parent::__construct($registry);
		$this->ymm_cache = $this->setYmmCache();
		$this->ymm_where = $this->setYmmWhere();
	}

	private function setYmmCache()
	{
		$ymm_cache = '';
		if(isset($this->session->data['ymm'])){
			$ymm_cache .= '.' . (int)$this->session->data['ymm']['make'];
			if(!empty($this->session->data['ymm']['model'])){
				$ymm_cache .= '.' . (int)$this->session->data['ymm']['model'];
			}
			if(!empty($this->session->data['ymm']['engine'])){
				$ymm_cache .= '.' . (int)$this->session->data['ymm']['engine'];
			}
			if(!empty($this->session->data['ymm']['year'])){
				$ymm_cache .= '.' . (int)$this->session->data['ymm']['year'];
			}
		}

		return $ymm_cache;
	}

	private function setYmmWhere()
	{
		$ymm_where = '';
		if(isset($this->session->data['ymm'])){
			$ymm_where .= "(p.product_id IN (SELECT p2y.product_id FROM " . DB_PREFIX . "product_to_ymm p2y WHERE p2y.make_id = '" . $this->session->data['ymm']['make'] . "'";
			if(!empty($this->session->data['ymm']['model'])){
				$ymm_where .= " AND p2y.model_id = '" . $this->session->data['ymm']['model'] . "'";
			}
			if(!empty($this->session->data['ymm']['engine'])){
				$ymm_where .= " AND p2y.engine_id = '" . $this->session->data['ymm']['engine'] . "'";
			}
			if(!empty($this->session->data['ymm']['year'])){
				$ymm_where .= " AND p2y.begin_year <= '" . $this->session->data['ymm']['year'] . "' AND p2y.end_year >= '" . $this->session->data['ymm']['year'] . "'";
			}
			$ymm_where .= ")";
			if(($this->config->get('ymmfilter_search_universal') == '1') || (isset($this->request->get['route']) && $this->request->get['route'] != 'product/search')) {
				$ymm_where .= " OR p.product_id IN (SELECT p2.product_id FROM " . DB_PREFIX . "product p2 WHERE p2.universal = '1')";
			}
			$ymm_where .= ") AND ";

		}

		return $ymm_where;
	}
	
	
	public function updateViewed($product_id) {
		$this->db->query("UPDATE " . DB_PREFIX . "product SET viewed = (viewed + 1) WHERE product_id = '" . (int)$product_id . "'");
	}

https://www.dbkdimitrov.com
https://www.tuningcenterbg.com
https://www.samozamen.com
https://www.h-r.bg


Newbie

Posts

Joined
Sun Aug 19, 2018 12:30 pm


Post by straightlight » Sun Dec 30, 2018 12:07 am

Contact the extension developer of the original extension to resolved the issue.

The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.


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 8 guests