A
A
Anto2017-09-15 12:09:28
1C-Bitrix
Anto, 2017-09-15 12:09:28

How to add a product to the cart with an attribute?

Good afternoon!
I use the complex component Catalog, I had to redo the standard output of the product, or rather display my popup when placing an order. I display the buttons to buy and more details next to there is the size of clothes / shoes. By clicking on the buy button, the product does not go into the basket with the selected size, but the page reloads (supposedly the product has been added), below is the code that I display this block. Tell me how to make it so that by choosing the size, if there is one, the goods fall into the baskets with this property.

<?if(!empty($item['PRODUCT_PROPERTIES'])):?>
<div class="bottom-click-popup-antfas">                                 
   <fo rm action="<?=POST_FORM_ACTION_URI?>" method="post" enctype="multipart/form-data">
      <input type="hidden" name="<?echo $arParams["ACTION_VARIABLE"]?>" value="BUY">
      <input type="hidden" value="<?=$item["ID"]?>" name="order-id">
      <input type="hidden" name="order-id" value="<?=$arResult["ID"]?>">
      <input type="submit" class="bottom-antfas" value="Добавить в корзину" name="<?echo $arParams["ACTION_VARIABLE"]."ADD2BASKET"?>" class="order-btn-small">
   </form>
</div>
<?endif?> 
<?//damp($item["ID"])?>
<?
$PRODUCT_ID = $_POST['order-id'];
if (CModule::IncludeModule("catalog")) {
   if ($PRODUCT_ID) {
      Add2BasketByProductID(
         $PRODUCT_ID,
         false
      );

      //LocalRedirect("/personal/cart/");
   }
}
?>                     <div class="select-box-antfas">
                              <? // размер обуви
                                 foreach ($item['PRODUCT_PROPERTIES'] as $propID => $propInfo)
                                 {
                                    ?>
                                    <select class="select-razmer-antfas" name="<?=$arParams['PRODUCT_PROPS_VARIABLE']?>[<?=$propID?>]">
                                       <?foreach ($propInfo['VALUES'] as $valueID => $value){   
                                             $selected = $valueID === $propInfo['SELECTED'] ? 'selected' : '';
                                       ?>
                                       <option value="<?=$valueID?>" <?=$selected?>>
                                          <?=$value?>
                                       </option>
                                       <?}?>
                                    </select>                        
                                 <?}?>
                                 </div>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Emelyanov, 2017-09-15
@babarun

https://dev.1c-bitrix.ru/api_help/catalog/basket.p...
See the 4th parameter arProductParams of the Add2BasketByProductID method

arProductParams	Массив, содержащий перечень свойств товара, добавленного в корзину. 
Ключи:
NAME - название свойства;
CODE - символьный код свойства;
VALUE - значение свойства;
SORT - сортировка.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question