/**
  * Get coupon details and calculate the value
  * @author Oscar van Eijk
  * @param $_code Coupon code
  */
 protected function couponHandler($_code)
 {
     JPluginHelper::importPlugin('vmcoupon');
     $dispatcher = JDispatcher::getInstance();
     $returnValues = $dispatcher->trigger('plgVmCouponHandler', array($_code, &$this->_cartData, &$this->_cartPrices));
     if (!empty($returnValues)) {
         foreach ($returnValues as $returnValue) {
             if ($returnValue !== null) {
                 return $returnValue;
             }
         }
     }
     if (!class_exists('CouponHelper')) {
         require JPATH_VM_SITE . DS . 'helpers' . DS . 'coupon.php';
     }
     if (!($_data = CouponHelper::getCouponDetails($_code))) {
         return;
         // TODO give some error here
     }
     $_value_is_total = $_data->percent_or_total == 'total';
     $this->_cartData['couponCode'] = $_code;
     $this->_cartData['couponDescr'] = $_value_is_total ? '' : round($_data->coupon_value) . '%';
     $this->_cartPrices['salesPriceCoupon'] = $_value_is_total ? $_data->coupon_value * -1 : $this->_cartPrices['salesPrice'] * ($_data->coupon_value / 100) * -1;
     // TODO Calculate the tax
     $this->_cartPrices['couponTax'] = 0;
     $this->_cartPrices['couponValue'] = $this->_cartPrices['salesPriceCoupon'] - $this->_cartPrices['couponTax'];
     //$this->_cartPrices['billTotal'] -= $this->_cartPrices['salesPriceCoupon'];
     //if($this->_cartPrices['billTotal'] < 0){
     //	$this->_cartPrices['billTotal'] = 0.0;
     //}
 }
Exemple #2
0
 /**
  * Get coupon details and calculate the value
  * @author Oscar van Eijk
  * @param $_code Coupon code
  */
 protected function couponHandler($_code)
 {
     JPluginHelper::importPlugin('vmcoupon');
     $dispatcher = JDispatcher::getInstance();
     $returnValues = $dispatcher->trigger('plgVmCouponHandler', array($_code, &$this->_cart->cartData, &$this->_cart->cartPrices));
     if (!empty($returnValues)) {
         foreach ($returnValues as $returnValue) {
             if ($returnValue !== null) {
                 return $returnValue;
             }
         }
     }
     if (!class_exists('CouponHelper')) {
         require VMPATH_SITE . DS . 'helpers' . DS . 'coupon.php';
     }
     if (!($_data = CouponHelper::getCouponDetails($_code))) {
         return;
         // TODO give some error here
     }
     vmdebug('my  coupon data', $_data);
     $_value_is_total = $_data->percent_or_total == 'total';
     $this->_cart->cartData['couponCode'] = $_code;
     if ($_value_is_total) {
         $this->_cart->cartData['couponDescr'] = $this->_currencyDisplay->priceDisplay($_data->coupon_value);
     } else {
         $this->_cart->cartData['couponDescr'] = rtrim(rtrim($_data->coupon_value, '0'), '.') . ' %';
     }
     $this->_cart->cartPrices['salesPriceCoupon'] = $_value_is_total ? $_data->coupon_value * -1 : $this->_cart->cartPrices['salesPrice'] * ($_data->coupon_value / 100) * -1;
     $this->_cart->cartPrices['couponTax'] = 0;
     $this->_cart->cartPrices['couponValue'] = $this->_cart->cartPrices['salesPriceCoupon'] - $this->_cart->cartPrices['couponTax'];
 }