 <p>There is an event in magento,</p> <pre><code>sales_quote_collect_totals_after </code></pre> <p>This is fired whenever your total is calculated, what you can do is set a flag in session on click on the button to apply discount, and in this above event's observer method, check if it is set then apply discount.</p> <p>In your config.xml</p> <pre><code>&lt;global&gt; &lt;events&gt; &lt;sales_quote_collect_totals_after&gt; &lt;observers&gt; &lt;class&gt;Custom_Module_Model_Observer&lt;/class&gt; &lt;method&gt;collectTotals&lt;/method&gt; &lt;/observers&gt; &lt;/sales_quote_collect_totals_after&gt; &lt;/events&gt; &lt;/global&gt; </code></pre> <p>Make a Observer.php in</p> <pre><code>Custom /Module /Model /Observer.php </code></pre> <p>Make a function in Observer.php</p> <pre><code>public function collectTotals(Varien_Event_Observer $observer) { $quote=$observer-&gt;getEvent()-&gt;getQuote(); $quoteid=$quote-&gt;getId(); //check condition here if need to apply Discount if($disocuntApply) $discountAmount =5; if($quoteid) { if($discountAmount&gt;0) { $total=$quote-&gt;getBaseSubtotal(); $quote-&gt;setSubtotal(0); $quote-&gt;setBaseSubtotal(0); $quote-&gt;setSubtotalWithDiscount(0); $quote-&gt;setBaseSubtotalWithDiscount(0); $quote-&gt;setGrandTotal(0); $quote-&gt;setBaseGrandTotal(0); $canAddItems = $quote-&gt;isVirtual()? ('billing') : ('shipping'); foreach ($quote-&gt;getAllAddresses() as $address) { $address-&gt;setSubtotal(0); $address-&gt;setBaseSubtotal(0); $address-&gt;setGrandTotal(0); $address-&gt;setBaseGrandTotal(0); $address-&gt;collectTotals(); $quote-&gt;setSubtotal((float) $quote-&gt;getSubtotal() + $address-&gt;getSubtotal()); $quote-&gt;setBaseSubtotal((float) $quote-&gt;getBaseSubtotal() + $address-&gt;getBaseSubtotal()); $quote-&gt;setSubtotalWithDiscount( (float) $quote-&gt;getSubtotalWithDiscount() + $address-&gt;getSubtotalWithDiscount() ); $quote-&gt;setBaseSubtotalWithDiscount( (float) $quote-&gt;getBaseSubtotalWithDiscount() + $address-&gt;getBaseSubtotalWithDiscount() ); $quote-&gt;setGrandTotal((float) $quote-&gt;getGrandTotal() + $address-&gt;getGrandTotal()); $quote-&gt;setBaseGrandTotal((float) $quote-&gt;getBaseGrandTotal() + $address-&gt;getBaseGrandTotal()); $quote -&gt;save(); $quote-&gt;setGrandTotal($quote-&gt;getBaseSubtotal()-$discountAmount) -&gt;setBaseGrandTotal($quote-&gt;getBaseSubtotal()-$discountAmount) -&gt;setSubtotalWithDiscount($quote-&gt;getBaseSubtotal()-$discountAmount) -&gt;setBaseSubtotalWithDiscount($quote-&gt;getBaseSubtotal()-$discountAmount) -&gt;save(); if($address-&gt;getAddressType()==$canAddItems) { $address-&gt;setSubtotalWithDiscount((float) $address-&gt;getSubtotalWithDiscount()-$discountAmount); $address-&gt;setGrandTotal((float) $address-&gt;getGrandTotal()-$discountAmount); $address-&gt;setBaseSubtotalWithDiscount((float) $address-&gt;getBaseSubtotalWithDiscount()-$discountAmount); $address-&gt;setBaseGrandTotal((float) $address-&gt;getBaseGrandTotal()-$discountAmount); if($address-&gt;getDiscountDescription()){ $address-&gt;setDiscountAmount(-($address-&gt;getDiscountAmount()-$discountAmount)); $address-&gt;setDiscountDescription($address-&gt;getDiscountDescription().', Amount Waived'); $address-&gt;setBaseDiscountAmount(-($address-&gt;getBaseDiscountAmount()-$discountAmount)); }else { $address-&gt;setDiscountAmount(-($discountAmount)); $address-&gt;setDiscountDescription('Amount Waived'); $address-&gt;setBaseDiscountAmount(-($discountAmount)); } $address-&gt;save(); }//end: if } //end: foreach //echo $quote-&gt;getGrandTotal(); foreach($quote-&gt;getAllItems() as $item){ //We apply discount amount based on the ratio between the GrandTotal and the RowTotal $rat=$item-&gt;getPriceInclTax()/$total; $ratdisc=$discountAmount*$rat; $item-&gt;setDiscountAmount(($item-&gt;getDiscountAmount()+$ratdisc) * $item-&gt;getQty()); $item-&gt;setBaseDiscountAmount(($item-&gt;getBaseDiscountAmount()+$ratdisc) * $item-&gt;getQty())-&gt;save(); } } } } </code></pre> <p><code>collectTotals</code> function will be called, whenever the quote totals is updated, so there is no need to call it explicitly.</p> <p>Check for how it works <a href="http://www.aschroder.com/2010/01/magento-events-explained-and-a-few-gotchas-avoided/" rel="nofollow">here</a>.</p> <p>Setting magento session variables, check <a href="http://www.apptha.com/blog/how-to-set-retrieve-and-unset-session-variables-in-magento/" rel="nofollow">here</a>.</p> <p>hope it helps!</p>