The list of files required for the Overriding model through a new module:
app/etc/modules/Magemonkeys_Catalog.xml
app/code/local/Magemonkeys/Catalog/etc/config.xml
app/code/local/Magemonkeys/Catalog/Model/Category.php
Creating Files and Folders: Custom Module
What we need to do is to create a module file.
Make a file – “app/etc/modules/Magemonkeys_Catalog.xml”
Then, add the below code inside the file
1 2 3 4 5 6 7 8 9 |
<?xml version="1.0"?> <config> <modules> <Magemonkeys_Catalog> <active>true</active> <codePool>local</codePool> </Magemonkeys_Catalog> </modules> </config> |
Now create “app/code/local/Magemonkeys/Catalog/etc/config.xml” and add the below code inside the file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<?xml version="1.0"?> <config> <modules> <Magemonkeys_Catalog> <version>1.0</version> </Magemonkeys_Catalog> </modules> <global> <models> <catalog> <rewrite> <category>Magemonkeys_Catalog_Model_Category</category> </rewrite> </catalog> </models> </global> </config> |
We have defined a module version using the <version> tag. After that, the <catalog> & <rewrite> tags are used to override a “model” of the “Catalog” core module.
The final step will be to define a model class Magemonkeys_Catalog_Model_Category.
Make a model file “app/code/local/Magemonkeys/Catalog/Model/Category.php” and paste the following code inside it:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<?php class Magemonkeys_Catalog_Model_Category extends Mage_Catalog_Model_Category { public function getProductCollection() { // Put your custom code here! $collection = Mage::getResourceModel('catalog/product_collection') ->setStoreId($this->getStoreId()) ->addCategoryFilter($this); return $collection; } } ?> |
That’s it.
Please follow the below methods to get the attribute options...
Update product attribute value programmatically in Magento 2 . [crayon-628777b8eb2ae404990600/]...
If you want restrict customer to checkout based on your...
Sometime we need to set html data without load or...
If you want get query string params in controller file,...