Esempio n. 1
0
 /**
  * @deprecated deprecated since catalog 15.0.4
  * @see \Bitrix\Sale\DiscountCouponsManager::add
  *
  * @param int $intUserID				User id.
  * @param string $strCoupon			Coupon code.
  * @return bool
  */
 public static function SetCouponByManage($intUserID, $strCoupon)
 {
     $intUserID = (int) $intUserID;
     if ($intUserID >= 0) {
         if (self::$existCouponsManager === null) {
             self::initCouponManager();
         }
         if (self::$existCouponsManager) {
             if (DiscountCouponsManager::usedByManager() && DiscountCouponsManager::getUserId() == $intUserID) {
                 return DiscountCouponsManager::add($strCoupon);
             }
             return false;
         } else {
             $strCoupon = trim((string) $strCoupon);
             if (empty($strCoupon)) {
                 return false;
             }
             if (!isset($_SESSION['CATALOG_MANAGE_COUPONS']) || !is_array($_SESSION['CATALOG_MANAGE_COUPONS'])) {
                 $_SESSION['CATALOG_MANAGE_COUPONS'] = array();
             }
             if (!isset($_SESSION['CATALOG_MANAGE_COUPONS'][$intUserID]) || !is_array($_SESSION['CATALOG_MANAGE_COUPONS'][$intUserID])) {
                 $_SESSION['CATALOG_MANAGE_COUPONS'][$intUserID] = array();
             }
             $couponIterator = Catalog\DiscountCouponTable::getList(array('select' => array('ID', 'COUPON'), 'filter' => array('=COUPON' => $strCoupon, '=ACTIVE' => 'Y')));
             if ($existCoupon = $couponIterator->fetch()) {
                 if (!in_array($existCoupon['COUPON'], $_SESSION['CATALOG_MANAGE_COUPONS'][$intUserID])) {
                     $_SESSION['CATALOG_MANAGE_COUPONS'][$intUserID][] = $existCoupon['COUPON'];
                 }
                 return true;
             }
         }
     }
     return false;
 }
Esempio n. 2
0
 /**
  * @deprecated deprecated since catalog 15.0.4
  * @see \Bitrix\Sale\DiscountCouponsManager
  */
 public static function CouponApply($intUserID, $strCoupon)
 {
     if (self::$existCouponsManager === null) {
         self::initCouponManager();
     }
     if (self::$existCouponsManager) {
         $couponList = is_array($strCoupon) ? $strCoupon : array($strCoupon);
         return DiscountCouponsManager::setApplyByProduct(array('MODULE' => 'catalog'), $couponList, true);
     } else {
         global $DB;
         $mxResult = false;
         $intUserID = (int) $intUserID;
         if ($intUserID < 0) {
             $intUserID = 0;
         }
         $arCouponList = array();
         $arCheck = is_array($strCoupon) ? $strCoupon : array($strCoupon);
         foreach ($arCheck as &$strOneCheck) {
             $strOneCheck = (string) $strOneCheck;
             if ('' != $strOneCheck) {
                 $arCouponList[] = $strOneCheck;
             }
         }
         if (isset($strOneCheck)) {
             unset($strOneCheck);
         }
         if (empty($arCouponList)) {
             return $mxResult;
         }
         $strDateFunction = $DB->GetNowFunction();
         $boolFlag = false;
         $couponIterator = Catalog\DiscountCouponTable::getList(array('select' => array('ID', 'TYPE', 'COUPON'), 'filter' => array('=COUPON' => $arCouponList, '=ACTIVE' => 'Y')));
         while ($arCoupon = $couponIterator->fetch()) {
             $arCoupon['ID'] = (int) $arCoupon['ID'];
             $arFields = array("~DATE_APPLY" => $strDateFunction);
             if ($arCoupon['TYPE'] == Catalog\DiscountCouponTable::TYPE_ONE_ROW) {
                 $arFields["ACTIVE"] = "N";
                 if (0 < $intUserID) {
                     CCatalogDiscountCoupon::EraseCouponByManage($intUserID, $arCoupon['COUPON']);
                 } else {
                     CCatalogDiscountCoupon::EraseCoupon($arCoupon['COUPON']);
                 }
             } elseif ($arCoupon['TYPE'] == Catalog\DiscountCouponTable::TYPE_ONE_ORDER) {
                 $boolFlag = true;
                 if (!isset(self::$arOneOrderCoupons[$arCoupon['ID']])) {
                     self::$arOneOrderCoupons[$arCoupon['ID']] = array('COUPON' => $arCoupon['COUPON'], 'USER_ID' => $intUserID);
                 }
             }
             $strUpdate = $DB->PrepareUpdate("b_catalog_discount_coupon", $arFields);
             if (!empty($strUpdate)) {
                 $strSql = "UPDATE b_catalog_discount_coupon SET " . $strUpdate . " WHERE ID = " . $arCoupon['ID'];
                 $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
                 $mxResult = true;
             }
         }
         unset($arCoupon, $couponIterator);
         if ($boolFlag) {
             AddEventHandler('sale', 'OnBasketOrder', array('CCatalogDiscountCoupon', 'CouponOneOrderDisable'));
             AddEventHandler('sale', 'OnDoBasketOrder', array('CCatalogDiscountCoupon', 'CouponOneOrderDisable'));
         }
         return $mxResult;
     }
 }
Esempio n. 3
0
 /**
  * Check coupon for convert.
  *
  * @param string $coupon				Coupon.
  * @return bool
  * @throws Main\ArgumentException
  * @throws Main\LoaderException
  */
 private static function checkMigrateCoupon($coupon)
 {
     if (self::$catalogIncluded === null) {
         self::$catalogIncluded = Main\Loader::includeModule('catalog');
     }
     if (!self::$catalogIncluded) {
         return false;
     }
     static $catalogCouponTypes = null;
     if ($catalogCouponTypes === null) {
         $catalogCouponTypes = array(Catalog\DiscountCouponTable::TYPE_ONE_ROW => Internals\DiscountCouponTable::TYPE_BASKET_ROW, Catalog\DiscountCouponTable::TYPE_ONE_ORDER => Internals\DiscountCouponTable::TYPE_ONE_ORDER, Catalog\DiscountCouponTable::TYPE_NO_LIMIT => Internals\DiscountCouponTable::TYPE_MULTI_ORDER);
     }
     if (!isset(self::$migrateCouponsCache[$coupon])) {
         self::$migrateCouponsCache[$coupon] = false;
         $couponIterator = Catalog\DiscountCouponTable::getList(array('select' => array('COUPON_ID' => 'ID', 'COUPON', 'TYPE', 'DISCOUNT_ID', 'DISCOUNT_NAME' => 'DISCOUNT.NAME'), 'filter' => array('=COUPON' => $coupon)));
         $existCoupon = $couponIterator->fetch();
         unset($couponIterator);
         if (!empty($existCoupon)) {
             $existCoupon['TYPE'] = isset($catalogCouponTypes[$existCoupon['TYPE']]) ? $catalogCouponTypes[$existCoupon['TYPE']] : Internals\DiscountCouponTable::TYPE_ARCHIVED;
             $existCoupon['DATA'] = array('MODE' => DiscountCouponsManager::COUPON_MODE_SIMPLE, 'MODULE' => 'catalog', 'DISCOUNT_ID' => 0, 'TYPE' => Internals\DiscountCouponTable::TYPE_ARCHIVED, 'USER_INFO' => array());
             self::$migrateCouponsCache[$coupon] = $existCoupon;
         } else {
             self::$migrateCouponsCache[$coupon] = self::createEmptyCoupon($coupon);
         }
         unset($existCoupon);
     }
     return true;
 }