226 $clearFields =
array(
227 'NEGATIVE_AMOUNT_TRACE',
228 '~NEGATIVE_AMOUNT_TRACE',
234 $clearFields[] =
'ID';
235 $clearFields[] =
'~ID';
239 $clearFields[] =
'BUNDLE';
240 $clearFields[] =
'~BUNDLE';
243 foreach ($clearFields as $fieldName)
245 if (array_key_exists($fieldName,
$arFields))
248 unset($fieldName, $clearFields);
252 if (!array_key_exists(
'SUBSCRIBE',
$arFields))
293 $arFields[
"RECUR_SCHEME_TYPE"] = self::TIME_PERIOD_DAY;
308 $existPurchasingPrice = array_key_exists(
'PURCHASING_PRICE',
$arFields);
309 $existPurchasingCurrency = array_key_exists(
'PURCHASING_CURRENCY',
$arFields);
312 $purchasingPrice =
false;
313 $purchasingCurrency =
false;
315 if ($existPurchasingPrice)
317 $purchasingPrice = static::checkPriceValue(
$arFields[
'PURCHASING_PRICE']);
318 if ($purchasingPrice !==
false)
320 $purchasingCurrency = static::checkPriceCurrency(
$arFields[
'PURCHASING_CURRENCY']);
321 if ($purchasingCurrency ===
false)
323 $arMsg[] =
array(
'id' =>
'PURCHASING_CURRENCY',
'text' =>
Loc::getMessage(
'BT_MOD_CATALOG_PROD_ERR_COST_CURRENCY'));
329 $arFields[
'PURCHASING_PRICE'] = $purchasingPrice;
330 $arFields[
'PURCHASING_CURRENCY'] = $purchasingCurrency;
331 unset($purchasingCurrency, $purchasingPrice);
335 if ($existPurchasingPrice || $existPurchasingCurrency)
337 if ($existPurchasingPrice)
339 $arFields[
'PURCHASING_PRICE'] = static::checkPriceValue(
$arFields[
'PURCHASING_PRICE']);
340 if (
$arFields[
'PURCHASING_PRICE'] ===
false)
342 $arFields[
'PURCHASING_CURRENCY'] =
false;
346 if ($existPurchasingCurrency)
348 $purchasingCurrency = static::checkPriceCurrency(
$arFields[
'PURCHASING_CURRENCY']);
349 if ($purchasingCurrency ===
false)
351 $arMsg[] =
array(
'id' =>
'PURCHASING_CURRENCY',
'text' =>
Loc::getMessage(
'BT_MOD_CATALOG_PROD_ERR_COST_CURRENCY'));
356 $arFields[
'PURCHASING_CURRENCY'] = $purchasingCurrency;
358 unset($purchasingCurrency);
362 elseif ($existPurchasingCurrency)
364 $purchasingCurrency = static::checkPriceCurrency(
$arFields[
'PURCHASING_CURRENCY']);
365 if ($purchasingCurrency ===
false)
367 $arMsg[] =
array(
'id' =>
'PURCHASING_CURRENCY',
'text' =>
Loc::getMessage(
'BT_MOD_CATALOG_PROD_ERR_COST_CURRENCY'));
372 $arFields[
'PURCHASING_CURRENCY'] = $purchasingCurrency;
374 unset($purchasingCurrency);
378 unset($existPurchasingCurrency, $existPurchasingPrice);
382 if (array_key_exists(
'SUBSCRIBE',
$arFields))
387 if (array_key_exists(
'BUNDLE',
$arFields))
392 $availableFieldsList =
array(
397 $needCalculateAvailable =
false;
399 if (isset($copyFields[
'QUANTITY_TRACE']) && $copyFields[
'QUANTITY_TRACE'] ==
'D')
401 if (isset($copyFields[
'CAN_BUY_ZERO']) && $copyFields[
'CAN_BUY_ZERO'] ==
'D')
421 $needCalculateAvailable =
true;
425 $needFields =
array();
426 foreach ($availableFieldsList as $availableField)
429 $needCalculateAvailable =
true;
431 $needFields[] = $availableField;
433 unset($availableField);
434 if ($needCalculateAvailable && !empty($needFields))
437 'select' => $needFields,
440 $product = $productIterator->fetch();
441 unset($productIterator);
442 if (!empty($product) && is_array($product))
444 foreach ($availableFieldsList as $availableField)
446 if (isset($copyFields[$availableField]))
448 $copyFields[$availableField] = $product[$availableField];
450 unset($availableField);
462 $skuAvailable =
false;
464 'select' =>
array(
'ID',
'QUANTITY',
'QUANTITY_TRACE',
'CAN_BUY_ZERO'),
467 while ($offer = $offerIterator->fetch())
470 $skuAvailable =
true;
472 unset($offer, $offerIterator);
495 if ($needCalculateAvailable)
853 static $eventOnGetExists =
null;
854 static $eventOnResultExists =
null;
858 if ($eventOnGetExists ===
true || $eventOnGetExists ===
null)
860 foreach (
GetModuleEvents(
'catalog',
'OnGetNearestQuantityPrice',
true) as $arEvent)
862 $eventOnGetExists =
true;
871 if ($mxResult !==
true)
874 if ($eventOnGetExists ===
null)
875 $eventOnGetExists =
false;
879 $productID = (int)$productID;
886 $quantity = (float)$quantity;
893 if (!is_array($arUserGroups) && (
int)$arUserGroups.
'|' == (
string)$arUserGroups.
'|')
894 $arUserGroups =
array((
int)$arUserGroups);
896 if (!is_array($arUserGroups))
897 $arUserGroups =
array();
899 if (!in_array(2, $arUserGroups))
902 $quantityDifference = -1;
903 $nearestQuantity = -1;
911 'select' =>
array(
'ID',
'QUANTITY_FROM',
'QUANTITY_TO'),
913 '=PRODUCT_ID' => $productID,
917 while ($arPriceList =
$iterator->fetch())
919 $arPriceList[
'QUANTITY_FROM'] = (float)$arPriceList[
'QUANTITY_FROM'];
920 $arPriceList[
'QUANTITY_TO'] = (float)$arPriceList[
'QUANTITY_TO'];
921 if ($quantity >= $arPriceList[
"QUANTITY_FROM"]
922 && ($quantity <= $arPriceList[
"QUANTITY_TO"] || $arPriceList[
"QUANTITY_TO"] == 0))
924 $nearestQuantity = $quantity;
928 if ($quantity < $arPriceList[
"QUANTITY_FROM"])
930 $nearestQuantity_tmp = $arPriceList[
"QUANTITY_FROM"];
931 $quantityDifference_tmp = $arPriceList[
"QUANTITY_FROM"] - $quantity;
935 $nearestQuantity_tmp = $arPriceList[
"QUANTITY_TO"];
936 $quantityDifference_tmp = $quantity - $arPriceList[
"QUANTITY_TO"];
939 if ($quantityDifference < 0 || $quantityDifference_tmp < $quantityDifference)
941 $quantityDifference = $quantityDifference_tmp;
942 $nearestQuantity = $nearestQuantity_tmp;
948 if ($eventOnResultExists ===
true || $eventOnResultExists ===
null)
950 foreach (
GetModuleEvents(
'catalog',
'OnGetNearestQuantityPriceResult',
true) as $arEvent)
952 $eventOnResultExists =
true;
956 if ($eventOnResultExists ===
null)
957 $eventOnResultExists =
false;
960 return ($nearestQuantity > 0 ? $nearestQuantity :
false);
973 public static function GetOptimalPrice($intProductID, $quantity = 1, $arUserGroups =
array(), $renewal =
"N", $priceList =
array(),
$siteID =
false, $arDiscountCoupons =
false)
975 static $eventOnGetExists =
null;
976 static $eventOnResultExists =
null;
980 if ($eventOnGetExists ===
true || $eventOnGetExists ===
null)
982 foreach (
GetModuleEvents(
'catalog',
'OnGetOptimalPrice',
true) as $arEvent)
996 if ($mxResult ===
null)
1000 $eventOnGetExists =
true;
1001 if ($mxResult !==
true)
1003 self::updateUserHandlerOptimalPrice(
1005 [
'PRODUCT_ID' => $intProductID]
1010 if ($eventOnGetExists ===
null)
1011 $eventOnGetExists =
false;
1014 $intProductID = (int)$intProductID;
1015 if ($intProductID <= 0)
1021 $quantity = (float)$quantity;
1028 if (!is_array($arUserGroups) && (
int)$arUserGroups.
'|' == (
string)$arUserGroups.
'|')
1029 $arUserGroups =
array((
int)$arUserGroups);
1031 if (!is_array($arUserGroups))
1032 $arUserGroups =
array();
1034 if (!in_array(2, $arUserGroups))
1035 $arUserGroups[] = 2;
1038 $renewal = ($renewal ==
'Y' ?
'Y' :
'N');
1044 if (empty($resultCurrency))
1050 $intIBlockID = (int)CIBlockElement::GetIBlockByID($intProductID);
1055 'BT_MOD_CATALOG_PROD_ERR_ELEMENT_ID_NOT_FOUND',
1056 array(
'#ID#' => $intProductID)
1063 if (!isset($priceList) || !is_array($priceList))
1064 $priceList =
array();
1066 if (empty($priceList))
1073 'select' =>
array(
'ID',
'CATALOG_GROUP_ID',
'PRICE',
'CURRENCY',
'PRICE_SCALE'),
1075 '=PRODUCT_ID' => $intProductID,
1079 '<=QUANTITY_FROM' => $quantity,
1080 '=QUANTITY_FROM' =>
null
1084 '>=QUANTITY_TO' => $quantity,
1085 '=QUANTITY_TO' =>
null
1088 'order' =>
array(
'CATALOG_GROUP_ID' =>
'ASC')
1093 $priceList[] = $row;
1100 foreach (array_keys($priceList) as $priceIndex)
1101 $priceList[$priceIndex][
'ELEMENT_IBLOCK_ID'] =
$intIBlockID;
1105 if (empty($priceList))
1111 if (
$vat[
'EXCLUDE_VAT'] ===
'N')
1113 $vat[
'RATE'] =
$vat[
'RATE'] * 0.01;
1120 'VAT_INCLUDED' =>
'N',
1121 'EXCLUDE_VAT' =>
'Y',
1128 if ($isNeedDiscounts)
1130 if ($arDiscountCoupons ===
false)
1134 $minimalPrice =
array();
1136 if (self::$saleIncluded ===
null)
1138 $isNeedleToMinimizeCatalogGroup = self::isNeedleToMinimizeCatalogGroup($priceList);
1140 foreach ($priceList as $priceData)
1142 $priceData[
'VAT_RATE'] =
$vat[
'RATE'];
1143 $priceData[
'VAT_INCLUDED'] =
$vat[
'VAT_INCLUDED'];
1144 $priceData[
'NO_VAT'] =
$vat[
'EXCLUDE_VAT'];
1146 $currentPrice = (float)$priceData[
'PRICE'];
1147 if ($priceData[
'NO_VAT'] ===
'N')
1149 if ($priceData[
'VAT_INCLUDED'] ===
'N')
1151 $currentPrice *= (1 + $priceData[
'VAT_RATE']);
1154 if ($priceData[
'CURRENCY'] != $resultCurrency)
1159 'BASE_PRICE' => $currentPrice,
1160 'COMPARE_PRICE' => $currentPrice,
1161 'PRICE' => $currentPrice,
1162 'CURRENCY' => $resultCurrency,
1163 'DISCOUNT_LIST' =>
array(),
1164 'RAW_PRICE' => $priceData
1166 if ($isNeedDiscounts)
1168 $arDiscounts = CCatalogDiscount::GetDiscount(
1171 array($priceData[
'CATALOG_GROUP_ID']),
1179 unset($arDiscounts);
1180 if ($discountResult ===
false)
1182 $result[
'PRICE'] = $discountResult[
'PRICE'];
1183 $result[
'COMPARE_PRICE'] = $discountResult[
'PRICE'];
1184 $result[
'DISCOUNT_LIST'] = $discountResult[
'DISCOUNT_LIST'];
1185 unset($discountResult);
1187 elseif($isNeedleToMinimizeCatalogGroup)
1189 $calculateData = $priceData;
1190 $calculateData[
'PRICE'] = $currentPrice;
1191 $calculateData[
'CURRENCY'] = $resultCurrency;
1192 $possibleSalePrice = self::getPossibleSalePrice(
1200 unset($calculateData);
1201 if ($possibleSalePrice ===
null)
1203 $result[
'COMPARE_PRICE'] = $possibleSalePrice;
1204 unset($possibleSalePrice);
1207 if ($priceData[
'NO_VAT'] ===
'N')
1209 if (!$resultWithVat)
1211 $result[
'PRICE'] /= (1 + $priceData[
'VAT_RATE']);
1212 $result[
'COMPARE_PRICE'] /= (1 + $priceData[
'VAT_RATE']);
1213 $result[
'BASE_PRICE'] /= (1 + $priceData[
'VAT_RATE']);
1221 $result[
'BASE_PRICE'] = Catalog\Product\Price::roundPrice(
1222 $priceData[
'CATALOG_GROUP_ID'],
1226 $result[
'PRICE'] = Catalog\Product\Price::roundPrice(
1227 $priceData[
'CATALOG_GROUP_ID'],
1232 empty(
$result[
'DISCOUNT_LIST'])
1241 if (empty($minimalPrice) || $minimalPrice[
'COMPARE_PRICE'] >
$result[
'COMPARE_PRICE'])
1246 $minimalPrice[
'COMPARE_PRICE'] ==
$result[
'COMPARE_PRICE']
1247 && $minimalPrice[
'RAW_PRICE'][
'PRICE_SCALE'] >
$result[
'RAW_PRICE'][
'PRICE_SCALE']
1253 unset($currentPrice,
$result);
1258 $discountValue = ($minimalPrice[
'BASE_PRICE'] - $minimalPrice[
'PRICE']);
1260 if ($minimalPrice[
'RAW_PRICE'][
'NO_VAT'] ===
'N')
1262 $vatIncluded = $resultWithVat ?
'Y' :
'N';
1268 unset($minimalPrice[
'RAW_PRICE'][
'PRICE_SCALE']);
1270 'PRICE' => $minimalPrice[
'RAW_PRICE'],
1271 'RESULT_PRICE' =>
array(
1272 'ID' => $minimalPrice[
'RAW_PRICE'][
'ID'],
1273 'PRICE_TYPE_ID' => $minimalPrice[
'RAW_PRICE'][
'CATALOG_GROUP_ID'],
1274 'BASE_PRICE' => $minimalPrice[
'BASE_PRICE'],
1275 'DISCOUNT_PRICE' => $minimalPrice[
'PRICE'],
1276 'CURRENCY' => $resultCurrency,
1277 'DISCOUNT' => $discountValue,
1279 $minimalPrice[
'BASE_PRICE'] > 0 && $discountValue > 0
1280 ? round((100*$discountValue)/$minimalPrice[
'BASE_PRICE'], 0)
1283 'VAT_RATE' => $minimalPrice[
'RAW_PRICE'][
'VAT_RATE'],
1284 'VAT_INCLUDED' => $vatIncluded,
1285 'NO_VAT' => $minimalPrice[
'RAW_PRICE'][
'NO_VAT'],
1286 'UNROUND_BASE_PRICE' => $minimalPrice[
'UNROUND_BASE_PRICE'],
1287 'UNROUND_DISCOUNT_PRICE' => $minimalPrice[
'UNROUND_PRICE']
1289 'DISCOUNT_PRICE' => $minimalPrice[
'PRICE'],
1290 'DISCOUNT' =>
array(),
1291 'DISCOUNT_LIST' =>
array(),
1292 'PRODUCT_ID' => $intProductID
1294 if (!empty($minimalPrice[
'DISCOUNT_LIST']))
1296 reset($minimalPrice[
'DISCOUNT_LIST']);
1297 $arResult[
'DISCOUNT'] = current($minimalPrice[
'DISCOUNT_LIST']);
1298 $arResult[
'DISCOUNT_LIST'] = $minimalPrice[
'DISCOUNT_LIST'];
1300 unset($minimalPrice);
1302 if ($eventOnResultExists ===
true || $eventOnResultExists ===
null)
1304 foreach (
GetModuleEvents(
'catalog',
'OnGetOptimalPriceResult',
true) as $arEvent)
1306 $eventOnResultExists =
true;
1310 if ($eventOnResultExists ===
null)
1311 $eventOnResultExists =
false;
1319 $needCoupons = ($needCoupons ===
true);
1321 $resultList =
array();
1323 $iblockListId =
array();
1324 $productIblockGetIdList =
array();
1325 $ignoreList =
array();
1329 foreach ($products as $productId => $productData)
1333 'USE_DISCOUNTS' => (isset($productData[
'BUNDLE_CHILD']) && $productData[
'BUNDLE_CHILD'] ===
true ?
false :
$useDiscount),
1337 foreach (
GetModuleEvents(
'catalog',
'OnGetOptimalPrice',
true) as $arEvent)
1339 if (!empty($productData[
'QUANTITY_LIST']))
1341 foreach ($productData[
'QUANTITY_LIST'] as $basketCode => $quantity)
1355 $needCoupons ?
false :
array()
1358 if ($mxResult ===
null)
1362 if ($mxResult !==
true)
1364 self::updateUserHandlerOptimalPrice(
1366 [
'PRODUCT_ID' => $productId]
1368 $resultList[$productId][$productData[
'BASKET_CODE']] = $mxResult;
1369 $ignoreList[$productId.
"|".$quantity] =
true;
1376 if (!empty($productData[
'QUANTITY_LIST']))
1378 foreach ($productData[
'QUANTITY_LIST'] as $basketCode => $quantity)
1380 $resultList[$productId][$basketCode] =
false;
1385 $resultList[$productId][$productData[
'BASKET_CODE']] =
false;
1388 if (!isset($iblockListId[$productId]) && isset($productData[
'IBLOCK_ID']) && $productData[
'IBLOCK_ID'] > 0)
1390 $iblockListId[$productId] = $productData[
'IBLOCK_ID'];
1393 if (!isset($iblockListId[$productId]))
1395 $productIblockGetIdList[] = $productId;
1401 if (!is_array($arUserGroups) && (
int)$arUserGroups.
'|' == (
string)$arUserGroups.
'|')
1402 $arUserGroups =
array((
int)$arUserGroups);
1404 if (!is_array($arUserGroups))
1405 $arUserGroups =
array();
1407 if (!in_array(2, $arUserGroups))
1408 $arUserGroups[] = 2;
1411 $renewal = ($renewal ==
'Y' ?
'Y' :
'N');
1417 if (empty($resultCurrency))
1423 if (!empty($productIblockGetIdList))
1425 $iblockIdList = CIBlockElement::GetIBlockByIDList($productIblockGetIdList);
1426 if (!empty($iblockIdList) && is_array($iblockIdList))
1428 $iblockListId = $iblockIdList + $iblockListId;
1432 if (!isset($priceList) || !is_array($priceList))
1433 $priceList =
array();
1435 if (empty($priceList))
1440 if (!empty($resultList))
1450 'ID',
'PRODUCT_ID',
'CATALOG_GROUP_ID',
1451 'PRICE',
'CURRENCY',
'QUANTITY_FROM',
'QUANTITY_TO',
'PRICE_SCALE'
1454 '=PRODUCT_ID' => array_keys($products),
1460 $row[
'ELEMENT_IBLOCK_ID'] = $iblockListId[$row[
'PRODUCT_ID']];
1462 if (isset($products[$row[
'PRODUCT_ID']]))
1464 $productData = $products[$row[
'PRODUCT_ID']];
1465 if (!empty($productData[
'QUANTITY_LIST']))
1467 foreach ($productData[
'QUANTITY_LIST'] as $basketCode => $quantity)
1469 if(isset($ignoreList[$row[
'PRODUCT_ID'].
"|".$quantity]))
1476 $quantityList =
array();
1477 if (!empty($productData[
'QUANTITY']))
1479 $quantityList =
array($productData[
'QUANTITY']);
1482 if (!empty($productData[
'QUANTITY_LIST']))
1484 $quantityList = $productData[
'QUANTITY_LIST'];
1487 foreach ($quantityList as $basketCode => $quantity)
1489 $checkQuantity = abs(floatval($quantity));
1490 if (($row[
'QUANTITY_FROM'] <= $checkQuantity || empty($row[
'QUANTITY_FROM']))
1491 && ($row[
'QUANTITY_TO'] >= $checkQuantity || empty($row[
'QUANTITY_TO'])))
1493 $row[
'QUANTITY'] = floatval($quantity);
1494 $row[
'BASKET_CODE'] = $basketCode;
1495 $priceList[] = $row;
1505 foreach ($priceList as $priceIndex => $priceData)
1507 $priceList[$priceIndex][
'ELEMENT_IBLOCK_ID'] = $iblockListId[$priceData[
'PRODUCT_ID']];
1512 if (empty($priceList))
1514 if (!empty($resultList))
1527 foreach (
$vatList as $productId => $vatValue)
1529 if ($vatValue ===
false)
1533 'VAT_INCLUDED' =>
'N',
1534 'EXCLUDE_VAT' =>
'Y',
1539 if ($vatValue[
'EXCLUDE_VAT'] ===
'N')
1541 $vatList[$productId][
'RATE'] = $vatValue[
'RATE'] * 0.01;
1550 $discountList =
array();
1552 if (self::$saleIncluded ===
null)
1554 $isNeedleToMinimizeCatalogGroup = self::isNeedleToMinimizeCatalogGroup($priceList);
1556 $lastProductId =
false;
1557 $lastBasketCode =
false;
1558 $ignoreProductIdList =
array();
1560 $minimalPrice =
array();
1562 foreach ($priceList as $priceData)
1564 $productId = $priceData[
'PRODUCT_ID'];
1565 $basketCode = $priceData[
'BASKET_CODE'];
1567 if (in_array($productId, $ignoreProductIdList))
1572 if ($lastBasketCode != $basketCode)
1574 if ($lastBasketCode !==
false)
1576 foreach (
GetModuleEvents(
'catalog',
'OnGetOptimalPriceResult',
true) as $arEvent)
1584 $productHash =
array(
1585 'MODULE' =>
'catalog',
1586 'PRODUCT_ID' => $lastProductId,
1587 'BASKET_ID' => $lastBasketCode
1589 if (!empty($resultList[$lastProductId][$lastBasketCode][
'DISCOUNT_LIST']))
1591 $applyCoupons =
array();
1592 foreach ($resultList[$lastProductId][$lastBasketCode][
'DISCOUNT_LIST'] as
$discount)
1599 if (!empty($applyCoupons))
1606 if ($isNeedDiscounts && $needCoupons)
1608 $coupons = static::getCoupons($productId, $basketCode);
1611 $lastBasketCode = $basketCode;
1612 $lastProductId = $productId;
1616 'USE_DISCOUNTS' => (isset($products[$productId][
'BUNDLE_CHILD']) && $products[$productId][
'BUNDLE_CHILD'] ===
true ?
false :
$useDiscount),
1624 $priceData[
'VAT_RATE'] =
$vat[
'RATE'];
1625 $priceData[
'VAT_INCLUDED'] =
$vat[
'VAT_INCLUDED'];
1626 $priceData[
'NO_VAT'] =
$vat[
'EXCLUDE_VAT'];
1628 $currentPrice = (float)$priceData[
'PRICE'];
1629 if ($priceData[
'NO_VAT'] ===
'N')
1631 if ($priceData[
'VAT_INCLUDED'] ==
'N')
1633 $currentPrice *= (1 + $priceData[
'VAT_RATE']);
1637 if ($priceData[
'CURRENCY'] != $resultCurrency)
1642 'BASE_PRICE' => $currentPrice,
1643 'COMPARE_PRICE' => $currentPrice,
1644 'PRICE' => $currentPrice,
1645 'CURRENCY' => $resultCurrency,
1646 'DISCOUNT_LIST' =>
array(),
1647 'RAW_PRICE' => $priceData
1650 if ($isNeedDiscounts)
1652 $discountList[$priceData[
'PRODUCT_ID']] = \CCatalogDiscount::GetDiscount(
1654 $iblockListId[$priceData[
'PRODUCT_ID']],
1655 array($priceData[
'CATALOG_GROUP_ID']),
1663 if ($discountResult ===
false)
1665 $ignoreProductIdList[] = $productId;
1666 $resultList[$productId][$basketCode] =
false;
1670 $result[
'PRICE'] = $discountResult[
'PRICE'];
1671 $result[
'COMPARE_PRICE'] = $discountResult[
'PRICE'];
1672 $result[
'DISCOUNT_LIST'] = $discountResult[
'DISCOUNT_LIST'];
1673 unset($discountResult);
1675 elseif($isNeedleToMinimizeCatalogGroup)
1677 if (!isset($products[$productId][
'QUANTITY_LIST'][$basketCode]))
1680 $calculateData = $priceData;
1681 $calculateData[
'PRICE'] = $currentPrice;
1682 $calculateData[
'CURRENCY'] = $resultCurrency;
1683 $possibleSalePrice = self::getPossibleSalePrice(
1686 $products[$productId][
'QUANTITY_LIST'][$basketCode],
1689 ($needCoupons ?
false: [])
1691 unset($calculateData);
1692 if ($possibleSalePrice ===
null)
1694 $result[
'COMPARE_PRICE'] = $possibleSalePrice;
1695 unset($possibleSalePrice);
1698 if ($priceData[
'NO_VAT'] ===
'N')
1700 if (!$resultWithVat)
1702 $result[
'PRICE'] /= (1 + $priceData[
'VAT_RATE']);
1703 $result[
'COMPARE_PRICE'] /= (1 + $priceData[
'VAT_RATE']);
1704 $result[
'BASE_PRICE'] /= (1 + $priceData[
'VAT_RATE']);
1712 $result[
'BASE_PRICE'] = Catalog\Product\Price::roundPrice(
1713 $priceData[
'CATALOG_GROUP_ID'],
1717 $result[
'PRICE'] = Catalog\Product\Price::roundPrice(
1718 $priceData[
'CATALOG_GROUP_ID'],
1723 empty(
$result[
'DISCOUNT_LIST'])
1733 empty($minimalPrice[$basketCode])
1734 || $minimalPrice[$basketCode][
'COMPARE_PRICE'] >
$result[
'COMPARE_PRICE']
1737 $minimalPrice[$basketCode] =
$result;
1740 $minimalPrice[$basketCode][
'COMPARE_PRICE'] ==
$result[
'COMPARE_PRICE']
1741 && $minimalPrice[$basketCode][
'RAW_PRICE'][
'PRICE_SCALE'] >
$result[
'RAW_PRICE'][
'PRICE_SCALE']
1744 $minimalPrice[$basketCode] =
$result;
1747 unset($currentPrice,
$result);
1749 $discountValue = ($minimalPrice[$basketCode][
'BASE_PRICE'] - $minimalPrice[$basketCode][
'PRICE']);
1751 if ($minimalPrice[$basketCode][
'RAW_PRICE'][
'NO_VAT'] ===
'N')
1753 $vatIncluded = $resultWithVat ?
'Y' :
'N';
1759 unset($minimalPrice[$basketCode][
'RAW_PRICE'][
'PRICE_SCALE']);
1760 $productResult =
array(
1761 'PRICE' => $minimalPrice[$basketCode][
'RAW_PRICE'],
1762 'RESULT_PRICE' =>
array(
1763 'ID' => $minimalPrice[$basketCode][
'RAW_PRICE'][
'ID'],
1764 'PRICE_TYPE_ID' => $minimalPrice[$basketCode][
'RAW_PRICE'][
'CATALOG_GROUP_ID'],
1765 'BASE_PRICE' => $minimalPrice[$basketCode][
'BASE_PRICE'],
1766 'DISCOUNT_PRICE' => $minimalPrice[$basketCode][
'PRICE'],
1767 'CURRENCY' => $resultCurrency,
1768 'DISCOUNT' => $discountValue,
1770 $minimalPrice[$basketCode][
'BASE_PRICE'] > 0 && $discountValue > 0
1771 ? round((100 * $discountValue)/$minimalPrice[$basketCode][
'BASE_PRICE'], 0)
1774 'VAT_RATE' => $minimalPrice[$basketCode][
'RAW_PRICE'][
'VAT_RATE'],
1775 'VAT_INCLUDED' => $vatIncluded,
1776 'NO_VAT' => $minimalPrice[$basketCode][
'RAW_PRICE'][
'NO_VAT'],
1777 'UNROUND_BASE_PRICE' => $minimalPrice[$basketCode][
'UNROUND_BASE_PRICE'],
1778 'UNROUND_DISCOUNT_PRICE' => $minimalPrice[$basketCode][
'UNROUND_PRICE']
1780 'DISCOUNT_PRICE' => $minimalPrice[$basketCode][
'PRICE'],
1781 'DISCOUNT' =>
array(),
1782 'DISCOUNT_LIST' =>
array(),
1783 'PRODUCT_ID' => $productId
1786 if (!empty($minimalPrice[$basketCode][
'DISCOUNT_LIST']))
1788 reset($minimalPrice[$basketCode][
'DISCOUNT_LIST']);
1789 $productResult[
'DISCOUNT'] = current($minimalPrice[$basketCode][
'DISCOUNT_LIST']);
1790 $productResult[
'DISCOUNT_LIST'] = $minimalPrice[$basketCode][
'DISCOUNT_LIST'];
1793 $resultList[$productId][$priceData[
'BASKET_CODE']] = $productResult;
1796 unset($minimalPrice);
1800 if ($lastBasketCode !==
false)
1802 foreach (
GetModuleEvents(
'catalog',
'OnGetOptimalPriceResult',
true) as $arEvent)
1810 $productHash =
array(
1811 'MODULE' =>
'catalog',
1812 'PRODUCT_ID' => $lastProductId,
1813 'BASKET_ID' => $lastBasketCode
1815 if (!empty($resultList[$lastProductId][$lastBasketCode][
'DISCOUNT_LIST']))
1817 $applyCoupons =
array();
1818 foreach ($resultList[$lastProductId][$lastBasketCode][
'DISCOUNT_LIST'] as
$discount)
1825 if (!empty($applyCoupons))
1917 global $stackCacheManager;
1924 if (defined(
'CATALOG_CACHE_TIME'))
1925 $cacheTime = intval(CATALOG_CACHE_TIME);
1927 $arProductSections =
array();
1929 $dbElementSections = CIBlockElement::GetElementGroups(
$ID,
false,
array(
'ID',
'ADDITIONAL_PROPERTY_ID'));
1930 while ($arElementSections = $dbElementSections->Fetch())
1932 if ((
int)$arElementSections[
'ADDITIONAL_PROPERTY_ID'] > 0)
1934 $arSectionsTmp =
array();
1936 $strCacheKey =
"p".$arElementSections[
"ID"];
1938 $stackCacheManager->SetLength(
"catalog_group_parents", 50);
1939 $stackCacheManager->SetTTL(
"catalog_group_parents", $cacheTime);
1940 if ($stackCacheManager->Exist(
"catalog_group_parents", $strCacheKey))
1942 $arSectionsTmp = $stackCacheManager->Get(
"catalog_group_parents", $strCacheKey);
1946 $dbSection = CIBlockSection::GetList(
1948 array(
'ID' => $arElementSections[
"ID"]),
1957 if ($arSection = $dbSection->Fetch())
1959 $dbSectionTree = CIBlockSection::GetList(
1960 array(
"LEFT_MARGIN" =>
"DESC"),
1962 "IBLOCK_ID" => $arSection[
"IBLOCK_ID"],
1964 "GLOBAL_ACTIVE" =>
"Y",
1965 "IBLOCK_ACTIVE" =>
"Y",
1966 "<=LEFT_BORDER" => $arSection[
"LEFT_MARGIN"],
1967 ">=RIGHT_BORDER" => $arSection[
"RIGHT_MARGIN"]
1972 while ($arSectionTree = $dbSectionTree->Fetch())
1974 $arSectionTree[
"ID"] = intval($arSectionTree[
"ID"]);
1975 $arSectionsTmp[] = $arSectionTree[
"ID"];
1977 unset($arSectionTree, $dbSectionTree);
1979 unset($arSection, $dbSection);
1981 $stackCacheManager->Set(
"catalog_group_parents", $strCacheKey, $arSectionsTmp);
1984 $arProductSections = array_merge($arProductSections, $arSectionsTmp);
1986 unset($arElementSections, $dbElementSections);
1988 $arProductSections = array_unique($arProductSections);
1990 return $arProductSections;