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.

asked Jan 4, 2019 at 8:44

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

Himanshu
1,76618 silver badges34 bronze badges
answered Jan 4, 2019 at 9:04
2
  • Please click on up arrow near my answer if it was useful for you. Commented Jan 4, 2019 at 16:12
  • Any help thanks magento.stackexchange.com/q/307347/57334 @Anton Commented Mar 18, 2020 at 6:34
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.

answered Jan 6, 2019 at 19:06
1

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.