开发者

Magento save order total in checkout page

We have a system like gift cards balance usage in the checkout page.While customers on the checkout page customers can use their Gift card balance amount to buy products.

So i have added a a tab before payment tab in which customers have option to enter the amount o use from their gift card balance amount so when they say proceed am getting the entered value in custom Onepage controller and pass it to Onepage.php(Model class) to reduce the total amount.

This is what am doing on the model class.

public function saveCustomDiscount($discount=0)
{       
    $this->getQuote()->setGrandTotal($this->getQuote()->getGrandTotal() - $discount);
    $this->getQuote()->setBaseGrandTotal($this->getQuote()->getBaseGrandTotal() - $discount);
    $this->getQuote()->save();
    //$this->getQuote()->collectTotals()->save();
    $order = $this->getQuote()->getData();  
    Zend_Debug::dump($order);      
    return array();
}

And am calling this function from the controller Action function were am getting the user input.

Here what ever am passing as discount the total amount and base total is not reducing. Its same as original.

Note : Before custom order save.

array(51) {
   ---------------
  ["grand_total"] => string(8) "243.7200"
  ["base_grand_total"] => string(8) "243.7200"
  ----------------- 
}

After custom order save.

array(51) {
   ---------------
   ["grand_total"] => float(223.72)
   ["base_grand_to开发者_如何学编程tal"] => float(223.72)
  ----------------- 
}

The data type is changed from string to float when am doing debug. What i have to do, to reduce the order total from the custom discount. Please help me.

Thanks


Did you set the discountCode?

i.e.  $quote->setCouponCode(strlen($couponCode) ? $couponCode : '')
                 ->collectTotals()
                 ->save();

Later on, in the Quote, did you apply the discount?

i.e. $order->setDiscountAmount(Mage::getSingleton('checkout/session')->getQuote()->getSubtotalWithDiscount() - Mage::getSingleton('checkout/session')->getQuote()->getSubtotal());
            $order->setShippingAmount(Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress()->getShippingAmount());
            $order->setSubtotalWithDiscount(Mage::getSingleton('checkout/session')->getQuote()->getSubtotalWithDiscount());
            $order->setGrandTotal(Mage::getSingleton('checkout/session')->getQuote()->getGrandTotal());

etc.

EDIT:

I've worked with a team to do a Wordpress / Magento hybrid and it's definitely left some learning lessons on me. Magento was used as a purely transactional engine and we had to do this entire checkout process by hand (including creating a custom WP plugin to handle each step in the cart).

Log this out at the end so we can see what you have (possibly put this in your edited question):

Mage::log("checkoutprocess: getSubtotal: " . $order->getSubtotal());
            Mage::log("checkoutprocess: getTaxAmount: " . $order->getTaxAmount());
            Mage::log("checkoutprocess: getDiscountAmount: " . $order->getDiscountAmount());
            Mage::log("checkoutprocess: getShippingAmount: " . $order->getShippingAmount());
            Mage::log("checkoutprocess: getGrandTotal: " . $order->getGrandTotal());

            Mage::log("checkoutprocess: getBaseSubtotal: " . $order->getBaseSubtotal());
            Mage::log("checkoutprocess: getBaseDiscountAmount: " . $order->getBaseDiscountAmount());
            Mage::log("checkoutprocess: getSubtotalWithDiscount: " . $order->getSubtotalWithDiscount());
            Mage::log("checkoutprocess: getBaseGrandTotal: " . $order->getBaseGrandTotal());
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜