Add discount programmatically in Opencart

To add the discount in opencart programmatically follow the following steps:

1. Open <projectFolder>/catalog/model/total/coupon.php
2. Add the code in the getTotal() function

$discount_total=0;
if($total>=0 && $total<=500){
  $discount_total=$total*0.1;
}else if($total>500 && $total<=1000){
  $discount_total=$total*0.2;
}else if($total>1000 && $total<=10000){
  $discount_total=$total*0.3;
}
*/
$total_data[] = array(
'code'       => 'discount',
'title'      => sprintf("My Special Discount"),
'value'      => -$discount_total,
'sort_order' => 4
);

3. Now add the products in the cart
4. Goto Cart page check your order info (See the sample screenshot)



Popular posts from this blog

What are EAR, JAR and WAR files in J2EE?

ATG Issue - ConcurrentUpdateException - on BCC Deployment

How the competition helps to reduce the price of TEA?