- Модуль: sale
- Путь к файлу: ~/bitrix/modules/sale/lib/providerbase.php
- Класс: BitrixSaleProviderBase
- Вызов: ProviderBase::getProductDataByList
static function getProductDataByList(array $products, $providerClassName, array $select, array $context, array $options = array())
{
$result = new Result();
$resultList = array();
$needPrice = in_array('PRICE', $select);
$needBasePrice = in_array('BASE_PRICE', $select);
$needCoupons = in_array('COUPONS', $select);
$data = array(
'USER_ID' => $context['USER_ID'],
'SITE_ID' => $context['SITE_ID'],
'CURRENCY' => $context['CURRENCY'],
'CHECK_QUANTITY' => (in_array('QUANTITY', $select) ? 'Y' : 'N'),
'AVAILABLE_QUANTITY' => (in_array('AVAILABLE_QUANTITY', $select) ? 'Y' : 'N'),
'CHECK_PRICE' => ($needPrice ? 'Y' : 'N'),
'CHECK_COUPONS' => ($needCoupons ? 'Y' : 'N'),
'RENEWAL' => (in_array('RENEWAL', $select) ? 'Y' : 'N')
);
if ($needBasePrice)
$data['CHECK_DISCOUNT'] = 'N';
$useOrderProduct = false;
if ($needPrice)
$useOrderProduct = true;
if ($needCoupons)
$useOrderProduct = false;
$data['USE_ORDER_PRODUCT'] = $useOrderProduct;
unset($needCoupons, $needPrice);
if ($providerClassName)
{
if (array_key_exists("IBXSaleProductProvider", class_implements($providerClassName)))
{
$resultProductList = static::getProductProviderData($products, $providerClassName, $data, $select);
if (in_array('RETURN_BASKET_ID', $options))
{
$basketList = array();
foreach ($products as $productId => $productData)
{
$basketItem = $productData['BASKET_ITEM'];
$basketList[] = $basketItem;
}
$resultProductList = static::createItemsAfterGetProductData($basketList, $resultProductList, $select);
}
}
elseif (class_exists($providerClassName))
{
$basketList = array();
foreach ($products as $productId => $productData)
{
$basketList[] = $productData['BASKET_ITEM'];
}
$r = InternalsCatalogProvider::getProductData($basketList, $context);
if ($r->isSuccess())
{
$resultProductData = $r->getData();
if (!empty($resultProductData['PRODUCT_DATA_LIST']))
{
$itemsList = $resultProductData['PRODUCT_DATA_LIST'];
$resultItemsList = array();
$resultProductList = array();
foreach ($itemsList as $providerName => $products)
{
$resultItemsList = static::createItemsAfterGetProductData($basketList, $products, $select);
}
$resultProductList = $resultProductList + $resultItemsList;
}
}
}
if (!empty($resultProductList))
{
if (!empty($resultList) && is_array($resultList))
{
$resultList = $resultList + $resultProductList;
}
else
{
$resultList = $resultProductList;
}
}
}
else
{
$priceFields = static::getPriceFields();
foreach ($products as $productId => $productData)
{
$callbackFunction = null;
if (!empty($productData['CALLBACK_FUNC']))
{
$callbackFunction = $productData['CALLBACK_FUNC'];
}
$quantityList = array();
if (array_key_exists('QUANTITY', $productData))
{
$quantityList = array($productData['BASKET_CODE'] => $productData['QUANTITY']);
}
elseif (!empty($productData['QUANTITY_LIST']))
{
$quantityList = $productData['QUANTITY_LIST'];
}
foreach($quantityList as $basketCode => $quantity)
{
if (!empty($callbackFunction))
{
$resultProductData = CSaleBasket::executeCallbackFunction(
$callbackFunction,
$productData['MODULE'],
$productId,
$quantity
);
}
else
{
$resultProductData = array(
'QUANTITY' => $quantity,
'AVAILABLE_QUANTITY' => $quantity,
);
}
$itemCode = $productId;
if (in_array('RETURN_BASKET_ID', $options))
{
$itemCode = $basketCode;
}
if (empty($resultList[$itemCode]))
{
$resultList[$itemCode] = $resultProductData;
}
if (!empty($resultProductData))
{
$resultList[$itemCode]['PRICE_LIST'][$basketCode] = array(
'QUANTITY' => $resultProductData['QUANTITY'],
'AVAILABLE_QUANTITY' => $resultProductData['AVAILABLE_QUANTITY'],
"ITEM_CODE" => $productId,
"BASKET_CODE" => $basketCode,
);
foreach ($priceFields as $fieldName)
{
if (isset($resultProductData[$fieldName]))
{
$resultList[$itemCode]['PRICE_LIST'][$basketCode][$fieldName] = $resultProductData[$fieldName];
}
}
}
}
}
}
if (!empty($resultList))
{
$result->setData(
array(
'PRODUCT_DATA_LIST' => $resultList
)
);
}
return $result;
}