1

I have add an observer to sales_quote_collect_totals_after to changing tax amount, the tax is changed but order totals and tax totals are wrong. I tried with :

<checkout_submit_all_after>
            <observers>
                <Module_Sales>
                    <type>singleton</type>
                    <class>Module_Sales_Model_Observer</class>
                    <method>setTaxAmountOrder</method>
                </Module_Sales>
            </observers>
        </checkout_submit_all_after>

Without success finally i try to change the totals by :

 $order = Mage::getModel('sales/order')->load(356);
 $order->setSubtotal(500) ;
 $order->setBaseSubtotal(500) ;
 $order->setGrandTotal(500) ;
 $order->setBaseGrandTotal(500) ;
 $order->setBaseSubtotalInclTax(500) ;

Without success because only setSubtotal has changed. Can you help me.

this is when i save order

$_items = $order->getAllVisibleItems();
    foreach ($_items as $item) {
        $price = $item->getPrice();
        $basePrice = $item->getBasePrice();
        $_taxHelper = Mage::helper('tax');
        $_store = $item->getProduct()->getStore();
        $_convertedPrice_ = $_store->roundPrice($_store->convertPrice($item->getPrice()));
        $_convertedBasePrice_ = $_store->roundPrice($_store->convertPrice($item->getPrice()));
        $taxamount = $_taxHelper->getPrice($item, ($price * 0.2), null, null, null, null, null, null, false);
        $baseNewTaxAmount = $_taxHelper->getPrice($item, ($basePrice * 0.2), null, null, null, null, null, null, false);
        $finalprodprice = $_convertedPrice_ + ($_convertedPrice_ * 0.2) + ($taxamount - ($item->getProduct()->getPrice() * 0.2));
        $finalprodBaseprice = $_convertedBasePrice_ + ($_convertedBasePrice_ * 0.2) + ($baseNewTaxAmount - ($basePrice * 0.2));
        $item->setTaxAmount($taxamount - ($item->getPrice() * 0.2));
        $item->setBaseTaxAmount($baseNewTaxAmount - ($item->getPrice() * 0.2));
        $item->setPrice($finalprodprice);
        $item->setPriceInclTax($finalprodprice);
        $item->setBasePriceInclTax($finalprodBaseprice);

        $item->save();
    }
    $order->setSubtotal($finalprodprice)->setBaseSubtotal($finalprodprice);
    $order->setGrandTotal($finalprodprice)->setBaseGrandTotal($finalprodprice);
    $order->setBaseSubtotalInclTax($finalprodprice);
    $order->save();
2
  • did you save this order instanse like $order->save(); in your observer method setTaxAmountOrder
    – Mujahidh
    Aug 29, 2017 at 9:11
  • Yes i save it in observer setTaxAmountOrder, i added the code in my question. i have always a single product in cart.
    – abdessalem
    Aug 29, 2017 at 10:11

1 Answer 1

0

For those how has the same problem, the execution of my module where not the last their is another module how is executed the last by the observer. i rename my module with the first lettre Z .Now my module is executed the last because the order of execution is alphabetic.

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.