Magento定制购物车/结账价值在“下订单”上重置

We are using Magento Enterprise 1.10 and have been implementing a custom way to provide free shipping and no taxes on specific products. I have successfully implemented the display part of this in cart and in Onepage checkout (step 5). The issue I am having is when you we click "Place Order" it erases (or resets) the custom values for subTotal, grandTotal and taxAmount. I can see in the sales_flat_quote and sales_flat_quote_item tables that the values are being set with the custom values I have given it. But the grandTotal and taxAmount in the sales_flat_quote_address table aren't being set properly (not sure if this is related, but assuming). They are being re-calculated the default way Magento calculates them.

So for example I might setTaxAmount a custom value of say $20. But Magento takes the product price and the tax percentage and recalculates it. If that makes sense.

I have pinpointed that in our OnepageController.php in the method saveOrderAction()

if ($data = $this->getRequest()->getPost('payment', false)) {
   $this->getOnepage()->getQuote()->getPayment()->importData($data);
}

This section of code is replacing the custom values I've set with with how Magento normally sets them in:

My questions is there any why to prevent the above block of code from recalculating the values and just use the values I've already set in:

Mage::getSingleton('checkout/session')->getQuote()

Thanks in advance,

I don't think overriding the onepage-controller is the best way to apply custom discounts/taxes. It would be better to place an observer on the event sales_quote_collect_totals_after and re-calculate order-totals/modify items/apply discounts here.

Also, I often see people making the mistake that they forget to invoke collectTotals(), or that they forget to save their changes, i.e.

$quote = Mage::getSingleton('checkout/session')->getQuote();
$quote->setGrandTotal(999.99)->save();

If I miss the point of your question, please provide further detail. Do you use custom columns in your order-table?

Best regards

you can not set order amounts like below.

$quote->setGrandTotal(999.99)->save();

Because subtotal,grandtotal,tax amounts are order totals and calculated when the below code called.

$quote->collectTotals();

This will merge your value.

Just check the function in Mage_Sales_Model_Quote_Address_Total_Abstract called collect and add below code in the beginning of the function.

foreach (Mage::getSingleton('checkout/cart')->getQuote()->getAllVisibleItems() as $item ) {
                 if ($item->getParentItem()) {
                     $item = $item->getParentItem();
                 }


                    $item->setTaxAmount(20);

                    $item->getProduct()->setIsSuperMode(true);
            }

Ofcourse you should override this method. Use below if you want to override in your module's config.xml

<sales>
            <quote>
                <totals>
                    <wrapping>
                        <class>pay/total_taksit</class>
                        <before>subtotal</before>
                    </wrapping>
                </totals>
            </quote>
        </sales>