3

I re-wrote updatePostAction() in a new class extended from Mage_Checkout_CartController. It has a special formula to calculate its subtotal. In debug mode, it calculates correctly, but the correct subtotals are not persistent. For example,

Line 88: $item->setRowTotalInclTax( $totalAmountInclTax );

In debug mode: Before executing Line 88, $item->getRowTotalInclTax() returns 85.09. After executing, $item->getRowTotalInclTax() returns 92.61. This is correct in debug mode according to requirements.

But, shopping cart page displays old value 85.09 instead of 92.61. Should I save this new calculated value again somehow?

Edit: Later, I wrote an extension to override Mage_Sales_Model_Quote_Address_Total_Subtotal as follows:

<config>
    <global>
        <models>
            <sales>
                <rewrite>
                    <quote_address_total_subtotal>MyExt_Sales_Model_Quote_Address_Total_Subtotal</quote_address_total_subtotal>
                </rewrite>
            </sales>
        </models>
    </global>
</config>

Model:

class MyExt_Sales_Model_Quote_Address_Total_Subtotal extends Mage_Sales_Model_Quote_Address_Total_Abstract
{
    public function collect(Mage_Sales_Model_Quote_Address $address)
    {
        ...

        //test
        $baseVirtualAmount = 333;
        $virtualAmount = 333;

        $address->setBaseVirtualAmount($baseVirtualAmount);
        $address->setVirtualAmount($virtualAmount);

        .....

        return $this;
    }

But, the cart Update event doesn't call this collect() method.

3
+50

I don't have a working solution, but I have an idea.
Magento offers 2 events dispatched when the totals are calculated.
The event names are sales_quote_collect_totals_before and sales_quote_collect_totals_after. Bot of them are dispatched in the method Mage_Sales_Model_Quote::collectTotals().

Mage::dispatchEvent($this->_eventPrefix . '_collect_totals_before', array($this->_eventObject => $this));
...
Mage::dispatchEvent($this->_eventPrefix . '_collect_totals_after', array($this->_eventObject => $this));

Usually after the collectTotals method is called, there is a save called also.
I doubt you can do much with the before event, but you can try to use the after one to execute your custom code based on the quote object you have.

2

You can extend class Mage_Sales_Model_Quote_Address_Total_Subtotal.

In this class you can override collect or initItem methods.

  • I wrote this following code, but it doesn't call this method in Cart Update event: class MyExt_Sales_Model_Quote_Address_Total_Subtotal extends Mage_Sales_Model_Quote_Address_Total_Abstract { public function collect(Mage_Sales_Model_Quote_Address $address) { //var_dump(get_class($this)); exit(); ... //test $baseVirtualAmount = 333; $virtualAmount = 333; $address->setBaseVirtualAmount($baseVirtualAmount); $address->setVirtualAmount($virtualAmount); ..... return $this; } – Agilox Dec 16 '14 at 14:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.