How to install vQmod

Install vQmod in opencart :

If you have opencart version 2.0.0.0 or above, you don’t need to install vQmod. Opencart 2.0.0.0 or above already install vQmod ( exactly called OCMOD ).

It is for opencart 1.5.6.4 or below versions.

Here is the following steps to install vQmod.

  1. Download the latest version of vQmod form here. You have to download vQmod version with opencart. Standalone version is not compatible with opencart.
  2. Extract the archive and copy all files in the your OpenCart root directory. File structures of opencart root directory is given below.
    - admin
    - catalog
    - download
    - image
    - system
    - vqmod
    --- install
    --- vqcache
    --- log
    --- xml
  3. Give write access permission to following files:
    - index.php
    - admin/index.php
    And directories :
    vqmod/
    vqmod/logs/
    vqmod/vqcache/
  4. Openlink link in the browser : http://yourwebsite.com/vqmod/install

If you have done everything, you will see this message on browser : ‘VQMOD HAS BEEN INSTALLED ON YOUR SYSTEM!‘.

How to create vQmod file

vQmod

What is vQmod and why you need it you can read here.

For create vQmod file you need any simple text editor (better with the code highlighter). Create a file with “xml” extension, for example a2bizz_vqmod.xml. Here is a listing of this file:

<?xml version="1.0" encoding="UTF-8"?>
 
<modification>
 
  <!-- Modification id -->
  <id>My first fix</id>
 
  <!-- Modification version -->
  <version>1.0.0</version>
 
  <!-- vQmod version for this modification -->
  <vqmver>2.3.0</vqmver>
 
  <!-- The author of the modification -->
  <author><a href="mailto:blog.a2bizz@gmail.com">blog.a2bizz@gmail.com</a></author>
 
  <comment><![CDATA[
    Leave some comment here
  ]]></comment>
 
  <!-- File to change. Such files can be several in one xml file -->
  <file name="admin/model/catalog/product.php">
 
    <!-- Operation for one change. Such operations can be several for this file -->
    <operation>
 
      <!-- Exact place where you need to add your change. You can set position position for it (in our case "after") and the code between <![CDATA[...]]> It means that "after" this code you will add some your code. If you want to add your code before you need to set "before" position. You can also "replace" some code with your code. Important! The code to change must to be exactly like in the file. One space or tab more or less between words and vQmod will find nothing. -->
      <search position="after"><![CDATA[$product_id = $this->db->getLastId();]]></search>
 
      <!-- Here we write our code what we want to add after, before, or instead of the existing code -->
      <add><![CDATA[
$this->load->model('module/my_module');
$this->model_module_my_module->action($product_id);
      ]]></add>
    </operation>
  </file>
</modification>

As you can see above xml, it starts with the standard <?xml> tag declaration followed by a <modification>tag. Other tags include <version>,<id> , and <author>. You should not change <vqmver> as it indicates the vQmod version.

Work starts with the <file> tag. The name attribute indicates the file name that will be patched. It could be that you need multiple modifications to the same file. So that’s where the <operation> tag comes into play. Each modification will be wrapped by the <operation> tag. The info attribute allows you to add some useful message.

In this particular example, the <search> tag is used for the replace operation. You can use the position attribute to tell vQmod which operation will be performed. The content which is enclosed inside the <search> tag will be replaced with the content which is enclosed within the <add> tag.

As you may have noticed, the content for search and replace is enclosed within a CDATA tag, which means that the content won’t be interpreted as a markup but as character data.

Other options available for the position attribute:

  • before is used to insert the content before the search string.
  • after is used to insert the content after the search string.
  • top is used to insert the data at the top of the file. In this case, there’s no need for the <search> tag. Even if you’ve used it, it’ll be ignored.
  • bottom is used to insert the data at the bottom of the file. In this case, there’s no need for the <search> tag. Even if you’ve used it, it’ll be ignored.
  • In the case of ibefore, the data will be appended before the search data in the same line.
  • In the case of iafter, the data will be appended after the search data in the same line.

There are also a couple of optional attributes available for the <search> tag. Let’s have a quick look at these.

  • offset is an attribute designed to work in conjunction with the position attribute. So, for example, if position is set to before and offset is set to 3, it means that the content will be inserted before the three lines of the searched data.
  • index: Sometimes you want to replace only couple of instances of a particular string, not all the instances of that string in the search data. Say, for example, there are five instances of the $abc variable in your search data, but you only want to replace the first two instances of $abc with $def. In this case you need to specify index to 1,2.
  • The regex attribute is useful if you want to perform a regular expression based search for your operations. In that case, you’ll need to set regex to TRUE.

 

  • Download and extract the OpenCart-specific vQmod library.
  • Upload the vqmod directory to the root of your OpenCart installation.
  • Please make sure the vqcache directory that is under the vqmod directory is writable by the web server.
  • Visit http://www.mysite.com/vqmod/install and you should be presented with a success message. If that’s not the case, it’s likely a permissions issue.

vQmod (OCMod)

“vQmod” (Virtual Quick Mod) is an override system designed to avoid having to change core files. The concept is quite simple… Instead of making changes to the core files directly, the changes are created as xml search/replace script files. These script files are parsed during page load as each “source” core file is loaded with the “include” or “require” php functions. The source is then patched with the script file changes, and saved to a temp file. That temp file is then substituted for the original during execution. The original source file is never altered. This results in a “virtual” change to the core during execution without any actual modification to the core files

How it works ?

Instead of modifying actual files to add custom modifications, source files are parsed “on-the-fly” right before any of the follow functions are called :

  • include()
  • include_once()
  • require()
  • require_once()

The source is then cloned to a temp file and modifications read from an external script file are made to that temp file. The temp file is then substituted for the real file in the include path. Now the modification is in place while the original file has not actually been altered. Remove the script file and the original source is loaded.

vQmod class is currently written in PHP and script files are xml based, but the concept could be ported to any language and parse could be created for any format. Opencart is only fully tested and working platform that vQmod works with, but this is a concept that can work for other projects and platforms that are controller-based.

There are some files that cannot be used with vQmod :

  • index.php – this is the main file of the Opencart site, it has to load vQmod first for it to work on other pages. So you can’t put the cart in front of the horse.
  • Standalone files – Files that are just standalone and don’t extend or have no hierarchy will not work with vQmod. vQmod works by intercepting the “include” functions. So if file isn’t being included or required, then it cannot be vQmodded
  • css & js files – These files are rendered at the browser level, not at the server level, so vQmod has no effect on these. You can, however, create new files and use vQmod to alter the tpl files to point to these new css/js files. Or you can put.

 

Create a vqmod file from here

Upgrading modules from OpenCart 1.5.x to OpenCart 2.0.x

Opencart has released version opencart 2 and it is very Cheap Manchester United football shirts different from opencart 1.5+. Extensions build in 1.5 will not work on opencart 2.x.x  . You have to upgrade these extension for opencart version 2.x.x

Changes in opencart 2

Coding standards: As many CMS doesn’t use this PHP end tag ” ?> “ in the php file. Opencart 2 also not use the PHP end tag ” ?> “.

Bootstrap : Opencart 2 uses bootstrap 3.0 .

OCMOD instead of VQMOD : It is almost the same. It has similar syntax, but OCMOD is cheap football tops built in the OpenCart. OCMOD planned to be Cheap Barcelona football shirts more simple for reduce amount of the conflicts.

Controllers : Controller changes has been cheap football shirts given below.

1. Assigning template variables

OpenCart 1.5:

$this->data['foo'] = $foo;

OpenCart 2.0:

$data['foo'] = $foo;

2. Assigning a template

OpenCart 1.5:

$this->template = 'module/module.tpl';

OpenCart 2.0:

$this->response->setOutput($this->load->view('module/module', $data));

3. Adding child controllers

OpenCart 1.5:

$this->children = array(
  'common/header',
  'common/footer'
);

OpenCart 2.0 (you can load controllers now):

$data['header'] = $this->load->controller('common/header');
$data['column_left'] = $this->load->controller('common/column_left');
$data['footer'] = $this->load->controller('common/footer');

4. Redirect

OpenCart 1.5:

$this->redirect($this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL'));

OpenCart 2.0:

$this->response->redirect($this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL'));

5. Status field is mandatory for the module now:

if (isset($this->request->post['module_name_status'])) {
  $data['featured_status'] = $this->request->post['module_name_status'];
} else {
  $data['featured_status'] = $this->config->get('module_name_status');
}

Note : If during upgrade your modules you will find cheap football kits a new change not described here. I will add it in blog.

Opencart 2.x.x Event System Tutorial

Overview

OpenCart 2.x introduces a number of new features for the module developers and one of them is the event system. This is going to be a quick tutorial teaching you how to make use of it in your modules.

The concept is simple, yet very effective. It allows you to write code which will get executed when something interesting happens in OpenCart. Like when an order is made, or a customer is created without the need of using vQmod or OCMOD. By using the events system, you can avoid collisions which happen when you are using a modification system like vQmod or OCMOD. Additionally since you write the event handlers in PHP file, you get to enjoy proper code coloring/completion/linting from your editor/IDE.

Basics

Use of events involves only two steps:

  1. Register an event handler
  2. Implement the event handler

The event handlers are simply methods defined in controller files. You can use one file for all your methods or you can create separate controller for your event handlers. To register your event handlers you need to use the extension/event model (OpenCart 2.0.1+) or the tool/event model for OpenCart 2.0.0.0. The extension/event model has 2 methods: addEvent($code, $trigger, $action) and deleteEvent($code). As you can guess the addEvent() method is used to register event handlers and the deleteEvent() is used to unregister event handlers. It is a good practice to register your event handlers in the install() method of your module’s controller in the admin/ directory. It is also advised to unregister your event handlers when your module is being uninstalled, which can be done in the uninstall() method of the same controller file.

The $code argument is used to group your event handlers. It is a good idea to set this to the name of your module, much like you have named your main controller file.

The $trigger argument is the event name which you would like to set your handler to. A list of all available triggers can be found here: https://github.com/opencart/opencart/wiki/Events-(script-notifications).

The $action argument is the route to your handler function. It is written in the form of a standard route to a controller. For example module/a2bizz/on_user_created.

Example

Steps of implementing an event handler with simple code examples are given below.

The example assumes that we are working with OpenCart 2.0.1+. Now let’s assume that we are creating a module called “a2bizz”. The admin controller file for the module will be admin/controller/module/a2bizz.php. The catalog controller file for the module will be catalog/controller/module/a2bizz.php.

The module will achieve 2 simple tasks – send e-mail messages to the administrator when a store is deleted and upon a customer registration. The triggers that we are going to use are pre.admin.store.delete and post.customer.add.

First we will register our event handlers in the install() method of our module:

public function install() {
    $this->load->model('extension/event');
    $this->model_extension_event->addEvent('a2bizz', 'pre.admin.store.delete', 'module/mymodule/on_store_delete');
    $this->model_extension_event->addEvent('a2bizz', 'post.customer.add', 'module/mymodule/on_customer_add');
}

Uninstall process like this:

public function uninstall() {
    $this->load->model('extension/event');
    $this->model_extension_event->deleteEvent('a2bizz');
}

Next, we need to implement the event handlers. The pre.admin.store.delete event is emitted in the admin area, so its handler must be implemented in the admin controller file for our module. We would like our event handler method to notify the administrator that a store Cheap Manchester United football shirts has been deleted. Events starting with pre are emitted before the action is executed, and events starting with post are executed after the action has been taken. We would also like to include the store domain in our message, which is why we have chosen the “pre” event instead of the “post”. If we register for the post.admin.store.delete event, we will not be able to read the store’s domain.

Our event handler should look something like this:

public function on_store_delete($store_id) {
    $this->load->model('setting/store');
    $store_info = $this->model_setting_store->getStore($store_id);
    $admin_mail = $this->config->get('config_email');
    mail($admin_mail, "A store has been deleted", "The store " . $store_info['url'] . " was deleted.");
}

All that is left now is to implement the handler method for the post.customer.add event. We will do this in the catalog controller of our module. The method will notify the administrator when a new customer is registered. The method should look similar to this:

public function on_customer_add($customer_id) {
    $this->load->model('account/customer');
    $customer_info = $this->model_account_customer->getCustomer($customer_id);
    $admin_mail = $this->config->get('config_email');
    mail($admin_mail, "New Customer", "A new customer has just registered with the following e-mail: " . $customer_info['email']);
}

Note: We are using the mail() function for sending e-mails for simplicity. In a real module you need to use OpenCart’s Mail class for sending e-mails.

That’s it! Our module is ready to rock. The final cheap football shirts versions of our files is as follows:

admin/controller/module/a2bizz.php

<?php class ControllerModuleA2bizz extends Controller { public function install() { $this->load->model('extension/event');
        $this->model_extension_event->addEvent('a2bizz', 'pre.admin.store.delete', 'module/a2bizz/on_store_delete');
        $this->model_extension_event->addEvent('a2bizz', 'post.customer.add', 'module/a2bizz/on_customer_add');
    }
    
    public function uninstall() {
        $this->load->model('extension/event');
        $this->model_extension_event->deleteEvent('a2bizz');
    }
    
    public function on_store_delete($store_id) {
        $this->load->model('setting/store');
        $store_info = $this->model_setting_store->getStore($store_id);
        $admin_mail = $this->config->get('config_email');
        mail($admin_mail, "A store has been deleted", "The store " . $store_info['url'] . " was deleted.");
    }
}

catalog/controller/module/a2bizz.php

<?php class ControllerModuleA2bizz extends Controller { public function on_customer_add($customer_id) { $this->load->model('account/customer');
        $customer_info = $this->model_account_customer->getCustomer($customer_id);
        $admin_mail = $this->config->get('config_email');
        mail($admin_mail, "New Customer", "A new customer has just registered with the following e-mail: " . $customer_info['email']);
    }
}

Apart from the standard use, the event system can be used to create cross-module integrations. Using the Event object ($this->event), you can trigger any event at any point. You can use it to trigger your own events as well. Imagine that you cheap football kits are developing a module for customer comments. You can trigger events on a comment post, for example. This will allow other module developers to create handler methods for your events and execute code without the need of vQmod or OCMOD. This will ensure better system stability and better customer experience. You can also use the system to register and trigger your own cheap football tops events at runtime.

cheap Barcelona football shirts  |
cheap Real Madrid football shirts  |
cheap Manchester United football shirts  |
cheap England football shirts  |
cheap AC Milan football shirts  |
cheap Inter Milan football shirts  |
cheap Liverpool footbal lshirts  |
cheap France football shirts  |
cheap Juventus football shirts  |
cheap Celtic football shirts  |
cheap Celtic football shirts  |
cheap Italy football shirts  |
cheap Inter Milan football shirts  |
cheap Barcelona football shirts  |
cheap Chelsea football kits  |
cheap Arsenal football kits  |
cheap Liverpool football shirts  |
cheap Real Madrid football shirts  |
cheap Portugal football shirts  |
cheap Belgium football shirts  |
cheap Barcelona football shirts  |
cheap France football shirts  |
cheap Germany football shirts  |
cheap North Ireland football shirts  |
cheap Juventus football shirts  |
cheap AC Milan football shirts  |
cheap Manchester United football shirts  |
cheap Italy football shirts  |
cheap Manchester United football shirts  |
cheap Real Madrid football shirts  |
cheap Real Madrid football shirts  |
cheap Chelsea football shirts  |
cheap Germany football shirts  |