Author Topic: Coupon - Activated only when total exceeds 50€/USD  (Read 2675 times)

Amukinado

  • Beginner
  • *
  • Posts: 9
Coupon - Activated only when total exceeds 50€/USD
« on: November 17, 2009, 19:37:01 pm »
Hi. I did thi on my own, but i'm still very fresh to PHP.
I hacked 3 files to make my coupons only active if the total amount of the order is biger then 50.

The problem is that, when have a product that is 29€(example), and you add 2 of this products to the cart, everithing is good until here, but if you go to see the cart, and alter the quantity from 2, to 1, the message saying that the coupon is only valid for orders bigger than 50€, shows up twice. I'll post the code and the duplicated message. Feel free to use this code, and if you can change it in order to make the message  show up only once, i would apreciate it.

Added this line to my language file  -
/administrator/components/com_virtuemart/languages/common

Code: [Select]

'PHPSHOP_DOWNLOAD_VALID_UNTIL' => ' until {date}',
//hack begin
'MODCOUPON_MIN50' => 'O cupão só é válido para encomendas superiores a 50€'
//hack end
); $VM_LANG->initModule( 'common', $langvars );
?>


This one goes around line 194, on coupon.php -(i added the IF's)
/administrator/components/com_virtuemart/classes

Code: [Select]
if ($coupon_db->f("percent_or_total") == "percent")

            {

                /* percent */    

                //$subtotal = $checkout->calc_order_subtotal( $d );

                

                /* take the subtotal for calculation of the discount */

                //$_SESSION['coupon_discount'] = round( ($subtotal * $coupon_db->f("coupon_value") / 100), 2);

                
                 //Hack begin para que vale de desconto só funcione com encomendas superiores a 50€


if ($d["total"]>=50){
$coupon_value = round( ($d["total"] * $coupon_db->f("coupon_value") / 100), 2);
}
if ($d["total"]<50){ echo "<b>".$VM_LANG->_('MODCOUPON_MIN50')."</b>";}
//hack end


                

                 if( $d["total"] < $coupon_value ) {

                   $coupon_value = (float)$d['total'] +(float)$d['order_tax'] ;

                   $vmLogger->info( str_replace('{value}',$GLOBALS['CURRENCY_DISPLAY']->getFullValue( $coupon_value ),$VM_LANG->_('VM_COUPON_GREATER_TOTAL_SETTO')) );

                }

The total when you remove all products was the previous disccount *(-1)
Hacked it to show up 0 beacuse when you add another product it calculates everything right.

shop.basket_short.php(or in my template, could be mod_virtuemart_s5_dropdown_cart.php)

line 117

Code: [Select]
if( !empty($_SESSION['coupon_discount']) ) {

$total -= $_SESSION['coupon_discount'];
//hack begin para recolocar o total a 0, quando é aplicado o desconto e retirado o produto do carrinho.
if ($total<0){ $total=0;}
//hack final para recolocar o total a 0, quando é aplicado o desconto e retirado o produto do carrinho.

}

Duplicated message.



Enjoy it, and help make it better! Thanks