...Человеческий поиск в разработке...
- Модуль: crm
- Путь к файлу: ~/bitrix/modules/crm/classes/general/crm_product.php
- Класс: \CCrmProduct
- Вызов: CCrmProduct::ObtainPricesVats
static function ObtainPricesVats(&$arProducts, &$arProductId, &$arPricesSelect, &$arCatalogProductSelect, $bRealPrice = false) { if (is_array($arProducts) && is_array($arProductId) && is_array($arPricesSelect) && is_array($arCatalogProductSelect) && count($arProductId) > 0 && count($arProducts) > 0 && (count($arPricesSelect) + count($arCatalogProductSelect)) > 0) { $arEntitiesFieldsets = array(); if (count($arPricesSelect) > 0) $arEntitiesFieldsets[] = array( 'name' => 'price', 'class' => 'CCrmProduct', 'method' => 'GetPrices', 'fieldset' => &$arPricesSelect, 'idField' => 'PRODUCT_ID', 'fieldMap' => array( 'PRICE' => 'PRICE', 'CURRENCY_ID' => 'CURRENCY' ) ); if (count($arCatalogProductSelect) > 0 || (in_array('PRICE', $arPricesSelect, true) && !$bRealPrice)) $arEntitiesFieldsets[] = array( 'name' => 'vat', 'class' => 'CCrmProduct', 'method' => 'GetCatalogProductFields', 'fieldset' => &$arCatalogProductSelect, 'idField' => 'ID', 'fieldMap' => array( 'VAT_INCLUDED' => 'VAT_INCLUDED', 'VAT_ID' => 'VAT_ID', 'MEASURE' => 'MEASURE' ) ); $nProducts = count($arProductId); $nStepSize = 500; $nSteps = intval(floor($nProducts / $nStepSize)) + 1; $nOffset = $nRange = 0; $arStepProductId = $fieldset = $arRow = array(); $fieldName = ''; while ($nSteps > 0) { $nRange = ($nSteps > 1) ? $nStepSize : $nProducts - $nOffset; if ($nRange > 0) { $arStepProductId = array_slice($arProductId, $nOffset, $nRange); foreach ($arEntitiesFieldsets as $fieldset) { $dbStep = call_user_func(array($fieldset['class'], $fieldset['method']), $arStepProductId); if ($dbStep) { /** @var Main\ORM\Query\Result $dbStep */ while ($arRow = $dbStep->fetch()) { foreach ($fieldset['fieldset'] as $fieldName) { if (isset($arProducts[$arRow[$fieldset['idField']]])) { $arProduct = &$arProducts[$arRow[$fieldset['idField']]]; if (array_key_exists($fieldName, $arProduct) && array_key_exists($fieldset['fieldMap'][$fieldName], $arRow)) { $prefix = array_key_exists('~'.$fieldName, $arProduct) ? '~' : ''; $arProduct[$prefix.$fieldName] = $arRow[$fieldset['fieldMap'][$fieldName]]; if (!empty($prefix)) $arProduct[$fieldName] = htmlspecialcharsbx($arProduct[$prefix.$fieldName]); } } } if ($fieldset['name'] === 'vat' && (!isset($bRealPrice) || $bRealPrice !== true)) { if (isset($arProducts[$arRow[$fieldset['idField']]])) { $arProduct = &$arProducts[$arRow[$fieldset['idField']]]; $prefix = isset($arProduct['~PRICE']) ? '~' : ''; if (isset($arProduct[$prefix.'PRICE']) && doubleval($arProduct[$prefix.'PRICE']) != 0.0 && $arRow['VAT_INCLUDED'] !== 'Y' && intval($arRow['VAT_ID']) > 0) { $arProduct[$prefix.'PRICE'] = self::RecalculatePriceVat( $arProduct[$prefix.'PRICE'], $arRow['VAT_INCLUDED'], $arRow['VAT_ID'] ); if (!empty($prefix)) $arProduct['PRICE'] = htmlspecialcharsbx($arProduct[$prefix.'PRICE']); } } } } } } } $nOffset += $nStepSize; $nSteps--; } } }