1

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

magento/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Alerts/Stock.php

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

<?xml version="1.0"?>
<config>
    <modules>
        <MF_Adminhtml>
            <active>true</active>
            <codePool>local</codePool>
        </MF_Adminhtml>
    </modules>
</config>

And my module's config file

<?xml version="1.0"?>
<config>
    <modules>
        <MF_Adminhtml>
            <version>0.0.1</version>
        </MF_Adminhtml>
    </modules>
    <global>
        <blocks>
            <adminhtml>
                <rewrite>
<catalog_product_edit_tab_alerts_stock>MF_Adminhtml_Block_Catalog_Product_Edit_Tab_Alerts_Stock</catalog_product_edit_tab_alerts_stock>
                </rewrite>
            </adminhtml>
        </blocks>
    </global>
</config>

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')
                ->getCustomerCollection()
                ->join($productId, $websiteId);
            $this->setCollection($collection);
        }
        return parent::_prepareCollection();
    }
}

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

2
  • I cannot spot any mistake. Did you clear the cache? How do you know the block is not used? Sep 22, 2016 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, 2016 at 15:31

1 Answer 1

2

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

3
  • 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, 2016 at 15:42
  • @jrmf is your module enabled ? Do you see an corresponding entry in core_resource ? Sep 22, 2016 at 15:43
  • 1
    Nope, problem was that I forgot to add .xml to my file under app/etc/modules
    – jrmf
    Sep 22, 2016 at 15:49

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