Пример #1
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;
     }
 }
Пример #2
0
$boolMulti = isset($_REQUEST['MULTI']) && 'Y' == $_REQUEST['MULTI'];
if (!$boolMulti) {
    $aTabs = array(array("DIV" => "sub_edit1", "TAB" => GetMessage("CDEN_TAB_DISCOUNT"), "ICON" => "catalog", "TITLE" => GetMessage("CDEN_TAB_DISCOUNT_DESCR")));
} else {
    $aTabs = array(array("DIV" => "sub_edit1", "TAB" => GetMessage("CDEN_TAB_DISCOUNT_MULTI"), "ICON" => "catalog", "TITLE" => ""));
}
$arPostParams = array('bxpublic' => 'Y');
if (0 < $intDiscountID) {
    $arPostParams['DISCOUNT_ID'] = $intDiscountID;
    $arPostParams['sessid'] = bitrix_sessid();
}
$arListUrl = array('LINK' => $APPLICATION->GetCurPageParam(), 'POST_PARAMS' => $arPostParams);
$errorMessage = "";
$bVarsFromForm = false;
$ID = intval($ID);
$arTypeList = Catalog\DiscountCouponTable::getCouponTypes(true);
if (!$bReadOnly && $_SERVER['REQUEST_METHOD'] == "POST" && !empty($_POST['Update']) && check_bitrix_sessid()) {
    if (!$boolMulti) {
        $DB->StartTransaction();
        $arFields = array("ACTIVE" => isset($_POST['ACTIVE']) && 'Y' == $_POST['ACTIVE'] ? 'Y' : 'N', "COUPON" => isset($_POST["COUPON"]) ? $_POST["COUPON"] : '', "DATE_APPLY" => isset($_POST['DATE_APPLY']) ? $_POST['DATE_APPLY'] : '', "ONE_TIME" => isset($_POST['ONE_TIME']) ? $_POST['ONE_TIME'] : '', "DESCRIPTION" => isset($_POST['DESCRIPTION']) ? $_POST['DESCRIPTION'] : '');
        if ($ID > 0) {
            $res = CCatalogDiscountCoupon::Update($ID, $arFields);
        } else {
            $arFields["DISCOUNT_ID"] = isset($_POST['DISCOUNT_ID']) ? $_POST['DISCOUNT_ID'] : 0;
            $ID = CCatalogDiscountCoupon::Add($arFields);
            $res = $ID > 0;
        }
        if (!$res) {
            if ($ex = $APPLICATION->GetException()) {
                $errorMessage .= $ex->GetString() . "<br>";
            } else {
Пример #3
0
        }
    }
}
$CAdminCalendar_ShowScript = '';
if (true == B_ADMIN_SUBCOUPONS_LIST) {
    $CAdminCalendar_ShowScript = CAdminCalendar::ShowScript();
}
$lAdmin->AddHeaders(array(array("id" => "ID", "content" => "ID", "sort" => "ID", "default" => true), array("id" => "ACTIVE", "content" => GetMessage("DSC_CPN_ACTIVE"), "sort" => "ACTIVE", "default" => true), array("id" => "COUPON", "content" => GetMessage("DSC_CPN_CPN"), "sort" => "COUPON", "default" => true), array("id" => "DATE_APPLY", "content" => GetMessage("DSC_CPN_DATE"), "sort" => "DATE_APPLY", "default" => true), array("id" => "ONE_TIME", "content" => GetMessage("DSC_CPN_TIME2"), "sort" => "ONE_TIME", "default" => true), array("id" => "DESCRIPTION", "content" => GetMessage("DSC_CPN_DESCRIPTION"), "sort" => "", "default" => false), array("id" => "MODIFIED_BY", "content" => GetMessage('DSC_MODIFIED_BY'), "sort" => "MODIFIED_BY", "default" => true), array("id" => "TIMESTAMP_X", "content" => GetMessage('DSC_TIMESTAMP_X'), "sort" => "TIMESTAMP_X", "default" => true), array("id" => "CREATED_BY", "content" => GetMessage('DSC_CREATED_BY'), "sort" => "CREATED_BY", "default" => false), array("id" => "DATE_CREATE", "content" => GetMessage('DSC_DATE_CREATE'), "sort" => "DATE_CREATE", "default" => false)));
$arSelectFieldsMap = array("ID" => false, "ACTIVE" => false, "COUPON" => false, "DATE_APPLY" => false, "ONE_TIME" => false, "DESCRIPTION" => false, "MODIFIED_BY" => false, "TIMESTAMP_X" => false, "CREATED_BY" => false, "DATE_CREATE" => false);
$arSelectFields = $lAdmin->GetVisibleHeaderColumns();
if (!in_array('ID', $arSelectFields)) {
    $arSelectFields[] = 'ID';
}
$arSelectFields = array_values($arSelectFields);
$arSelectFieldsMap = array_merge($arSelectFieldsMap, array_fill_keys($arSelectFields, true));
$arCouponType = Catalog\DiscountCouponTable::getCouponTypes(true);
$arUserList = array();
$arUserID = array();
$strNameFormat = CSite::GetNameFormat(true);
if (!(false == B_ADMIN_SUBCOUPONS_LIST && $bCopy)) {
    $arNavParams = isset($_REQUEST['mode']) && 'excel' == $_REQUEST["mode"] ? false : array("nPageSize" => CAdminSubResult::GetNavSize($sTableID, 20, $lAdmin->GetListUrl(true)));
    $dbResultList = CCatalogDiscountCoupon::GetList(array($by => $order), $arFilter, false, $arNavParams, $arSelectFields);
    $dbResultList = new CAdminSubResult($dbResultList, $sTableID, $lAdmin->GetListUrl(true));
    $dbResultList->NavStart();
    $lAdmin->NavText($dbResultList->GetNavPrint(htmlspecialcharsbx(GetMessage("DSC_NAV"))));
    $arRows = array();
    while ($arCouponDiscount = $dbResultList->Fetch()) {
        $edit_url = '/bitrix/admin/cat_subcoupon_edit.php?ID=' . $arCouponDiscount['ID'] . '&DISCOUNT_ID=' . $intDiscountID . '&lang=' . LANGUAGE_ID . '&TMP_ID=' . $strSubTMP_ID;
        $arCouponDiscount['ID'] = (int) $arCouponDiscount['ID'];
        if ($arSelectFieldsMap['CREATED_BY']) {
            $arCouponDiscount['CREATED_BY'] = (int) $arCouponDiscount['CREATED_BY'];
Пример #4
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;
 }
Пример #5
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;
 }