我在管理员中创建了目录价格规则。现在它正在前端。但是,我想在购物车中显示实际价格。所以我做了以下代码 abstract.php 文件。之后,我称之为 default.phtml. 。现在,我可以看到产品价格显示出我想要的。但是现在,我需要在大总标签之前以折扣价展示一条线。

    public function getPriceWithoutDiscount()
    {/*Edit by Yesh*/
       if ($this->getProductId()) {
             $productID = $this->_getData('product');
             $productID = $this->getProductId();
             $product = Mage::getModel('catalog/product')->load($productID);
             $price = $product->getPrice();
       }
    return $price;
    }

有什么建议么?


请查看我的屏幕截图

enter image description here

有帮助吗?

解决方案

如果您希望将折扣用于总计,则应使用购物车价格规则,而不是目录价格规则。可以根据购物车中的产品指定购物车价格规则,也只能对某些产品应用折扣。

那么唯一剩下的问题是在产品详细信息页面上显示原始价格和折扣价,这比您最初尝试的更容易解决(只是前端,内部价格和总计算没有变化)

其他提示

对于单个产品,我认为您可以使用 $product->getPrice() - $product->getFinalPrice()

(https://stackoverflow.com/questions/13587968/magento-what-is-the-difference-bet-ween-getprice-and-getfinalprice).

对于整个订单,都使用以下方式: $order->getBaseDiscountAmount(). 。请注意,此方法返回的值是负数。假设您有60美元的折扣。这将为您提供-60,因此使用它是有意义的: abs($order->getBaseDiscountAmount()). 。除了基本货币使用以外 $order->getDiscountAmount().

您需要适应的第一个模板位于: app/design/frontend/base/default/template/checkout/cart/item/default.phtml. 。也看一下 app/design/frontend/base/default/template/checkout/cart/cart.phtml 在第131行(Magento 1.8.0.0)上,每个项目的渲染过程都启动了。

这是一个详细的描述:在 app/design/frontend/base/default/template/checkout/cart/item/default.phtml 有几个 。这是您需要进行更改的地方。也不要编辑核心文件。
有关结帐定价详细信息,请查看本文: http://nikunjvadariya.wordpress.com/2013/06/17/magento-get-checkout-cart-cart-total-detal-details-subtotalgrandtotallandtallandtaldiscounttax/

尝试这个。

以下代码显示了如何获得折扣金额。

$totalItemsInCart = Mage::helper(‘checkout/cart’)->getItemsCount(); //total items in cart
$totals = Mage::getSingleton(‘checkout/session’)->getQuote()->getTotals(); //Total object
$subtotal = round($totals["subtotal"]->getValue()); //Subtotal value
$grandtotal = round($totals["grand_total"]->getValue()); //Grandtotal value

if(isset($totals['discount']) && $totals['discount']->getValue()) {
$discount = round($totals['discount']->getValue()); //Discount value if applied
} else {
    $discount = '';
}

renderTotals() 功能在 app/code/core/Mage/Checkout/Block/Cart/Totals.php 负责显示您在图像中突出显示的部分。如果检查此功能,您可以看到此方法将总值返回为HTML代码段。

您可以覆盖此类,并在此功能中附加折扣价值。

注意:不要编辑核心文件

您要寻找的方法是

$product->getOriginalPrice()
许可以下: CC-BY-SA归因
scroll top