Пример #1
0
 /**
  * Add cart rules to surcharges
  */
 public function findSurcharges(IsotopeProductCollection $objCollection)
 {
     // The checkout review pages shows an order, but we need the cart
     // Only the cart contains coupons etc.
     if ($objCollection instanceof Order) {
         $objCollection = $objCollection->getRelated('source_collection_id');
     }
     // Rules should only be applied to Cart, not any other product collection
     if (!$objCollection instanceof Cart) {
         return array();
     }
     $arrSurcharges = array();
     $objRules = Rule::findForCart();
     if (null !== $objRules) {
         while ($objRules->next()) {
             $objSurcharge = RuleSurcharge::createForRuleInCollection($objRules->current(), $objCollection);
             if (null !== $objSurcharge) {
                 $arrSurcharges[] = $objSurcharge;
             }
         }
     }
     $arrCoupons = deserialize($objCollection->coupons);
     if (!empty($arrCoupons) && is_array($arrCoupons)) {
         $arrDropped = array();
         foreach ($arrCoupons as $code) {
             $objRule = Rule::findOneByCouponCode($code, $objCollection->getItems());
             if (null === $objRule) {
                 $arrDropped[] = $code;
             } else {
                 // cart rules should total all eligible products for the cart discount and apply the discount to that amount rather than individual products.
                 $objSurcharge = RuleSurcharge::createForRuleInCollection($objRule, $objCollection);
                 if (null !== $objSurcharge) {
                     $arrSurcharges[] = $objSurcharge;
                 }
             }
         }
         if (!empty($arrDropped)) {
             // @todo show dropped coupons
             $arrCoupons = array_diff($arrCoupons, $arrDropped);
             \Database::getInstance()->query("UPDATE tl_iso_product_collection SET coupons='" . serialize($arrCoupons) . "' WHERE id=" . (int) Isotope::getCart()->id);
         }
     }
     return $arrSurcharges;
 }