26 private const NOTIFY_DISCOUNT_REINDEX_ID =
'CATALOG_DISC_FORMAT';
41 static private $needDiscountCache = [];
43 private static function calculatePriceByDiscount($basePrice, $currentPrice, $oneDiscount, &$needErase)
45 $calculatePrice =
false;
46 switch ($oneDiscount[
'VALUE_TYPE'])
48 case self::TYPE_PERCENT:
50 -(self::$getPercentFromBasePrice ? $basePrice : $currentPrice) * $oneDiscount[
'VALUE'] / 100
52 if (isset($oneDiscount[
'DISCOUNT_CONVERT']) && $oneDiscount[
'DISCOUNT_CONVERT'] > 0)
54 if ($discountValue + $oneDiscount[
'DISCOUNT_CONVERT'] <= 0)
55 $discountValue = -$oneDiscount[
'DISCOUNT_CONVERT'];
57 $needErase = ($currentPrice + $discountValue < 0);
60 $calculatePrice = $currentPrice + $discountValue;
62 unset($discountValue);
65 $needErase = ($oneDiscount[
'DISCOUNT_CONVERT'] > $currentPrice);
68 $calculatePrice = $currentPrice - $oneDiscount[
'DISCOUNT_CONVERT'];
72 $needErase = ($oneDiscount[
'DISCOUNT_CONVERT'] >= $currentPrice);
75 $calculatePrice = $oneDiscount[
'DISCOUNT_CONVERT'];
83 return $calculatePrice;
93 || (
string)
Option::get(
'sale',
'use_sale_discount_only') !==
'N')
100 [
'MODULE_ID' =>
'catalog',
'TAG' => self::NOTIFY_DISCOUNT_REINDEX_ID]
111 'select' => [
'ID',
'DEF'],
112 'filter' => [
'=ACTIVE' =>
'Y']
116 if ($defaultLang ==
'')
117 $defaultLang = $row[
'ID'];
118 if ($row[
'DEF'] ==
'Y')
119 $defaultLang = $row[
'ID'];
120 $languageId = $row[
'ID'];
126 'CATALOG_DISCOUNT_REINDEX_MESS',
127 [
'#LANGUAGE_ID#' => $languageId],
136 'MODULE_ID' =>
'catalog',
137 'TAG' => self::NOTIFY_DISCOUNT_REINDEX_ID,
138 'ENABLE_CLOSE' =>
'Y',
151 $boolFull = ($boolFull ===
true);
170 if (self::$useSaleDiscount)
172 self::$getPriceTypesOnly = ($priceTypesOnly ===
true);
183 if (self::$getPercentFromBasePrice ===
null)
185 return self::$getPercentFromBasePrice;
196 if ($useBasePrice !==
true && $useBasePrice !==
false)
198 self::$getPercentFromBasePrice = $useBasePrice;
216 $boolValueType =
false;
223 $clearFields =
array(
243 $clearFields[] =
'CREATED_BY';
245 foreach ($clearFields as &$fieldName)
250 unset($fieldName, $clearFields);
253 $arFields[
'VERSION'] = self::CURRENT_FORMAT;
257 $boolValueType =
true;
267 'VALUE_TYPE' => self::TYPE_PERCENT,
268 'MIN_ORDER_SUM' => 0,
270 'LAST_DISCOUNT' =>
'Y'
293 $arMsg[] =
array(
'id' =>
'VALUE',
'text' =>
Loc::getMessage(
'BT_MOD_CATALOG_DISC_ERR_BAD_VALUE'));
298 $arMsg[] =
array(
'id' =>
'CONDITIONS',
'text' =>
Loc::getMessage(
'BT_MOD_CATALOG_DISC_ERR_EMPTY_CONDITIONS'));
313 $boolValueType = isset(
$arFields[
'VALUE_TYPE']);
315 if ($boolValueType != $boolValue)
322 array(
'ID',
'VALUE_TYPE',
'VALUE')
324 if ($arCurrent = $rsDiscounts->Fetch())
326 $arCurrent[
'VALUE'] = doubleval($arCurrent[
'VALUE']);
370 if (!
$DB->IsDate(
$arFields[
'ACTIVE_FROM'],
false, LANGUAGE_ID,
'FULL'))
377 if (!
$DB->IsDate(
$arFields[
'ACTIVE_TO'],
false, LANGUAGE_ID,
'FULL'))
420 $arFields[
'VALUE_TYPE'] = self::TYPE_PERCENT;
429 $arMsg[] =
array(
'id' =>
'VALUE',
'text' =>
Loc::getMessage(
'BT_MOD_CATALOG_DISC_ERR_BAD_VALUE'));
434 if ($boolValue != $boolValueType)
438 $arFields[
'VALUE'] = $arCurrent[
'VALUE'];
443 $arFields[
'VALUE_TYPE'] = $arCurrent[
'VALUE_TYPE'];
444 $boolValueType =
true;
448 if ($boolValue && $boolValueType)
453 $arMsg[] =
array(
'id' =>
'VALUE',
'text' =>
Loc::getMessage(
"BT_MOD_CATALOG_DISC_ERR_BAD_VALUE"));
481 $arMsg[] =
array(
'id' =>
'CONDITIONS',
'text' =>
Loc::getMessage(
"BT_MOD_CATALOG_DISC_ERR_EMPTY_CONDITIONS"));
485 $usedHandlers =
array();
486 $usedEntities =
array();
495 $arMsg[] =
array(
'id' =>
'CONDITIONS',
'text' =>
Loc::getMessage(
"BT_MOD_CATALOG_DISC_ERR_BAD_CONDITIONS"));
499 $arFields[
'CONDITIONS'] = unserialize(
$arFields[
'CONDITIONS'], [
'allowed_classes' =>
false]);
504 $arMsg[] =
array(
'id' =>
'CONDITIONS',
'text' =>
Loc::getMessage(
"BT_MOD_CATALOG_DISC_ERR_BAD_CONDITIONS"));
516 $strEval = $obCond->Generate(
$arFields[
'CONDITIONS'],
array(
'FIELD' =>
'$arProduct'));
517 if (empty($strEval) ||
'false' == $strEval)
521 $arMsg[] =
array(
'id' =>
'CONDITIONS',
'text' =>
Loc::getMessage(
"BT_MOD_CATALOG_DISC_ERR_BAD_CONDITIONS"));
525 $usedHandlers = $obCond->GetConditionHandlers();
526 $usedEntities = $obCond->GetUsedEntityList();
533 if (!empty($usedHandlers))
535 if (!empty($usedEntities))
538 if (
$DB->type ==
'MYSQL')
543 $arMsg[] =
array(
'id' =>
'CONDITIONS',
'text' =>
Loc::getMessage(
'BT_MOD_CATALOG_DISC_ERR_CONDITIONS_TOO_LONG'));
545 $arFields[
'CONDITIONS'] = unserialize(
$arFields[
'CONDITIONS'], [
'allowed_classes' =>
false]);
556 $intUserID = (int)
$USER->GetID();
557 $strDateFunction =
$DB->GetNowFunction();
558 $arFields[
'~TIMESTAMP_X'] = $strDateFunction;
566 $arFields[
'~DATE_CREATE'] = $strDateFunction;
585 foreach (
GetModuleEvents(
"catalog",
"OnBeforeDiscountAdd",
true) as $arEvent)
592 if (empty($mxRows) || !is_array($mxRows))
595 $boolNewVersion =
true;
596 if (!array_key_exists(
'CONDITIONS',
$arFields))
599 $boolNewVersion =
false;
610 if (is_array($arValuesList) && !empty($arValuesList))
626 'DISCOUNT_ID' =>
$ID,
627 'MODULE_ID' =>
$entity[
'MODULE'],
629 'FIELD_ENTITY' =>
$entity[
'FIELD_ENTITY'],
631 if (isset(
$entity[
'ENTITY_ID']))
633 if (isset(
$entity[
'ENTITY_VALUE']))
635 if (is_array(
$fields[
'FIELD_ENTITY']))
637 if (isset(
$entity[
'FIELD_TABLE']) && is_array(
$entity[
'FIELD_TABLE']))
639 foreach (
$entity[
'FIELD_TABLE'] as $oneField)
641 if (empty($oneField))
643 $fields[
'FIELD_TABLE'] = $oneField;
658 if (!is_array(
$arFields[
"CATALOG_COUPONS"]))
661 "DISCOUNT_ID" =>
$ID,
664 "COUPON" =>
$arFields[
"CATALOG_COUPONS"],
665 "DATE_APPLY" =>
false
669 $arKeys = array_keys(
$arFields[
"CATALOG_COUPONS"]);
670 if (!is_array(
$arFields[
"CATALOG_COUPONS"][$arKeys[0]]))
673 foreach (
$arFields[
"CATALOG_COUPONS"] as &$arOneCoupon)
675 if (!empty($arOneCoupon[
'COUPON']))
677 $arOneCoupon[
'DISCOUNT_ID'] =
$ID;
681 if (isset($arOneCoupon))
686 foreach (
GetModuleEvents(
"catalog",
"OnDiscountAdd",
true) as $arEvent)
700 foreach (
GetModuleEvents(
"catalog",
"OnBeforeDiscountUpdate",
true) as $arEvent)
706 $boolExistUserGroups = (isset(
$arFields[
'GROUP_IDS']) && is_array(
$arFields[
'GROUP_IDS']));
707 $boolExistPriceTypes = (isset(
$arFields[
'CATALOG_GROUP_IDS']) && is_array(
$arFields[
'CATALOG_GROUP_IDS']));
708 $boolUpdateRestrictions = $boolExistUserGroups || $boolExistPriceTypes || isset(
$arFields[
'ACTIVE']);
711 if ($boolUpdateRestrictions)
713 if (!$boolExistUserGroups)
718 if (!$boolExistPriceTypes)
724 if (empty($mxRows) || !is_array($mxRows))
728 $boolNewVersion =
true;
729 if (!array_key_exists(
'CONDITIONS',
$arFields))
732 $boolNewVersion =
false;
741 if (is_array($arValuesList) && !empty($arValuesList))
749 if ($boolUpdateRestrictions)
761 'filter' => [
'=DISCOUNT_ID' =>
$ID],
762 'order' => [
'ID' =>
'ASC']
769 'DISCOUNT_ID' =>
$ID,
770 'MODULE_ID' =>
$entity[
'MODULE'],
772 'FIELD_ENTITY' =>
$entity[
'FIELD_ENTITY'],
774 if (isset(
$entity[
'ENTITY_ID']))
776 if (isset(
$entity[
'ENTITY_VALUE']))
778 if (is_array(
$fields[
'FIELD_ENTITY']))
780 if (isset(
$entity[
'FIELD_TABLE']) && is_array(
$entity[
'FIELD_TABLE']))
782 foreach (
$entity[
'FIELD_TABLE'] as $oneField)
784 if (empty($oneField))
786 $fields[
'FIELD_TABLE'] = $oneField;
787 if (!empty($entityIds))
789 $rowId = array_shift($entityIds);
802 if (!empty($entityIds))
804 $rowId = array_shift($entityIds);
814 if (!empty($entityIds))
816 foreach ($entityIds as $rowId)
826 if (!is_array(
$arFields[
"CATALOG_COUPONS"]))
829 "DISCOUNT_ID" =>
$ID,
832 "COUPON" =>
$arFields[
"CATALOG_COUPONS"],
833 "DATE_APPLY" =>
false
837 $arKeys = array_keys(
$arFields[
"CATALOG_COUPONS"]);
838 if (!is_array(
$arFields[
"CATALOG_COUPONS"][$arKeys[0]]))
841 foreach (
$arFields[
"CATALOG_COUPONS"] as &$arOneCoupon)
843 if (!empty($arOneCoupon[
'COUPON']))
845 $arOneCoupon[
'DISCOUNT_ID'] =
$ID;
848 if (isset($arOneCoupon))
853 foreach (
GetModuleEvents(
"catalog",
"OnDiscountUpdate",
true) as $arEvent)
967 if (empty($Currency))
return false;
970 while ($arDiscounts = $dbDiscounts->Fetch())
981 $GroupID = (int)$GroupID;
985 return $DB->Query(
"DELETE FROM b_catalog_discount2group WHERE GROUP_ID = ".$GroupID,
true);
1013 foreach (
GetModuleEvents(
"catalog",
"OnGetDiscountByPrice",
true) as $arEvent)
1016 if (
true !== $mxResult)
1020 $productPriceID = (int)$productPriceID;
1021 if ($productPriceID <= 0)
1029 array(
"ID" => $productPriceID),
1032 array(
"ID",
"PRODUCT_ID",
"CATALOG_GROUP_ID",
"ELEMENT_IBLOCK_ID")
1034 if ($arPrice = $dbPrice->Fetch())
1036 return CCatalogDiscount::GetDiscount($arPrice[
"PRODUCT_ID"], $arPrice[
"ELEMENT_IBLOCK_ID"],
array($arPrice[
"CATALOG_GROUP_ID"]), $arUserGroups, $renewal,
$siteID, $arDiscountCoupons);
1042 'BT_MOD_CATALOG_DISC_ERR_PRICE_ID_NOT_FOUND',
1044 '#ID#' => $productPriceID
1057 foreach (
GetModuleEvents(
"catalog",
"OnGetDiscountByProduct",
true) as $arEvent)
1060 if (
true !== $mxResult)
1064 $productID = (int)$productID;
1065 if ($productID <= 0)
1069 'BT_MOD_CATALOG_DISC_ERR_ELEMENT_ID_NOT_FOUND',
1078 $intIBlockID = CIBlockElement::GetIBlockByID($productID);
1083 'BT_MOD_CATALOG_DISC_ERR_ELEMENT_ID_NOT_FOUND',
1085 '#ID#' => $productID
1093 return CCatalogDiscount::GetDiscount($productID,
$intIBlockID, $arCatalogGroups, $arUserGroups, $renewal,
$siteID, $arDiscountCoupons);
1096 private static function getDiscountsFromApplyResult(
array $calcResults, \
Bitrix\Sale\BasketItemBase $basketItem)
1098 $finalDiscountList =
array();
1100 if($calcResults && !empty($calcResults[
'PRICES'][
'BASKET']) &&
count($calcResults[
'PRICES'][
'BASKET']) === 1)
1102 if(isset($calcResults[
'PRICES'][
'BASKET'][$basketItem->getBasketCode()]))
1104 $priceData = $calcResults[
'PRICES'][
'BASKET'][$basketItem->getBasketCode()];
1105 if (!empty($calcResults[
'RESULT'][
'BASKET'][$basketItem->getBasketCode()]))
1107 foreach($calcResults[
'RESULT'][
'BASKET'][$basketItem->getBasketCode()] as $resultRow)
1109 $realDiscountId =
null;
1110 if(!isset($calcResults[
'DISCOUNT_LIST'][$resultRow[
'DISCOUNT_ID']]))
1115 $realDiscountId = $calcResults[
'DISCOUNT_LIST'][$resultRow[
'DISCOUNT_ID']][
'REAL_DISCOUNT_ID'];
1116 if(isset($finalDiscountList[$realDiscountId]))
1121 $finalDiscountList[$realDiscountId] = array_merge(
1122 $calcResults[
'DISCOUNT_LIST'][$resultRow[
'DISCOUNT_ID']],
1123 $calcResults[
'FULL_DISCOUNT_LIST'][$realDiscountId]
1130 return $finalDiscountList;
1133 private static function getReformattedDiscounts(
array $finalDiscountList,
array $calcResults,
$siteId, $isRenewal =
false)
1135 $reformatList =
array();
1136 foreach($finalDiscountList as
$discount)
1138 if(
$discount[
'SHORT_DESCRIPTION_STRUCTURE'])
1140 $actionConfiguration =
$discount[
'SHORT_DESCRIPTION_STRUCTURE'];
1144 $actionConfiguration = \Bitrix\Sale\Discount\Actions::getActionConfiguration(
$discount);
1147 if(!$actionConfiguration || $actionConfiguration[
'VALUE_TYPE'] === \Bitrix\Sale\Discount\Actions::VALUE_TYPE_SUMM)
1152 if($actionConfiguration[
'TYPE'] ==
'Extra')
1157 if ($actionConfiguration[
'TYPE'] ==
'Closeout')
1158 $actionConfiguration[
'VALUE_TYPE'] = self::TYPE_SALE;
1160 $reformattedDiscount =
array(
1165 'ACTIVE_FROM' => empty(
$discount[
'ACTIVE_FROM']) ?
'' :
$discount[
'ACTIVE_FROM']->toString(),
1166 'ACTIVE_TO' => empty(
$discount[
'ACTIVE_TO']) ?
'' :
$discount[
'ACTIVE_TO']->toString(),
1167 'RENEWAL' => $isRenewal?
'Y' :
'N',
1170 'MAX_DISCOUNT' => $actionConfiguration[
'LIMIT_VALUE'],
1171 'VALUE_TYPE' => $actionConfiguration[
'VALUE_TYPE'],
1172 'VALUE' => $actionConfiguration[
'VALUE'],
1175 'LAST_DISCOUNT' =>
$discount[
'LAST_DISCOUNT'],
1176 'LAST_LEVEL_DISCOUNT' =>
$discount[
'LAST_LEVEL_DISCOUNT'],
1178 'COUPON_ONE_TIME' =>
null,
1179 'COUPON_ACTIVE' =>
'',
1181 'CONDITIONS' => serialize(
$discount[
'CONDITIONS']),
1182 'HANDLERS' =>
array(
1183 'MODULES' =>
array(),
1184 'EXT_FILES' =>
array(),
1186 'MODULE_ID' =>
'sale',
1191 foreach($calcResults[
'COUPON_LIST'] as $coupon)
1193 if($coupon[
'DATA'][
'DISCOUNT_ID'] !=
$discount[
'REAL_DISCOUNT_ID'])
1198 $reformattedDiscount[
'COUPON'] = $coupon[
'COUPON'];
1199 $reformattedDiscount[
'COUPON_ACTIVE'] = $coupon[
'DATA'][
'ACTIVE'];
1200 if($coupon[
'TYPE'] == \Bitrix\Sale\Internals\DiscountCouponTable::TYPE_BASKET_ROW)
1202 $reformattedDiscount[
'COUPON_ONE_TIME'] =
'Y';
1204 elseif($coupon[
'TYPE'] == \Bitrix\Sale\Internals\DiscountCouponTable::TYPE_ONE_ORDER)
1206 $reformattedDiscount[
'COUPON_ONE_TIME'] =
'O';
1208 elseif($coupon[
'TYPE'] == \Bitrix\Sale\Internals\DiscountCouponTable::TYPE_MULTI_ORDER)
1210 $reformattedDiscount[
'COUPON_ONE_TIME'] =
'N';
1215 $reformatList[
$discount[
'ID']] = $reformattedDiscount;
1218 return $reformatList;
1221 private static function getSaleDiscountsByProduct(
array $product,
$siteId,
array $userGroups,
array $priceRow, $isRenewal, $coupons)
1223 if (empty($priceRow))
1226 $registry = Sale\Registry::getInstance(Sale\Registry::REGISTRY_TYPE_ORDER);
1228 $couponManagerClass = $registry->getDiscountCouponClassName();
1230 $freezeCoupons = (empty($coupons) && is_array($coupons));
1231 $directCoupons = (!empty($coupons) && is_array($coupons));
1232 $additionalCoupons = [];
1236 $couponManagerClass::freezeCouponStorage();
1242 $existsCoupons = $couponManagerClass::get(
1244 [
'COUPON' => $coupons]
1246 if (is_array($existsCoupons))
1248 $additionalCoupons = array_diff(
1254 if (!empty($additionalCoupons))
1256 foreach ($additionalCoupons as $oneCoupon)
1258 $couponManagerClass::add($oneCoupon);
1265 static $basket =
null,
1269 if ($basket !==
null)
1271 if ($basket->getSiteId() !=
$siteId)
1277 if ($basket !==
null)
1279 $orderedBasket = $basket->getOrder() !==
null;
1280 if ($orderedBasket !== $isRenewal)
1286 if ($basket ===
null)
1289 $basketClass = $registry->getBasketClassName();
1291 $basket = $basketClass::create(
$siteId);
1292 $basketItem = $basket->createItem($product[
'MODULE'], $product[
'ID']);
1295 $config = Catalog\Product\Price\Calculation::getConfig();
1296 if (
$config[
'CURRENCY'] !==
null &&
$config[
'CURRENCY'] != $priceRow[
'CURRENCY'])
1298 $priceRow[
'PRICE'] = \CCurrencyRates::ConvertCurrency(
1300 $priceRow[
'CURRENCY'],
1303 $priceRow[
'CURRENCY'] =
$config[
'CURRENCY'];
1307 'PRODUCT_ID' => $product[
'ID'],
1310 'PRODUCT_PRICE_ID' => $priceRow[
'ID'],
1311 'PRICE' => $priceRow[
'PRICE'],
1312 'BASE_PRICE' => $priceRow[
'PRICE'],
1313 'DISCOUNT_PRICE' => 0,
1314 'CURRENCY' => $priceRow[
'CURRENCY'],
1317 'PRICE_TYPE_ID' => (
int)$priceRow[
'CATALOG_GROUP_ID']
1320 $basketItem->setFieldsNoDemand(
$fields);
1325 $orderClass = $registry->getOrderClassName();
1328 $order->setField(
'RECURRING_ID', 1);
1329 $order->setBasket($basket);
1335 $discount = Sale\Discount::buildFromBasket($basket,
new Context\UserGroup($userGroups));
1341 $calcResults =
$discount->getApplyResult(
true);
1342 $finalDiscountList = static::getDiscountsFromApplyResult($calcResults, $basketItem);
1346 $couponManagerClass::unFreezeCouponStorage();
1352 if (!empty($additionalCoupons))
1354 foreach ($additionalCoupons as $oneCoupon)
1356 $couponManagerClass::delete($oneCoupon);
1361 $discount->setExecuteModuleFilter(
array(
'all',
'sale',
'catalog'));
1363 return static::getReformattedDiscounts($finalDiscountList, $calcResults,
$siteId, $isRenewal);
1378 public static function GetDiscount($intProductID,
$intIBlockID, $arCatalogGroups =
array(), $arUserGroups =
array(), $strRenewal =
"N",
$siteID =
false, $arDiscountCoupons =
false, $boolSKU =
true, $boolGetIDS =
false)
1380 static $eventOnGetExists =
null;
1381 static $eventOnResultExists =
null;
1388 if ($eventOnGetExists ===
true || $eventOnGetExists ===
null)
1390 foreach (
GetModuleEvents(
"catalog",
"OnGetDiscount",
true) as $arEvent)
1392 $eventOnGetExists =
true;
1394 if ($mxResult !==
true)
1397 if ($eventOnGetExists ===
null)
1398 $eventOnGetExists =
false;
1401 $boolSKU = ($boolSKU ===
true);
1402 $boolGetIDS = ($boolGetIDS ===
true);
1404 $intProductID = (int)$intProductID;
1405 if ($intProductID <= 0)
1407 $APPLICATION->ThrowException(Loc::getMessage(
"BT_MOD_CATALOG_DISC_ERR_PRODUCT_ID_ABSENT"),
"NO_PRODUCT_ID");
1414 $APPLICATION->ThrowException(Loc::getMessage(
"BT_MOD_CATALOG_DISC_ERR_IBLOCK_ID_ABSENT"),
"NO_IBLOCK_ID");
1418 if (!is_array($arUserGroups))
1419 $arUserGroups =
array($arUserGroups);
1420 $arUserGroups[] = 2;
1421 if (!empty($arUserGroups))
1422 Main\Type\Collection::normalizeArrayValuesByInt($arUserGroups,
true);
1424 if (!is_array($arCatalogGroups))
1425 $arCatalogGroups =
array($arCatalogGroups);
1426 if (empty($arCatalogGroups))
1429 'GROUP_ID' => $arUserGroups,
1430 'BUY' =>
array(
'Y',
'N')
1432 while ($catalogGroup = $catalogGroupIterator->Fetch())
1433 $arCatalogGroups[$catalogGroup[
'CATALOG_GROUP_ID']] = $catalogGroup[
'CATALOG_GROUP_ID'];
1434 unset($catalogGroup, $catalogGroupIterator);
1436 if (!empty($arCatalogGroups))
1438 $emptyExist = (in_array(-1, $arCatalogGroups));
1439 Main\Type\Collection::normalizeArrayValuesByInt($arCatalogGroups,
true);
1441 $arCatalogGroups = array_merge(
array(-1), $arCatalogGroups);
1444 if (empty($arCatalogGroups))
1447 $strRenewal = ((string)$strRenewal ==
'Y' ?
'Y' :
'N');
1456 $boolSKU = !empty($arSKUExt);
1460 $arResultID =
array();
1462 if (self::$useSaleDiscount && Loader::includeModule(
'sale'))
1464 $registry = Sale\Registry::getInstance(Sale\Registry::REGISTRY_TYPE_ORDER);
1466 $couponManagerClass = $registry->getDiscountCouponClassName();
1468 $cacheIndex =
'S'.$siteID.
'-U'.implode(
'_', $arUserGroups);
1470 if (!empty($arDiscountCoupons) && is_array($arDiscountCoupons))
1472 $clearCoupons = array_filter($arDiscountCoupons);
1473 if (!empty($clearCoupons))
1475 foreach ($clearCoupons as $coupon)
1477 $row = $couponManagerClass::getData($coupon,
true);
1478 if (!is_array($row))
1482 if ($row[
'CHECK_CODE'] !== $couponManagerClass::COUPON_CHECK_OK)
1486 $needCoupons[$coupon] = $row;
1490 unset($clearCoupons);
1492 if (!empty($needCoupons))
1494 $cacheIndex .=
'-C' . implode(
'_', array_keys($needCoupons));
1496 $cacheIndex = md5($cacheIndex);
1497 if (!isset(self::$needDiscountCache[$cacheIndex]))
1499 self::$needDiscountCache[$cacheIndex] =
false;
1501 $cache = Sale\Discount\RuntimeCache\DiscountCache::getInstance();
1502 $ids = $cache->getDiscountIds($arUserGroups);
1505 $discountList = $cache->getDiscounts(
1511 if (!empty($discountList))
1513 self::$needDiscountCache[$cacheIndex] =
true;
1515 unset($discountList);
1517 unset($ids, $cache);
1521 'ID' => $intProductID,
1522 'MODULE' =>
'catalog',
1525 if (self::$needDiscountCache[$cacheIndex] && $arCatalogGroups !==
array(-1))
1527 Catalog\Product\Price\Calculation::pushConfig();
1528 Catalog\Product\Price\Calculation::setConfig([
1529 'CURRENCY' => Sale\Internals\SiteCurrencyTable::getSiteCurrency(
$siteID)
1532 $isCompatibilityUsed = Sale\Compatible\DiscountCompatibility::isUsed();
1533 Sale\Compatible\DiscountCompatibility::stopUsageCompatible();
1535 foreach ($arCatalogGroups as $catalogGroup)
1537 $priceRow = Catalog\Discount\DiscountManager::getPriceDataByProductId($intProductID, $catalogGroup);
1541 $discountList = self::getSaleDiscountsByProduct(
1546 $strRenewal ===
'Y',
1558 if ($isCompatibilityUsed)
1559 Sale\Compatible\DiscountCompatibility::revertUsageCompatible();
1560 unset($isCompatibilityUsed);
1562 Catalog\Product\Price\Calculation::popConfig();
1568 $strCacheKey = md5(
'C'.implode(
'_', $arCatalogGroups).
'-'.
'U'.implode(
'_', $arUserGroups));
1569 if (!isset(self::$arCacheDiscountFilter[$strCacheKey]))
1572 'PRICE_TYPE_ID' => $arCatalogGroups,
1573 'USER_GROUP_ID' => $arUserGroups,
1576 if (!empty($arDiscountIDs))
1577 sort($arDiscountIDs);
1579 self::$arCacheDiscountFilter[$strCacheKey] = $arDiscountIDs;
1583 $arDiscountIDs = self::$arCacheDiscountFilter[$strCacheKey];
1586 $arProduct =
array();
1587 if (!empty($arDiscountIDs))
1589 $orderCoupons =
array();
1590 if ($arDiscountCoupons ===
false)
1592 if (self::$existCouponsManager && Loader::includeModule(
'sale'))
1594 $arDiscountCoupons = DiscountCouponsManager::getForApply(
1595 array(
'MODULE_ID' =>
'catalog',
'DISCOUNT_ID' => $arDiscountIDs),
1596 array(
'MODULE_ID' =>
'catalog',
'PRODUCT_ID' => $intProductID,
'BASKET_ID' =>
'0'),
1599 if (!empty($arDiscountCoupons))
1601 $orderCoupons = array_filter($arDiscountCoupons,
'\Bitrix\Sale\DiscountCouponsManager::filterOrderCoupons');
1602 $arDiscountCoupons = array_keys($arDiscountCoupons);
1607 if (!isset($_SESSION[
'CATALOG_USER_COUPONS']) || !is_array($_SESSION[
'CATALOG_USER_COUPONS']))
1608 $_SESSION[
'CATALOG_USER_COUPONS'] =
array();
1609 $arDiscountCoupons = $_SESSION[
"CATALOG_USER_COUPONS"];
1614 if (self::$existCouponsManager && Loader::includeModule(
'sale'))
1616 $orderCoupons = DiscountCouponsManager::getOrderedCoupons(
true,
array(
'COUPON' => $arDiscountCoupons));
1619 if ($arDiscountCoupons ===
false)
1620 $arDiscountCoupons =
array();
1621 $boolGenerate =
false;
1622 if (empty(self::$cacheDiscountHandlers))
1628 $needDiscountHandlers =
array();
1629 foreach ($arDiscountIDs as &$discountID)
1631 if (!isset(self::$cacheDiscountHandlers[$discountID]))
1632 $needDiscountHandlers[] = $discountID;
1635 if (!empty($needDiscountHandlers))
1638 if (!empty($discountHandlersList))
1640 foreach ($discountHandlersList as $discountID => $discountHandlers)
1641 self::$cacheDiscountHandlers[$discountID] = $discountHandlers;
1643 unset($discountHandlers, $discountID);
1645 unset($discountHandlersList);
1647 unset($needDiscountHandlers);
1650 $strCacheKey =
'D'.implode(
'_', $arDiscountIDs).
'-'.
'S'.$siteID.
'-R'.$strRenewal;
1651 if (!empty($arDiscountCoupons))
1652 $strCacheKey .=
'-C'.implode(
'|', $arDiscountCoupons);
1654 $strCacheKey = md5($strCacheKey);
1656 if (!isset(self::$arCacheDiscountResult[$strCacheKey]))
1658 $arDiscountList =
array();
1660 $couponsDiscount =
array();
1661 $couponsList =
array();
1662 if (!empty($arDiscountCoupons) && is_array($arDiscountCoupons))
1665 'select' =>
array(
'DISCOUNT_ID',
'COUPON',
'ACTIVE',
'TYPE'),
1666 'filter' =>
array(
'@DISCOUNT_ID' => $arDiscountIDs,
'@COUPON' => $arDiscountCoupons),
1667 'order' =>
array(
'DISCOUNT_ID' =>
'ASC')
1671 $id = (int)$row[
'DISCOUNT_ID'];
1672 $couponsList[$row[
'COUPON']] = $row;
1673 if (isset($couponsDiscount[$id]))
1675 $couponsDiscount[$id] = $row[
'COUPON'];
1681 'ID',
'TYPE',
'SITE_ID',
'ACTIVE',
'ACTIVE_FROM',
'ACTIVE_TO',
1682 'RENEWAL',
'NAME',
'SORT',
'MAX_DISCOUNT',
'VALUE_TYPE',
'VALUE',
'CURRENCY',
1683 'PRIORITY',
'LAST_DISCOUNT',
1684 'USE_COUPONS',
'UNPACK',
'CONDITIONS'
1686 $currentDatetime =
new Main\Type\DateTime();
1687 $discountRows = array_chunk($arDiscountIDs, 500);
1688 foreach ($discountRows as $pageIds)
1690 $discountFilter =
array(
1693 '=TYPE' => Catalog\DiscountTable::TYPE_DISCOUNT,
1696 'ACTIVE_FROM' =>
'',
1697 '<=ACTIVE_FROM' => $currentDatetime
1702 '>=ACTIVE_TO' => $currentDatetime
1704 '=RENEWAL' => $strRenewal
1706 if (empty($couponsDiscount))
1708 $discountFilter[
'=USE_COUPONS'] =
'N';
1712 $discountFilter[] =
array(
1714 '=USE_COUPONS' =>
'N',
1716 '=USE_COUPONS' =>
'Y',
1717 '@ID' => array_keys($couponsDiscount)
1724 'filter' => $discountFilter
1728 $row[
'HANDLERS'] =
array();
1729 $row[
'MODULE_ID'] =
'catalog';
1730 $row[
'TYPE'] = (int)$row[
'TYPE'];
1731 if ($row[
'ACTIVE_FROM'] instanceof Main\Type\DateTime)
1732 $row[
'ACTIVE_FROM'] = $row[
'ACTIVE_FROM']->toString();
1733 if ($row[
'ACTIVE_TO'] instanceof Main\Type\DateTime)
1734 $row[
'ACTIVE_TO'] = $row[
'ACTIVE_TO']->toString();
1735 if ($row[
'USE_COUPONS'] ==
'N')
1737 $row[
'COUPON_ACTIVE'] =
'';
1738 $row[
'COUPON'] =
'';
1739 $row[
'COUPON_ONE_TIME'] =
null;
1743 $id = (int)$row[
'ID'];
1744 if (isset($couponsDiscount[$id]))
1746 $coupon = $couponsDiscount[$id];
1747 $row[
'COUPON'] = $coupon;
1748 $row[
'COUPON_ACTIVE'] = $couponsList[$coupon][
'ACTIVE'];
1749 $row[
'COUPON_ONE_TIME'] = $couponsList[$coupon][
'TYPE'];
1757 $arDiscountList[] = $row;
1762 unset($pageIds, $discountRows);
1764 self::$arCacheDiscountResult[$strCacheKey] = $arDiscountList;
1768 $arDiscountList = self::$arCacheDiscountResult[$strCacheKey];
1771 if (!empty($arDiscountList))
1773 $discountApply =
array();
1774 foreach ($arDiscountList as &$arPriceDiscount)
1776 if (isset($discountApply[$arPriceDiscount[
'ID']]))
1780 $arPriceDiscount[
'COUPON'] !=
''
1781 && $arPriceDiscount[
'COUPON_ACTIVE'] ==
'N'
1782 && !isset($orderCoupons[$arPriceDiscount[
'COUPON']])
1788 if (!isset(self::$arCacheProduct[$intProductID]))
1791 if (!self::__GenerateFields($arProduct))
1795 if (!self::__GenerateParent($arProduct, $arSKUExt))
1798 $boolGenerate =
true;
1799 self::$arCacheProduct[$intProductID] = $arProduct;
1803 $boolGenerate =
true;
1804 $arProduct = self::$arCacheProduct[$intProductID];
1807 $discountApply[$arPriceDiscount[
'ID']] =
true;
1809 if (isset(self::$cacheDiscountHandlers[$arPriceDiscount[
'ID']]))
1811 $arPriceDiscount[
'HANDLERS'] = self::$cacheDiscountHandlers[$arPriceDiscount[
'ID']];
1812 $moduleList = self::$cacheDiscountHandlers[$arPriceDiscount[
'ID']][
'MODULES'];
1813 if (!empty($moduleList))
1817 if (!isset(self::$usedModules[
$moduleID]))
1833 $arResultID[] = $arPriceDiscount[
'ID'];
1836 unset($arPriceDiscount);
1837 unset($discountApply);
1845 'USER_GROUPS' => $arUserGroups,
1848 if (!empty($arDiscSave))
1857 if ($eventOnResultExists ===
true || $eventOnResultExists ===
null)
1859 foreach (
GetModuleEvents(
"catalog",
"OnGetDiscountResult",
true) as $arEvent)
1861 $eventOnResultExists =
true;
1864 if ($eventOnResultExists ===
null)
1865 $eventOnResultExists =
false;
1879 $excludeID = (int)$excludeID;
1947 if (empty($arProduct) || !is_array($arProduct))
1953 if (!isset($arProduct[
'ID']))
1954 $arProduct[
'ID'] = 0;
1955 $arProduct[
'ID'] = (int)$arProduct[
'ID'];
1956 if (!isset($arProduct[
'IBLOCK_ID']))
1957 $arProduct[
'IBLOCK_ID'] = 0;
1958 $arProduct[
'IBLOCK_ID'] = (int)$arProduct[
'IBLOCK_ID'];
1959 if ($arProduct[
'IBLOCK_ID'] <= 0 || $arProduct[
'ID'] <= 0)
1963 $strRenewal = ($strRenewal ==
'Y' ?
'Y' :
'N');
1976 'select' =>
array(
'SITE_ID'),
1977 'filter' =>
array(
'=IBLOCK_ID' => $arProduct[
'IBLOCK_ID'])
1987 if (empty($groupList))
1990 foreach (array_keys($groupList) as $groupId)
1993 if (!empty($priceRow))
1994 $prices[$groupId] = $priceRow;
1997 unset($groupId, $groupList);
2001 $renewal = ($strRenewal ==
'Y');
2003 'ID' => $arProduct[
'ID'],
2004 'MODULE' =>
'catalog',
2007 $allUserGroupsId = array_keys(static::getAllUserGroups());
2010 foreach ($prices as $priceRow)
2017 $siteResult = self::getSaleDiscountsByProduct(
2025 if (empty($siteResult))
2044 $arSKUExt = CCatalogSku::GetInfoByOfferIBlock($arProduct[
'IBLOCK_ID']);
2046 $arFieldsParams =
array();
2048 $arFieldsParams[
'TIME_ZONE'] =
$arParams[
'TIME_ZONE'];
2050 $arFieldsParams[
'PRODUCT'] =
$arParams[
'PRODUCT'];
2051 $boolGenerate =
false;
2053 $arSelect =
array(
'ID',
'SITE_ID',
'SORT',
'NAME',
'VALUE_TYPE',
'VALUE',
'MAX_DISCOUNT',
'CURRENCY',
'UNPACK',
'NOTES');
2055 $arSelect =
$arParams[
'DISCOUNT_FIELDS'];
2056 if (!in_array(
'UNPACK', $arSelect))
2057 $arSelect[] =
'UNPACK';
2059 $strDate = date(
$DB->DateFormatToPHP(CSite::GetDateFormat(
"FULL")));
2064 $strRenewal = ($strRenewal ==
'Y' ?
'Y' :
'N');
2068 'TYPE' => self::ENTITY_ID,
2070 'RENEWAL' => $strRenewal,
2071 '+<=ACTIVE_FROM' => $strDate,
2072 '+>=ACTIVE_TO' => $strDate,
2073 'USE_COUPONS' =>
'N'
2075 CTimeZone::Disable();
2083 CTimeZone::Enable();
2084 while ($arPriceDiscount = $rsPriceDiscounts->Fetch())
2088 if (!isset(self::$arCacheProduct[$arProduct[
'ID']]))
2090 if (!self::__GenerateFields($arProduct, $arFieldsParams))
2092 if (!empty($arSKUExt))
2095 $boolGenerate =
true;
2096 self::$arCacheProduct[$arProduct[
'ID']] = $arProduct;
2098 $arProduct = self::$arCacheProduct[$arProduct[
'ID']];
2100 if (!self::__Unpack($arProduct, $arPriceDiscount[
'UNPACK']))
2103 unset($arPriceDiscount[
'UNPACK']);
2106 unset($arPriceDiscount, $rsPriceDiscounts);
2119 while ($group = $dbGroupsList->Fetch())
2121 $groups[$group[
"ID"]] = $group[
"NAME"];
2130 $boolKeys = !!$boolKeys;
2131 $boolRevert = !!$boolRevert;
2152 foreach (
$arResult[
'RESTRICTIONS'] as &$arOneDiscount)
2154 $arOneDiscount[
'USER_GROUP'] = array_keys($arOneDiscount[
'USER_GROUP']);
2155 $arOneDiscount[
'PRICE_TYPE'] = array_keys($arOneDiscount[
'PRICE_TYPE']);
2157 unset($arOneDiscount);
2166 if (empty($arProduct) || !is_array($arProduct))
2168 if (empty($arDiscount) || !is_array($arDiscount) || !isset($arDiscount[
'UNPACK']))
2175 $price = (float)$price;
2177 if (
$currency ===
false || !is_array($discountList))
2180 if (self::$useSaleDiscount ===
null)
2183 $currentPrice = $price;
2184 $applyDiscountList =
array();
2189 'DISCOUNT_LIST' =>
array()
2191 if ($price <= 0 || empty($discountList))
2194 $accumulativeDiscountMode = (string)
Option::get(
'catalog',
'discsave_apply');
2195 $productDiscountList =
array();
2196 $accumulativeDiscountList =
array();
2202 $productDiscountList,
2203 $accumulativeDiscountList
2205 if (!empty($productDiscountList))
2213 $applyDiscountList =
array();
2214 foreach ($productDiscountList as $priority => $discounts)
2218 $currentPrice = self::calculatePriceByDiscount($price, $currentPrice,
$discount, $needErase);
2219 if ($currentPrice !==
false)
2226 if(
$discount[
'LAST_LEVEL_DISCOUNT'] ===
'Y')
2237 foreach ($productDiscountList as &$priority)
2240 if ($currentPrice ===
false)
2242 if (!empty($applyDiscountList))
2244 $lastDiscount = end($applyDiscountList);
2245 reset($applyDiscountList);
2246 if (isset($lastDiscount[
'LAST_DISCOUNT']) && $lastDiscount[
'LAST_DISCOUNT'] ==
'Y')
2254 if (!empty($accumulativeDiscountList))
2256 switch ($accumulativeDiscountMode)
2259 $applyAccumulativeList =
array();
2264 $accumulativeDiscountList,
2265 $applyAccumulativeList
2267 if ($accumulativePrice ===
false)
2269 if (!empty($applyAccumulativeList) && $accumulativePrice < $currentPrice)
2271 $currentPrice = $accumulativePrice;
2272 $applyDiscountList = $applyAccumulativeList;
2280 $accumulativeDiscountList,
2283 if ($currentPrice ===
false)
2287 if (empty($applyDiscountList))
2293 $accumulativeDiscountList,
2296 if ($currentPrice ===
false)
2304 'PRICE' => $currentPrice,
2306 'DISCOUNT_LIST' => $applyDiscountList
2313 $getWithVat = ($getWithVat !==
false);
2315 if (empty($priceData) || !is_array($priceData))
2317 $priceData[
'PRICE'] = (float)$priceData[
'PRICE'];
2320 if ($priceData[
'CURRENCY'] ===
false ||
$currency ===
false || !is_array($discountList))
2324 $discountVat =
true;
2328 ? $priceData[
'PRICE']
2331 $priceData[
'ORIG_VAT_INCLUDED'] = $priceData[
'VAT_INCLUDED'];
2334 if ($priceData[
'VAT_INCLUDED'] ==
'N')
2336 $currentPrice *= (1 + $priceData[
'VAT_RATE']);
2337 $priceData[
'VAT_INCLUDED'] =
'Y';
2342 if ($priceData[
'VAT_INCLUDED'] ==
'Y')
2344 $currentPrice /= (1 + $priceData[
'VAT_RATE']);
2345 $priceData[
'VAT_INCLUDED'] =
'N';
2349 $calculatePrice = $currentPrice;
2354 case self::TYPE_FIX:
2360 $currentPrice = $currentPrice - $currentDiscount;
2362 case self::TYPE_PERCENT:
2363 $currentDiscount = $currentPrice*
$discount[
'VALUE']/100.0;
2367 $maxDiscount =
$discount[
'MAX_DISCOUNT'];
2370 if ($currentDiscount > $maxDiscount)
2371 $currentDiscount = $maxDiscount;
2374 $currentPrice = $currentPrice - $currentDiscount;
2376 case self::TYPE_SALE:
2387 $vatRate = (1 + $priceData[
'VAT_RATE']);
2392 $calculatePrice /= $vatRate;
2393 $currentPrice /= $vatRate;
2400 $calculatePrice *= $vatRate;
2401 $currentPrice *= $vatRate;
2405 unset($priceData[
'ORIG_VAT_INCLUDED']);
2406 $unroundBasePrice = $calculatePrice;
2407 $unroundPrice = $currentPrice;
2410 $calculatePrice = Catalog\Product\Price::roundPrice(
2411 $priceData[
'CATALOG_GROUP_ID'],
2415 $currentPrice = Catalog\Product\Price::roundPrice(
2416 $priceData[
'CATALOG_GROUP_ID'],
2421 empty($discountList)
2428 $currentDiscount = ($calculatePrice - $currentPrice);
2431 'PRICE_TYPE_ID' => $priceData[
'CATALOG_GROUP_ID'],
2432 'BASE_PRICE' => $calculatePrice,
2433 'DISCOUNT_PRICE' => $currentPrice,
2434 'UNROUND_BASE_PRICE' => $unroundBasePrice,
2435 'UNROUND_DISCOUNT_PRICE' => $unroundPrice,
2437 'DISCOUNT' => $currentDiscount,
2439 $calculatePrice > 0 && $currentDiscount > 0
2440 ? round((100*$currentDiscount)/$calculatePrice, 0)
2443 'VAT_RATE' => $priceData[
'VAT_RATE'],
2444 'VAT_INCLUDED' => ($getWithVat ?
'Y' :
'N')
2455 'COUPON_TYPE' =>
'',
2460 'VALUE_TYPE' =>
$discount[
'VALUE_TYPE'],
2461 'LAST_DISCOUNT' =>
$discount[
'LAST_DISCOUNT'],
2479 public static function ExtendBasketItems(&$arBasket, $arExtend)
2500 $arCatFields =
array(
2509 $boolFields =
false;
2510 if (isset($arExtend[
'catalog'][
'fields']))
2511 $boolFields = (boolean)$arExtend[
'catalog'][
'fields'];
2513 if (isset($arExtend[
'catalog'][
'props']))
2514 $boolProps = (boolean)$arExtend[
'catalog'][
'props'];
2516 $boolPrice = !empty($arExtend[
'catalog'][
'price']);
2517 $productPriceIds =
array();
2518 $basketItemIds =
array();
2520 if ($boolFields || $boolProps || $boolPrice)
2524 foreach ($arBasket as $strKey => $arOneRow)
2526 if (isset($arOneRow[
'MODULE']) &&
'catalog' == $arOneRow[
'MODULE'])
2528 $intProductID = (int)$arOneRow[
'PRODUCT_ID'];
2529 if ($intProductID > 0)
2531 $arIDS[$intProductID] =
true;
2532 if (!isset($arMap[$intProductID]))
2533 $arMap[$intProductID] =
array();
2534 $arMap[$intProductID][] = $strKey;
2539 if(isset($arOneRow[
'PRODUCT_PRICE_ID']))
2541 $productPriceIds[] = $arOneRow[
'PRODUCT_PRICE_ID'];
2545 $basketItemIds[] = $arOneRow[
'ID'];
2551 if($boolPrice && empty($productPriceIds) && $basketItemIds)
2554 $basketFilter =
array(
2556 '@ID' => $basketItemIds
2558 'select' =>
array(
'ID',
'PRODUCT_PRICE_ID',),
2560 $registry = Sale\Registry::getInstance(Sale\Registry::REGISTRY_TYPE_ORDER);
2563 $basketClass = $registry->getBasketClassName();
2565 $res = $basketClass::getList($basketFilter);
2566 while($basketItem =
$res->fetch())
2568 $productPriceIds[] = $basketItem[
'PRODUCT_PRICE_ID'];
2574 $offerIds =
array();
2575 $arBasketResult =
array();
2576 $iblockGroup =
array();
2577 $arIDS = array_keys($arIDS);
2581 while ($arItem = $rsItems->Fetch())
2583 $arBasketData =
array();
2584 $arItem[
'ID'] = (int)$arItem[
'ID'];
2585 $arItem[
'IBLOCK_ID'] = (int)$arItem[
'IBLOCK_ID'];
2586 if (!isset($iblockGroup[$arItem[
'IBLOCK_ID']]))
2587 $iblockGroup[$arItem[
'IBLOCK_ID']] =
array();
2588 $iblockGroup[$arItem[
'IBLOCK_ID']][] = $arItem[
'ID'];
2591 $arBasketData[
'ID'] = $arItem[
'ID'];
2592 $arBasketData[
'IBLOCK_ID'] = $arItem[
'IBLOCK_ID'];
2593 $arBasketData[
'NAME'] = $arItem[
'NAME'];
2594 $arBasketData[
'XML_ID'] = (string)$arItem[
'XML_ID'];
2595 $arBasketData[
'CODE'] = (string)$arItem[
'CODE'];
2596 $arBasketData[
'TAGS'] = (string)$arItem[
'TAGS'];
2597 $arBasketData[
'SORT'] = (int)$arItem[
'SORT'];
2598 $arBasketData[
'PREVIEW_TEXT'] = (string)$arItem[
'PREVIEW_TEXT'];
2599 $arBasketData[
'DETAIL_TEXT'] = (string)$arItem[
'DETAIL_TEXT'];
2600 $arBasketData[
'CREATED_BY'] = (int)$arItem[
'CREATED_BY'];
2601 $arBasketData[
'MODIFIED_BY'] = (int)$arItem[
'MODIFIED_BY'];
2603 $arBasketData[
'DATE_ACTIVE_FROM'] = (string)$arItem[
'DATE_ACTIVE_FROM'];
2604 if (!empty($arBasketData[
'DATE_ACTIVE_FROM']))
2605 $arBasketData[
'DATE_ACTIVE_FROM'] = (int)
MakeTimeStamp($arBasketData[
'DATE_ACTIVE_FROM']);
2607 $arBasketData[
'DATE_ACTIVE_TO'] = (string)$arItem[
'DATE_ACTIVE_TO'];
2608 if (!empty($arBasketData[
'DATE_ACTIVE_TO']))
2609 $arBasketData[
'DATE_ACTIVE_TO'] = (int)
MakeTimeStamp($arBasketData[
'DATE_ACTIVE_TO']);
2611 if (isset($arItem[
'DATE_CREATE_UNIX']))
2613 $arBasketData[
'DATE_CREATE'] = (string)$arItem[
'DATE_CREATE_UNIX'];
2614 if ($arBasketData[
'DATE_CREATE'] !=
'')
2615 $arBasketData[
'DATE_CREATE'] = (int)$arBasketData[
'DATE_CREATE'];
2619 $arBasketData[
'DATE_CREATE'] = (string)$arItem[
'DATE_CREATE'];
2620 if ($arBasketData[
'DATE_CREATE'] !=
'')
2621 $arBasketData[
'DATE_CREATE'] = (int)
MakeTimeStamp($arBasketData[
'DATE_CREATE']);
2624 if (isset($arItem[
'TIMESTAMP_X_UNIX']))
2626 $arBasketData[
'TIMESTAMP_X'] = (string)$arItem[
'TIMESTAMP_X_UNIX'];
2627 if ($arBasketData[
'TIMESTAMP_X'] !=
'')
2628 $arBasketData[
'TIMESTAMP_X'] = (int)$arBasketData[
'TIMESTAMP_X'];
2632 $arBasketData[
'TIMESTAMP_X'] = (string)$arItem[
'TIMESTAMP_X'];
2633 if ($arBasketData[
'TIMESTAMP_X'] !=
'')
2634 $arBasketData[
'TIMESTAMP_X'] = (int)
MakeTimeStamp($arBasketData[
'TIMESTAMP_X']);
2638 if ($arProductSections !==
false)
2639 $arBasketData[
'SECTION_ID'] = $arProductSections;
2641 $arBasketData[
'SECTION_ID'] =
array();
2645 $arBasketData[
'PROPERTIES'] =
array();
2647 $arBasketResult[$arItem[
'ID']] = $arBasketData;
2649 $propertyFilter =
array();
2650 if (isset($arExtend[
'iblock'][
'props']) && is_array($arExtend[
'iblock'][
'props']))
2651 $propertyFilter =
array(
'ID' => $arExtend[
'iblock'][
'props']);
2652 if (!empty($iblockGroup))
2655 'select' =>
array(
'IBLOCK_ID',
'SKU_PROPERTY_ID',
'PRODUCT_IBLOCK_ID'),
2656 'filter' =>
array(
'@IBLOCK_ID' => array_keys($iblockGroup))
2660 $skuPropertyId = (int)
$catalog[
'SKU_PROPERTY_ID'];
2661 if ($skuPropertyId > 0)
2663 if (!isset($propertyFilter[
'ID']))
2664 $propertyFilter[
'ID'] =
array();
2665 $propertyFilter[
'ID'][] = $skuPropertyId;
2666 if (!empty($iblockGroup[
$catalog[
'IBLOCK_ID']]))
2668 foreach ($iblockGroup[
$catalog[
'IBLOCK_ID']] as $itemId)
2670 if (!isset($arBasketResult[$itemId][
'PROPERTIES']))
2671 $arBasketResult[$itemId][
'PROPERTIES'] =
array();
2681 if ($boolProps && !empty($iblockGroup))
2683 foreach ($iblockGroup as $iblockID => $iblockItems)
2686 'ID' => $iblockItems,
2687 'IBLOCK_ID' =>$iblockID
2696 'PROPERTY_TYPE' =>
true,
2698 'USER_TYPE' =>
true,
2702 unset($iblockItems, $iblockID);
2703 foreach ($arBasketResult as &$basketItem)
2712 $priceList = Catalog\PriceTable::getList(
array(
2717 'filter' =>
array(
'@ID' => $productPriceIds),
2719 while($price = $priceList->fetch())
2721 if(!isset($arBasketResult[$price[
'PRODUCT_ID']]))
2723 $arBasketResult[$price[
'PRODUCT_ID']] =
array();
2725 $arBasketResult[$price[
'PRODUCT_ID']][
'CATALOG_GROUP_ID'] = $price[
'CATALOG_GROUP_ID'];
2731 while ($arProduct = $rsProducts->Fetch())
2734 $arProduct[
'TYPE'] = (int)$arProduct[
'TYPE'];
2735 if ($arProduct[
'TYPE'] == Catalog\ProductTable::TYPE_OFFER)
2737 if (!isset($arBasketResult[$productId]))
2739 unset($arProduct[
'ID'], $arProduct[
'TYPE']);
2741 foreach ($arProduct as $productKey => $productValue)
2742 $arBasketResult[
$productId][
'CATALOG_'.$productKey] = $productValue;
2743 unset($productKey, $productValue);
2745 unset($productId, $arProduct, $rsProducts);
2747 if (!empty($offerIds))
2749 $products =
array();
2750 $productIds =
array();
2752 if (!empty($productList))
2754 foreach (array_keys($productList) as $index)
2756 $id = $productList[$index][
'ID'];
2757 $iblockId = $productList[$index][
'IBLOCK_ID'];
2768 unset($productList);
2769 if (!empty($products))
2772 $stackData = self::$useSaleDiscount;
2773 self::$useSaleDiscount =
false;
2774 foreach (array_keys($products) as
$iblockId)
2776 if (!empty($propertyFilter))
2778 $arPropFilter =
array(
2789 'PROPERTY_TYPE' =>
true,
2791 'USER_TYPE' =>
true,
2796 foreach (array_keys($products[
$iblockId]) as $id)
2803 self::$useSaleDiscount = $stackData;
2807 if (!empty($iblockGroup))
2809 foreach ($iblockGroup as $iblockID => $iblockItems)
2814 foreach ($iblockItems as $itemID)
2818 unset($isSku, $itemID);
2821 unset($sku, $iblockItems, $iblockID);
2824 if (!empty($arBasketResult))
2826 foreach ($arBasketResult as $intProductID => $arBasketData)
2828 foreach ($arMap[$intProductID] as $mxRowID)
2830 $arBasket[$mxRowID][
'CATALOG'] = $arBasketData;
2837 'PROPERTIES' =>
true
2850 $boolResult =
false;
2851 if (!empty($arProduct) && is_array($arProduct))
2853 if (!isset($arProduct[
'IBLOCK_ID']))
2854 $arProduct[
'IBLOCK_ID'] = 0;
2855 $arProduct[
'IBLOCK_ID'] = (int)$arProduct[
'IBLOCK_ID'];
2856 if ($arProduct[
'IBLOCK_ID'] > 0)
2861 if (!isset($arProduct[
'ID']))
2862 $arProduct[
'ID'] = 0;
2863 $arProduct[
'ID'] = (int)$arProduct[
'ID'];
2864 if ($arProduct[
'ID'] > 0)
2868 $arDefaultProduct =
array(
2869 'DATE_ACTIVE_FROM' =>
'',
2870 'DATE_ACTIVE_TO' =>
'',
2872 'PREVIEW_TEXT' =>
'',
2873 'DETAIL_TEXT' =>
'',
2875 'DATE_CREATE' =>
'',
2876 'TIMESTAMP_X' =>
'',
2879 'CATALOG_QUANTITY' =>
'',
2880 'CATALOG_WEIGHT' =>
'',
2881 'CATALOG_VAT_ID' =>
'',
2882 'CATALOG_VAT_INCLUDED' =>
''
2884 $arProduct = array_merge($arDefaultProduct, $arProduct);
2886 static $intTimeOffset =
false;
2887 if (
false === $intTimeOffset)
2888 $intTimeOffset = CTimeZone::GetOffset();
2892 if (!isset($arProduct[
'SECTION_ID']))
2895 if (
false !== $arProductSections)
2896 $arProduct[
'SECTION_ID'] = $arProductSections;
2898 $arProduct[
'SECTION_ID'] =
array();
2902 if (!is_array($arProduct[
'SECTION_ID']))
2903 $arProduct[
'SECTION_ID'] =
array($arProduct[
'SECTION_ID']);
2907 if (!empty($arProduct[
'DATE_ACTIVE_FROM']))
2909 $intStackTimestamp = (int)$arProduct[
'DATE_ACTIVE_FROM'];
2910 if ($intStackTimestamp.
'!' != $arProduct[
'DATE_ACTIVE_FROM'].
'!')
2911 $arProduct[
'DATE_ACTIVE_FROM'] = (int)
MakeTimeStamp($arProduct[
'DATE_ACTIVE_FROM']) - $intTimeOffset;
2913 $arProduct[
'DATE_ACTIVE_FROM'] = $intStackTimestamp;
2916 if (!empty($arProduct[
'DATE_ACTIVE_TO']))
2918 $intStackTimestamp = (int)$arProduct[
'DATE_ACTIVE_TO'];
2919 if ($intStackTimestamp.
'!' != $arProduct[
'DATE_ACTIVE_TO'].
'!')
2920 $arProduct[
'DATE_ACTIVE_TO'] = (int)
MakeTimeStamp($arProduct[
'DATE_ACTIVE_TO']) - $intTimeOffset;
2922 $arProduct[
'DATE_ACTIVE_TO'] = $intStackTimestamp;
2925 $arProduct[
'SORT'] = (int)$arProduct[
'SORT'];
2927 if (!empty($arProduct[
'DATE_CREATE']))
2929 $intStackTimestamp = (int)$arProduct[
'DATE_CREATE'];
2930 if ($intStackTimestamp.
'!' != $arProduct[
'DATE_CREATE'].
'!')
2931 $arProduct[
'DATE_CREATE'] = (int)
MakeTimeStamp($arProduct[
'DATE_CREATE']) - $intTimeOffset;
2933 $arProduct[
'DATE_CREATE'] = $intStackTimestamp;
2936 if (!empty($arProduct[
'TIMESTAMP_X']))
2938 $intStackTimestamp = (int)$arProduct[
'TIMESTAMP_X'];
2939 if ($intStackTimestamp.
'!' != $arProduct[
'TIMESTAMP_X'].
'!')
2940 $arProduct[
'TIMESTAMP_X'] = (int)
MakeTimeStamp($arProduct[
'TIMESTAMP_X']) - $intTimeOffset;
2942 $arProduct[
'TIMESTAMP_X'] = $intStackTimestamp;
2945 $arProduct[
'CREATED_BY'] = (int)$arProduct[
'CREATED_BY'];
2946 $arProduct[
'MODIFIED_BY'] = (int)$arProduct[
'MODIFIED_BY'];
2948 if (isset($arProduct[
'QUANTITY']))
2950 $arProduct[
'CATALOG_QUANTITY'] = $arProduct[
'QUANTITY'];
2951 unset($arProduct[
'QUANTITY']);
2953 if (
'' != $arProduct[
'CATALOG_QUANTITY'])
2954 $arProduct[
'CATALOG_QUANTITY'] = doubleval($arProduct[
'CATALOG_QUANTITY']);
2956 if (isset($arProduct[
'WEIGHT']))
2958 $arProduct[
'CATALOG_WEIGHT'] = $arProduct[
'WEIGHT'];
2959 unset($arProduct[
'WEIGHT']);
2961 if (
'' != $arProduct[
'CATALOG_WEIGHT'])
2962 $arProduct[
'CATALOG_WEIGHT'] = doubleval($arProduct[
'CATALOG_WEIGHT']);
2964 if (isset($arProduct[
'VAT_ID']))
2966 $arProduct[
'CATALOG_VAT_ID'] = $arProduct[
'VAT_ID'];
2967 unset($arProduct[
'VAT_ID']);
2969 if (
'' != $arProduct[
'CATALOG_VAT_ID'])
2970 $arProduct[
'CATALOG_VAT_ID'] = (int)$arProduct[
'CATALOG_VAT_ID'];
2972 if (isset($arProduct[
'VAT_INCLUDED']))
2974 $arProduct[
'CATALOG_VAT_INCLUDED'] = $arProduct[
'VAT_INCLUDED'];
2975 unset($arProduct[
'VAT_INCLUDED']);
2978 $arPropParams =
array();
2980 $arPropParams[
'TIME_ZONE'] =
'N';
2982 if (isset($arProduct[
'PROPERTIES']))
2984 if (!empty($arProduct[
'PROPERTIES']) && is_array($arProduct[
'PROPERTIES']))
2988 unset($arProduct[
'PROPERTIES']);
2993 $arSelect =
array(
'ID',
'IBLOCK_ID',
'CODE',
'XML_ID',
'NAME',
'ACTIVE',
'DATE_ACTIVE_FROM',
'DATE_ACTIVE_TO',
2994 'SORT',
'PREVIEW_TEXT',
'DETAIL_TEXT',
'DATE_CREATE',
'DATE_CREATE_UNIX',
'CREATED_BY',
'TIMESTAMP_X',
'TIMESTAMP_X_UNIX',
'MODIFIED_BY',
'TAGS',
'CATALOG_QUANTITY');
2995 CTimeZone::Disable();
2996 $rsProducts = CIBlockElement::GetList(
array(),
array(
'ID' => $arProduct[
'ID'],
'IBLOCK_ID' => $arProduct[
'IBLOCK_ID']),
false,
false, $arSelect);
2997 CTimeZone::Enable();
2998 if (!($obProduct = $rsProducts->GetNextElement(
false,
true)))
3001 $arProduct =
array();
3002 $arProductFields = $obProduct->GetFields();
3004 $arProduct[
'ID'] = (int)$arProductFields[
'ID'];
3005 $arProduct[
'IBLOCK_ID'] = (int)$arProductFields[
'IBLOCK_ID'];
3007 $arProduct[
'SECTION_ID'] =
array();
3009 if (
false !== $arProductSections)
3010 $arProduct[
'SECTION_ID'] = $arProductSections;
3012 $arProduct[
'CODE'] = (string)$arProductFields[
'~CODE'];
3013 $arProduct[
'XML_ID'] = (string)$arProductFields[
'~XML_ID'];
3014 $arProduct[
'NAME'] = $arProductFields[
'~NAME'];
3016 $arProduct[
'ACTIVE'] = $arProductFields[
'ACTIVE'];
3018 $arProduct[
'DATE_ACTIVE_FROM'] = (string)$arProductFields[
'DATE_ACTIVE_FROM'];
3019 if (!empty($arProduct[
'DATE_ACTIVE_FROM']))
3020 $arProduct[
'DATE_ACTIVE_FROM'] = (int)
MakeTimeStamp($arProduct[
'DATE_ACTIVE_FROM']);
3022 $arProduct[
'DATE_ACTIVE_TO'] = (string)$arProductFields[
'DATE_ACTIVE_TO'];
3023 if (!empty($arProduct[
'DATE_ACTIVE_TO']))
3024 $arProduct[
'DATE_ACTIVE_TO'] = (int)
MakeTimeStamp($arProduct[
'DATE_ACTIVE_TO']);
3026 $arProduct[
'SORT'] = (int)$arProductFields[
'SORT'];
3028 $arProduct[
'PREVIEW_TEXT'] = (string)$arProductFields[
'~PREVIEW_TEXT'];
3029 $arProduct[
'DETAIL_TEXT'] = (string)$arProductFields[
'~DETAIL_TEXT'];
3030 $arProduct[
'TAGS'] = (string)$arProductFields[
'~TAGS'];
3032 if (isset($arProductFields[
'DATE_CREATE_UNIX']))
3034 $arProduct[
'DATE_CREATE'] = (string)$arProductFields[
'DATE_CREATE_UNIX'];
3035 if (
'' != $arProduct[
'DATE_CREATE'])
3036 $arProduct[
'DATE_CREATE'] = (int)$arProduct[
'DATE_CREATE'];
3040 $arProduct[
'DATE_CREATE'] = (string)$arProductFields[
'DATE_CREATE'];
3041 if (
'' != $arProduct[
'DATE_CREATE'])
3042 $arProduct[
'DATE_CREATE'] = (int)
MakeTimeStamp($arProduct[
'DATE_CREATE']);
3045 if (isset($arProductFields[
'TIMESTAMP_X_UNIX']))
3047 $arProduct[
'TIMESTAMP_X'] = (string)$arProductFields[
'TIMESTAMP_X_UNIX'];
3048 if (
'' != $arProduct[
'TIMESTAMP_X'])
3049 $arProduct[
'TIMESTAMP_X'] = (int)$arProduct[
'TIMESTAMP_X'];
3053 $arProduct[
'TIMESTAMP_X'] = (string)$arProductFields[
'TIMESTAMP_X'];
3054 if (
'' != $arProduct[
'TIMESTAMP_X'])
3055 $arProduct[
'TIMESTAMP_X'] = (int)
MakeTimeStamp($arProduct[
'TIMESTAMP_X']);
3058 $arProduct[
'CREATED_BY'] = (int)$arProductFields[
'CREATED_BY'];
3059 $arProduct[
'MODIFIED_BY'] = (int)$arProductFields[
'MODIFIED_BY'];
3061 $arProduct[
'CATALOG_QUANTITY'] = (string)$arProductFields[
'CATALOG_QUANTITY'];
3062 if (
'' != $arProduct[
'CATALOG_QUANTITY'])
3063 $arProduct[
'CATALOG_QUANTITY'] = doubleval($arProduct[
'CATALOG_QUANTITY']);
3064 $arProduct[
'CATALOG_WEIGHT'] = (string)$arProductFields[
'CATALOG_WEIGHT'];
3065 if (
'' != $arProduct[
'CATALOG_WEIGHT'])
3066 $arProduct[
'CATALOG_WEIGHT'] = doubleval($arProduct[
'CATALOG_WEIGHT']);
3068 $arProduct[
'CATALOG_VAT_ID'] = (string)$arProductFields[
'CATALOG_VAT_ID'];
3069 if (
'' != $arProduct[
'CATALOG_VAT_ID'])
3070 $arProduct[
'CATALOG_VAT_ID'] = (int)$arProduct[
'CATALOG_VAT_ID'];
3072 $arProduct[
'CATALOG_VAT_INCLUDED'] = (string)$arProductFields[
'CATALOG_VAT_INCLUDED'];
3074 unset($arProductFields);
3075 if (!isset(self::$arCacheProductProperties[$arProduct[
'ID']]))
3077 $arProps = $obProduct->GetProperties(
array(),
array(
'ACTIVE' =>
'Y',
'EMPTY' =>
'N'));
3081 $arProps = self::$arCacheProductProperties[$arProduct[
'ID']];
3084 if (isset(self::$arCacheProductProperties[$arProduct[
'ID']]))
3085 unset(self::$arCacheProductProperties[$arProduct[
'ID']]);
3086 if (isset(self::$arCacheProductSections[$arProduct[
'ID']]))
3087 unset(self::$arCacheProductSections[$arProduct[
'ID']]);
3092 $arProduct[
'ID'] = 0;
3093 if (!isset($arProduct[
'SECTION_ID']))
3094 $arProduct[
'SECTION_ID'] =
array();
3095 if (!is_array($arProduct[
'SECTION_ID']))
3096 $arProduct[
'SECTION_ID'] =
array($arProduct[
'SECTION_ID']);
3099 $arProduct[
'DATE_ACTIVE_FROM'] =
'';
3100 $arProduct[
'DATE_ACTIVE_TO'] =
'';
3101 $arProduct[
'SORT'] = 500;
3103 $arProduct[
'PREVIEW_TEXT'] =
'';
3104 $arProduct[
'DETAIL_TEXT'] =
'';
3105 $arProduct[
'TAGS'] =
'';
3107 $arProduct[
'DATE_CREATE'] =
'';
3108 $arProduct[
'TIMESTAMP_X'] =
'';
3110 $arProduct[
'CREATED_BY'] = 0;
3111 $arProduct[
'MODIFIED_BY'] = 0;
3113 $arProduct[
'CATALOG_QUANTITY'] =
'';
3114 $arProduct[
'CATALOG_WEIGHT'] =
'';
3115 $arProduct[
'CATALOG_VAT_ID'] =
'';
3116 $arProduct[
'CATALOG_VAT_INCLUDED'] =
'';
3128 $intProductID = (int)$intProductID;
3131 $mxResult =
array();
3132 $arProductSections =
array();
3133 if (!isset(self::$arCacheProductSections[$intProductID]))
3135 $rsSections = CIBlockElement::GetElementGroups($intProductID,
true,
array(
"ID",
"IBLOCK_SECTION_ID",
"IBLOCK_ELEMENT_ID"));
3136 while ($arSection = $rsSections->Fetch())
3138 $arSection[
'ID'] = (int)$arSection[
'ID'];
3139 $arSection[
'IBLOCK_SECTION_ID'] = (int)$arSection[
'IBLOCK_SECTION_ID'];
3140 $arProductSections[] = $arSection;
3142 if (isset($arSection))
3144 self::$arCacheProductSections[$intProductID] = $arProductSections;
3148 $arProductSections = self::$arCacheProductSections[$intProductID];
3150 if (!empty($arProductSections))
3152 foreach ($arProductSections as &$arSection)
3154 $mxResult[$arSection[
'ID']] =
true;
3155 if (0 < $arSection[
'IBLOCK_SECTION_ID'])
3157 if (!isset(self::$arCacheProductSectionChain[$arSection[
'ID']]))
3159 self::$arCacheProductSectionChain[$arSection[
'ID']] =
array();
3160 $rsParents = CIBlockSection::GetNavChain(
$intIBlockID, $arSection[
'ID'],
array(
'ID'));
3161 while ($arParent = $rsParents->Fetch())
3163 $arParent[
'ID'] = (int)$arParent[
'ID'];
3164 $mxResult[$arParent[
'ID']] =
true;
3165 self::$arCacheProductSectionChain[$arSection[
'ID']][] = $arParent[
"ID"];
3170 foreach (self::$arCacheProductSectionChain[$arSection[
'ID']] as $intOneID)
3172 $mxResult[$intOneID] =
true;
3174 if (isset($intOneID))
3179 if (isset($arSection))
3182 if (!empty($mxResult))
3184 $mxResult = array_keys($mxResult);
3198 static $iblockProperties =
array();
3200 if (empty($arProps) || !is_array($arProps))
3205 static $intTimeOffset =
false;
3206 if (
false === $intTimeOffset)
3207 $intTimeOffset = CTimeZone::GetOffset();
3211 if (!isset($iblockProperties[$arProduct[
'IBLOCK_ID']]))
3213 $iblockProperties[$arProduct[
'IBLOCK_ID']] =
array();
3215 'select' =>
array(
'ID',
'IBLOCK_ID',
'CODE',
'PROPERTY_TYPE',
'MULTIPLE',
'USER_TYPE',
'USER_TYPE_SETTINGS'),
3217 'order' =>
array(
'ID' =>
'ASC')
3219 while ($property = $propertyIterator->fetch())
3221 $id = (int)$property[
'ID'];
3222 $property[
'USER_TYPE'] = (string)$property[
'USER_TYPE'];
3223 $property[
'USER_TYPE_SETTINGS'] = (string)$property[
'USER_TYPE_SETTINGS'];
3224 if ($property[
'USER_TYPE'] !=
'')
3226 $property[
'USER_TYPE_SETTINGS'] = (
3228 ? unserialize($property[
'USER_TYPE_SETTINGS'], [
'allowed_classes' =>
false])
3232 switch ($property[
'PROPERTY_TYPE'])
3237 $property[
'EMPTY_VALUE'] =
array(-1);
3240 $property[
'EMPTY_VALUE'] =
array(
'');
3243 $iblockProperties[$arProduct[
'IBLOCK_ID']][$id] = $property;
3245 unset($property, $propertyIterator);
3248 $propertyList = $iblockProperties[$arProduct[
'IBLOCK_ID']];
3249 foreach ($arProps as &$arOneProp)
3253 $propertyId = (int)$arOneProp[
'ID'];
3254 if (isset($propertyList[$propertyId]))
3255 unset($propertyList[$propertyId]);
3258 if (
'N' == $arOneProp[
'MULTIPLE'])
3260 if (isset($arOneProp[
'USER_TYPE']) && !empty($arOneProp[
'USER_TYPE']))
3262 switch($arOneProp[
'USER_TYPE'])
3266 $arOneProp[
'VALUE'] = (string)$arOneProp[
'VALUE'];
3267 if (
'' != $arOneProp[
'VALUE'])
3269 $propertyFormat =
false;
3270 if ($arOneProp[
'USER_TYPE'] ==
'DateTime')
3272 if (defined(
'FORMAT_DATETIME'))
3277 if (defined(
'FORMAT_DATE'))
3280 $intStackTimestamp = (int)$arOneProp[
'VALUE'];
3281 if ($intStackTimestamp.
'!' != $arOneProp[
'VALUE'].
'!')
3282 $arOneProp[
'VALUE'] = (int)
MakeTimeStamp($arOneProp[
'VALUE'], $propertyFormat) - $intTimeOffset;
3284 $arOneProp[
'VALUE'] = $intStackTimestamp;
3286 $arProduct[
'PROPERTY_'.$arOneProp[
'ID'].
'_VALUE'] = $arOneProp[
'VALUE'];
3293 if (
'L' == $arOneProp[
'PROPERTY_TYPE'])
3295 $arOneProp[
'VALUE_ENUM_ID'] = (int)$arOneProp[
'VALUE_ENUM_ID'];
3296 if (0 < $arOneProp[
'VALUE_ENUM_ID'])
3297 $arProduct[
'PROPERTY_'.$arOneProp[
'ID'].
'_VALUE'] = $arOneProp[
'VALUE_ENUM_ID'];
3299 $arProduct[
'PROPERTY_'.$arOneProp[
'ID'].
'_VALUE'] = -1;
3301 elseif (
'E' == $arOneProp[
'PROPERTY_TYPE'] ||
'G' == $arOneProp[
'PROPERTY_TYPE'])
3303 $arOneProp[
'VALUE'] = (int)$arOneProp[
'VALUE'];
3304 if (0 < $arOneProp[
'VALUE'])
3305 $arProduct[
'PROPERTY_'.$arOneProp[
'ID'].
'_VALUE'] = $arOneProp[
'VALUE'];
3307 $arProduct[
'PROPERTY_'.$arOneProp[
'ID'].
'_VALUE'] = -1;
3311 $arProduct[
'PROPERTY_'.$arOneProp[
'ID'].
'_VALUE'] = $arOneProp[
'VALUE'];
3317 if (isset($arOneProp[
'USER_TYPE']) && !empty($arOneProp[
'USER_TYPE']))
3319 switch($arOneProp[
'USER_TYPE'])
3324 if (is_array($arOneProp[
'VALUE']) && !empty($arOneProp[
'VALUE']))
3326 $propertyFormat =
false;
3327 if ($arOneProp[
'USER_TYPE'] ==
'DateTime')
3329 if (defined(
'FORMAT_DATETIME'))
3334 if (defined(
'FORMAT_DATE'))
3337 foreach ($arOneProp[
'VALUE'] as &$strOneValue)
3339 $strOneValue = (string)$strOneValue;
3340 if (
'' != $strOneValue)
3342 $intStackTimestamp = (int)$strOneValue;
3343 if ($intStackTimestamp.
'!' != $strOneValue.
'!')
3344 $strOneValue = (int)
MakeTimeStamp($strOneValue, $propertyFormat) - $intTimeOffset;
3346 $strOneValue = $intStackTimestamp;
3350 if (isset($strOneValue))
3351 unset($strOneValue);
3353 $arProduct[
'PROPERTY_'.$arOneProp[
'ID'].
'_VALUE'] =
$arValues;
3360 if (
'L' == $arOneProp[
'PROPERTY_TYPE'])
3363 if (is_array($arOneProp[
'VALUE_ENUM_ID']) && !empty($arOneProp[
'VALUE_ENUM_ID']))
3365 foreach ($arOneProp[
'VALUE_ENUM_ID'] as &$intOneValue)
3367 $intOneValue = (int)$intOneValue;
3368 if (0 < $intOneValue)
3371 if (isset($intOneValue))
3372 unset($intOneValue);
3376 $arProduct[
'PROPERTY_'.$arOneProp[
'ID'].
'_VALUE'] =
$arValues;
3378 elseif (
'E' == $arOneProp[
'PROPERTY_TYPE'] ||
'G' == $arOneProp[
'PROPERTY_TYPE'])
3381 if (is_array($arOneProp[
'VALUE']) && !empty($arOneProp[
'VALUE']))
3383 foreach ($arOneProp[
'VALUE'] as &$intOneValue)
3385 $intOneValue = (int)$intOneValue;
3386 if (0 < $intOneValue)
3389 if (isset($intOneValue))
3390 unset($intOneValue);
3394 $arProduct[
'PROPERTY_'.$arOneProp[
'ID'].
'_VALUE'] =
$arValues;
3398 $arProduct[
'PROPERTY_'.$arOneProp[
'ID'].
'_VALUE'] = $arOneProp[
'VALUE'];
3402 if (!is_array($arProduct[
'PROPERTY_'.$arOneProp[
'ID'].
'_VALUE']))
3403 $arProduct[
'PROPERTY_'.$arOneProp[
'ID'].
'_VALUE'] =
array($arProduct[
'PROPERTY_'.$arOneProp[
'ID'].
'_VALUE']);
3407 if (!empty($propertyList))
3409 foreach ($propertyList as &$property)
3410 $arProduct[
'PROPERTY_'.$property[
'ID'].
'_VALUE'] = $property[
'EMPTY_VALUE'];
3413 unset($propertyList);
3419 if (isset($product[
'PARENT_ID']))
3420 $parentID = (int)$product[
'PARENT_ID'];
3421 elseif (isset($product[
'PROPERTY_'.$sku[
'SKU_PROPERTY_ID'].
'_VALUE']))
3422 $parentID = (int)current($product[
'PROPERTY_'.$sku[
'SKU_PROPERTY_ID'].
'_VALUE']);
3425 if (!isset(self::$arCacheProduct[$parentID]))
3427 $parent =
array(
'ID' => $parentID,
'IBLOCK_ID' => $sku[
'PRODUCT_IBLOCK_ID']);
3428 if (!self::__GenerateFields($parent))
3430 self::$arCacheProduct[$parentID] = $parent;
3434 $parent = self::$arCacheProduct[$parentID];
3436 foreach ($parent as
$key => $value)
3438 if (
$key ==
'SECTION_ID')
3440 $product[
$key] = array_merge($product[
$key], $value);
3444 $product[
$key] = $value;
3448 $product[
'PARENT_'.$key] = $value;
3451 unset($value,
$key, $parent);
3465 if (!self::__CheckOneEntity(
$arFields,
'GROUP_IDS'))
3467 $arMsg[] =
array(
'id' =>
'GROUP_IDS',
"text" =>
Loc::getMessage(
'BT_MOD_CATALOG_DISC_ERR_PARSE_USER_GROUP'));
3468 $boolResult =
false;
3470 if (!self::__CheckOneEntity(
$arFields,
'CATALOG_GROUP_IDS'))
3472 $arMsg[] =
array(
'id' =>
'CATALOG_GROUP_IDS',
"text" =>
Loc::getMessage(
'BT_MOD_CATALOG_DISC_ERR_PARSE_PRICE_TYPE'));
3473 $boolResult =
false;
3479 'USER_GROUP_ID' =>
$arFields[
'GROUP_IDS'],
3480 'PRICE_TYPE_ID' =>
$arFields[
'CATALOG_GROUP_IDS'],
3507 $boolResult =
false;
3508 $strEntityID = trim(strval($strEntityID));
3509 if (!empty($strEntityID))
3518 foreach (
$arFields[$strEntityID] as &$value)
3520 $value = (int)$value;
3522 $arValid[] = $value;
3526 if (!empty($arValid))
3528 $arValid = array_unique($arValid);
3553 if (empty($arTuple))
3556 'EQUAL' => array_combine($arOrder, $arTemp),
3561 $head = array_shift($arTuple);
3563 if (is_array($head))
3567 $arTemp[
count($arTemp)-1] = -1;
3572 foreach ($head as &$value)
3574 $arTemp[
count($arTemp)-1] = $value;
3583 $arTemp[
count($arTemp)-1] = $head;
3589 protected static function __Unpack($arProduct, $strUnpack)
3591 if (empty($strUnpack))
3593 return eval(
'return '.$strUnpack.
';');
3598 $strAction = mb_strtoupper($strAction);
3601 $arConditions =
array(
3602 'CLASS_ID' =>
'CondGroup',
3607 'CHILDREN' =>
array(),
3609 $intEntityCount = 0;
3612 if (!empty($arIBlockList))
3618 if (!empty($arSectionList))
3624 if (!empty($arElementList))
3629 if (0 < $intEntityCount)
3636 if (
'ADD' == $strAction)
3638 $arFields[
'CONDITIONS'] = $arConditions;
3642 if (0 < $intEntityCount)
3644 $arFields[
'CONDITIONS'] = $arConditions;
3653 if (!empty($strEntityID))
3660 foreach (
$arFields[$strEntityID] as &$value)
3662 $value = (int)$value;
3677 protected static function __AddOldOneEntity(&$arConditions, $strCondID, $arEntityValues, $boolOneEntity)
3679 if (!empty($strCondID))
3681 $boolOneEntity = (
true == $boolOneEntity ? true :
false);
3682 if (!empty($arEntityValues))
3684 if (1 <
count($arEntityValues))
3687 foreach ($arEntityValues as &$intItemID)
3690 'CLASS_ID' => $strCondID,
3693 'value' => $intItemID
3697 if (isset($intItemID))
3701 $arConditions =
array(
3702 'CLASS_ID' =>
'CondGroup',
3707 'CHILDREN' => $arList,
3712 $arConditions[
'CHILDREN'][] =
array(
3713 'CLASS_ID' =>
'CondGroup',
3718 'CHILDREN' => $arList,
3724 $arConditions[
'CHILDREN'][] =
array(
3725 'CLASS_ID' => $strCondID,
3728 'value' => current($arEntityValues)
3741 $arConditions =
false;
3746 $arConditions = unserialize(
$arFields[
'CONDITIONS'], [
'allowed_classes' =>
false]);
3751 $arConditions =
$arFields[
'CONDITIONS'];
3754 if (is_array($arConditions) && !empty($arConditions))
3760 $arResult = $obCond->GetConditionValues($arConditions);
3769 if (is_array($arCondList) && !empty($arCondList))
3772 if (isset($arCondList[$strCondID]) && !empty($arCondList[$strCondID]) && is_array($arCondList[$strCondID]))
3774 if (isset($arCondList[$strCondID][
'VALUES']) && !empty($arCondList[$strCondID][
'VALUES']) && is_array($arCondList[$strCondID][
'VALUES']))
3777 foreach ($arCondList[$strCondID][
'VALUES'] as &$intValue)
3779 $intValue = (int)$intValue;
3781 $arCheck[] = $intValue;
3783 if (isset($intValue))
3785 $arCheck = array_values(array_unique($arCheck));
3796 $boolUpdate = (
false === $boolUpdate ?
false :
true);
3797 $intID = (int)$intID;
3808 $DB->Query(
"DELETE FROM ".
$arParams[
'TABLE_ID'].
" WHERE DISCOUNT_ID = ".$intID);
3814 $strSql =
"INSERT INTO ".$arParams[
'TABLE_ID'].
"(DISCOUNT_ID, ".
$arParams[
'FIELD_ID'].
") VALUES(".$intID.
", ".$intValue.
")";
3815 $DB->Query($strSql);
3817 if (isset($intValue))
3827 if (!is_array($arDiscountIDs))
3831 if (!is_array($arCatalogGroups))
3834 if (empty($arCatalogGroups))
3837 if (!is_array($arUserGroups))
3840 if (empty($arUserGroups))
3843 $strCacheKey = md5(
'C'.implode(
'_', $arCatalogGroups).
'-'.
'U'.implode(
'_', $arUserGroups));
3844 self::$arCacheDiscountFilter[$strCacheKey] = $arDiscountIDs;
3851 if (empty($arDiscountCache) || !is_array($arDiscountCache))
3853 $boolNeedClear = !!$boolNeedClear;
3854 foreach ($arDiscountCache as $strCacheKey => $arDiscountIDs)
3856 if (!is_array($arDiscountIDs))
3860 self::$arCacheDiscountFilter[$strCacheKey] = $arDiscountIDs;
3867 if (!is_array($arCatalogGroups))
3870 if (empty($arCatalogGroups))
3873 if (!is_array($arUserGroups))
3876 if (empty($arUserGroups))
3879 $strCacheKey = md5(
'C'.implode(
'_', $arCatalogGroups).
'-'.
'U'.implode(
'_', $arUserGroups));
3880 return (isset(self::$arCacheDiscountFilter[$strCacheKey]) ? self::$arCacheDiscountFilter[$strCacheKey] :
false);
3885 if (!is_array($arCatalogGroups))
3888 if (empty($arCatalogGroups))
3891 if (!is_array($arUserGroups))
3894 if (empty($arUserGroups))
3897 $strCacheKey = md5(
'C'.implode(
'_', $arCatalogGroups).
'-'.
'U'.implode(
'_', $arUserGroups));
3898 return isset(self::$arCacheDiscountFilter[$strCacheKey]);
3903 if (empty($strCacheKey))
3905 $strCacheKey = md5($strCacheKey);
3906 return (isset(self::$arCacheDiscountFilter[$strCacheKey]) ? self::$arCacheDiscountFilter[$strCacheKey] :
false);
3911 if (empty($strCacheKey))
3913 $strCacheKey = md5($strCacheKey);
3914 return isset(self::$arCacheDiscountFilter[$strCacheKey]);
3919 $boolNeedClear = !!$boolNeedClear;
3922 if (!is_array($arCatalogGroups))
3925 if (empty($arCatalogGroups))
3928 if (!is_array($arUserGroups))
3931 if (empty($arUserGroups))
3935 return md5(
'C'.implode(
'_', $arCatalogGroups).
'-'.
'U'.implode(
'_', $arUserGroups));
3940 if (!is_array($arDiscountList))
3942 if (!is_array($arDiscountIDs))
3945 if (empty($arDiscountIDs))
3947 if (
'' == $strSiteID)
3949 $strRenewal = (
'Y' == $strRenewal ?
'Y' :
'N');
3950 $strCacheKey = md5(
'D'.implode(
'_', $arDiscountIDs).
'-'.
'S'.$strSiteID.
'-R'.$strRenewal);
3951 self::$arCacheDiscountResult[$strCacheKey] = $arDiscountIDs;
3958 if (empty($arDiscountResultCache) || !is_array($arDiscountResultCache))
3960 foreach ($arDiscountResultCache as $strCacheKey => $arDiscountIDs)
3962 self::$arCacheDiscountResult[$strCacheKey] = $arDiscountIDs;
3970 $boolNeedClear = !!$boolNeedClear;
3973 if (!is_array($arDiscountIDs))
3976 if (empty($arDiscountIDs))
3979 if (
'' == $strSiteID)
3981 $strRenewal = (
'Y' == $strRenewal ?
'Y' :
'N');
3983 return md5(
'D'.implode(
'_', $arDiscountIDs).
'-'.
'S'.$strSiteID.
'-R'.$strRenewal);
3988 if (empty($arItem) || !is_array($arItem))
3991 if(self::isUsedSaleDiscountOnly())
4004 $select =
array(
'ID',
'IBLOCK_ID',
'CODE',
'XML_ID',
'NAME',
'ACTIVE',
'DATE_ACTIVE_FROM',
'DATE_ACTIVE_TO',
4005 'SORT',
'PREVIEW_TEXT',
'DETAIL_TEXT',
'DATE_CREATE',
'DATE_CREATE_UNIX',
'CREATED_BY',
'TIMESTAMP_X',
'TIMESTAMP_X_UNIX',
4006 'MODIFIED_BY',
'TAGS',
'CATALOG_QUANTITY'
4008 CTimeZone::Disable();
4010 CTimeZone::Enable();
4011 while ($arProductFields = $rsProducts->GetNext(
false,
true))
4013 $arProduct =
array();
4015 $arProduct[
'ID'] = (int)$arProductFields[
'ID'];
4016 $arProduct[
'IBLOCK_ID'] = (int)$arProductFields[
'IBLOCK_ID'];
4018 $arProduct[
'SECTION_ID'] =
array();
4020 if (
false !== $arProductSections)
4021 $arProduct[
'SECTION_ID'] = $arProductSections;
4023 $arProduct[
'CODE'] = (string)$arProductFields[
'~CODE'];
4024 $arProduct[
'XML_ID'] = (string)$arProductFields[
'~XML_ID'];
4025 $arProduct[
'NAME'] = $arProductFields[
'~NAME'];
4027 $arProduct[
'ACTIVE'] = $arProductFields[
'ACTIVE'];
4029 $arProduct[
'DATE_ACTIVE_FROM'] = (string)$arProductFields[
'DATE_ACTIVE_FROM'];
4030 if (!empty($arProduct[
'DATE_ACTIVE_FROM']))
4031 $arProduct[
'DATE_ACTIVE_FROM'] = (int)
MakeTimeStamp($arProduct[
'DATE_ACTIVE_FROM']);
4033 $arProduct[
'DATE_ACTIVE_TO'] = (string)$arProductFields[
'DATE_ACTIVE_TO'];
4034 if (!empty($arProduct[
'DATE_ACTIVE_TO']))
4035 $arProduct[
'DATE_ACTIVE_TO'] = (int)
MakeTimeStamp($arProduct[
'DATE_ACTIVE_TO']);
4037 $arProduct[
'SORT'] = (int)$arProductFields[
'SORT'];
4039 $arProduct[
'PREVIEW_TEXT'] = (string)$arProductFields[
'~PREVIEW_TEXT'];
4040 $arProduct[
'DETAIL_TEXT'] = (string)$arProductFields[
'~DETAIL_TEXT'];
4041 $arProduct[
'TAGS'] = (string)$arProductFields[
'~TAGS'];
4043 if (isset($arProductFields[
'DATE_CREATE_UNIX']))
4045 $arProduct[
'DATE_CREATE'] = (string)$arProductFields[
'DATE_CREATE_UNIX'];
4046 if (
'' != $arProduct[
'DATE_CREATE'])
4047 $arProduct[
'DATE_CREATE'] = (int)$arProduct[
'DATE_CREATE'];
4051 $arProduct[
'DATE_CREATE'] = (string)$arProductFields[
'DATE_CREATE'];
4052 if (
'' != $arProduct[
'DATE_CREATE'])
4053 $arProduct[
'DATE_CREATE'] = (int)
MakeTimeStamp($arProduct[
'DATE_CREATE']);
4056 if (isset($arProductFields[
'TIMESTAMP_X_UNIX']))
4058 $arProduct[
'TIMESTAMP_X'] = (string)$arProductFields[
'TIMESTAMP_X_UNIX'];
4059 if (
'' != $arProduct[
'TIMESTAMP_X'])
4060 $arProduct[
'TIMESTAMP_X'] = (int)$arProduct[
'TIMESTAMP_X'];
4064 $arProduct[
'TIMESTAMP_X'] = (string)$arProductFields[
'TIMESTAMP_X'];
4065 if (
'' != $arProduct[
'TIMESTAMP_X'])
4066 $arProduct[
'TIMESTAMP_X'] = (int)
MakeTimeStamp($arProduct[
'TIMESTAMP_X']);
4069 $arProduct[
'CREATED_BY'] = (int)$arProductFields[
'CREATED_BY'];
4070 $arProduct[
'MODIFIED_BY'] = (int)$arProductFields[
'MODIFIED_BY'];
4072 $arProduct[
'CATALOG_QUANTITY'] = (string)$arProductFields[
'CATALOG_QUANTITY'];
4073 if (
'' != $arProduct[
'CATALOG_QUANTITY'])
4074 $arProduct[
'CATALOG_QUANTITY'] = doubleval($arProduct[
'CATALOG_QUANTITY']);
4075 $arProduct[
'CATALOG_WEIGHT'] = (string)$arProductFields[
'CATALOG_WEIGHT'];
4076 if (
'' != $arProduct[
'CATALOG_WEIGHT'])
4077 $arProduct[
'CATALOG_WEIGHT'] = doubleval($arProduct[
'CATALOG_WEIGHT']);
4079 $arProduct[
'CATALOG_VAT_ID'] = (string)$arProductFields[
'CATALOG_VAT_ID'];
4080 if (
'' != $arProduct[
'CATALOG_VAT_ID'])
4081 $arProduct[
'CATALOG_VAT_ID'] = (int)$arProduct[
'CATALOG_VAT_ID'];
4083 $arProduct[
'CATALOG_VAT_INCLUDED'] = (string)$arProductFields[
'CATALOG_VAT_INCLUDED'];
4085 if (!isset(self::$arCacheProductProperties[$arProduct[
'ID']]))
4088 $arProduct[
'ID'] =>
array()
4090 CIBlockElement::GetPropertyValuesArray(
4092 $arProduct[
'IBLOCK_ID'],
4093 array(
'ID' => $arProduct[
'ID'],
'IBLOCK_ID' => $arProduct[
'IBLOCK_ID']),
4097 'PROPERTY_TYPE' =>
true,
4099 'USER_TYPE' =>
true,
4102 self::$arCacheProductProperties[$arProduct[
'ID']] = $propsList[$arProduct[
'ID']];
4105 $arProps = self::$arCacheProductProperties[$arProduct[
'ID']];
4108 if (isset(self::$arCacheProductProperties[$arProduct[
'ID']]))
4109 unset(self::$arCacheProductProperties[$arProduct[
'ID']]);
4110 if (isset(self::$arCacheProductSections[$arProduct[
'ID']]))
4111 unset(self::$arCacheProductSections[$arProduct[
'ID']]);
4113 $sku = CCatalogSku::GetInfoByOfferIBlock($arProduct[
'IBLOCK_ID']);
4116 self::$arCacheProduct[$arProduct[
'ID']] = $arProduct;
4121 if (!isset(self::$arCacheProduct[$arItem[
'ID']]))
4126 if (!self::__GenerateFields($arItem,
$arParams))
4129 $sku = CCatalogSku::GetInfoByOfferIBlock($arItem[
'IBLOCK_ID']);
4132 self::$arCacheProduct[$arItem[
'ID']] = $arItem;
4139 if(!isset(self::$arCacheProduct[$productId]))
4144 return self::$arCacheProduct[$productId];
4149 if (empty($arItemIDs) || !is_array($arItemIDs))
4152 if (empty($arItemIDs))
4155 if (empty(self::$arCacheProductSections))
4157 self::$arCacheProductSections = array_fill_keys($arItemIDs,
array());
4161 foreach ($arItemIDs as $intOneID)
4162 self::$arCacheProductSections[$intOneID] =
array();
4166 foreach (array_chunk($arItemIDs, 500) as $pageIds)
4168 $rsSections = CIBlockElement::GetElementGroups(
4171 array(
"ID",
"IBLOCK_SECTION_ID",
"IBLOCK_ELEMENT_ID")
4173 while ($arSection = $rsSections->Fetch())
4175 $arSection[
'ID'] = (int)$arSection[
'ID'];
4176 $arSection[
'IBLOCK_SECTION_ID'] = (int)$arSection[
'IBLOCK_SECTION_ID'];
4177 $arSection[
'IBLOCK_ELEMENT_ID'] = (int)$arSection[
'IBLOCK_ELEMENT_ID'];
4178 self::$arCacheProductSections[$arSection[
'IBLOCK_ELEMENT_ID']][] = $arSection;
4180 unset($arSection, $rsSections);
4187 $intProductID = (int)$intProductID;
4188 if ($intProductID <= 0)
4190 if (!is_array($arProps))
4196 'PROPERTY_TYPE' =>
true,
4197 '~PROPERTY_TYPE' =>
true,
4199 '~MULTIPLE' =>
true,
4200 'USER_TYPE' =>
true,
4201 '~USER_TYPE' =>
true,
4204 'VALUE_ENUM_ID' =>
true,
4205 '~VALUE_ENUM_ID' =>
true
4207 if (!empty($arProps))
4209 foreach (array_keys($arProps) as $index)
4211 $arProps[$index] = array_intersect_key($arProps[$index], $whiteList);
4212 if (empty($arProps[$index]))
4213 unset($arProps[$index]);
4218 if (self::isUsedSaleDiscountOnly())
4221 self::$arCacheProductProperties[$intProductID] = $arProps;
4229 if (self::isUsedSaleDiscountOnly())
4237 self::$arCacheProduct =
array();
4239 self::$arCacheProductSections =
array();
4240 if (isset(
$arTypes[
'SECTION_CHAINS']))
4241 self::$arCacheProductSectionChain =
array();
4243 self::$arCacheProductProperties =
array();
4248 if (self::$useSaleDiscount ===
null)
4251 return self::$useSaleDiscount;
4256 $price = (float)$price;
4261 $priceDiscountList =
array();
4262 $accumulativeDiscountList =
array();
4263 foreach ($discountList as $oneDiscount)
4265 $oneDiscount[
'PRIORITY'] = (int)$oneDiscount[
'PRIORITY'];
4266 $oneDiscount[
'VALUE_TYPE'] = (string)$oneDiscount[
'VALUE_TYPE'];
4267 $oneDiscount[
'VALUE'] = (float)$oneDiscount[
'VALUE'];
4268 $oneDiscount[
'TYPE'] = (int)$oneDiscount[
'TYPE'];
4269 $changeData = ($oneDiscount[
'CURRENCY'] !=
$currency);
4270 switch ($oneDiscount[
'VALUE_TYPE'])
4272 case self::TYPE_FIX:
4275 ? $oneDiscount[
'VALUE']
4280 $validDiscount = ($price >= $discountValue);
4283 $oneDiscount[
'DISCOUNT_CONVERT'] = $discountValue;
4285 $oneDiscount[
'VALUE'] = $oneDiscount[
'DISCOUNT_CONVERT'];
4288 case self::TYPE_SALE:
4291 ? $oneDiscount[
'VALUE']
4296 $validDiscount = ($price > $discountValue);
4299 $oneDiscount[
'DISCOUNT_CONVERT'] = $discountValue;
4301 $oneDiscount[
'VALUE'] = $oneDiscount[
'DISCOUNT_CONVERT'];
4304 case self::TYPE_PERCENT:
4305 $validDiscount = ($oneDiscount[
'VALUE'] <= 100);
4308 $oneDiscount[
'MAX_DISCOUNT'] = (float)$oneDiscount[
'MAX_DISCOUNT'];
4309 if ($oneDiscount[
'TYPE'] == self::ENTITY_ID && $oneDiscount[
'MAX_DISCOUNT'] > 0)
4311 $oneDiscount[
'DISCOUNT_CONVERT'] = (
4313 ? $oneDiscount[
'MAX_DISCOUNT']
4319 $oneDiscount[
'MAX_DISCOUNT'] = $oneDiscount[
'DISCOUNT_CONVERT'];
4324 $validDiscount =
false;
4326 if (!$validDiscount)
4332 $accumulativeDiscountList[] = $oneDiscount;
4334 elseif ($oneDiscount[
'TYPE'] == self::ENTITY_ID)
4336 if (!isset($priceDiscountList[$oneDiscount[
'PRIORITY']]))
4337 $priceDiscountList[$oneDiscount[
'PRIORITY']] =
array();
4338 $priceDiscountList[$oneDiscount[
'PRIORITY']][] = $oneDiscount;
4341 unset($oneDiscount);
4343 if (!empty($priceDiscountList))
4344 krsort($priceDiscountList);
4349 $basePrice = (float)$basePrice;
4350 $price = (float)$price;
4352 if ($basePrice <= 0 || $price <= 0 ||
$currency ===
false)
4355 if (!is_array($resultDiscount))
4356 $resultDiscount =
array();
4358 $currentPrice = $price;
4363 foreach ($discountList as $discountIndex => $oneDiscount)
4365 $calculatePrice = self::calculatePriceByDiscount($basePrice, $currentPrice, $oneDiscount, $needErase);
4368 unset($discountList[$discountIndex]);
4372 $apply = ($minPrice ===
false || $minPrice > $calculatePrice);
4375 $minPrice = $calculatePrice;
4376 $minIndex = $discountIndex;
4380 unset($calculatePrice);
4382 unset($oneDiscount, $discountIndex);
4384 if ($minPrice !==
false)
4386 $currentPrice = $minPrice;
4387 $resultDiscount[] = $discountList[$minIndex];
4388 if ($discountList[$minIndex][
'LAST_DISCOUNT'] ==
'Y')
4390 $discountList =
array();
4394 unset($discountList[$minIndex]);
4398 while (!empty($discountList));
4400 return $currentPrice;
4405 $basePrice = (float)$basePrice;
4406 $price = (float)$price;
4408 if ($basePrice <= 0 || $price <= 0 ||
$currency ===
false)
4411 $currentPrice = $price;
4414 foreach ($discsaveList as $discountIndex => $oneDiscount)
4416 $calculatePrice =
false;
4417 switch($oneDiscount[
'VALUE_TYPE'])
4421 self::$getPercentFromBasePrice
4424 )*$oneDiscount[
'VALUE']/100
4426 $needErase = ($currentPrice < $discountValue);
4428 $calculatePrice = $currentPrice - $discountValue;
4429 unset($discountValue);
4432 $needErase = ($oneDiscount[
'DISCOUNT_CONVERT'] > $currentPrice);
4434 $calculatePrice = $currentPrice - $oneDiscount[
'DISCOUNT_CONVERT'];
4442 $apply = ($minPrice ===
false || $minPrice > $calculatePrice);
4445 $minPrice = $calculatePrice;
4446 $minIndex = $discountIndex;
4451 if ($minPrice !==
false && isset($discsaveList[$minIndex]))
4453 $currentPrice = $minPrice;
4454 $resultDiscount[] = $discsaveList[$minIndex];
4457 return $currentPrice;
4462 return ($value !==
null);
4468 if (self::$useSaleDiscount ===
null)
4469 self::$useSaleDiscount = $saleInstalled && (string)
Option::get(
'sale',
'use_sale_discount_only') ==
'Y';
4470 if (self::$getPercentFromBasePrice ===
null)
4472 $moduleID = ($saleInstalled ?
'sale' :
'catalog');
4473 self::$getPercentFromBasePrice = (string)
Option::get(
$moduleID,
'get_discount_percent_from_base_price') ==
'Y';
4475 if (self::$existCouponsManager ===
null)
4476 self::$existCouponsManager = $saleInstalled;