Saturday, August 24, 2013

caching mechanism in opencart

Opencart caches the data at every page load. we have caching on currencies, languages, categories, products, category product counts, weight classes, tax classes, etc.

In front-end models, when fetching data from database, OpenCart looks for the cached data prior to querying the database. They are stored in plain text files using PHP's function serialize(). If system gets any cached data, they are fetched and unserialized and returned to the controller without querying the database.

Thus the fetching should be much quicker. If there are no cached data, then the database is queried and these data are then serialized using PHP's function serialize() and saved to the corresponding cache file.

Here is one small problem that may occur. After You have edited the data directly in the database, (using phpMyAdmin, may the reason be whatever for this) the change is not present at frontend. This is because, there are older data cached that are fetched when asked for them. If You have to do such editing, then do not forget to manually delete corresponding cache file(s).

The cache is instantiated and registered within index.php. it is then accessible in both controllers and models as $this->cache; while methods set(), get() and delete() are callable. The cache class itself could be found at system/library/cache.php and is quite simple and straight forward.

Now, in the administration (backend) part of models, when editing or adding data (category, product, currencies, weight classes, etc), after the data is successfully stored to the database the corresponding cache file is immediately deleted. So it could be re-created at frontend containing up-to-date data.

The cache files could be find at /system/cache/ folder.


See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Technical Support:

If you still face the technical problem, please get support of our highly skilled technical team: garazlab.com.


Wordpress Plugins:
  1. Real-Time Health Data from Every Where:WP plugin to display real-time health data & increase sale by promoting user specific products according to health information: garazlab.com.
  2. Woocommerce Stock Notification Builder:Sends desktop, mobile & email notifications with full customization.Build your own product notification system with it: garazlab.com.

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

view unpushed git commits

Git version control system is gained very much popularity in recent times. It is a distributed version control system. Today we will see about how to see our unpushed local git commits.

We have done some coding in our local work machine and we had committed those in several times in past few days. Now, we want to see what commits are still waiting to go to the remote repository.

We can get the commit with log comments using the comparison between master and HEAD.

git log origin/master..HEAD

You can also view the difference using the same syntax with the same comparison between master and HEAD.

git diff origin/master..HEAD


See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Technical Support:

If you still face the technical problem, please get support of our highly skilled technical team: garazlab.com.


Wordpress Plugins:
  1. Real-Time Health Data from Every Where:WP plugin to display real-time health data & increase sale by promoting user specific products according to health information: garazlab.com.
  2. Woocommerce Stock Notification Builder:Sends desktop, mobile & email notifications with full customization.Build your own product notification system with it: garazlab.com.

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

character count while copying from other document

we have strlen or mb_strlen to count normal strings or multibyte UTF-8 encoded strings. When we have HTML elements into our strings, then we need to remove the elements.

And if we want to copy rich content text from other websites, then we need to consider the white space characters. we need to replace newline, carriage return and tabs etc.

Here, we first strips the tags from content.
$description = trim(strip_tags(html_entity_decode($this->request->post['description'])));


Then we replace the carriage returns and newlines in the contents.

$description = str_replace("\r\n",'', $description);


Now, we will remove the tabs.

$description = str_replace("\t",'', $description);


Finally, we count our processed content.
echo mb_strlen($description);


See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Technical Support:

If you still face the technical problem, please get support of our highly skilled technical team: garazlab.com.


Wordpress Plugins:
  1. Real-Time Health Data from Every Where:WP plugin to display real-time health data & increase sale by promoting user specific products according to health information: garazlab.com.
  2. Woocommerce Stock Notification Builder:Sends desktop, mobile & email notifications with full customization.Build your own product notification system with it: garazlab.com.

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide

strip selected html tags

Using strip_tags we can remove HTML element from a string. But we want to remove selected tags from a string. we can use regular expression to implement this feature.

The below regular expression provide us a way to remove the selected HTML tags from the string.
preg_match_all('/<'.$tag.'[^>]*>(.*)<\/'.$tag.'>/iU', $text, $found)

Then we replace the matched pattern with the matched text string of preg_match_all. The PREG_PATTERN_ORDER returns the matched tag pattern in the first array and returns text pattern on the second pattern.
$text = str_replace($found[0],$found[1],$text);
The complete function becomes like this:
function strip_selected_tags($text, $tags = array())
    {        
        foreach ($tags as $tag){
            if(preg_match_all('/<'.$tag.'[^>]*>(.*)<\/'.$tag.'>/iU', $text, $found)){
                $text = str_replace($found[0],$found[1],$text);
          }
        }

        return $text;
    }
 

  echo htmlentities(strip_selected_tags('
Person:
Salavert', array('strong', 'div')));


See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide




List of my works:

Technical Support:

If you still face the technical problem, please get support of our highly skilled technical team: garazlab.com.


Wordpress Plugins:
  1. Real-Time Health Data from Every Where:WP plugin to display real-time health data & increase sale by promoting user specific products according to health information: garazlab.com.
  2. Woocommerce Stock Notification Builder:Sends desktop, mobile & email notifications with full customization.Build your own product notification system with it: garazlab.com.

Opencart Extensions:

  1. Product Based Quantity Wise Shipping: Find it here.
  2. OpenSSLCOMMERZ: integrate SSLCOMMERZ with opencart: Find it here.
  3. Fine Search v.1.0 - Improves Opencart search feature to find relevant: Find it here.
  4. Opensweetcaptcha - An easy way to generate attractive captcha for your system!: Find it here.
  5. Custom Field Product - add unlimited custom fields to the product form: Find it here.
  6. Formcaptcha - add captcha on the register page: Find it here.

My Books:

  1. OpenCart 1.4 Template Design Cookbook.
  2. Joomla Mobile Development Beginners Guide