/**
  * Fill discount list for update use coupons flag.
  *
  * @param array|int $discountList			Discount ids for check.
  * @return void
  */
 public static function setDiscountCheckList($discountList)
 {
     if (!is_array($discountList)) {
         $discountList = array($discountList => $discountList);
     }
     if (!empty($discountList)) {
         self::$discountCheckList = empty(self::$discountCheckList) ? $discountList : array_merge(self::$discountCheckList, $discountList);
     }
 }
Esempio n. 2
0
 /**
  * Update use coupon flag for discount list.
  *
  * @return void
  */
 public static function updateUseCoupons()
 {
     if (!self::isCheckedCouponsUse() || empty(self::$discountCheckList)) {
         return;
     }
     Main\Type\Collection::normalizeArrayValuesByInt(self::$discountCheckList);
     if (empty(self::$discountCheckList)) {
         return;
     }
     $withoutCoupons = array_fill_keys(self::$discountCheckList, true);
     $withCoupons = array();
     $couponIterator = DiscountCouponTable::getList(array('select' => array('DISCOUNT_ID', new Main\Entity\ExpressionField('CNT', 'COUNT(*)')), 'filter' => array('@DISCOUNT_ID' => self::$discountCheckList), 'group' => array('DISCOUNT_ID')));
     while ($coupon = $couponIterator->fetch()) {
         $coupon['CNT'] = (int) $coupon['CNT'];
         if ($coupon['CNT'] > 0) {
             $coupon['DISCOUNT_ID'] = (int) $coupon['DISCOUNT_ID'];
             unset($withoutCoupons[$coupon['DISCOUNT_ID']]);
             $withCoupons[$coupon['DISCOUNT_ID']] = true;
         }
     }
     unset($coupon, $couponIterator);
     if (!empty($withoutCoupons)) {
         $withoutCoupons = array_keys($withoutCoupons);
         DiscountTable::setUseCoupons($withoutCoupons, 'N');
     }
     if (!empty($withCoupons)) {
         $withCoupons = array_keys($withCoupons);
         DiscountTable::setUseCoupons($withCoupons, 'Y');
     }
     unset($withCoupons, $withoutCoupons);
     self::$discountCheckList = array();
 }