1

Why can not extend core block with below configs?!

file config.xml modified

URL : app/code/community/Mycompnay/Mymodule/etc/config.xml

    <config>
        <global>
            <blocks>
                <mymodule>
                    <class>Mycompany_Mymodule_Block</class>
                </mymodule>
                <checkout>
                    <rewrite>
                        <block_cart_shipping>Mycompany_Mymodule_Block_Cart_Shipping</block_cart_shipping>
                    </rewrite>
                </checkout>            
            </blocks>
        </global>
     </config>

file Shipping.php to extend

URL : app/code/community/Mycompany/Mymodule/Block/Cart/Shipping.php

class Mycompany_Mymodule_Block_Cart_Shipping extends Mage_Checkout_Block_Cart_Shipping
{
    public function getCityActive()
    {
        return (bool)Mage::getStoreConfig('carriers/mymodule/active');
    }
}

1 Answer 1

3

Looking briefly at your configuration, you're trying to create a rewrite for a block in the checkout group, and that block's name is block_cart_shipping

            <checkout>
                <rewrite>
                    <block_cart_shipping>Mycompany_Mymodule_Block_Cart_Shipping</block_cart_shipping>
                </rewrite>
            </checkout>

In other words, block that instantiated like

Mage::getSingleton('core/layout')->createBlock('checkout/block_cart_shipping');

There's no such block in Magento. You're probably looking for

   <cart_shipping>Mycompany_Mymodule_Block_Cart_Shipping</cart_shipping>

Also, this answer will show you where Magento swaps out the standard class name for a rewritten one, and is where you'll want to focus your debugging efforts.

2
  • Great Alan, but really I don't know, why you said that block is not available ? I can see this block in app/code/core/Mage/Checkout/Block/Cart/Shipping.php
    – sIiiS
    Commented Mar 12, 2014 at 20:57
  • Where is a block with the class/type of checkout/block_cart_shipping instantiated in the system? Commented Mar 12, 2014 at 21:05

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.