A
A
Anton2018-11-21 16:56:28
1C-Bitrix
Anton, 2018-11-21 16:56:28

How to display trading offers via api in Bitrix?

Displays the names of elements (products).

spoiler
<?
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>';
}
?>

How to display trade offers for products, for example, a symbolic code?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Eugene, 2018-11-21
@udjin123

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>';
        }
    }
}

A
Anton, 2018-11-21
@anton99zel

$arSKU = CCatalogSKU::getOffersList($arResult[ID], 0, array('ACTIVE' => 'Y'), array('NAME'), array("CODE"=>array('HEIGHT', 'WIDTH')));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question