Thursday , March 30 2017
Home >> All tutorial >> Magento Developers’ Guide – Part 9: Rewrite to modify a Magento Model

Magento Developers’ Guide – Part 9: Rewrite to modify a Magento Model

Today we will extend a Model, this may be useful sometimes so you need to know how to do it. This can be useful for exemple, if you want to change the method getName() of a customer.

1. How to rewrite a model?

Let’s start from the plugin MyProduct you have made in the previous tutorials and extend it model.

  1. class Pfay_MonProduit_Model_Customer  extends Mage_Customer_Model_Customer
  2. {
  3.   public function getName()
  4.   {
  5.      $name = ;
  6.         if ($this->getPrefix()) {
  7.             $name .= $this->getPrefix() . ‘ ‘;
  8.         }
  9.         $name .= $this->getFirstname();
  10.         if ($this->getMiddlename()) {
  11.             $name .= ‘ ‘ . $this->getMiddlename();
  12.         }
  13.         $name .=  ‘ ‘ . $this->getLastname();
  14.         if ($this->getSuffix()) {
  15.             $name .= ‘ ‘ . $this->getSuffix();
  16.         }
  17.         return $name.‘22222222’;
  18.   }
  19. }
Then the same principle, edit config.xml and add :
  1. <models>
  2.   <customer>
  3.     <rewrite>
  4.       <product> Pfay_MonProduit_Model_Customer</product>
  5.     </rewrite>
  6.   </customer>
  7. </models>
Hope it helpful for you!
Tutorial by: pierrefay.com

Ready to foster your knowledge with MAGENTO 2 BASIC GUIDE

The new Order Success combo with Magento 2 Inventory Management, Magento 2 Order Fulfillment, Magento 2 Dropship, Magento 2 Barcode Management and Magento 2 Purchase Management

magento website development services


About Champ

Leave a Reply

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