I have my module with my custom discount and it's OK.
config.xml:
<sales>
<quote>
<totals>
<aver>
<class>Dani_Prueba_Model_Total_Aver</class>
<after>subtotal</after>
</aver>
</totals>
</quote>
</sales>
My module:
<?php
class Dani_Prueba_Model_Total_Aver extends Mage_Sales_Model_Quote_Address_Total_Abstract{
public function collect(Mage_Sales_Model_Quote_Address $address){
$baseDiscount = 2.5;
$discount = Mage::app()->getStore()->convertPrice($baseDiscount);
$address->setCustomDiscount($baseDiscount);
$address->setBaseGrandTotal($address->getBaseGrandTotal() - $baseDiscount);
$address->setGrandTotal($address->getGrandTotal() - $discount);
return $this;
}
public function fetch(Mage_Sales_Model_Quote_Address $address){
$this->setCode('aver');
$amount = $address->getCustomDiscount();
if ($amount != 0){
$address->addTotal(array(
'code' => $this->getCode(),
'title' => 'Custom Discount',
'value' => $amount
));
}
return $this;
}
}
This it is OK and when I add a product to cart, automatically apply my custom discount.
But now I need do it with a button. When I add products to cart not apply discount and have the correct total. But when I click a button, apply my custom discount, and with other button "Cancel", cancel the discount. I need some similar like the function a coupon code.
How I do it??