Exemplo n.º 1
0
	public static function GetOffersArray($arFilter, $arElementID, $arOrder, $arSelectFields, $arSelectProperties, $limit, $arPrices, $vat_include, $arCurrencyParams = array(), $USER_ID = 0, $LID = SITE_ID)
	{
		$arResult = array();

		$boolCheckPermissions = false;
		$boolHideNotAvailable = false;
		$IBLOCK_ID = 0;
		if (!empty($arFilter) && is_array($arFilter))
		{
			if (isset($arFilter['IBLOCK_ID']))
				$IBLOCK_ID = $arFilter['IBLOCK_ID'];
			if (isset($arFilter['HIDE_NOT_AVAILABLE']))
				$boolHideNotAvailable = 'Y' === $arFilter['HIDE_NOT_AVAILABLE'];
			if (isset($arFilter['CHECK_PERMISSIONS']))
				$boolCheckPermissions = 'Y' === $arFilter['CHECK_PERMISSIONS'];
		}
		else
		{
			$IBLOCK_ID = $arFilter;
		}

		$arOffersIBlock = CIBlockPriceTools::GetOffersIBlock($IBLOCK_ID);
		if($arOffersIBlock)
		{
			$arDefaultMeasure = CCatalogMeasure::getDefaultMeasure(true, true);

			$limit = intval($limit);
			if (0 > $limit)
				$limit = 0;

			if(!isset($arOrder["ID"]))
				$arOrder["ID"] = "DESC";

			$intOfferIBlockID = $arOffersIBlock["OFFERS_IBLOCK_ID"];

			$arFilter = array(
				"IBLOCK_ID" => $intOfferIBlockID,
				"PROPERTY_".$arOffersIBlock["OFFERS_PROPERTY_ID"] => $arElementID,
				"ACTIVE" => "Y",
				"ACTIVE_DATE" => "Y",
			);
			if ($boolHideNotAvailable)
				$arFilter['CATALOG_AVAILABLE'] = 'Y';
			if ($boolCheckPermissions)
			{
				$arFilter['CHECK_PERMISSIONS'] = "Y";
				$arFilter['MIN_PERMISSION'] = "R";
			}

			$arSelect = array(
				"ID" => 1,
				"IBLOCK_ID" => 1,
				"PROPERTY_".$arOffersIBlock["OFFERS_PROPERTY_ID"] => 1,
				"CATALOG_QUANTITY" => 1
			);
			//if(!$arParams["USE_PRICE_COUNT"])
			{
				foreach($arPrices as $value)
				{
					if (!$value['CAN_VIEW'] && !$value['CAN_BUY'])
						continue;
					$arSelect[$value["SELECT"]] = 1;
				}
			}

			foreach($arSelectFields as $code)
				$arSelect[$code] = 1; //mark to select
			if (!isset($arSelect['PREVIEW_PICTURE']))
				$arSelect['PREVIEW_PICTURE'] = 1;
			if (!isset($arSelect['DETAIL_PICTURE']))
				$arSelect['DETAIL_PICTURE'] = 1;

			$arOfferIDs = array();
			$arMeasureMap = array();
			$intKey = 0;
			$arOffersPerElement = array();
			$arOffersLink = array();
			$rsOffers = CIBlockElement::GetList($arOrder, $arFilter, false, false, array_keys($arSelect));
			while($arOffer = $rsOffers->GetNext())
			{
				$arOffer['ID'] = intval($arOffer['ID']);
				$element_id = $arOffer["PROPERTY_".$arOffersIBlock["OFFERS_PROPERTY_ID"]."_VALUE"];
				//No more than limit offers per element
				if($limit > 0)
				{
					$arOffersPerElement[$element_id]++;
					if($arOffersPerElement[$element_id] > $limit)
						continue;
				}

				if($element_id > 0)
				{
					$arOffer["LINK_ELEMENT_ID"] = intval($element_id);
					$arOffer["PROPERTIES"] = array();
					$arOffer["DISPLAY_PROPERTIES"] = array();

					$arOffer['CHECK_QUANTITY'] = ('Y' == $arOffer['CATALOG_QUANTITY_TRACE'] && 'N' == $arOffer['CATALOG_CAN_BUY_ZERO']);
					$arOffer['CATALOG_TYPE'] = CCatalogProduct::TYPE_OFFER;
					$arOffer['CATALOG_MEASURE_NAME'] = $arDefaultMeasure['SYMBOL_RUS'];
					$arOffer['~CATALOG_MEASURE_NAME'] = $arDefaultMeasure['SYMBOL_RUS'];
					$arOffer["CATALOG_MEASURE_RATIO"] = 1;
					if (!isset($arOffer['CATALOG_MEASURE']))
						$arOffer['CATALOG_MEASURE'] = 0;
					$arOffer['CATALOG_MEASURE'] = intval($arOffer['CATALOG_MEASURE']);
					if (0 > $arOffer['CATALOG_MEASURE'])
						$arOffer['CATALOG_MEASURE'] = 0;
					if (0 < $arOffer['CATALOG_MEASURE'])
					{
						if (!isset($arMeasureMap[$arOffer['CATALOG_MEASURE']]))
							$arMeasureMap[$arOffer['CATALOG_MEASURE']] = array();
						$arMeasureMap[$arOffer['CATALOG_MEASURE']][] = $intKey;
					}

					$arOfferIDs[] = $arOffer['ID'];
					$arResult[$intKey] = $arOffer;
					$arOffersLink[$arOffer['ID']] = &$arResult[$intKey];
					$intKey++;
				}
			}
			if (!empty($arOfferIDs))
			{
				$rsRatios = CCatalogMeasureRatio::getList(
					array(),
					array('PRODUCT_ID' => $arOfferIDs),
					false,
					false,
					array('PRODUCT_ID', 'RATIO')
				);
				while ($arRatio = $rsRatios->Fetch())
				{
					$arRatio['PRODUCT_ID'] = intval($arRatio['PRODUCT_ID']);
					if (isset($arOffersLink[$arRatio['PRODUCT_ID']]))
					{
						$intRatio = intval($arRatio['RATIO']);
						$dblRatio = doubleval($arRatio['RATIO']);
						$mxRatio = ($dblRatio > $intRatio ? $dblRatio : $intRatio);
						if (CATALOG_VALUE_EPSILON > abs($mxRatio))
							$mxRatio = 1;
						elseif (0 > $mxRatio)
							$mxRatio = 1;
						$arOffersLink[$arRatio['PRODUCT_ID']]['CATALOG_MEASURE_RATIO'] = $mxRatio;
					}
				}

				if (!empty($arSelectProperties))
				{
					CIBlockElement::GetPropertyValuesArray($arOffersLink, $intOfferIBlockID, $arFilter);
					foreach ($arResult as &$arOffer)
					{
						CCatalogDiscount::SetProductPropertiesCache($arOffer['ID'], $arOffer["PROPERTIES"]);
						foreach ($arSelectProperties as $pid)
						{
							if (!isset($arOffer["PROPERTIES"][$pid]))
								continue;
							$prop = &$arOffer["PROPERTIES"][$pid];
							$boolArr = is_array($prop["VALUE"]);
							if(
								($boolArr && !empty($prop["VALUE"])) ||
								(!$boolArr && strlen($prop["VALUE"])>0))
							{
								$arOffer["DISPLAY_PROPERTIES"][$pid] = CIBlockFormatProperties::GetDisplayValue($arOffer, $prop, "catalog_out");
							}
						}
						if (isset($arOffer))
							unset($arOffer);
					}
				}

				CCatalogDiscount::SetProductSectionsCache($arOfferIDs);
				CCatalogDiscount::SetDiscountProductCache($arOfferIDs, array('IBLOCK_ID' => $intOfferIBlockID, 'GET_BY_ID' => 'Y'));
				foreach ($arResult as &$arOffer)
				{
					$arOffer['CATALOG_QUANTITY'] = (
						0 < $arOffer['CATALOG_QUANTITY'] && is_float($arOffer['CATALOG_MEASURE_RATIO'])
						? floatval($arOffer['CATALOG_QUANTITY'])
						: intval($arOffer['CATALOG_QUANTITY'])
					);
					$arOffer['MIN_PRICE'] = false;
					$arOffer["PRICES"] = CIBlockPriceTools::GetItemPrices($arOffersIBlock["OFFERS_IBLOCK_ID"], $arPrices, $arOffer, $vat_include, $arCurrencyParams, $USER_ID, $LID);
					if (!empty($arOffer["PRICES"]))
					{
						foreach ($arOffer['PRICES'] as &$arOnePrice)
						{
							if ('Y' == $arOnePrice['MIN_PRICE'])
							{
								$arOffer['MIN_PRICE'] = $arOnePrice;
								break;
							}
						}
						unset($arOnePrice);
					}
					$arOffer["CAN_BUY"] = CIBlockPriceTools::CanBuy($arOffersIBlock["OFFERS_IBLOCK_ID"], $arPrices, $arOffer);
				}
				if (isset($arOffer))
					unset($arOffer);
			}
			if (!empty($arMeasureMap))
			{
				$rsMeasures = CCatalogMeasure::getList(
					array(),
					array('@ID' => array_keys($arMeasureMap)),
					false,
					false,
					array('ID', 'SYMBOL_RUS')
				);
				while ($arMeasure = $rsMeasures->GetNext())
				{
					$arMeasure['ID'] = intval($arMeasure['ID']);
					if (isset($arMeasureMap[$arMeasure['ID']]) && !empty($arMeasureMap[$arMeasure['ID']]))
					{
						foreach ($arMeasureMap[$arMeasure['ID']] as &$intOneKey)
						{
							$arResult[$intOneKey]['CATALOG_MEASURE_NAME'] = $arMeasure['SYMBOL_RUS'];
							$arResult[$intOneKey]['~CATALOG_MEASURE_NAME'] = $arMeasure['~SYMBOL_RUS'];
						}
						unset($intOneKey);
					}
				}
			}
		}

		return $arResult;
	}
Exemplo n.º 2
0
     if (!empty($arMeasureMap)) {
         $rsMeasures = CCatalogMeasure::getList(array(), array('@ID' => array_keys($arMeasureMap)), false, false, array('ID', 'SYMBOL_RUS'));
         while ($arMeasure = $rsMeasures->GetNext()) {
             $arMeasure['ID'] = (int) $arMeasure['ID'];
             if (isset($arMeasureMap[$arMeasure['ID']]) && !empty($arMeasureMap[$arMeasure['ID']])) {
                 foreach ($arMeasureMap[$arMeasure['ID']] as &$intOneKey) {
                     $arResult['ITEMS'][$intOneKey]['CATALOG_MEASURE_NAME'] = $arMeasure['SYMBOL_RUS'];
                     $arResult['ITEMS'][$intOneKey]['~CATALOG_MEASURE_NAME'] = $arMeasure['~SYMBOL_RUS'];
                 }
                 unset($intOneKey);
             }
         }
     }
 }
 if ($bCatalog && $boolNeedCatalogCache && !empty($arResult["ELEMENTS"])) {
     CCatalogDiscount::SetProductSectionsCache($arResult["ELEMENTS"]);
     CCatalogDiscount::SetDiscountProductCache($arResult["ELEMENTS"], array('IBLOCK_ID' => $arParams["IBLOCK_ID"], 'GET_BY_ID' => 'Y'));
 }
 if (isset($arItem)) {
     unset($arItem);
 }
 $currentPath = CHTTP::urlDeleteParams($APPLICATION->GetCurPageParam(), array($arParams['PRODUCT_ID_VARIABLE'], $arParams['ACTION_VARIABLE'], ''), array('delete_system_params' => true));
 $currentPath .= stripos($currentPath, '?') === false ? '?' : '&';
 if ($arParams['COMPARE_PATH'] == '') {
     $comparePath = $currentPath;
 } else {
     $comparePath = CHTTP::urlDeleteParams($arParams['COMPARE_PATH'], array($arParams['PRODUCT_ID_VARIABLE'], $arParams['ACTION_VARIABLE'], ''), array('delete_system_params' => true));
     $comparePath .= stripos($comparePath, '?') === false ? '?' : '&';
 }
 $arParams['COMPARE_PATH'] = $comparePath . $arParams['ACTION_VARIABLE'] . '=COMPARE';
 $arResult['~BUY_URL_TEMPLATE'] = $currentPath . $arParams["ACTION_VARIABLE"] . "=BUY&" . $arParams["PRODUCT_ID_VARIABLE"] . "=#ID#";
Exemplo n.º 3
0
 public static function GetOffersArray($arFilter, $arElementID, $arOrder, $arSelectFields, $arSelectProperties, $limit, $arPrices, $vat_include, $arCurrencyParams = array(), $USER_ID = 0, $LID = SITE_ID)
 {
     global $USER;
     $arResult = array();
     $boolCheckPermissions = false;
     $boolHideNotAvailable = false;
     $showPriceCount = false;
     $IBLOCK_ID = 0;
     if (!empty($arFilter) && is_array($arFilter)) {
         if (isset($arFilter['IBLOCK_ID'])) {
             $IBLOCK_ID = $arFilter['IBLOCK_ID'];
         }
         if (isset($arFilter['HIDE_NOT_AVAILABLE'])) {
             $boolHideNotAvailable = $arFilter['HIDE_NOT_AVAILABLE'] === 'Y';
         }
         if (isset($arFilter['CHECK_PERMISSIONS'])) {
             $boolCheckPermissions = $arFilter['CHECK_PERMISSIONS'] === 'Y';
         }
         if (isset($arFilter['SHOW_PRICE_COUNT'])) {
             $showPriceCount = (int) $arFilter['SHOW_PRICE_COUNT'];
             if ($showPriceCount <= 0) {
                 $showPriceCount = false;
             }
         }
     } else {
         $IBLOCK_ID = $arFilter;
     }
     if (self::$needDiscountCache === null) {
         $pricesAllow = CIBlockPriceTools::GetAllowCatalogPrices($arPrices);
         if (empty($pricesAllow)) {
             self::$needDiscountCache = false;
         } else {
             $USER_ID = (int) $USER_ID;
             $userGroups = $USER_ID > 0 ? CUser::GetUserGroup($USER_ID) : $USER->GetUserGroupArray();
             self::$needDiscountCache = CIBlockPriceTools::SetCatalogDiscountCache($pricesAllow, $userGroups);
             unset($userGroups);
         }
         unset($pricesAllow);
     }
     $arOffersIBlock = CIBlockPriceTools::GetOffersIBlock($IBLOCK_ID);
     if ($arOffersIBlock) {
         $arDefaultMeasure = CCatalogMeasure::getDefaultMeasure(true, true);
         $limit = (int) $limit;
         if (0 > $limit) {
             $limit = 0;
         }
         if (!isset($arOrder["ID"])) {
             $arOrder["ID"] = "DESC";
         }
         $intOfferIBlockID = $arOffersIBlock["OFFERS_IBLOCK_ID"];
         $productProperty = 'PROPERTY_' . $arOffersIBlock['OFFERS_PROPERTY_ID'];
         $productPropertyValue = $productProperty . '_VALUE';
         $arFilter = array("IBLOCK_ID" => $intOfferIBlockID, $productProperty => $arElementID, "ACTIVE" => "Y", "ACTIVE_DATE" => "Y");
         if ($boolHideNotAvailable) {
             $arFilter['CATALOG_AVAILABLE'] = 'Y';
         }
         if ($boolCheckPermissions) {
             $arFilter['CHECK_PERMISSIONS'] = "Y";
             $arFilter['MIN_PERMISSION'] = "R";
         }
         $arSelect = array("ID" => 1, "IBLOCK_ID" => 1, $productProperty => 1, "CATALOG_QUANTITY" => 1);
         foreach ($arPrices as $value) {
             if (!$value['CAN_VIEW'] && !$value['CAN_BUY']) {
                 continue;
             }
             $arSelect[$value["SELECT"]] = 1;
             if ($showPriceCount !== false) {
                 $arFilter['CATALOG_SHOP_QUANTITY_' . $value['ID']] = $showPriceCount;
             }
         }
         foreach ($arSelectFields as $code) {
             $arSelect[$code] = 1;
         }
         //mark to select
         if (!isset($arSelect['PREVIEW_PICTURE'])) {
             $arSelect['PREVIEW_PICTURE'] = 1;
         }
         if (!isset($arSelect['DETAIL_PICTURE'])) {
             $arSelect['DETAIL_PICTURE'] = 1;
         }
         $arOfferIDs = array();
         $arMeasureMap = array();
         $intKey = 0;
         $arOffersPerElement = array();
         $arOffersLink = array();
         $extPrices = array();
         $rsOffers = CIBlockElement::GetList($arOrder, $arFilter, false, false, array_keys($arSelect));
         while ($arOffer = $rsOffers->GetNext()) {
             $arOffer['ID'] = (int) $arOffer['ID'];
             $element_id = (int) $arOffer[$productPropertyValue];
             //No more than limit offers per element
             if ($limit > 0) {
                 $arOffersPerElement[$element_id]++;
                 if ($arOffersPerElement[$element_id] > $limit) {
                     continue;
                 }
             }
             if ($element_id > 0) {
                 $arOffer["LINK_ELEMENT_ID"] = $element_id;
                 $arOffer["PROPERTIES"] = array();
                 $arOffer["DISPLAY_PROPERTIES"] = array();
                 $arOffer['CHECK_QUANTITY'] = 'Y' == $arOffer['CATALOG_QUANTITY_TRACE'] && 'N' == $arOffer['CATALOG_CAN_BUY_ZERO'];
                 $arOffer['CATALOG_TYPE'] = CCatalogProduct::TYPE_OFFER;
                 $arOffer['CATALOG_MEASURE_NAME'] = $arDefaultMeasure['SYMBOL_RUS'];
                 $arOffer['~CATALOG_MEASURE_NAME'] = $arDefaultMeasure['SYMBOL_RUS'];
                 $arOffer["CATALOG_MEASURE_RATIO"] = 1;
                 if (!isset($arOffer['CATALOG_MEASURE'])) {
                     $arOffer['CATALOG_MEASURE'] = 0;
                 }
                 $arOffer['CATALOG_MEASURE'] = (int) $arOffer['CATALOG_MEASURE'];
                 if (0 > $arOffer['CATALOG_MEASURE']) {
                     $arOffer['CATALOG_MEASURE'] = 0;
                 }
                 if (0 < $arOffer['CATALOG_MEASURE']) {
                     if (!isset($arMeasureMap[$arOffer['CATALOG_MEASURE']])) {
                         $arMeasureMap[$arOffer['CATALOG_MEASURE']] = array();
                     }
                     $arMeasureMap[$arOffer['CATALOG_MEASURE']][] = $intKey;
                 }
                 $arOfferIDs[] = $arOffer['ID'];
                 $arResult[$intKey] = $arOffer;
                 if (!isset($arOffersLink[$arOffer['ID']])) {
                     $arOffersLink[$arOffer['ID']] =& $arResult[$intKey];
                 } else {
                     if (!isset($extPrices[$arOffer['ID']])) {
                         $extPrices[$arOffer['ID']] = array();
                     }
                     $extPrices[$arOffer['ID']][] =& $arResult[$intKey];
                 }
                 $intKey++;
             }
         }
         if (!empty($arOfferIDs)) {
             $rsRatios = CCatalogMeasureRatio::getList(array(), array('@PRODUCT_ID' => $arOfferIDs), false, false, array('PRODUCT_ID', 'RATIO'));
             while ($arRatio = $rsRatios->Fetch()) {
                 $arRatio['PRODUCT_ID'] = (int) $arRatio['PRODUCT_ID'];
                 if (isset($arOffersLink[$arRatio['PRODUCT_ID']])) {
                     $intRatio = (int) $arRatio['RATIO'];
                     $dblRatio = (double) $arRatio['RATIO'];
                     $mxRatio = $dblRatio > $intRatio ? $dblRatio : $intRatio;
                     if (CATALOG_VALUE_EPSILON > abs($mxRatio)) {
                         $mxRatio = 1;
                     } elseif (0 > $mxRatio) {
                         $mxRatio = 1;
                     }
                     $arOffersLink[$arRatio['PRODUCT_ID']]['CATALOG_MEASURE_RATIO'] = $mxRatio;
                 }
             }
             if (!empty($arSelectProperties)) {
                 CIBlockElement::GetPropertyValuesArray($arOffersLink, $intOfferIBlockID, $arFilter);
                 foreach ($arResult as &$arOffer) {
                     if (self::$needDiscountCache) {
                         CCatalogDiscount::SetProductPropertiesCache($arOffer['ID'], $arOffer["PROPERTIES"]);
                     }
                     foreach ($arSelectProperties as $pid) {
                         if (!isset($arOffer["PROPERTIES"][$pid])) {
                             continue;
                         }
                         $prop =& $arOffer["PROPERTIES"][$pid];
                         $boolArr = is_array($prop["VALUE"]);
                         if ($boolArr && !empty($prop["VALUE"]) || !$boolArr && strlen($prop["VALUE"]) > 0) {
                             $arOffer["DISPLAY_PROPERTIES"][$pid] = CIBlockFormatProperties::GetDisplayValue($arOffer, $prop, "catalog_out");
                         }
                         unset($prop);
                     }
                 }
                 unset($arOffer);
             }
             if (!empty($extPrices)) {
                 foreach ($extPrices as $origID => $prices) {
                     foreach ($prices as $oneRow) {
                         $oneRow['PROPERTIES'] = $arOffersLink[$origID]['PROPERTIES'];
                         $oneRow['DISPLAY_PROPERTIES'] = $arOffersLink[$origID]['DISPLAY_PROPERTIES'];
                         $oneRow['CATALOG_MEASURE_RATIO'] = $arOffersLink[$origID]['CATALOG_MEASURE_RATIO'];
                     }
                 }
             }
             if (self::$needDiscountCache) {
                 CCatalogDiscount::SetProductSectionsCache($arOfferIDs);
                 CCatalogDiscount::SetDiscountProductCache($arOfferIDs, array('IBLOCK_ID' => $intOfferIBlockID, 'GET_BY_ID' => 'Y'));
             }
             foreach ($arResult as &$arOffer) {
                 $arOffer['CATALOG_QUANTITY'] = 0 < $arOffer['CATALOG_QUANTITY'] && is_float($arOffer['CATALOG_MEASURE_RATIO']) ? (double) $arOffer['CATALOG_QUANTITY'] : (int) $arOffer['CATALOG_QUANTITY'];
                 $arOffer['MIN_PRICE'] = false;
                 $arOffer["PRICES"] = CIBlockPriceTools::GetItemPrices($arOffersIBlock["OFFERS_IBLOCK_ID"], $arPrices, $arOffer, $vat_include, $arCurrencyParams, $USER_ID, $LID);
                 if (!empty($arOffer["PRICES"])) {
                     foreach ($arOffer['PRICES'] as &$arOnePrice) {
                         if ($arOnePrice['MIN_PRICE'] == 'Y') {
                             $arOffer['MIN_PRICE'] = $arOnePrice;
                             break;
                         }
                     }
                     unset($arOnePrice);
                 }
                 $arOffer["CAN_BUY"] = CIBlockPriceTools::CanBuy($arOffersIBlock["OFFERS_IBLOCK_ID"], $arPrices, $arOffer);
             }
             if (isset($arOffer)) {
                 unset($arOffer);
             }
         }
         if (!empty($arMeasureMap)) {
             $rsMeasures = CCatalogMeasure::getList(array(), array('@ID' => array_keys($arMeasureMap)), false, false, array('ID', 'SYMBOL_RUS'));
             while ($arMeasure = $rsMeasures->GetNext()) {
                 $arMeasure['ID'] = (int) $arMeasure['ID'];
                 if (isset($arMeasureMap[$arMeasure['ID']]) && !empty($arMeasureMap[$arMeasure['ID']])) {
                     foreach ($arMeasureMap[$arMeasure['ID']] as &$intOneKey) {
                         $arResult[$intOneKey]['CATALOG_MEASURE_NAME'] = $arMeasure['SYMBOL_RUS'];
                         $arResult[$intOneKey]['~CATALOG_MEASURE_NAME'] = $arMeasure['~SYMBOL_RUS'];
                     }
                     unset($intOneKey);
                 }
             }
         }
     }
     return $arResult;
 }