1

I'm trying to overwrite Mage_Adminhtml_Block_Sales_Order_Create_Form_Address in the local codepool and within our company namespace. I made the changes within the core codepool just as a proof of concept, which checked out, but upon transferring those changes into local, it stopped working. The class itself doesn't seem to be overwriting the core one.

What I have right now:

class Company_Adminhtml_Block_Sales_Order_Create_Form_Address
    extends Mage_Adminhtml_Block_Sales_Order_Create_Form_Abstract
{
...
}

is at /app/code/local/Company/Adminhtml/Block/Sales/Order/Create/Form/Address.php, mirroring the original file's placement, but within our local namespace.

Within /app/code/local/Company/Adminhtml/etc/config.xml I have:

<config>
    <global>
        <blocks>
            <adminhtml>
                <rewrite>
                    <sales_order_create_form_address>Company_Adminhtml_Block_Sales_Order_Create_Form_Address</sales_order_create_form_address>
                </rewrite>
            </adminhtml>
        </blocks>
    </global>
</config>

I imagine that I just have something misplaced/missing an entry or something that's not configured properly, but I'm not quite sure what. Any ideas or help would be greatly appreciated. Thanks!

1

Mage_Adminhtml_Block_Sales_Order_Create_Form_Address is not overridden by your custom module because it is never directly loaded as a block class. Instead, two other core classes extend it directly:

code/Mage/Adminhtml/Block/Sales/Order/Create/Billing/Address

class Mage_Adminhtml_Block_Sales_Order_Create_Billing_Address
    extends Mage_Adminhtml_Block_Sales_Order_Create_Form_Address

and code/Mage/Adminhtml/Block/Sales/Order/Create/Shipping/Address

class Mage_Adminhtml_Block_Sales_Order_Create_Shipping_Address
    extends Mage_Adminhtml_Block_Sales_Order_Create_Form_Address

Neither overriding Mage_Adminhtml_Block_Sales_Order_Create_Form_Address either through xml in config.xml or copying the block file to app/code/local/Mage/... work to override this.

What does work is to override both of these files: code/Mage/Adminhtml/Block/Sales/Order/Create/Billing/Address code/Mage/Adminhtml/Block/Sales/Order/Create/Shipping/Address

So, something like this:

Namespace/Modulename/etc/config.xml

<blocks>
    <adminhtml>
        <rewrite>
            ...
            <sales_order_create_billing_address>Namepace_Modulename_Block_Adminhtml_Sales_Order_Create_Billing_Address</sales_order_create_billing_address>
            <sales_order_create_shipping_address>Namepace_Modulename_Block_Adminhtml_Sales_Order_Create_Shipping_Address</sales_order_create_shipping_address>
            ...
        </rewrite>
    </adminhtml>
</blocks>

Namespace/Modulename/Block/Adminhtml/Sales/Order/Create/Billing/Address.php

class Namespace_Modulename_Block_Adminhtml_Sales_Order_Create_Billing_Address
    extends Mage_Adminhtml_Block_Sales_Order_Create_Billing_Address
{
    protected function _prepareForm()
    {
        parent::_prepareForm();
        // Do form customisation here            
        return $this;
    }

}

Namespace/Modulename/Block/Adminhtml/Sales/Order/Create/Shipping/Address.php

class Namespace_Modulename_Block_Adminhtml_Sales_Order_Create_Shipping_Address
    extends Mage_Adminhtml_Block_Sales_Order_Create_Shipping_Address
{
    protected function _prepareForm()
    {
        parent::_prepareForm();
        // Do form customisation here            
        return $this;
    }

}

It's a shame about the repetition. You could call a helper or something to do the form customisation if it's going to be the same on both forms.

0

In your config.xml you are defining you are rewriting Mage_Adminhtml_Block_Sales_Order_Create_Form_Address class

But your class is extending Mage_Adminhtml_Block_Sales_Order_Create_Form_Address_Abstract, your class definition should be

class Company_Adminhtml_Block_Sales_Order_Create_Form_Address
extends Mage_Adminhtml_Block_Sales_Order_Create_Form_Address

Anyways, using Adminhtml as your module name seems a very bad idea, I'd change it before your module grows

  • Hi, thanks for the response. I changed the class definition but still no luck. It still looks like the class isn't getting loaded at all. Is there anything else in there that looks defined wrong at all? – Eric Strom Feb 24 '16 at 17:23
  • I assume you control module basics, app/etc/modules file, etc... so your module has all the needed files to work. If so, try changing your module name, to avoid possible conflicts with Adminhtml magento module – Raul Sanchez Feb 24 '16 at 17:26
0

Please use below code for config.xml

    <blocks>
          <comapnyadminhtml>
            <class>Company_Adminhtml_Block</class>
          </comapnyadminhtml>
          <adminhtml>
                <rewrite>
                        <sales_order_create_form_abstract>Company_Adminhtml_Block_Adminhtml_Sales_Order_Create_Form_Abstract</sales_order_create_form_abstract>
                </rewrite>
        </adminhtml>
   </blocks>

Block:

<?php
class Company_Adminhtml_Block_Adminhtml_Sales_Order_Create_Form_Abstract extends Mage_Adminhtml_Block_Sales_Order_Create_Form_Abstract
{
}

As rahul says "using Adminhtml as your module name seems a very bad idea". Please check your module group name must not "adminhtml".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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