S
S
spbty2020-12-16 16:23:08
1C-Bitrix
spbty, 2020-12-16 16:23:08

How to sum the same items in the cart?

Now, when adding the same product to the cart, the product is not summed up, i.e. the cart displays

Product name 1 pc
Product name 1 pc
Product name 1 pc

What settings are responsible for summing up the product in the cart? it is necessary that the same products in the basket are summed up

Product name 3 pcs

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Ainur Valiev, 2020-12-17
@vaajnur

$basketItems = $basket->getBasketItems();
            $isset_ids = array();
          foreach ($basket as $basketItem) {
             $id = $basketItem->getProductId();
             // совпал только id
             if($productId == $id){
               $props = $basketItem->getPropertyCollection();
               $vals = $props->getPropertyValues();
               	// совпадают все параметры
                  if( 
                        ( isset($vals['SIZE']) && $vals['SIZE']['VALUE'] == $_REQUEST["SIZE"] ) &&
                        ( isset($vals['ARTICLE']) && $vals['ARTICLE']['VALUE'] == $arItem["PROPERTY_ARTICUL_VALUE"] ) &&
                        ( isset($vals['COLOR']) && $vals['COLOR']['VALUE'] == $arItem["PROPERTY_COLOR_VALUE"] )
                  ){
                  	echo "finded!";
                  $basketItem->setField('QUANTITY', $basketItem->getQuantity() + 1);
                  $basketItem->save();
                  $isset_ids[] = $id;
                  }          
             }
          }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question