Пример #1
0
 /**
  * Callback for checkout Hook. Transfer active rules to usage table.
  */
 public function writeRuleUsages($objOrder)
 {
     $objCart = Cart::findByPk($objOrder->source_collection_id);
     $objRules = Rule::findActiveWitoutCoupons();
     $arrRules = null === $objRules ? array() : $objRules->fetchEach('id');
     $arrCoupons = deserialize($objCart->coupons);
     if (is_array($arrCoupons) && !empty($arrCoupons)) {
         $blnError = false;
         foreach ($arrCoupons as $k => $code) {
             $objRule = Rule::findOneByCouponCode($code, $objCart->getItems());
             if (null === $objRule) {
                 Message::addError(sprintf($GLOBALS['TL_LANG']['ERR']['couponCodeDropped'], $code));
                 unset($arrCoupons[$k]);
                 $blnError = true;
             } else {
                 $arrRules[] = $objRule->id;
             }
         }
         if ($blnError) {
             $objCart->coupons = $arrCoupons;
             return false;
         }
     }
     if (!empty($arrRules)) {
         $time = time();
         \Database::getInstance()->query("INSERT INTO tl_iso_rule_usage (pid,tstamp,order_id,config_id,member_id) VALUES (" . implode(", {$time}, {$objOrder->id}, " . (int) Isotope::getConfig()->id . ", {$objOrder->member}), (", $arrRules) . ", {$time}, {$objOrder->id}, " . (int) Isotope::getConfig()->id . ", {$objOrder->member})");
     }
     return true;
 }