Question

I create a Catalog price rule in admin. Now it's applying in the front-end. But, I want to show actual price in the shopping cart. So I did the below code in abstract.php file. After that I call it in default.phtml. Now I can see the product price are showing like that I want. But now I need to show one line with discounted price before the grand total label.

    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;
    }

Any suggestions?


Please see my screenshot

enter image description here

Was it helpful?

Solution

If you want the discount to be applied in the totals you should use shopping cart price rules, not catalog price rules. It is possible to specify shopping cart price rules based on the products in the cart and also apply discounts only to certain products.

Then the only problem left is to display original and discounted price on the product detail page which is way easier to solve than what you tried originally (just frontend, no changes in internal price and total calculation)

OTHER TIPS

For a single product I think you can use $product->getPrice() - $product->getFinalPrice()

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

For the entire order use this : $order->getBaseDiscountAmount(). Please note, that the value returned by this method is a negative one. So let's say you have 60$ discount. This will give you -60, so it makes sense to use it like that: abs($order->getBaseDiscountAmount()). For other than the base currency use $order->getDiscountAmount().

The first template that you need to adapt is located at: app/design/frontend/base/default/template/checkout/cart/item/default.phtml. Also take a look at app/design/frontend/base/default/template/checkout/cart/cart.phtml at line 131(Magento 1.8.0.0) the rendering process for every single item is started.

Here is a detailed description: in app/design/frontend/base/default/template/checkout/cart/item/default.phtml there are several . This is where you need to make changes. Also DO NOT EDIT THE CORE FILES.
For checkout pricing details take a look at this article: http://nikunjvadariya.wordpress.com/2013/06/17/magento-get-checkout-cart-total-details-subtotalgrandtotaldiscounttax/

Try this.

The following code shows how to get the discount amount if applied.

$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 = '';
}

The renderTotals() function in app/code/core/Mage/Checkout/Block/Cart/Totals.php is responsible for showing that section which you have highlighted in your image. If you check this function you can see that this method returns total values as a html code snippet.

You can override this class and append the discount value inside this function.

NOTE: Do not edit the core files

The method you are looking for is

$product->getOriginalPrice()
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top