Opencart : Extend Core Classes using factory Design Pattern – if you are writing modules in opencart over riding of the classes are really pain in the ass . unlike magento opencart does not support observers designer pattern so every time you need to replace opencart core files thats is really a bad module design practice . Fortunately there are two methods available for extending core classes
1 – VQMOD
2 – Override Engine
at webkul we are using override engine and its fairly easy to use and no uses of xmls like in vqmod .
Example – suppose that you want a custom sql query in your catalog model catalog/model/account/customer.php file like this
$this->db->query("UPDATE " . DB_PREFIX . "customer SET address_id = '" . (int)$address_id . "
', newfield = 1 WHERE customer_id = '" . (int)$customer_id . "'");
Then by using override engine it can easily achievable
<?php
class myaddon_ModelAccountCustomer extends ModelAccountCustomer {
public function addCustomer($data) {
parent::addCustomer($data);
// also add the newfield to the customer record
$sql = "UPDATE `".DB_PREFIX."customer` SET newfield = '".$data['newfield']."' ";
$sql .= "WHERE email = '".$data['email']."'";
$this->db->query( $sql );
}
}
....
?>
and many more . enjoy the Php factory design pattern 🙂


Be the first to comment.