Answer the question
In order to leave comments, you need to log in
How to display trading offers via api in Bitrix?
Displays the names of elements (products).
<?
CModule::IncludeModule("catalog");
$my_slider = CIBlockElement::GetList (
Array("NAME" => "ASC"),
Array("IBLOCK_ID" => 1),
false,
false,
Array(
'ID',
'NAME',
)
);
while($ar_fields = $my_slider->GetNext())
{
echo $ar_fields['NAME'].'</br>';
}
?>
Answer the question
In order to leave comments, you need to log in
Bad idea, you'll end up with a database call in a loop, never do that.
Moreover, the getOffersList method takes as the first parameter an array of product IDs for which you need to get trade offers
https://dev.1c-bitrix.ru/api_help/catalog/classes/...
If you do this, then it will cost everything with two queries to the database
$elements = [];
CModule::IncludeModule("catalog");
$my_slider = CIBlockElement::GetList (
Array("NAME" => "ASC"),
Array("IBLOCK_ID" => 1),
false,
false,
Array(
'ID',
'NAME',
)
);
while($ar_fields = $my_slider->GetNext())
{
$elements[] = $ar_fields;
}
$productID = array_column($elements, 'ID');
$arSKU = CCatalogSKU::getOffersList(
$productID,
0,
array('ACTIVE' => 'Y'),
array('ID', 'NAME', 'CODE'),
array()
);
foreach ($elements as $element) {
echo $element['NAME'] . '</br>';
if ($arSKU[$element['ID']]) {
foreach ($arSKU[$element['ID']] as $offer) {
echo $offer['CODE'] . '<br>';
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question