Skip to content

Instantly share code, notes, and snippets.

@weismannweb
Last active February 28, 2021 00:08
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save weismannweb/8add8fab5be99854db5c618d751281b2 to your computer and use it in GitHub Desktop.
Save weismannweb/8add8fab5be99854db5c618d751281b2 to your computer and use it in GitHub Desktop.
Caches category data for Opencart 3.0 to make it faster. Opencart installs with alot of categories are really slow. http://forum.opencart.com/viewtopic.php?f=161&t=126241
<modification>
<id>Cache category data to speed up page load for store with many categories and sub categories.</id>
<version>1.0.1</version>
<vqmver>2.3.2</vqmver>
<author>Weismann Web - www.weismannweb.com</author>
<file name="catalog/controller/extension/module/category.php">
<operation>
<search position="after"><![CDATA[
foreach ($categories as $category) {
]]></search>
<add><![CDATA[
$category_data = $this->cache->get('vqmod_category_data_controller_module_category_'.$data['category_id'].'_'.$this->config->get('config_store_id'));
if ($category_data) {
$data['categories'] = $category_data;
break;
}
]]></add>
</operation>
<operation>
<search position="replace"><![CDATA[
return $this->load->view('extension/module/category', $data);
]]></search>
<add><![CDATA[
if (empty($category_data)) {
$this->cache->set('vqmod_category_data_controller_module_category_'.$data['category_id'].'_'.$this->config->get('config_store_id'), $data['categories']);
}
return $this->load->view('extension/module/category', $data);
]]></add>
</operation>
</file>
<file name="catalog/controller/common/menu.php">
<operation>
<search position="after"><![CDATA[
foreach ($categories as $category) {
]]></search>
<add><![CDATA[
$category_data = $this->cache->get('vqmod_category_data_controller_common_header'.$this->config->get('config_store_id'));
if ($category_data) {
$data['categories'] = $category_data;
break;
}
]]></add>
</operation>
<operation>
<search position="replace"><![CDATA[
return $this->load->view('common/menu', $data);
]]></search>
<add><![CDATA[
if (empty($category_data)) {
$this->cache->set('vqmod_category_data_controller_common_header'.$this->config->get('config_store_id'), $data['categories']);
}
return $this->load->view('common/menu', $data);
]]></add>
</operation>
</file>
</modification>
@hpapagaj
Copy link

Is there any similar exists for OC 1.5?

@mckrahman
Copy link

I have around 47000 products in my store and is too slow when load each category.
I disabled category count, still it is same.

I am using OC 3.0.3.3 and where can I use the code cache_category_data.xml please

@weismannweb
Copy link
Author

weismannweb commented Feb 28, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment