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
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
-
Please click on up arrow near my answer if it was useful for you.Anton– Anton2019年01月04日 16:12:19 +00:00Commented Jan 4, 2019 at 16:12
-
Any help thanks magento.stackexchange.com/q/307347/57334 @Antonzus– zus2020年03月18日 06:34:44 +00:00Commented Mar 18, 2020 at 6:34
_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.
-
Any help thanks magento.stackexchange.com/q/307347/57334 @Prateekzus– zus2020年03月18日 06:34:01 +00:00Commented Mar 18, 2020 at 6:34