LESS in OpenCart with LessEngine

What is LESS?

LESS stands short for Leaner CSS. LESS lets you write CSS in a more cheap football kits dynamic and functional manner, using variables and functions. When you write in LESS the code has to be transformed into CSS by a compiler. LESS is dynamic stylesheet language. You can read more about the LESS project and how to write in LESS here – http://lesscss.org/

What is LessEngine for OpenCart?

It is powered by a PHP compiler for LESS, built into the module to make it easy for developers to write and compile code using their OpenCart installation. When writing your LESS files you only need to put them in a server directory of your choice and the module cheap football shirts will automatically compile the LESS code when you visit the website or when you compile on demand from the module settings. There is no need to compile files locally on your computer and then to upload the already compiled CSS to your server.

Why should I use it?
If you are an extension or theme developer for OpenCart and you cheap football tops write LESS, LessEngine is just the tool for you. It allows you to specify input and output directories for your LESS and CSS files, as well as cache directories and directories with imported files. By default, they point to your default OpenCart theme, however, if you are developing a new theme you can always change that. The module will cache LESS files based on their modified time, so no unnecessary compiles Cheap Barcelona football shirts are made. Also, you have the option to get error reporting, in case you have made a syntax error. If you employ a more complex LESS framework using imported files, these files will also be checked for modifications and the main file will be re-compiled, if changes are found. Neat options is also to minify the Cheap Manchester United football shirts output CSS and remove comments in the code.

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  |