0

I have stuck with this. I am trying to override sales/ order model _saveafter function with my custom module. I have the following code

\app\code\local\Rkt\SalesNew\etc\config.xml

<modules>
    <Rkt_SalesNew>
        <version>0.0.1</version>
    </Rkt_SalesNew>
</modules>
<global>
    <models>
 <salesnew>
      <rewrite>
        <method>Rkt_SalesNew_Model_Order</method>
      </rewrite>
 </salesnew>
    </models>
</global>

\app\code\local\Rkt\SalesNew\Model\Order.php

class Rkt_SalesNew_Model_Order extends Mage_Sales_Model_Abstract

{

   protected function _afterSave()
{ 
    if (null !== $this->_addresses) {
        $this->_addresses->save();
        $billingAddress = $this->getBillingAddress();
        $attributesForSave = array();
        if ($billingAddress && $this->getBillingAddressId() != $billingAddress->getId()) {
            $this->setBillingAddressId($billingAddress->getId());
            $attributesForSave[] = 'billing_address_id';
        }

        $shippingAddress = $this->getShippingAddress();
        if ($shippingAddress && $this->getShippigAddressId() != $shippingAddress->getId()) {
            $this->setShippingAddressId($shippingAddress->getId());
            $attributesForSave[] = 'shipping_address_id';
        }

        if (!empty($attributesForSave)) {
            $this->_getResource()->saveAttribute($this, $attributesForSave);
        }

    }
    if (null !== $this->_items) {
        $this->_items->save();
    }
    if (null !== $this->_payments) {
        $this->_payments->save();
    }
    if (null !== $this->_statusHistory) {
        $this->_statusHistory->save();
    }
    foreach ($this->getRelatedObjects() as $object) {
        $object->save();
    } 
    return parent::_afterSave();
}

}

I am unable to override this function. Can any one please help me out.

2 Answers 2

0

You can rewrite abstract class just need to copy Mage_Sales_Model_Abstract file to community or local pool.

And after that, you can edit that file in that scope. autoload functionality will load files from following orders:
1. lib
2. core
3. community
4. local

app > code > community > Mage > Sales > Model > Abstract.php

2
0

_afterSave method is not defined in abstract class, it's in main Order class itself. Your config.xml file is wrong for rewrite declaration, it should be something like this (only relevant part added here ) :

<models>
    <sales>
        <rewrite>
            <order>Rkt_SalesNew_Model_Order</order>
        </rewrite>
    </sales>
</models>

And lastly, you'll be need to extend Mage_Sales_Model_Order class, not the abstract class.

1

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.