Your shopping cart is empty!
This package provides a replacement system engine for OpenCart. It uses the same MVC architecture as the standard OpenCart framework.
All instances of controller, model, and most of the library classes are created by a special factory class.
An additional override feature is supported. This allows 3rd party addons to do changes to the OpenCart core classes, templates, and language files. Core controller, model and library classes can be extended and their methods be overridden in a normal object oriented programming manner.
Installation
Frequently Asked Questions
All overrides go into a new directory named 'system/library/override'. It uses the following directory structure, only files which are to be modified in the OpenCart core are needed.
- system/library/override - <addon-1> - admin - controller + ... - language + ... - model + ... - catalog - controller + ... - language + ... - model + ... - system - library + ... + <addon-2> ... + <addon-n> ...
Sure, why not:
For example, if addon-x needs a new field named myfield on the frontend product page, it typically needs to modify the following core class files:
catalog/controller/product/product.phpcatalog/language/en-gb/product/product.phpcatalog/model/catalog/product.php
We therefore define the following override files (extended classes):
system/library/override/addon-x/catalog/controller/product/product.phpsystem/library/override/addon-x/catalog/language/en-gb/product/product.phpsystem/library/override/addon-x/catalog/model/catalog/product.php
Assuming the database has a new field named 'myfield' in the 'product' table, then the extended controller may look something like this:
<?phpclass addon_x_ControllerProductProduct extends ControllerProductProduct { /* overridden method, this newly introduced function is always called before the final rendering */ public function preRender( $template_buffer, $template_name, &$data ) { if ($template_name != $this->config->get('config_template').'/template/product/product.tpl') { return parent::preRender( $template_buffer, $template_name, $data ); } // add new controller variables if (isset($this->request->get['product_id'])) { $product_id = $this->request->get['product_id']; $this->load->model( 'catalog/product' ); $product = $this->model_catalog_product->getProduct($product_id); $data['myfield'] = $product['myfield']; $this->load->language( 'product/product' ); $data['text_myfield'] = $this->language->get( 'text_myfield' ); } else { $this->data['myfield'] = ''; $this->data['text_myfield'] = ''; } // modify template file $template_buffer = str_replace( '<?php echo $description; ?>', '<?php echo $description; ?><br /><?php echo $text_myfield; ?>:<?php echo $myfield; ?>', $template_buffer ); // call parent method return parent::preRender( $template_buffer, $template_name, $data ); }}?>
The model extension looks something like this:
<?phpclass addon_x_ModelCatalogProduct extends ModelCatalogProduct { /* override method */ public function getProduct($product_id) { $product = parent::getProduct( $product_id ); if ($product) { $sql = "SELECT myfield FROM `".DB_PREFIX."product` "; $sql .= "WHERE product_id='".(int)$product_id."'"; $result = $this->db->query($sql); $product['myfield'] = $result->row['myfield']; } else { $product['myfield'] = ''; } return $product; }}?>
<?php// new texts$_['text_myvar'] = 'This is the new field:';?>
You sure can!
However, in most cases you'd want to use your own web theme rather than OpenCart's 'default' theme. And if you use your own web theme, you can simply add any new fields directly into the template file of your new theme. This way, only the corresponding controller class needs to be extended with overridden methods which can populate your new variables for your template.
In case you think you have to modify a core OpenCart template file, you can extend the controller class and override a method called preRender, as in the previous example.
Method preRender is a newly added core controller function which is always called just before rendering a template. Always be nice and call the parent method, too!
Absolutely!
As part of the new OpenCart core engine, a special factory class is used for loading (possibly extended) classes. The nature of external addons is that they are not aware of each other. Each addon may extend and override the same OpenCart core class and method. However, if 2 or more addons do this, the new OpenCart factory loads the original core class and all extended classes and then modifies the parent class of each addon's extended class, so they all end up in a chain of class extensions. For example, if the addons addon_1, addon_2 and addon_3 all extend the same core class ControllerProductProduct, their original class definitions
class addon_1_ControllerProductProduct extends ControllerProductProduct { ....}
class addon_2_ControllerProductProduct extends ControllerProductProduct { ....}
class addon_3_ControllerProductProduct extends ControllerProductProduct { ....}
are automatically modified by the Override Engine so as to become a chain of class extensions, before loading them:
class addon_2_ControllerProductProduct extends addon_1_ControllerProductProduct { ....}
class addon_3_ControllerProductProduct extends addon_2_ControllerProductProduct { ....}
All classes modified this way are loaded, and then a new instance of 'addon_3_ControllerProductProduct' is created. Every overridden method in an extended class always has to call the parent method, otherwise the chain gets broken! But other than that, there are no restrictions.
Yes, they are.
The Override Engine can co-exist with OpenCart's XML-based dynamic source code modifications like OCmod and VQmod.
And the Override Engine can even be used to modify Event handlers, or simply co-exist with Event handlers.
This is actually a newly introduced hook function.
Any controller class can be extended and method preRender can then be overridden. Method preRender is called just before the selected template is rendered. You can do 3 things in here:
Further help and customized versions
This addon has been successfully tested for the standard OpenCart versions 3.x. Don't use other Opencart versions with it.
If you need a customized version of this addon, let us know and we can create one for a charge.
For support and technical enquiries please use our regular Contact Us page. This is for Reviews only!
0 reviews / Write a review
£0.00