本文介绍了Magento更新小计的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法更新购物车中的小计项目.我通过观察 checkout_cart_product_add_after 创建了模块,我可以从物料中获取小计价格:

I can't update subtotal item in cart.I created module with observe checkout_cart_product_add_after I can get subtotal price from item:

$subtotal = Mage::getSingleton('checkout/cart')->getQuote()->getSubtotal();

但是我无法更新,例如:

but I can't update this, for exmaple:

$subtotal = $subtotal + 100;
Mage::getSingleton('checkout/session')->getQuote()->setSubtotal($subtotal);
Mage::getSingleton('checkout/cart')->getQuote()->setSubtotal($subtotal);
Mage::getSingleton('checkout/session')->getQuote()->save();
Mage::getSingleton('checkout/cart')->getQuote()->save();

编辑

如果我在观察员中运行print_r($subtotal); exit;我得到正确的更新小计.在购物车页面中,我的原始小计仍没有更改.

If I run in my Observer print_r($subtotal); exit; I get correct updated subtotal. In cart page I have still orginal subtotal without change.

编辑2 我正在尝试使用 sales_quote_collect_totals_after 事件运行ModifySubtotal函数,但是在购物车页面上看不到更新的小计价格.下面的代码来自Observer.php的ModifySubtotal:

EDIT 2I'm trying run modifySubtotal function with sales_quote_collect_totals_after event, but I can't see on cart page updated subtotal price. Below code of modifySubtotal from Observer.php:

public function modifySubtotal(Varien_Event_Observer $observer)
    {

    $session = Mage::getSingleton('checkout/session');
    $quote=$observer->getQuote();
    $subtotal = $quote->getBaseSubtotal();
    $subtotal = $subtotal +123;
    $quote->setBaseSubtotal($subtotal);

    $quote->save();
    $subtotal2 = $quote->getBaseSubtotal();
    //print_r($subtotal2);exit;

}

如果有任何提示和帮助,我将不胜感激.

I'll be grateful for any tips and help.

推荐答案

问题已解决.我将 Subtotal.php 税收/模块/销售/Qoute/总计复制并复制到/app/local/Mage/....在545行附近,我计算了自定义$subtotal值并设置$item->setRowTotal($subtotal);这就是全部.

Issue solved. I override and copy Subtotal.php from Tax/Module/Sales/Qoute/Total to /app/local/Mage/... Near 545 line I calculated my custom $subtotal value and set $item->setRowTotal($subtotal);This is all.

这篇关于Magento更新小计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 20:54