问题
I am working on site where i want to add/subtract fee to cart total and grand total.I am firing this event to capture the cart details.sales_order_save_after
. while in observer i got the price using this code
public function modifyPrice(Varien_Event_Observer $obs)
{
$getotal = Mage::helper('checkout')->getQuote()->getGrandTotal();
$totals = Mage::getSingleton('checkout/session')->getQuote()->getTotals();
$subtotal = $totals["subtotal"]->getValue();
}.
But i don't know how to add/subtract amount from total and than update accordingly.Thanks in advance
回答1:
Rehman,
i am afraid this is not a straight forward task to complete, although you can take following as Ref to start
http://www.excellencemagentoblog.com/magento-add-fee-discount-order-total
Hope above link helps.
回答2:
After searching i found this tutorial http://magento.ikantam.com/qa/how-add-discount-total-magento.And on Discount model class i can add/subtract custom price to cart total like :
public function collect(Mage_Sales_Model_Quote_Address $address) {
if ($address->getData('address_type') == 'billing')
return $this;
$discount = Mage::helper('my_module')->getCurrentdiscount(); // Custom percentage
$grandTotal = $address->getGrandTotal();
$baseGrandTotal = $address->getBaseGrandTotal();
$totals = array_sum($address->getAllTotalAmounts());
$baseTotals = array_sum($address->getAllBaseTotalAmounts());
$address->setFeeAmount(-$totals * $discount / 100);
$address->setBaseFeeAmount(-$baseTotals * $discount / 100);
$address->setGrandTotal($grandTotal + $address->getFeeAmount());
$address->setBaseGrandTotal($baseGrandTotal + $address->getBaseFeeAmount());
return $this;
}
来源:https://stackoverflow.com/questions/20511309/add-custom-calculation-to-cart-total-and-grand-total-in-magento