I need to run some SQL to clear some custom tables in Magento when a category is being deleted. With that in mind, I have been following the examples laid out here: Magento – Overriding core files
I have entered this into my config.xml:
<global>
<models>
<catalog>
<rewrite>
<category_api>MyCompany_MyModule_Model_Catalog_Category_Apis</category_api>
</rewrite>
</catalog>
</models>
</global>
I then created the file structure:
MyCompany
-> MyModule
-> Model
->Catalog
->Category
->Api.php
In Api.php file I have the following:
class MyCompany_MyModule_Model_Catalog_Category_Api extends Mage_Catalog_Model_Category_Api
{
public function delete($categoryId)
{
Mage::log('I have overidden deletion of: ' . $categoryId);
return true;
}
}
I am getting nothing come out in the system.log when using this setup so I assume I am doing something wrong.
EDIT:
Changing my XML to <category> </category> seems to make it include my files as I now get an error:
Fatal error: Call to a member function setStoreId() on a non-object in C:\xampp\htdocs\magento\app\code\core\Mage\Adminhtml\controllers\Catalog\CategoryController.php on line 52
Do I need to do something special when overriding the class?
Would it not better to create an observer to catch the event
catalog_category_delete_after. Using events is preferred to function overrides and is more flexible too. Since your delete procedure does not alter catalog_category deletion but adds more functionality to it, using events seems to be a better option