A
A
Alexander2020-01-24 12:45:33
JavaScript
Alexander, 2020-01-24 12:45:33

How to add several products to the cart in Bitrix?

I have a product, this product has two "binding to elements" properties.
Those. I have an array with three IDs, this is a product ID and two element IDs by "binding".
You need to click on the button, transfer all these IDs to the basket. Making a button:

<a href="<?=$item['DETAIL_PAGE_URL'];?>&add2basket.php?quantity=1&amp;action=ADD2BASKET&amp;id=<?= $item['PROPERTIES']['PROP-1']['VALUE'] ?>&add2basket.php?quantity=1&amp;action=ADD2BASKET&amp;id=<?= $item['PROPERTIES']['PROP-2']['VALUE']&add2basket.php?quantity=1&amp;action=ADD2BASKET&amp;id=<?= $item['PROPERTIES']['PROP-3']['VALUE'] ?>" rel="nofollow" onclick="return addToCart(this');"><span class="add-basket"></span>В корзину</a>

The product is added, but only one is added. Tell me what you can think of or what is wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton, 2020-01-24
@anton99zel

<?require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php");
//смотрим что приходит сюда
print_r($_POST); 
//подключаем модули магазина и каталога
if (CModule::IncludeModule("sale") && CModule::IncludeModule("catalog")) { 
//Добавляем основной товар, указываем в переменной его id и количество 1 штука
Add2BasketByProductID( $_POST[main], 1 ); 
//Добавляем дополнительный товар в количестве 5 штук
Add2BasketByProductID($_POST[more], 5,
array(
//Перечисляем свойства, например цвет
array("CODE" => "COLOR", "NAME" => "Цвет", "VALUE" => $_POST[COLOR])
 )
); 
//Добаляем еще один доптовар
Add2BasketByProductID($_POST[more2], 1,
array(
//и свойства
array("CODE" => "COLOR", "NAME" => "Цвет", "VALUE" => $_POST[COLOR])
 )
);
//идём в корзину
LocalRedirect('/personal/cart/');
}else { echo "Не подключены модули"; }
?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question