public static function GetCatalogPrices($IBLOCK_ID, $arPriceCode) { global $USER; $arCatalogPrices = array(); if (self::$catalogIncluded === null) { self::$catalogIncluded = Loader::includeModule('catalog'); } if (self::$catalogIncluded) { $arCatalogGroupCodesFilter = array(); foreach ($arPriceCode as $value) { $t_value = trim($value); if ('' != $t_value) { $arCatalogGroupCodesFilter[$value] = true; } } $arCatalogGroupsFilter = array(); $arCatalogGroups = CCatalogGroup::GetListArray(); foreach ($arCatalogGroups as $key => $value) { if (isset($arCatalogGroupCodesFilter[$value['NAME']])) { $arCatalogGroupsFilter[] = $key; $arCatalogPrices[$value["NAME"]] = array("ID" => (int) $value["ID"], "TITLE" => htmlspecialcharsbx($value["NAME_LANG"]), "SELECT" => "CATALOG_GROUP_" . $value["ID"]); } } $arPriceGroups = CCatalogGroup::GetGroupsPerms($USER->GetUserGroupArray(), $arCatalogGroupsFilter); foreach ($arCatalogPrices as $name => $value) { $arCatalogPrices[$name]["CAN_VIEW"] = in_array($value["ID"], $arPriceGroups["view"]); $arCatalogPrices[$name]["CAN_BUY"] = in_array($value["ID"], $arPriceGroups["buy"]); } } else { $arPriceGroups = array("view" => array()); $rsProperties = CIBlockProperty::GetList(array(), array("IBLOCK_ID" => $IBLOCK_ID, "CHECK_PERMISSIONS" => "N", "PROPERTY_TYPE" => "N", "MULTIPLE" => "N")); while ($arProperty = $rsProperties->Fetch()) { if (in_array($arProperty["CODE"], $arPriceCode)) { $arPriceGroups["view"][] = htmlspecialcharsbx("PROPERTY_" . $arProperty["CODE"]); $arCatalogPrices[$arProperty["CODE"]] = array("ID" => (int) $arProperty["ID"], "TITLE" => htmlspecialcharsbx($arProperty["NAME"]), "SELECT" => "PROPERTY_" . $arProperty["ID"], "CAN_VIEW" => true, "CAN_BUY" => false); } } } return $arCatalogPrices; }
function GetCatalogPrices($IBLOCK_ID, $arPriceCode) { global $USER; $arCatalogPrices = array(); if (CModule::IncludeModule("catalog")) { $bFromCatalog = true; $arCatalogGroupCodesFilter = array(); foreach ($arPriceCode as $key => $value) { $t_value = trim($value); if (strlen($t_value) > 0) { $arCatalogGroupCodesFilter[$value] = true; } } $arCatalogGroupsFilter = array(); $arCatalogGroups = CCatalogGroup::GetListArray(); foreach ($arCatalogGroups as $key => $value) { if (array_key_exists($value["NAME"], $arCatalogGroupCodesFilter)) { $arCatalogGroupsFilter[] = $key; $arCatalogPrices[$value["NAME"]] = array("ID" => htmlspecialcharsbx($value["ID"]), "TITLE" => htmlspecialcharsbx($value["NAME_LANG"]), "SELECT" => "CATALOG_GROUP_" . $value["ID"]); } } $arPriceGroups = CCatalogGroup::GetGroupsPerms($USER->GetUserGroupArray(), $arCatalogGroupsFilter); foreach ($arCatalogPrices as $name => $value) { $arCatalogPrices[$name]["CAN_VIEW"] = in_array($value["ID"], $arPriceGroups["view"]); $arCatalogPrices[$name]["CAN_BUY"] = in_array($value["ID"], $arPriceGroups["buy"]); } } else { $bFromCatalog = false; $arPriceGroups = array("view" => array()); $rsProperties = CIBlockProperty::GetList(array(), array("IBLOCK_ID" => $IBLOCK_ID, "CHECK_PERMISSIONS" => "N", "PROPERTY_TYPE" => "N")); while ($arProperty = $rsProperties->Fetch()) { if ($arProperty["MULTIPLE"] == "N" && in_array($arProperty["CODE"], $arPriceCode)) { $arPriceGroups["view"][] = htmlspecialcharsbx("PROPERTY_" . $arProperty["CODE"]); $arCatalogPrices[$arProperty["CODE"]] = array("ID" => htmlspecialcharsbx($arProperty["ID"]), "TITLE" => htmlspecialcharsbx($arProperty["NAME"]), "SELECT" => "PROPERTY_" . $arProperty["ID"], "CAN_VIEW" => true, "CAN_BUY" => false); } } } return $arCatalogPrices; }
function CatalogGetPriceTableEx($ID, $filterQauntity = 0, $arFilterType = array(), $VAT_INCLUDE = 'Y', $arCurrencyParams = array()) { global $USER; static $arPriceTypes = array(); $ID = (int) $ID; if ($ID <= 0) { return false; } $filterQauntity = (int) $filterQauntity; if (!is_array($arFilterType)) { $arFilterType = array($arFilterType); } $boolConvert = false; $strCurrencyID = ''; $arCurrencyList = array(); if (!empty($arCurrencyParams) && is_array($arCurrencyParams) && !empty($arCurrencyParams['CURRENCY_ID'])) { $boolConvert = true; $strCurrencyID = $arCurrencyParams['CURRENCY_ID']; } $arResult = array(); $arResult["ROWS"] = array(); $arResult["COLS"] = array(); $arResult["MATRIX"] = array(); $arResult["CAN_BUY"] = array(); $arResult["AVAILABLE"] = "N"; $cacheTime = CATALOG_CACHE_DEFAULT_TIME; if (defined("CATALOG_CACHE_TIME")) { $cacheTime = intval(CATALOG_CACHE_TIME); } $arUserGroups = $USER->GetUserGroupArray(); CatalogClearArray($arUserGroups, true); $strCacheID = 'UG_' . implode('_', $arUserGroups); if (isset($arPriceTypes[$strCacheID])) { $arPriceGroups = $arPriceTypes[$strCacheID]; } else { $arPriceGroups = CCatalogGroup::GetGroupsPerms($arUserGroups, array()); $arPriceTypes[$strCacheID] = $arPriceGroups; } if (empty($arPriceGroups["view"])) { return $arResult; } $currentQuantity = -1; $rowsCnt = -1; $arFilter = array("PRODUCT_ID" => $ID); if ($filterQauntity > 0) { $arFilter["+<=QUANTITY_FROM"] = $filterQauntity; $arFilter["+>=QUANTITY_TO"] = $filterQauntity; } if (!empty($arFilterType)) { $arTmp = array(); foreach ($arPriceGroups["view"] as &$intOneGroup) { if (in_array($intOneGroup, $arFilterType)) { $arTmp[] = $intOneGroup; } } if (isset($intOneGroup)) { unset($intOneGroup); } if (empty($arTmp)) { return $arResult; } $arFilter["CATALOG_GROUP_ID"] = $arTmp; } else { $arFilter["CATALOG_GROUP_ID"] = $arPriceGroups["view"]; } $productQuantity = 0; $productQuantityTrace = "N"; $dbRes = CCatalogProduct::GetVATInfo($ID); if ($arVatInfo = $dbRes->Fetch()) { $fVatRate = floatval($arVatInfo['RATE'] * 0.01); $bVatIncluded = $arVatInfo['VAT_INCLUDED'] == 'Y'; } else { $fVatRate = 0.0; $bVatIncluded = false; } $rsProducts = CCatalogProduct::GetList(array(), array('ID' => $ID), false, false, array('ID', 'CAN_BUY_ZERO', 'QUANTITY_TRACE', 'QUANTITY')); if ($arProduct = $rsProducts->Fetch()) { $intIBlockID = CIBlockElement::GetIBlockByID($arProduct['ID']); if (!$intIBlockID) { return false; } $arProduct['IBLOCK_ID'] = $intIBlockID; } else { return false; } $dbPrice = CPrice::GetListEx(array("QUANTITY_FROM" => "ASC", "QUANTITY_TO" => "ASC"), $arFilter, false, false, array("ID", "CATALOG_GROUP_ID", "PRICE", "CURRENCY", "QUANTITY_FROM", "QUANTITY_TO")); while ($arPrice = $dbPrice->Fetch()) { if ($VAT_INCLUDE == 'N') { if ($bVatIncluded) { $arPrice['PRICE'] /= 1 + $fVatRate; } } else { if (!$bVatIncluded) { $arPrice['PRICE'] *= 1 + $fVatRate; } } $arPrice['VAT_RATE'] = $fVatRate; CCatalogDiscountSave::Disable(); $arDiscounts = CCatalogDiscount::GetDiscount($ID, $arProduct["IBLOCK_ID"], $arPrice["CATALOG_GROUP_ID"], $arUserGroups, "N", SITE_ID, array()); CCatalogDiscountSave::Enable(); $discountPrice = CCatalogProduct::CountPriceWithDiscount($arPrice["PRICE"], $arPrice["CURRENCY"], $arDiscounts); $arPrice["DISCOUNT_PRICE"] = $discountPrice; $arPrice["QUANTITY_FROM"] = doubleval($arPrice["QUANTITY_FROM"]); if ($currentQuantity != $arPrice["QUANTITY_FROM"]) { $rowsCnt++; $arResult["ROWS"][$rowsCnt]["QUANTITY_FROM"] = $arPrice["QUANTITY_FROM"]; $arResult["ROWS"][$rowsCnt]["QUANTITY_TO"] = doubleval($arPrice["QUANTITY_TO"]); $currentQuantity = $arPrice["QUANTITY_FROM"]; } if ($boolConvert && $strCurrencyID != $arPrice["CURRENCY"]) { $arResult["MATRIX"][intval($arPrice["CATALOG_GROUP_ID"])][$rowsCnt] = array("ID" => $arPrice["ID"], "ORIG_PRICE" => $arPrice["PRICE"], "ORIG_DISCOUNT_PRICE" => $arPrice["DISCOUNT_PRICE"], "ORIG_CURRENCY" => $arPrice["CURRENCY"], "ORIG_VAT_RATE" => $arPrice["VAT_RATE"], 'PRICE' => CCurrencyRates::ConvertCurrency($arPrice["PRICE"], $arPrice["CURRENCY"], $strCurrencyID), 'DISCOUNT_PRICE' => CCurrencyRates::ConvertCurrency($arPrice["DISCOUNT_PRICE"], $arPrice["CURRENCY"], $strCurrencyID), 'CURRENCY' => $strCurrencyID, 'VAT_RATE' => CCurrencyRates::ConvertCurrency($arPrice["VAT_RATE"], $arPrice["CURRENCY"], $strCurrencyID)); $arCurrencyList[] = $arPrice["CURRENCY"]; } else { $arResult["MATRIX"][intval($arPrice["CATALOG_GROUP_ID"])][$rowsCnt] = array("ID" => $arPrice["ID"], "PRICE" => $arPrice["PRICE"], "DISCOUNT_PRICE" => $arPrice["DISCOUNT_PRICE"], "CURRENCY" => $arPrice["CURRENCY"], "VAT_RATE" => $arPrice["VAT_RATE"]); } } $arCatalogGroups = CCatalogGroup::GetListArray(); foreach ($arCatalogGroups as $key => $value) { if (isset($arResult["MATRIX"][$key])) { $arResult["COLS"][$value["ID"]] = $value; } } $arResult["CAN_BUY"] = $arPriceGroups["buy"]; $arResult["AVAILABLE"] = 0 >= $arProduct['QUANTITY'] && 'Y' == $arProduct['QUANTITY_TRACE'] && 'N' == $arProduct['CAN_BUY_ZERO'] ? 'N' : 'Y'; if ($boolConvert) { if (!empty($arCurrencyList)) { $arCurrencyList[] = $strCurrencyID; } $arResult['CURRENCY_LIST'] = $arCurrencyList; } return $arResult; }
/** * * * * * * @param $I $D Код товара. (ID элемента инфоблока, для которого запрашиваются * цены.) * * * * @param $filterQauntit $y = 0 Если значение больше 0, то выводится диапазон цен, * соответствующий этому количеству. Имеет смысл только при * расширенном режиме управления ценами. * * * * @param $arFilterTyp $e = array() Массив ID типов цен. Если не задан, то выбираются все типы цен, * которые может просматривать пользователь. * * * * @param $VAT_INCLUD $E = 'Y' (Y/N) НДС включён. * * * * @param $arCurrencyParam $s = array() Массив параметров для показа цен в одной валюте. Если в * переданном массиве заполнено поле CURRENCY_ID, то произойдет * конвертация цен в валюту CURRENCY_ID по текущему курсу. Необязательный * параметр. * * * * @return mixed <p></p><br><br> * * @static * @link http://dev.1c-bitrix.ru/api_help/catalog/functions/cataloggetpricetableex.php * @author Bitrix */ function CatalogGetPriceTableEx($ID, $filterQauntity = 0, $arFilterType = array(), $VAT_INCLUDE = 'Y', $arCurrencyParams = array()) { global $USER; $ID = intval($ID); if ($ID <= 0) return False; $filterQauntity = intval($filterQauntity); if (!is_array($arFilterType)) $arFilterType = array($arFilterType); $boolConvert = false; $strCurrencyID = ''; $arCurrencyList = array(); if (is_array($arCurrencyParams) && !empty($arCurrencyParams) && !empty($arCurrencyParams['CURRENCY_ID'])) { $boolConvert = true; $strCurrencyID = $arCurrencyParams['CURRENCY_ID']; } $arResult = array(); $arResult["ROWS"] = array(); $arResult["COLS"] = array(); $arResult["MATRIX"] = array(); $arResult["CAN_BUY"] = array(); $arResult["AVAILABLE"] = "N"; $cacheTime = CATALOG_CACHE_DEFAULT_TIME; if (defined("CATALOG_CACHE_TIME")) $cacheTime = intval(CATALOG_CACHE_TIME); $arUserGroups = $USER->GetUserGroupArray(); $arPriceGroups = CCatalogGroup::GetGroupsPerms($arUserGroups, array()); if (empty($arPriceGroups["view"])) return $arResult; $currentQuantity = -1; $rowsCnt = -1; $arFilter = array("PRODUCT_ID" => $ID); if ($filterQauntity > 0) { $arFilter["+<=QUANTITY_FROM"] = $filterQauntity; $arFilter["+>=QUANTITY_TO"] = $filterQauntity; } if (!empty($arFilterType)) { $arTmp = array(); foreach ($arPriceGroups["view"] as &$intOneGroup) { if (in_array($intOneGroup, $arFilterType)) $arTmp[] = $intOneGroup; } if (isset($intOneGroup)) unset($intOneGroup); if (empty($arTmp)) return $arResult; $arFilter["CATALOG_GROUP_ID"] = $arTmp; } else { $arFilter["CATALOG_GROUP_ID"] = $arPriceGroups["view"]; } $productQuantity = 0; $productQuantityTrace = "N"; $dbRes = CCatalogProduct::GetVATInfo($ID); if ($arVatInfo = $dbRes->Fetch()) { $fVatRate = floatval($arVatInfo['RATE'] * 0.01); $bVatIncluded = $arVatInfo['VAT_INCLUDED'] == 'Y'; } else { $fVatRate = 0.00; $bVatIncluded = false; } $dbPrice = CPrice::GetListEx( array("QUANTITY_FROM" => "ASC", "QUANTITY_TO" => "ASC"), $arFilter, false, false, array("ID", "CATALOG_GROUP_ID", "PRICE", "CURRENCY", "QUANTITY_FROM", "QUANTITY_TO", "PRODUCT_QUANTITY", "PRODUCT_QUANTITY_TRACE", "PRODUCT_CAN_BUY_ZERO", "ELEMENT_IBLOCK_ID") ); while ($arPrice = $dbPrice->Fetch()) { if ($VAT_INCLUDE == 'N') { if ($bVatIncluded) $arPrice['PRICE'] /= (1 + $fVatRate); } else { if (!$bVatIncluded) $arPrice['PRICE'] *= (1 + $fVatRate); } $arPrice['VAT_RATE'] = $fVatRate; CCatalogDiscountSave::Disable(); $arDiscounts = CCatalogDiscount::GetDiscount($ID, $arPrice["ELEMENT_IBLOCK_ID"], $arPrice["CATALOG_GROUP_ID"], $arUserGroups, "N", SITE_ID); CCatalogDiscountSave::Enable(); $discountPrice = CCatalogProduct::CountPriceWithDiscount($arPrice["PRICE"], $arPrice["CURRENCY"], $arDiscounts); $arPrice["DISCOUNT_PRICE"] = $discountPrice; $productQuantity = $arPrice["PRODUCT_QUANTITY"]; $productQuantityTrace = $arPrice["PRODUCT_QUANTITY_TRACE"]; $productUseStoreFlag = $arPrice["PRODUCT_CAN_BUY_ZERO"]; $arPrice["QUANTITY_FROM"] = DoubleVal($arPrice["QUANTITY_FROM"]); if ($currentQuantity != $arPrice["QUANTITY_FROM"]) { $rowsCnt++; $arResult["ROWS"][$rowsCnt]["QUANTITY_FROM"] = $arPrice["QUANTITY_FROM"]; $arResult["ROWS"][$rowsCnt]["QUANTITY_TO"] = DoubleVal($arPrice["QUANTITY_TO"]); $currentQuantity = $arPrice["QUANTITY_FROM"]; } if ($boolConvert && $strCurrencyID != $arPrice["CURRENCY"]) { $arResult["MATRIX"][intval($arPrice["CATALOG_GROUP_ID"])][$rowsCnt] = array( "ID" => $arPrice["ID"], "ORIG_PRICE" => $arPrice["PRICE"], "ORIG_DISCOUNT_PRICE" => $arPrice["DISCOUNT_PRICE"], "ORIG_CURRENCY" => $arPrice["CURRENCY"], "ORIG_VAT_RATE" => $arPrice["VAT_RATE"], 'PRICE' => CCurrencyRates::ConvertCurrency($arPrice["PRICE"], $arPrice["CURRENCY"], $strCurrencyID), 'DISCOUNT_PRICE' => CCurrencyRates::ConvertCurrency($arPrice["DISCOUNT_PRICE"], $arPrice["CURRENCY"], $strCurrencyID), 'CURRENCY' => $strCurrencyID, 'VAT_RATE' => CCurrencyRates::ConvertCurrency($arPrice["VAT_RATE"], $arPrice["CURRENCY"], $strCurrencyID), ); $arCurrencyList[] = $arPrice["CURRENCY"]; } else { $arResult["MATRIX"][intval($arPrice["CATALOG_GROUP_ID"])][$rowsCnt] = array( "ID" => $arPrice["ID"], "PRICE" => $arPrice["PRICE"], "DISCOUNT_PRICE" => $arPrice["DISCOUNT_PRICE"], "CURRENCY" => $arPrice["CURRENCY"], "VAT_RATE" => $arPrice["VAT_RATE"] ); } } $colsCnt = -1; $arCatalogGroups = CCatalogGroup::GetListArray(); foreach ($arCatalogGroups as $key => $value) { if (array_key_exists($key, $arResult["MATRIX"])) $arResult["COLS"][$value["ID"]] = $value; } $arResult["CAN_BUY"] = $arPriceGroups["buy"]; $arResult["AVAILABLE"] = (($productUseStoreFlag == 'Y' || ($productQuantityTrace == "N" || $productQuantityTrace == "Y" && $productQuantity > 0)) ? "Y" : "N"); if ($boolConvert) { if (!empty($arCurrencyList)) $arCurrencyList[] = $strCurrencyID; $arResult['CURRENCY_LIST'] = $arCurrencyList; } return $arResult; }
} } /************************************************************************* Work with cache *************************************************************************/ $cacheID = SITE_ID . "|" . __FILE__ . md5(serialize($arParams) . $USER->GetGroups()); $cachePath = "/iblock/main_page/"; $obCache = new CPHPCache(); if ($obCache->StartDataCache($CACHE_TIME, $cacheID, $cachePath)) { /************************************ Price ************************************/ $arPriceGroups = array(); if (CModule::IncludeModule("catalog")) { $arCatalogGroupsFilter = array(); $arCatalogGroups = CCatalogGroup::GetListArray(); if (count($arCatalogGroupCodesFilter) > 0) { foreach ($arCatalogGroups as $key => $value) { if (in_array($value["NAME"], $arCatalogGroupCodesFilter)) { $arCatalogGroupsFilter[] = $key; } } } $arPriceGroups = CCatalogGroup::GetGroupsPerms($USER->GetUserGroupArray(), $arCatalogGroupsFilter); // Now in $arPriceGroups["view"] we've collected catalog group IDs that current user can view (filtered is nesessary) // and in $arPriceGroups["buy"] we've collected catalog group IDs that current user can buy (not filtered) // In $arCatalogGroups we have the array of all catalog groups } /************************************ Elements ************************************/