3
/app/design/frontend/rwd/amaze/template/checkout/cart/item/default.phtml

In above file i have added the bellow snippet code to display saving amount for each product and its working good now in this loop i have to save addition of $finaltot

suppose $finaltot displaying value 10 23 40 so i have to make like 10 + 23 + 40

I have tried with bellow code to make addition in $finaltot+ but its no working

<?php
    $product_orignalprice = $this->getProduct()->getPrice();
    $discountedprice=$_item->getPrice(); 
    $todatlsaving=$product_orignalprice-$discountedprice;
    $finaltot+=$todatlsaving * $this->getQty();
    echo $finaltot;
?>

so it will display $finaltot=73

so how do I do this within loop to store all value of variable in one variable.

you can check code on pastebin.com/YMGvEmr7 on the line 96 to 100

2 Answers 2

3

Finally i have done this with own way if you want display saving price of every product in cart and display to total saving amount near at Grand Total you need edit two file of your theme.

1)Display saving amount front of each product.

Add bellow snippet code in /app/design/frontend/rwd/your_theme_name/template/checkout/cart/item/default.phtml

Check the cart div html markup where exactly you have to display saving price because every theme have different lay out just put the bellow code in proper place.

<span class="savepricecustm">You Saved Rs
  <?php 
    $product_orignal_price = $this->getProduct()->getPrice();
    $discounted_price=$_item->getPriceInclTax(); 
    $total_saving=$product_orignal_price-$discounted_price;
    $final_tot+=$total_saving * $this->getQty();
    echo $final_tot;
  ?>
</span>

2) Display total saving amount of all product in the cart near at Grand Total

Add bellow snippet code in

/app/design/frontend/rwd/your_theme_name/template/checkout/cart/totals.phtml

Add this code after <?php echo $this->renderTotals(); in my case so you can put this according to your theme structure.

$cart = Mage::getModel('checkout/cart')->getQuote();
foreach ($cart->getAllItems() as $item) {
     $productPrice_orignal_price=$item->getProduct()->getPrice();
     $discountedprice=$item->getPrice(); 
     $todatlsaving=$productPrice_orignal_price-$discountedprice;
     $finaltot+=$todatlsaving * $item->getQty();
    }  
     $finaltot;
    ?>
    <p class="saveclss"><span class="savepricecustm">Total Saving</span>
    <span class="saving_session_price">Rs <?php
    echo money_format("%i",$finaltot);//echo $_SESSION["saving_session_price"]; ?>
    </span></p>

Out Put:-Now you will see effect of code in cart page like bellow.

cart out put

Note:- Updating the theme will overwrite this code.

2
  • For those who have tax included prices in cart page use this :- $productPrice_orignal_price = Mage::helper('tax')->getPrice($item->getProduct(),$item->getProduct()->getPrice()); $discountedprice = Mage::helper('tax')->getPrice($item->getProduct(),$item->getProduct()->getFinalPrice());
    – KA9
    Commented Jul 28, 2016 at 10:51
  • But what if the product is configurable containing some child with a different price from the parent one?
    – WaPoNe
    Commented Oct 17, 2016 at 9:57
2

you can use like define $finaltot out side loop = 0

$finaltot = $finaltot + ( $todatlsaving * $this->getQty());

so final code will look like

<?php
    $product_orignalprice = $this->getProduct()->getPrice();
    $discountedprice=$_item->getPrice(); 
    $todatlsaving=$product_orignalprice-$discountedprice;
    $finaltot = $finaltot + ( $todatlsaving * $this->getQty());
    echo $finaltot;
?>

hope it will work for you.

3
  • i tried this code but its showing different price like 60 and 30 i wanted some thing like 90 Commented Jun 29, 2015 at 12:17
  • you can check code on pastebin.com/YMGvEmr7 on the line 96 to 100 Commented Jun 29, 2015 at 12:20
  • how do i stop loop here Commented Jun 29, 2015 at 12:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.