2

I'm modifying getCountryHtmlSelect() through a custom class that extends another core class that extends Mage_Checkout_Block_Onepage_Abstract. Here's the class with the customized code:

local/Mycompany/Checkout/Block/Onepage/Billing.php:

class Mycompany_Checkout_Block_Onepage_Billing extends Mage_Checkout_Block_Onepage_Billing{

    // customizing from Mage_Checkout_Block_Onepage_Abstract
    public function getCountryHtmlSelect($type){
        [INSERT CUSTOM CODE]
    }

}

For your reference, here is class Mage_Checkout_Block_Onepage_Billing:

core/Mage/Checkout/Block/Onepage/Billing.php:

class Mage_Checkout_Block_Onepage_Billing extends Mage_Checkout_Block_Onepage_Abstract{
...
}

For completeness sake, here's Mage_Checkout_Block_Onepage_Abstract:

core/Mage/Checkout/Block/Onepage/Abstract.php:

abstract class Mage_Checkout_Block_Onepage_Abstract extends Mage_Core_Block_Template{

    public function getCountryHtmlSelect($type)
    {
       [CORE CODE]
    }
}

Unfortunately, Magento isn't picking up the customized version of getCountryHtmlSelect(); it's still using getCountryHtmlSelect() in class Mage_Checkout_Block_Onepage_Abstract.

Here's my config.xml:

app/code/local/Mycompany/Checkout/etc/config.xml:

<?xml version="1.0" ?>
<config>
    <modules>
        <Mycompany_Checkout>
            <version>0.0.1</version>
        </Mycompany_Checkout>
    </modules>
    <global>
        <blocks>
            <checkout>
                <rewrite>
                    <onepage>Mycompany_Checkout_Block_Onepage</onepage>
<onepage_shipping>Mycompany_Checkout_Block_Onepage_Shipping</onepage_shipping>
                </rewrite>
            </checkout>
        </blocks>
    </global>
    <frontend>
        <routers>
            <checkout>
                <args>
                    <modules>
                        <Mycompany_Checkout before="Mage_Checkout">Mycompany_Checkout</Mycompany_Checkout>
                    </modules>
                </args>
            </checkout>
        </routers>
    </frontend>
</config>

Questions:

  1. What do I need to do to get Magento to use getCountryHtmlSelect() in the custom class?

  2. Rather than approaching the problem by inserting getCountryHtmlSelect() in the custom class, is it better to do this:

local/Mycompany/Checkout/Block/Onepage/Abstract.php:

abstract class Mage_Checkout_Block_Onepage_Abstract extends Mage_Checkout_Block_Onepage_Abstract{

    public function getCountryHtmlSelect($type)
    {
        [INSERT CUSTOM CODE]
    }
}
5
  • Did you rewrite the core/Mage/Checkout/Block/Onepage/Billing.php? or changed the block name in layout file Commented Jul 27, 2015 at 4:34
  • Actually, I changed the block name in the config.xml file. Not supposed to rewrite core files right? Updated the question to contain config.xml.
    – Vee
    Commented Jul 27, 2015 at 4:37
  • ok. Whether it calls your local/Mycompany/Checkout/Block/Onepage/Billing.php? Commented Jul 27, 2015 at 4:39
  • Just figured out the answer! I'm modifying Billing instead of Shipping! Gonna try the fix and see if it works. Your questions helped me see the problem. Thanks, @saravanavelu!
    – Vee
    Commented Jul 27, 2015 at 4:43
  • Yup - that was the problem. I was modifying Shipping instead of Billing. Thanks, @saravanavelu!
    – Vee
    Commented Jul 27, 2015 at 4:47

1 Answer 1

0

Through @saravanavelu's comments, I ultimately noticed that I was modifying code related to Checkout Shipping while my config.xml file had renamed Checkout Billing. Simple fix. But, I'm leaving this question since it does show how to override an abstract class in case this helps somebody else.

Here's how the relevant part of config.xml that should look:

<?xml version="1.0" ?>
<config>
   ...
                <rewrite>
                    <onepage>Mycompany_Checkout_Block_Onepage</onepage>
<onepage_billing>Mycompany_Checkout_Block_Onepage_Billing</onepage_billing>
                </rewrite>
    ...
</config>
1
  • Feel free to mark your own answer as accepted to not leave the question as "unanswered" Commented Dec 19, 2016 at 9:25

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.