3

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

  • Could you upload a screenshot or give some more info, so that we can see exactly where you want your price to show. – Evgeni Ivanov Feb 7 '14 at 10:35
  • link Please use that link to view my screenshot. In here you can see Red dots. That is the original price and grand total. I need to add one line (mark it in blue) in there product discounted amount. – yeshansachithak Feb 7 '14 at 11:06
3

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)

  • I already solved the issue. But, I've waited for someone to put the correct answer. Great! This is the same way I found. Vote-Up! Marked! – yeshansachithak Nov 11 '14 at 13:26
1

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/

  • Thanks. I have no idea to put this code to where? – yeshansachithak Feb 7 '14 at 11:21
  • Did you manage to find your way? – Evgeni Ivanov Feb 7 '14 at 14:50
  • Thanks again. But it's not the right thing I want. I want to get the discounted price total from the cart items. and then need to display the discounted price before the Grand total. – yeshansachithak Feb 7 '14 at 18:05
  • So you need the total discount from the quote object? – Evgeni Ivanov Feb 7 '14 at 19:13
  • yes indeed. How do I do it? – yeshansachithak Feb 8 '14 at 6:27
1

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

0

The method you are looking for is

$product->getOriginalPrice()
  • so this gets the non-original price (after discount), what the OP is looking for? – ahnbizcad Jul 2 '15 at 1:15

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.