R
R
redesupar2022-03-15 09:25:28
1C-Bitrix
redesupar, 2022-03-15 09:25:28

How to export all product ids in Bitrix cart?

It is necessary to export all id in the format 123, 321, 123123, 12333

<?
$products_in_cart = CSaleBasket::GetList(
    array(), // сортировка
    array(
        'FUSER_ID' => CSaleBasket::GetBasketUserID(),
        'LID' => SITE_ID,
        'ORDER_ID' => NULL
    ),
    false, // группировать
    false, // постраничная навигация
    array('ID')
);
foreach ($products_in_cart->arResult as $product) {
    echo $product['ID'];
  }
?>

but it displays just solid output, and if you separately write <? echo $product['ID']; ? >, then displays only one ID

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Y
Yaroslav Alexandrov, 2022-03-16
@redesupar

Collect data into an array, and then process

<?foreach ($products_in_cart->arResult as $product) {
   $arProdutsIDs[] = $product['ID'];
  }
//объединяем все ID в строку
$string_id = implode(",", $arProdutsIDs);?>
<? echo $string_id;   ?>

R
redesupar, 2022-03-15
@redesupar

foreach ($products_in_cart->arResult as $product) {
    $arProdutsIDs[] = $product['ID'];
  }
?>
<?
//объединяем все ID в строку
$string_id = implode(",", $arProdutsIDs);?>
<? echo $string_id;   ?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question