I am trying to override the following block but it isn't working for me


Here's my config file under app/etc/modules

<?xml version="1.0"?>

And my module's config file

<?xml version="1.0"?>

And the local php class is located under magento/app/code/local/MF/Adminhtml/Block/Catalog/Product/Edit/Tab/Alerts/Stock.php and looks like this

class MF_Adminhtml_Block_Catalog_Product_Edit_Tab_Alerts_Stock extends Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Alerts_Stock
    protected function _prepareCollection()
        $productId = $this->getRequest()->getParam('id');
        $websiteId = 0;
        if ($store = $this->getRequest()->getParam('store')) {
            $websiteId = Mage::app()->getStore($store)->getWebsiteId();
        if (Mage::helper('catalog')->isModuleEnabled('MF_ProductAlert')) {
            $collection = Mage::getModel('mf_productalert/stock')
                ->join($productId, $websiteId);
        return parent::_prepareCollection();

Magento is still using the core block instead of the local one. Anyone got any ideas?

closed as off-topic by Fabian Schmengler, brentwpeterson, Raphael at Digital Pianism, Rakesh Jesadiya, Amit Bera Sep 23 '16 at 8:00

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions describing a problem that can't be reproduced OR seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." – Fabian Schmengler, brentwpeterson, Raphael at Digital Pianism, Rakesh Jesadiya, Amit Bera
If this question can be reworded to fit the rules in the help center, please edit the question.

  • I cannot spot any mistake. Did you clear the cache? How do you know the block is not used? – Fabian Schmengler Sep 22 '16 at 15:30
  • Cleared the cache multiple times. I put a breakpoint on the prepareCollection function on the local block and the core block and the core block is the one being called – jrmf Sep 22 '16 at 15:31

The problem in your case is that you call parent::_prepareCollection(); in your code.

Thus the original method from the core is being called and thus overrides your changes.

This is a common mistake when dealing with grid block overrides.

Try to replace that line with Mage_Adminhtml_Block_Widget_Grid::_prepareCollection(); instead

  • I've replaced that line but it doesn't even get to the local function to get to the parent call, must be something else. – jrmf Sep 22 '16 at 15:42
  • @jrmf is your module enabled ? Do you see an corresponding entry in core_resource ? – Raphael at Digital Pianism Sep 22 '16 at 15:43
  • 1
    Nope, problem was that I forgot to add .xml to my file under app/etc/modules – jrmf Sep 22 '16 at 15:49

Not the answer you're looking for? Browse other questions tagged or ask your own question.