Ejemplo n.º 1
0
 public function applyCoupons()
 {
     global $aecConfig;
     if (empty($aecConfig->cfg['checkout_coupons']) && empty($aecConfig->cfg['confirmation_coupons']) && empty($this->invoice->coupons)) {
         return null;
     }
     $coupons = $this->invoice->coupons;
     $cpsh = new couponsHandler($this->metaUser, $this, $coupons);
     if (!empty($this->cartobject) && !empty($this->cart)) {
         $this->items->itemlist = $cpsh->applyToCart($this->items->itemlist, $this->cartobject, $this->cart);
         if (count($cpsh->delete_list)) {
             foreach ($cpsh->delete_list as $couponcode) {
                 $this->invoice->removeCoupon($couponcode);
             }
             $this->invoice->storeload();
         }
         if ($cpsh->affectedCart) {
             // Reload cart object and cart - was changed by $cpsh
             $this->cartobject->reload();
             $this->getCart();
             $cpsh = new couponsHandler($this->metaUser, $this, $coupons);
             $this->items->itemlist = $cpsh->applyToCart($this->items->itemlist, $this->cartobject, $this->cart);
         }
     } else {
         $this->items->itemlist = $cpsh->applyToItemList($this->items->itemlist);
         if (count($cpsh->delete_list)) {
             foreach ($cpsh->delete_list as $couponcode) {
                 $this->invoice->removeCoupon($couponcode);
             }
             $this->invoice->storeload();
         }
     }
     $cpsh_err = $cpsh->getErrors();
     if (!empty($cpsh_err)) {
         $this->errors = $cpsh_err;
     }
     if (!empty($this->cartobject) && !empty($this->cart)) {
         $cpsh_exc = $cpsh->getExceptions();
         if (count($cpsh_exc)) {
             foreach ($cpsh_exc as $exception) {
                 $this->raiseException($exception);
             }
         }
     }
     if (!empty($this->cartobject) && !empty($this->cart)) {
         $this->items = $cpsh->applyToTotal($this->items, $this->cartobject, $this->cart);
     } else {
         $this->items = $cpsh->applyToTotal($this->items);
     }
     if (!empty($this->cart)) {
         $this->payment->amount = $this->cartobject->getAmount($this->metaUser, 0, $this);
     }
 }