0

I am trying to override a adminhtml block and I created all files accordingly. The problem is that it does not have any effect. My files are as follows:

app/code/local/Grando/Groupfilter/etc/config.xml

<?xml version="1.0"?>

<config>

<modules>

    <Grando_Groupfilter>

        <version>1.0</version>

    </Grando_Groupfilter>

</modules>

<global>
    <blocks>
    <grando_groupfilter>
        <class>Grando_Groupfilter_Block</class>
    </grando_groupfilter>
        <adminhtml>
            <rewrite>
                <catalog_product_edit_tab_super_group>Grando_Groupfilter_Block_Adminhtml_Catalog_Product_Edit_Tab_Super_Group</catalog_product_edit_tab_super_group>
            </rewrite>
        </adminhtml>
    </blocks>
</global>   

</config>

app/code/local/Grando/Groupfilter/Block/Adminhtml/Catalog/Product/Edit/Tab/Super/Group.php

class Grando_Groupfilter_Block_Adminhtml_Catalog_Product_Edit_Tab_Super_Group extends Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Super_Group {
   protected function _prepareCollection()
{
    //somecodehere
} 
   }

app/etc/modules/Grando_Groupfilter.xml

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

Is it not possible to do this? Am I missing something?

2
  • can you see this link may be it will use magento.stackexchange.com/questions/13709/…
    – Pawankumar
    Commented Jun 13, 2018 at 16:20
  • I already saw that one.. His accpted solution looks exactly as my code is... I really can't see any reason mine is not working... maybe the function that I am overriding? If I edit core directly, my code works fine...
    – Gabriel G
    Commented Jun 13, 2018 at 16:24

1 Answer 1

1

Why it is not working!!! Please see below

your function is inherited from below function which is protected. Yes, we can inherit protected function into our custom module but here slite difference is that we can not inherit private property.

protected function _prepareCollection()
    {
        $allowProductTypes = array();
        $allowProductTypeNodes = Mage::getConfig()
            ->getNode('global/catalog/product/type/grouped/allow_product_types')->children();
        foreach ($allowProductTypeNodes as $type) {
            $allowProductTypes[] = $type->getName();
        }

        $collection = Mage::getModel('catalog/product_link')->useGroupedLinks()
            ->getProductCollection()
            ->setProduct($this->_getProduct())
            ->addAttributeToSelect('*')
            ->addFilterByRequiredOptions()
            ->addAttributeToFilter('type_id', $allowProductTypes);

        if ($this->getIsReadonly() === true) {
            $collection->addFieldToFilter('entity_id', array('in' => $this->_getSelectedProducts()));
        }
        $this->setCollection($collection);
        return parent::_prepareCollection();
    }

->setProduct($this->_getProduct()) this is the function which is private So we can not set current product object.That's why your code is not working. Just make it app/code/local/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Super/Group.php

2
  • So in theory it is not possible to override this funcion without overriding entire file?
    – Gabriel G
    Commented Jun 14, 2018 at 13:00
  • just make it app/code/local/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Super/Group.php , it will work via codepool pref.
    – MR.R DNATH
    Commented Jun 14, 2018 at 15:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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