If I create an order with a script cod fee is correctly set in the quote but not in the order.
So the order total is wrong.
More info
Cod fee is set on the order by Phoenix_CashOnDelivery_Model_Observer::sales_order_payment_place_end
public function sales_order_payment_place_end(Varien_Event_Observer $observer)
{
// .....
$order = $payment->getOrder();
$quote = Mage::getSingleton('checkout/session')->getQuote();
if (!$quote->getId()) {
$quote = Mage::getSingleton('adminhtml/session_quote')->getQuote();
}
// .....
I can see the following issue:
you should use the config <fieldsets> <sales_convert_quote> node to automatically copy field from the quote into the order (this is the "magento way", with this approach the observer is not required at all)
OR
if you use the observer, quote_id should be retrieved by the order object otherwise, if you create a order by a script, the quote object is empty (because you retrieve it from the session)
( I suspect this issue would occur also if you create an order with Magento API )
I would suggest to use the <fieldsets> configuration way because it reduce this kind of problems
If you, instead, decide to go for the observer the below code fix the issue
public function sales_order_payment_place_end(Varien_Event_Observer $observer)
{
$payment = $observer->getPayment();
if ($payment->getMethodInstance()->getCode() != 'phoenix_cashondelivery') {
return $this;;
}
$order = $payment->getOrder();
$quote = Mage::getSingleton('checkout/session')->getQuote();
if (!$quote->getId()) {
$quote = Mage::getSingleton('adminhtml/session_quote')->getQuote();
}
// Fix for api/script execution
if (!$quote->getId()) {
$quote = $order->getQuote();
}
$order->setCodFee($quote->getCodFee());
$order->setBaseCodFee($quote->getBaseCodFee());
$order->setCodTaxAmount($quote->getCodTaxAmount());
$order->setBaseCodTaxAmount($quote->getBaseCodTaxAmount());
$order->save();
return $this;
}
If I create an order with a script cod fee is correctly set in the quote but not in the order. So the order total is wrong.
More info Cod fee is set on the order by
Phoenix_CashOnDelivery_Model_Observer::sales_order_payment_place_end
I can see the following issue:
<fieldsets> <sales_convert_quote>
node to automatically copy field from the quote into the order (this is the "magento way", with this approach the observer is not required at all) OR( I suspect this issue would occur also if you create an order with Magento API )
I would suggest to use the
<fieldsets>
configuration way because it reduce this kind of problemsIf you, instead, decide to go for the observer the below code fix the issue