title: How to set Dynamic Discount on each Cart Item programmatically?
body: <p>I want to set the Discount (say $10) per Item dynamically, after a custom button is pressed, in the Checkout Cart page. I have checked some of the coding of Magento, to find that:</p>
  <ul>
  <li>Mainly the &quot;<code>Mage_Sales_Model_Quote_Address</code>&quot; class is affected always, when anybody (any Magento code) is talking about discount.</li>
  <li>There are 2 instances of &quot;<code>Mage_Sales_Model_Quote_Address</code>&quot; - one for &quot;<strong>billing</strong>&quot; address type &amp; the other for &quot;<strong>shipping</strong>&quot; address type, but the latter one is mainly used for coupon code related discounts.</li>
  </ul>
  <p>After checking these area, I went on to write some code, targeting the &quot;<strong>shipping</strong>&quot; address type of &quot;<code>Mage_Sales_Model_Quote_Address</code>&quot;, as:-</p>
  <pre><code>$cart = Mage::getSingleton('checkout/cart');
  $objShippingAddress = $cart-&gt;getQuote()-&gt;getShippingAddress();
  $discountAmount = 10;
  
  $objShippingAddress-&gt;setDiscountDescription('any description');
  $objShippingAddress-&gt;addTotal(array(
      'code' =&gt; 'discount',
      'title' =&gt; &quot;Custom Discount&quot;,
      'value' =&gt; -$discountAmount,
  ));
  
  $totalDiscountAmount = $discountAmount;
  $subtotalWithDiscount = $discountAmount;
  $baseTotalDiscountAmount = $discountAmount;
  $baseSubtotalWithDiscount = $discountAmount;
  
  $objShippingAddress-&gt;setDiscountAmount($totalDiscountAmount);
  $objShippingAddress-&gt;setSubtotalWithDiscount($subtotalWithDiscount);
  $objShippingAddress-&gt;setBaseDiscountAmount($baseTotalDiscountAmount);
  $objShippingAddress-&gt;setBaseSubtotalWithDiscount($baseSubtotalWithDiscount);
  
  $objShippingAddress-&gt;setGrandTotal($objShippingAddress-&gt;getGrandTotal() - $objShippingAddress-&gt;getDiscountAmount());
  $objShippingAddress-&gt;setBaseGrandTotal($objShippingAddress-&gt;getBaseGrandTotal() - $objShippingAddress-&gt;getBaseDiscountAmount());
  </code></pre>
  <p>But still I don't get any line in the &quot;<code>totals</code>&quot; section of my checkout cart page &amp; in the order review section of checkout one-page.</p>