/** * [getFavoriteProducts description] * @param array $arFavorites * @return array products */ function getFavoriteProducts($arFavorites) { global $USER; foreach ($arFavorites as $key => $id) { $arSelect = array(); $arFilter = array("IBLOCK_ID" => 17, "ACTIVE" => "Y", "ID" => $id); $res = CIBlockElement::GetList(array(), $arFilter, false, false, $arSelect); if ($ob = $res->GetNextElement()) { $arItems = $ob->GetFields(); $arItems["PROPERTIES"] = $ob->GetProperties(); $dbPrice = CPrice::GetList(array("QUANTITY_FROM" => "ASC", "QUANTITY_TO" => "ASC", "SORT" => "ASC"), array("PRODUCT_ID" => $arItems["ID"]), false, false, array("ID", "CATALOG_GROUP_ID", "PRICE", "CURRENCY", "QUANTITY_FROM", "QUANTITY_TO")); if ($arPrice = $dbPrice->Fetch()) { $arDiscounts = CCatalogDiscount::GetDiscountByPrice($arPrice["ID"], $USER->GetUserGroupArray(), "N", SITE_ID); $discountPrice = CCatalogProduct::CountPriceWithDiscount($arPrice["PRICE"], $arPrice["CURRENCY"], $arDiscounts); $arPrice["DISCOUNT_VALUE"] = $discountPrice; $arItems["PRICES"] = $arPrice; } } if ($arItems) { $arFav[] = $arItems; } } return $arFav; }
false, false, array("ID", "CATALOG_GROUP_ID", "PRICE", "CURRENCY", "QUANTITY_FROM", "QUANTITY_TO") ); while ($arPrice = $dbPrice->Fetch()) { $arDiscounts = CCatalogDiscount::GetDiscountByPrice( $arPrice["ID"], $USER->GetUserGroupArray(), "N", SITE_ID ); if(count($arDiscounts)){ $discountPrice = CCatalogProduct::CountPriceWithDiscount( $arPrice["PRICE"], $arPrice["CURRENCY"], $arDiscounts ); $arPrice["DISCOUNT_PRICE"] = $discountPrice; }else{ $arPrice["DISCOUNT_PRICE"] = $arPrice['PRICE']; } $arFields['PRICE_VALUE'] = $arPrice; } $arResult['ITEMS'][] = $arFields; } } $this->IncludeComponentTemplate(); ?>
function CatalogGetPriceTable($ID) { global $USER; $ID = (int) $ID; if ($ID <= 0) { return false; } $arResult = array(); $arPriceGroups = array(); $cacheKey = LANGUAGE_ID . "_" . $USER->GetGroups(); if (isset($GLOBALS["CATALOG_PRICE_GROUPS_CACHE"]) && is_array($GLOBALS["CATALOG_PRICE_GROUPS_CACHE"]) && isset($GLOBALS["CATALOG_PRICE_GROUPS_CACHE"][$cacheKey]) && is_array($GLOBALS["CATALOG_PRICE_GROUPS_CACHE"][$cacheKey])) { $arPriceGroups = $GLOBALS["CATALOG_PRICE_GROUPS_CACHE"][$cacheKey]; } else { $dbPriceGroupsList = CCatalogGroup::GetList(array("SORT" => "ASC"), array("CAN_ACCESS" => "Y", "LID" => LANGUAGE_ID), array("ID", "NAME_LANG", "SORT"), false, array("ID", "NAME_LANG", "CAN_BUY", "SORT")); while ($arPriceGroupsList = $dbPriceGroupsList->Fetch()) { $arPriceGroups[] = $arPriceGroupsList; $GLOBALS["CATALOG_PRICE_GROUPS_CACHE"][$cacheKey][] = $arPriceGroupsList; } } if (empty($arPriceGroups)) { return false; } $arBorderMap = array(); $arPresentGroups = array(); $bMultiQuantity = False; $dbPrice = CPrice::GetList(array("QUANTITY_FROM" => "ASC", "QUANTITY_TO" => "ASC", "SORT" => "ASC"), array("PRODUCT_ID" => $ID), false, false, array("ID", "CATALOG_GROUP_ID", "PRICE", "CURRENCY", "QUANTITY_FROM", "QUANTITY_TO", "ELEMENT_IBLOCK_ID", "SORT")); while ($arPrice = $dbPrice->Fetch()) { CCatalogDiscountSave::Disable(); $arDiscounts = CCatalogDiscount::GetDiscount($ID, $arPrice["ELEMENT_IBLOCK_ID"], $arPrice["CATALOG_GROUP_ID"], $USER->GetUserGroupArray(), "N", SITE_ID, array()); CCatalogDiscountSave::Enable(); $discountPrice = CCatalogProduct::CountPriceWithDiscount($arPrice["PRICE"], $arPrice["CURRENCY"], $arDiscounts); $arPrice["DISCOUNT_PRICE"] = $discountPrice; if (array_key_exists($arPrice["QUANTITY_FROM"] . "-" . $arPrice["QUANTITY_TO"], $arBorderMap)) { $jnd = $arBorderMap[$arPrice["QUANTITY_FROM"] . "-" . $arPrice["QUANTITY_TO"]]; } else { $jnd = count($arBorderMap); $arBorderMap[$arPrice["QUANTITY_FROM"] . "-" . $arPrice["QUANTITY_TO"]] = $jnd; } $arResult[$jnd]["QUANTITY_FROM"] = DoubleVal($arPrice["QUANTITY_FROM"]); $arResult[$jnd]["QUANTITY_TO"] = DoubleVal($arPrice["QUANTITY_TO"]); if (DoubleVal($arPrice["QUANTITY_FROM"]) > 0 || DoubleVal($arPrice["QUANTITY_TO"]) > 0) { $bMultiQuantity = True; } $arResult[$jnd]["PRICE"][$arPrice["CATALOG_GROUP_ID"]] = $arPrice; } $numGroups = count($arPriceGroups); for ($i = 0; $i < $numGroups; $i++) { $bNeedKill = True; for ($j = 0, $intCount = count($arResult); $j < $intCount; $j++) { if (!array_key_exists($arPriceGroups[$i]["ID"], $arResult[$j]["PRICE"])) { $arResult[$j]["PRICE"][$arPriceGroups[$i]["ID"]] = False; } if ($arResult[$j]["PRICE"][$arPriceGroups[$i]["ID"]] != false) { $bNeedKill = False; } } if ($bNeedKill) { for ($j = 0, $intCount = count($arResult); $j < $intCount; $j++) { unset($arResult[$j]["PRICE"][$arPriceGroups[$i]["ID"]]); } unset($arPriceGroups[$i]); } } return array("COLS" => $arPriceGroups, "MATRIX" => $arResult, "MULTI_QUANTITY" => $bMultiQuantity ? "Y" : "N"); }
public static function GetItemPrices($IBLOCK_ID, $arCatalogPrices, $arItem, $bVATInclude = true, $arCurrencyParams = array(), $USER_ID = 0, $LID = SITE_ID) { $arPrices = array(); if (empty($arCatalogPrices) || !is_array($arCatalogPrices)) { return $arPrices; } global $USER; static $arCurUserGroups = array(); static $strBaseCurrency = ''; if (self::$catalogIncluded === null) self::$catalogIncluded = \Freetrix\Main\Loader::includeModule('catalog'); if (self::$catalogIncluded) { $USER_ID = intval($USER_ID); $intUserID = $USER_ID; if (0 >= $intUserID) $intUserID = $USER->GetID(); if (!isset($arCurUserGroups[$intUserID])) { $arUserGroups = (0 < $USER_ID ? CUser::GetUserGroup($USER_ID) : $USER->GetUserGroupArray()); CatalogClearArray($arUserGroups); $arCurUserGroups[$intUserID] = $arUserGroups; } else { $arUserGroups = $arCurUserGroups[$intUserID]; } $boolConvert = false; $strCurrencyID = ''; if (isset($arCurrencyParams['CURRENCY_ID']) && !empty($arCurrencyParams['CURRENCY_ID'])) { $boolConvert = true; $strCurrencyID = $arCurrencyParams['CURRENCY_ID']; } if (!$boolConvert && '' == $strBaseCurrency) $strBaseCurrency = CCurrency::GetBaseCurrency(); $strMinCode = ''; $boolStartMin = true; $dblMinPrice = 0; $strMinCurrency = ($boolConvert ? $strCurrencyID : $strBaseCurrency); CCatalogDiscountSave::Disable(); foreach($arCatalogPrices as $key => $value) { if($value["CAN_VIEW"] && strlen($arItem["CATALOG_PRICE_".$value["ID"]]) > 0) { // get final price with VAT included. if ($arItem['CATALOG_VAT_INCLUDED'] != 'Y') { $arItem['CATALOG_PRICE_'.$value['ID']] *= (1 + $arItem['CATALOG_VAT'] * 0.01); } // so discounts will include VAT $arDiscounts = CCatalogDiscount::GetDiscount( $arItem["ID"], $arItem["IBLOCK_ID"], array($value["ID"]), $arUserGroups, "N", $LID, array() ); $discountPrice = CCatalogProduct::CountPriceWithDiscount( $arItem["CATALOG_PRICE_".$value["ID"]], $arItem["CATALOG_CURRENCY_".$value["ID"]], $arDiscounts ); // get clear prices WO VAT $arItem['CATALOG_PRICE_'.$value['ID']] /= (1 + $arItem['CATALOG_VAT'] * 0.01); $discountPrice /= (1 + $arItem['CATALOG_VAT'] * 0.01); $vat_value_discount = $discountPrice * $arItem['CATALOG_VAT'] * 0.01; $vat_discountPrice = $discountPrice + $vat_value_discount; $vat_value = $arItem['CATALOG_PRICE_'.$value['ID']] * $arItem['CATALOG_VAT'] * 0.01; $vat_price = $arItem["CATALOG_PRICE_".$value["ID"]] + $vat_value; if ($boolConvert && $strCurrencyID != $arItem["CATALOG_CURRENCY_".$value["ID"]]) { $strOrigCurrencyID = $arItem["CATALOG_CURRENCY_".$value["ID"]]; $dblOrigNoVat = $arItem["CATALOG_PRICE_".$value["ID"]]; $dblNoVat = CCurrencyRates::ConvertCurrency($dblOrigNoVat, $strOrigCurrencyID, $strCurrencyID); $dblVatPrice = CCurrencyRates::ConvertCurrency($vat_price, $strOrigCurrencyID, $strCurrencyID); $dblVatValue = CCurrencyRates::ConvertCurrency($vat_value, $strOrigCurrencyID, $strCurrencyID); $dblDiscountValueNoVat = CCurrencyRates::ConvertCurrency($discountPrice, $strOrigCurrencyID, $strCurrencyID); $dblVatDiscountPrice = CCurrencyRates::ConvertCurrency($vat_discountPrice, $strOrigCurrencyID, $strCurrencyID); $dblDiscountValueVat = CCurrencyRates::ConvertCurrency($vat_value_discount, $strOrigCurrencyID, $strCurrencyID); $arPrices[$key] = array( 'ORIG_VALUE_NOVAT' => $dblOrigNoVat, "VALUE_NOVAT" => $dblNoVat, "PRINT_VALUE_NOVAT" => CCurrencyLang::CurrencyFormat($dblNoVat, $strCurrencyID, true), 'ORIG_VALUE_VAT' => $vat_price, "VALUE_VAT" => $dblVatPrice, "PRINT_VALUE_VAT" => CCurrencyLang::CurrencyFormat($dblVatPrice, $strCurrencyID, true), 'ORIG_VATRATE_VALUE' => $vat_value, "VATRATE_VALUE" => $dblVatValue, "PRINT_VATRATE_VALUE" => CCurrencyLang::CurrencyFormat($dblVatValue, $strCurrencyID, true), 'ORIG_DISCOUNT_VALUE_NOVAT' => $discountPrice, "DISCOUNT_VALUE_NOVAT" => $dblDiscountValueNoVat, "PRINT_DISCOUNT_VALUE_NOVAT" => CCurrencyLang::CurrencyFormat($dblDiscountValueNoVat, $strCurrencyID, true), "ORIG_DISCOUNT_VALUE_VAT" => $vat_discountPrice, "DISCOUNT_VALUE_VAT" => $dblVatDiscountPrice, "PRINT_DISCOUNT_VALUE_VAT" => CCurrencyLang::CurrencyFormat($dblVatDiscountPrice, $strCurrencyID, true), 'ORIG_DISCOUNT_VATRATE_VALUE' => $vat_value_discount, 'DISCOUNT_VATRATE_VALUE' => $dblDiscountValueVat, 'PRINT_DISCOUNT_VATRATE_VALUE' => CCurrencyLang::CurrencyFormat($dblDiscountValueVat, $strCurrencyID, true), 'ORIG_CURRENCY' => $strOrigCurrencyID, "CURRENCY" => $strCurrencyID, ); } else { $strPriceCurrency = $arItem["CATALOG_CURRENCY_".$value["ID"]]; $arPrices[$key] = array( "VALUE_NOVAT" => $arItem["CATALOG_PRICE_".$value["ID"]], "PRINT_VALUE_NOVAT" => CCurrencyLang::CurrencyFormat($arItem["CATALOG_PRICE_".$value["ID"]], $strPriceCurrency, true), "VALUE_VAT" => $vat_price, "PRINT_VALUE_VAT" => CCurrencyLang::CurrencyFormat($vat_price, $strPriceCurrency, true), "VATRATE_VALUE" => $vat_value, "PRINT_VATRATE_VALUE" => CCurrencyLang::CurrencyFormat($vat_value, $strPriceCurrency, true), "DISCOUNT_VALUE_NOVAT" => $discountPrice, "PRINT_DISCOUNT_VALUE_NOVAT" => CCurrencyLang::CurrencyFormat($discountPrice, $strPriceCurrency, true), "DISCOUNT_VALUE_VAT" => $vat_discountPrice, "PRINT_DISCOUNT_VALUE_VAT" => CCurrencyLang::CurrencyFormat($vat_discountPrice, $strPriceCurrency, true), 'DISCOUNT_VATRATE_VALUE' => $vat_value_discount, 'PRINT_DISCOUNT_VATRATE_VALUE' => CCurrencyLang::CurrencyFormat($vat_value_discount, $strPriceCurrency, true), "CURRENCY" => $arItem["CATALOG_CURRENCY_".$value["ID"]], ); } $arPrices[$key]["ID"] = $arItem["CATALOG_PRICE_ID_".$value["ID"]]; $arPrices[$key]["CAN_ACCESS"] = $arItem["CATALOG_CAN_ACCESS_".$value["ID"]]; $arPrices[$key]["CAN_BUY"] = $arItem["CATALOG_CAN_BUY_".$value["ID"]]; $arPrices[$key]['MIN_PRICE'] = 'N'; if ($bVATInclude) { $arPrices[$key]['VALUE'] = $arPrices[$key]['VALUE_VAT']; $arPrices[$key]['PRINT_VALUE'] = $arPrices[$key]['PRINT_VALUE_VAT']; $arPrices[$key]['DISCOUNT_VALUE'] = $arPrices[$key]['DISCOUNT_VALUE_VAT']; $arPrices[$key]['PRINT_DISCOUNT_VALUE'] = $arPrices[$key]['PRINT_DISCOUNT_VALUE_VAT']; } else { $arPrices[$key]['VALUE'] = $arPrices[$key]['VALUE_NOVAT']; $arPrices[$key]['PRINT_VALUE'] = $arPrices[$key]['PRINT_VALUE_NOVAT']; $arPrices[$key]['DISCOUNT_VALUE'] = $arPrices[$key]['DISCOUNT_VALUE_NOVAT']; $arPrices[$key]['PRINT_DISCOUNT_VALUE'] = $arPrices[$key]['PRINT_DISCOUNT_VALUE_NOVAT']; } if (roundEx($arPrices[$key]['VALUE'], 2) == roundEx($arPrices[$key]['DISCOUNT_VALUE'], 2)) { $arPrices[$key]['DISCOUNT_DIFF'] = 0; $arPrices[$key]['DISCOUNT_DIFF_PERCENT'] = 0; $arPrices[$key]['PRINT_DISCOUNT_DIFF'] = CCurrencyLang::CurrencyFormat(0, $arPrices[$key]['CURRENCY'], true); } else { $arPrices[$key]['DISCOUNT_DIFF'] = $arPrices[$key]['VALUE'] - $arPrices[$key]['DISCOUNT_VALUE']; $arPrices[$key]['DISCOUNT_DIFF_PERCENT'] = roundEx(100*$arPrices[$key]['DISCOUNT_DIFF']/$arPrices[$key]['VALUE'], 0); $arPrices[$key]['PRINT_DISCOUNT_DIFF'] = CCurrencyLang::CurrencyFormat($arPrices[$key]['DISCOUNT_DIFF'], $arPrices[$key]['CURRENCY'], true); } if ($value["CAN_VIEW"]) { if ($boolStartMin) { $dblMinPrice = ($boolConvert || ($arPrices[$key]['CURRENCY'] == $strMinCurrency) ? $arPrices[$key]['DISCOUNT_VALUE'] : CCurrencyRates::ConvertCurrency($arPrices[$key]['DISCOUNT_VALUE'], $arPrices[$key]['CURRENCY'], $strMinCurrency) ); $strMinCode = $key; $boolStartMin = false; } else { $dblComparePrice = ($boolConvert || ($arPrices[$key]['CURRENCY'] == $strMinCurrency) ? $arPrices[$key]['DISCOUNT_VALUE'] : CCurrencyRates::ConvertCurrency($arPrices[$key]['DISCOUNT_VALUE'], $arPrices[$key]['CURRENCY'], $strMinCurrency) ); if ($dblMinPrice > $dblComparePrice) { $dblMinPrice = $dblComparePrice; $strMinCode = $key; } } } } } if ('' != $strMinCode) $arPrices[$strMinCode]['MIN_PRICE'] = 'Y'; CCatalogDiscountSave::Enable(); } else { $strMinCode = ''; $boolStartMin = true; $dblMinPrice = 0; foreach($arCatalogPrices as $key => $value) { if($value["CAN_VIEW"]) { $dblValue = round(doubleval($arItem["PROPERTY_".$value["ID"]."_VALUE"]), 2); if ($boolStartMin) { $dblMinPrice = $dblValue; $strMinCode = $key; $boolStartMin = false; } else { if ($dblMinPrice > $dblValue) { $dblMinPrice = $dblValue; $strMinCode = $key; } } $arPrices[$key] = array( "ID" => $arItem["PROPERTY_".$value["ID"]."_VALUE_ID"], "VALUE" => $dblValue, "PRINT_VALUE" => $dblValue." ".$arItem["PROPERTY_".$value["ID"]."_DESCRIPTION"], "DISCOUNT_VALUE" => $dblValue, "PRINT_DISCOUNT_VALUE" => $dblValue." ".$arItem["PROPERTY_".$value["ID"]."_DESCRIPTION"], "CURRENCY" => $arItem["PROPERTY_".$value["ID"]."_DESCRIPTION"], "CAN_ACCESS" => true, "CAN_BUY" => false, 'DISCOUNT_DIFF_PERCENT' => 0, 'DISCOUNT_DIFF' => 0, 'PRINT_DISCOUNT_DIFF' => '0 '.$arItem["PROPERTY_".$value["ID"]."_DESCRIPTION"], "MIN_PRICE" => "N" ); } } if ('' != $strMinCode) $arPrices[$strMinCode]['MIN_PRICE'] = 'Y'; } return $arPrices; }
public static function GetItemPrices($IBLOCK_ID, $arCatalogPrices, $arItem, $bVATInclude = true, $arCurrencyParams = array(), $USER_ID = 0, $LID = SITE_ID) { static $arCurUserGroups = array(); global $USER; $arPrices = array(); if(CModule::IncludeModule("catalog")) { $USER_ID = intval($USER_ID); $intUserID = $USER_ID; if (0 >= $intUserID) $intUserID = $USER->GetID(); if (!array_key_exists($intUserID, $arCurUserGroups)) { $arCurUserGroups[$intUserID] = (0 < $USER_ID ? CUser::GetUserGroup($USER_ID) : $USER->GetUserGroupArray()); } $arUserGroups = $arCurUserGroups[$intUserID]; $boolConvert = false; $strCurrencyID = ''; if (is_array($arCurrencyParams) && !empty($arCurrencyParams) && !empty($arCurrencyParams['CURRENCY_ID'])) { $boolConvert = true; $strCurrencyID = $arCurrencyParams['CURRENCY_ID']; } foreach($arCatalogPrices as $key => $value) { if($value["CAN_VIEW"] && strlen($arItem["CATALOG_PRICE_".$value["ID"]]) > 0) { // get final price with VAT included. if ($arItem['CATALOG_VAT_INCLUDED'] != 'Y') { $arItem['CATALOG_PRICE_'.$value['ID']] *= (1 + $arItem['CATALOG_VAT'] * 0.01); } CCatalogDiscountSave::Disable(); // so discounts will include VAT $arDiscounts = CCatalogDiscount::GetDiscount( $arItem["ID"], $arItem["IBLOCK_ID"], array($value["ID"]), $arUserGroups, "N", $LID, array() ); CCatalogDiscountSave::Enable(); $discountPrice = CCatalogProduct::CountPriceWithDiscount( $arItem["CATALOG_PRICE_".$value["ID"]], $arItem["CATALOG_CURRENCY_".$value["ID"]], $arDiscounts ); // get clear prices WO VAT $arItem['CATALOG_PRICE_'.$value['ID']] /= (1 + $arItem['CATALOG_VAT'] * 0.01); $discountPrice /= (1 + $arItem['CATALOG_VAT'] * 0.01); $vat_value_discount = $discountPrice * $arItem['CATALOG_VAT'] * 0.01; $vat_discountPrice = $discountPrice + $vat_value_discount; $vat_value = $arItem['CATALOG_PRICE_'.$value['ID']] * $arItem['CATALOG_VAT'] * 0.01; $vat_price = $arItem["CATALOG_PRICE_".$value["ID"]] + $vat_value; if ($boolConvert && $strCurrencyID != $arItem["CATALOG_CURRENCY_".$value["ID"]]) { $strOrigCurrencyID = $arItem["CATALOG_CURRENCY_".$value["ID"]]; $dblOrigNoVat = $arItem["CATALOG_PRICE_".$value["ID"]]; $dblNoVat = CCurrencyRates::ConvertCurrency($dblOrigNoVat, $strOrigCurrencyID, $strCurrencyID); $dblVatPrice = CCurrencyRates::ConvertCurrency($vat_price, $strOrigCurrencyID, $strCurrencyID); $dblVatValue = CCurrencyRates::ConvertCurrency($vat_value, $strOrigCurrencyID, $strCurrencyID); $dblDiscountValueNoVat = CCurrencyRates::ConvertCurrency($discountPrice, $strOrigCurrencyID, $strCurrencyID); $dblVatDiscountPrice = CCurrencyRates::ConvertCurrency($vat_discountPrice, $strOrigCurrencyID, $strCurrencyID); $dblDiscountValueVat = CCurrencyRates::ConvertCurrency($vat_value_discount, $strOrigCurrencyID, $strCurrencyID); $arPrices[$key] = array( 'ORIG_VALUE_NOVAT' => $dblOrigNoVat, "VALUE_NOVAT" => $dblNoVat, "PRINT_VALUE_NOVAT" => FormatCurrency($dblNoVat, $strCurrencyID), 'ORIG_VALUE_VAT' => $vat_price, "VALUE_VAT" => $dblVatPrice, "PRINT_VALUE_VAT" => FormatCurrency($dblVatPrice, $strCurrencyID), 'ORIG_VATRATE_VALUE' => $vat_value, "VATRATE_VALUE" => $dblVatValue, "PRINT_VATRATE_VALUE" => FormatCurrency($dblVatValue, $strCurrencyID), 'ORIG_DISCOUNT_VALUE_NOVAT' => $discountPrice, "DISCOUNT_VALUE_NOVAT" => $dblDiscountValueNoVat, "PRINT_DISCOUNT_VALUE_NOVAT" => FormatCurrency($dblDiscountValueNoVat, $strCurrencyID), "ORIG_DISCOUNT_VALUE_VAT" => $vat_discountPrice, "DISCOUNT_VALUE_VAT" => $dblVatDiscountPrice, "PRINT_DISCOUNT_VALUE_VAT" => FormatCurrency($dblVatDiscountPrice, $strCurrencyID), 'ORIG_DISCOUNT_VATRATE_VALUE' => $vat_value_discount, 'DISCOUNT_VATRATE_VALUE' => $dblDiscountValueVat, 'PRINT_DISCOUNT_VATRATE_VALUE' => FormatCurrency($dblDiscountValueVat, $strCurrencyID), 'ORIG_CURRENCY' => $strOrigCurrencyID, "CURRENCY" => $strCurrencyID, ); } else { $arPrices[$key] = array( "VALUE_NOVAT" => $arItem["CATALOG_PRICE_".$value["ID"]], "PRINT_VALUE_NOVAT" => FormatCurrency($arItem["CATALOG_PRICE_".$value["ID"]],$arItem["CATALOG_CURRENCY_".$value["ID"]]), "VALUE_VAT" => $vat_price, "PRINT_VALUE_VAT" => FormatCurrency($vat_price, $arItem["CATALOG_CURRENCY_".$value["ID"]]), "VATRATE_VALUE" => $vat_value, "PRINT_VATRATE_VALUE" => FormatCurrency($vat_value, $arItem["CATALOG_CURRENCY_".$value["ID"]]), "DISCOUNT_VALUE_NOVAT" => $discountPrice, "PRINT_DISCOUNT_VALUE_NOVAT" => FormatCurrency($discountPrice, $arItem["CATALOG_CURRENCY_".$value["ID"]]), "DISCOUNT_VALUE_VAT" => $vat_discountPrice, "PRINT_DISCOUNT_VALUE_VAT" => FormatCurrency($vat_discountPrice, $arItem["CATALOG_CURRENCY_".$value["ID"]]), 'DISCOUNT_VATRATE_VALUE' => $vat_value_discount, 'PRINT_DISCOUNT_VATRATE_VALUE' => FormatCurrency($vat_value_discount, $arItem["CATALOG_CURRENCY_".$value["ID"]]), "CURRENCY" => $arItem["CATALOG_CURRENCY_".$value["ID"]], ); } $arPrices[$key]["ID"] = $arItem["CATALOG_PRICE_ID_".$value["ID"]]; $arPrices[$key]["CAN_ACCESS"] = $arItem["CATALOG_CAN_ACCESS_".$value["ID"]]; $arPrices[$key]["CAN_BUY"] = $arItem["CATALOG_CAN_BUY_".$value["ID"]]; if ($bVATInclude) { $arPrices[$key]['VALUE'] = $arPrices[$key]['VALUE_VAT']; $arPrices[$key]['PRINT_VALUE'] = $arPrices[$key]['PRINT_VALUE_VAT']; $arPrices[$key]['DISCOUNT_VALUE'] = $arPrices[$key]['DISCOUNT_VALUE_VAT']; $arPrices[$key]['PRINT_DISCOUNT_VALUE'] = $arPrices[$key]['PRINT_DISCOUNT_VALUE_VAT']; } else { $arPrices[$key]['VALUE'] = $arPrices[$key]['VALUE_NOVAT']; $arPrices[$key]['PRINT_VALUE'] = $arPrices[$key]['PRINT_VALUE_NOVAT']; $arPrices[$key]['DISCOUNT_VALUE'] = $arPrices[$key]['DISCOUNT_VALUE_NOVAT']; $arPrices[$key]['PRINT_DISCOUNT_VALUE'] = $arPrices[$key]['PRINT_DISCOUNT_VALUE_NOVAT']; } } } } else { foreach($arCatalogPrices as $key => $value) { if($value["CAN_VIEW"]) { $arPrices[$key] = array( "ID" => $arItem["PROPERTY_".$value["ID"]."_VALUE_ID"], "VALUE" => round(doubleval($arItem["PROPERTY_".$value["ID"]."_VALUE"]),2), "PRINT_VALUE" => round(doubleval($arItem["PROPERTY_".$value["ID"]."_VALUE"]),2)." ".$arItem["PROPERTY_".$value["ID"]."_DESCRIPTION"], "DISCOUNT_VALUE" => round(doubleval($arItem["PROPERTY_".$value["ID"]."_VALUE"]),2), "PRINT_DISCOUNT_VALUE" => round(doubleval($arItem["PROPERTY_".$value["ID"]."_VALUE"]),2)." ".$arItem["PROPERTY_".$value["ID"]."_DESCRIPTION"], "CURRENCY" => $arItem["PROPERTY_".$value["ID"]."_DESCRIPTION"], "CAN_ACCESS" => true, "CAN_BUY" => false, ); } } } return $arPrices; }
$elementIterator = CIBlockElement::GetList(array(), array("ID" => array_keys($arResult), "IBLOCK_TYPE_ID" => $arParams["IBLOCK_TYPE_ID"]), false, array(), $arSelect); unset($arSelect); while ($el = $elementIterator->GetNext()) { $iProductId = $arResult[$el["ID"]]; //Если запрос не вернул цену товара, то возможно это товар с торговым предложением, поэтому получаем его базовую цену этого товара if ($el["CATALOG_PURCHASING_PRICE"] == "") { $arPrice = CPrice::GetBasePrice($iProductId); $el["CATALOG_PURCHASING_PRICE"] = $arPrice["PRICE"]; $el["CATALOG_PURCHASING_CURRENCY"] = $arPrice["CURRENCY"]; } //получаем скидку для товара $arDiscounts = CCatalogDiscount::GetDiscountByProduct($iProductId, $USER->GetUserGroupArray(), "N", 1, SITE_ID); //получаем цену в зависимости от скидки $discountPrice = false; if ($arDiscounts) { $discountPrice = CCatalogProduct::CountPriceWithDiscount($el["CATALOG_PURCHASING_PRICE"], $el["CATALOG_PURCHASING_CURRENCY"], $arDiscounts); } // путь к директории, где хранятся изображения $imageId = empty($el["DETAIL_PICTURE"]) ? $el["PREVIEW_PICTURE"] : $el["DETAIL_PICTURE"]; if (!empty($imageId)) { /*Неэффективный кусок кода*/ $sPath = CFile::GetByID($imageId)->GetNext(); /**********************************/ $sPath = "/" . $strImageStorePath . "/" . $sPath["SUBDIR"] . "/" . $sPath["FILE_NAME"]; } else { $sPath = ""; } $price = CCurrencyLang::GetCurrencyFormat($el["CATALOG_PURCHASING_CURRENCY"], "ru")["FORMAT_STRING"]; $arResult[$el["ID"]] = $el; $arResult[$el["ID"]]["PRICE"] = str_replace("#", $el["CATALOG_PURCHASING_PRICE"], $price); $arResult[$el["ID"]]["PRICE_WITH_DISCOUNT"] = $discountPrice ? str_replace("#", $discountPrice, $price) : "";
echo $arElement["PREVIEW_TEXT_TYPE"] == "html" ? $arElement["PREVIEW_TEXT"] : TxtToHTML($arElement["~PREVIEW_TEXT"]); ?> </font> <?php } ?> </td> </tr> <?php if ($USE_PRICE_COUNT == "N") { if (count($arPriceGroups) > 0 && count($arPriceGroups["view"]) > 0) { foreach ($arCatalogGroups as $key => $value) { if (in_array($key, $arPriceGroups["view"])) { if (StrLen($arElement["CATALOG_PRICE_" . $key]) > 0) { $arDiscounts = CCatalogDiscount::GetDiscount($arElement["ID"], $IBLOCK_ID, array($key), $GLOBALS["USER"]->GetUserGroupArray(), "N", SITE_ID, false); $discountPrice = CCatalogProduct::CountPriceWithDiscount($arElement["CATALOG_PRICE_" . $key], $arElement["CATALOG_CURRENCY_" . $key], $arDiscounts); ?> <tr> <td colspan="3" style="padding-top:2px;"><font class="text"><?php echo $value["NAME_LANG"]; ?> : <b><?php if ($discountPrice < $arElement["CATALOG_PRICE_" . $key]) { echo '<s>' . FormatCurrency($arElement["CATALOG_PRICE_" . $key], $arElement["CATALOG_CURRENCY_" . $key]) . '</s> <font color="red">' . FormatCurrency($discountPrice, $arElement["CATALOG_CURRENCY_" . $key]) . '</font>'; } else { echo '<font color="red">' . FormatCurrency($arElement["CATALOG_PRICE_" . $key], $arElement["CATALOG_CURRENCY_" . $key]) . '</font>'; } ?> </b></font></td> </tr> <?php
/** * [getSpecificationsList description] * @param int $idUser * @return array or false */ function getSpecificationsList($idUser) { if (!CModule::IncludeModule('iblock')) { return false; } global $USER; if ($idUser) { $IBLOCK_ID = getIblockSpecifications(); $rsUser = CUser::GetByID($idUser); $arUser = $rsUser->Fetch(); $arSpecificationsId = $arUser["UF_SPECIFICATIONS"]; foreach ($arSpecificationsId as $key => $id) { $arFilterSec = array('IBLOCK_ID' => $IBLOCK_ID, 'GLOBAL_ACTIVE' => 'Y', "ID" => $id); $db_list = CIBlockSection::GetList(array("TIMESTAMP_X" => "DESC"), $arFilterSec, true); if ($ar_result = $db_list->GetNext()) { $ar_result["ITEMS"] = array(); $arSelect = array("NAME", "ID", "PROPERTY_PRODUCT", "PROPERTY_COUNT"); $arFilter = array("IBLOCK_ID" => $IBLOCK_ID, "ACTIVE" => "Y", "SECTION_ID" => $ar_result["ID"]); $res = CIBlockElement::GetList(array(), $arFilter, false, false, $arSelect); while ($ob = $res->GetNextElement()) { $arItem = $ob->GetFields(); $arProdSpec = getItemCart($arItem["PROPERTY_PRODUCT_VALUE"]); if ($arProdSpec && $arItem["PROPERTY_PRODUCT_VALUE"]) { $arItem["PRODUCT"] = $arProdSpec; $dbPrice = CPrice::GetList(array("QUANTITY_FROM" => "ASC", "QUANTITY_TO" => "ASC", "SORT" => "ASC"), array("PRODUCT_ID" => $arItem["PROPERTY_PRODUCT_VALUE"]), false, false, array("ID", "CATALOG_GROUP_ID", "PRICE", "CURRENCY", "QUANTITY_FROM", "QUANTITY_TO")); if ($arPrice = $dbPrice->Fetch()) { $arDiscounts = CCatalogDiscount::GetDiscountByPrice($arPrice["ID"], $USER->GetUserGroupArray(), "N", SITE_ID); $discountPrice = CCatalogProduct::CountPriceWithDiscount($arPrice["PRICE"], $arPrice["CURRENCY"], $arDiscounts); $arPrice["DISCOUNT_PRICE"] = $discountPrice; $arItem["DISCOUNT"] = $arPrice; } $ar_result["ITEMS"][] = $arItem; } elseif (!$arItem["PROPERTY_PRODUCT_VALUE"]) { $arParams["product"] = $arItem["ID"]; removeItemSpecification($arParams); } } $arSections[] = $ar_result; } } return $arSections; } return false; }
/** * [getSeoProducts description] * @param array $arParams * @return array */ function getSeoProducts($arParams) { global $USER; $arSelect = array(); $arFilter = array("IBLOCK_ID" => 22, "ACTIVE" => "Y", "ID" => $arParams["ID"]); $res = CIBlockElement::GetList(array(), $arFilter, false, false, $arSelect); if ($ob = $res->GetNextElement()) { $seo_items = $ob->GetFields(); $seo_items["PROPERTIES"] = $ob->GetProperties(); foreach ($seo_items["PROPERTIES"]["PRODUCTS"]["VALUE"] as $key => $idProd) { $arSelectProd = array("ID", "NAME", "PREVIEW_PICTURE", "PROPERTY_ARTIKUL", "PROPERTY_PRICE", "PROPERTY_OLD_PRICE", "PROPERTY_NEW", "PROPERTY_HIT", "PROPERTY_SALE", "DETAIL_PAGE_URL"); $arFilterProd = array("IBLOCK_ID" => 17, "ACTIVE" => "Y", "ID" => $idProd); $resProd = CIBlockElement::GetList(array(), $arFilterProd, false, false, $arSelectProd); while ($obProd = $resProd->GetNextElement()) { $arItem = $obProd->GetFields(); $dbPrice = CPrice::GetList(array("QUANTITY_FROM" => "ASC", "QUANTITY_TO" => "ASC", "SORT" => "ASC"), array("PRODUCT_ID" => $arItem["ID"]), false, false, array("ID", "CATALOG_GROUP_ID", "PRICE", "CURRENCY", "QUANTITY_FROM", "QUANTITY_TO")); if ($arPrice = $dbPrice->Fetch()) { $arDiscounts = CCatalogDiscount::GetDiscountByPrice($arPrice["ID"], $USER->GetUserGroupArray(), "N", SITE_ID); $discountPrice = CCatalogProduct::CountPriceWithDiscount($arPrice["PRICE"], $arPrice["CURRENCY"], $arDiscounts); $arPrice["DISCOUNT_VALUE"] = $discountPrice; $arItem["PRICES"] = $arPrice; } $arProducts[] = $arItem; } } return $arProducts; } }
function getFinalPriceInCurrency($item_id, $sale_currency = 'UAH') { global $USER; // Do item have offers? if (CCatalogSku::IsExistOffers($item_id)) { // Find price in offers $res = CIBlockElement::GetByID($item_id); if ($ar_res = $res->GetNext()) { if (isset($ar_res['IBLOCK_ID']) && $ar_res['IBLOCK_ID']) { // Find all offers $offers = CIBlockPriceTools::GetOffersArray(array('IBLOCK_ID' => $ar_res['IBLOCK_ID'], 'HIDE_NOT_AVAILABLE' => 'Y', 'CHECK_PERMISSIONS' => 'Y'), array($item_id), null, null, null, null, null, null, array('CURRENCY_ID' => $sale_currency), $USER->getId(), null); foreach ($offers as $offer) { $price = CCatalogProduct::GetOptimalPrice($offer['ID'], 1, $USER->GetUserGroupArray(), 'N'); if (isset($price['PRICE'])) { if ($price['PRICE']['CURRENCY'] != $sale_currency) { $price['PRICE']['PRICE'] = CCurrencyRates::ConvertCurrency($price['PRICE']['PRICE'], $price['PRICE']['CURRENCY'], $sale_currency); $price['PRICE']['CURRENCY'] = $sale_currency; } $price['PRICE']['PRICE_WITH_DISCOUNT'] = $price['PRICE']['PRICE']; $currency_code = $price['PRICE']['CURRENCY']; // Find discounts and calculate price with discounts $arDiscounts = CCatalogDiscount::GetDiscountByProduct($item_id, $USER->GetUserGroupArray(), "N"); if (is_array($arDiscounts) && sizeof($arDiscounts) > 0) { $price['PRICE']['PRICE_WITH_DISCOUNT'] = CCatalogProduct::CountPriceWithDiscount($price['PRICE']['PRICE_WITH_DISCOUNT'], $sale_currency, $arDiscounts); } // Stop cycle, use found value break; } } } } } else { // Simple product, not trade offers $price = CCatalogProduct::GetOptimalPrice($item_id, 1, $USER->GetUserGroupArray(), 'N'); // Got price? if (!$price || !isset($price['PRICE'])) { return false; } if ($price['PRICE']['CURRENCY'] != $sale_currency) { $price['PRICE']['PRICE'] = CCurrencyRates::ConvertCurrency($price['PRICE']['PRICE'], $price['PRICE']['CURRENCY'], $sale_currency); $price['DISCOUNT_PRICE'] = CCurrencyRates::ConvertCurrency($price['DISCOUNT_PRICE'], $price['PRICE']['CURRENCY'], $sale_currency); $price['PRICE']['CURRENCY'] = $sale_currency; } // Change currency code if found if (isset($price['CURRENCY'])) { $currency_code = $price['CURRENCY']; } if (isset($price['PRICE']['CURRENCY'])) { $currency_code = $price['PRICE']['CURRENCY']; } // Get final price $price['PRICE']['PRICE_WITH_DISCOUNT'] = $price['DISCOUNT_PRICE']; // Find discounts and calculate price with discounts $arDiscounts = CCatalogDiscount::GetDiscountByProduct($item_id, $USER->GetUserGroupArray(), "N", 2); if (is_array($arDiscounts) && sizeof($arDiscounts) > 0) { $price['PRICE']['PRICE_WITH_DISCOUNT'] = CCatalogProduct::CountPriceWithDiscount($price['PRICE']['PRICE_WITH_DISCOUNT'], $sale_currency, $arDiscounts); } } // Convert to sale currency if needed if ($currency_code != $sale_currency) { $price['PRICE']['PRICE_WITH_DISCOUNT'] = CCurrencyRates::ConvertCurrency($price['PRICE']['PRICE_WITH_DISCOUNT'], $sale_currency, $sale_currency); } return $price; }