Back to Top

Opencart : Extend Core Classes

Updated 19 August 2013

factory

 

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

Searching for an experienced
Opencart Company ?
Find out More

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 🙂

 

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

Back to Top

Message Sent!

If you have more details or questions, you can reply to the received confirmation email.

Back to Home