S
S
Stopy2017-07-31 06:44:32
PHP
Stopy, 2017-07-31 06:44:32

Why aren't cart item properties set?

\Bitrix\Main\Loader::includeModule('catalog');
$res = Add2BasketByProductID($id, 1, array(), array(
  array(
    array("NAME"=>"Shelovek", "CODE"=>"CHEL", "VALUE"=>"1"),
    array("NAME" => "Цвет", "CODE" => "CLR", "VALUE" => "красный"),
    array("NAME" => "Размер", "VALUE" => "25"),
  )
));
if($res !== false)
  $response = array('bool' => true, 'cnt' => getProductsCount());

The element appears in the basket, the quantity is set correctly, but it has no properties.
Output code:
$db_res = CSaleBasket::GetPropsList(
  array(
    "SORT" => "ASC",
    "NAME" => "ASC"
  ),
  array("BASKET_ID" => $product["ID"])
);
while ($ar_res = $db_res->Fetch())
{
  echo $ar_res["NAME"]."=".$ar_res["VALUE"]."<br>";
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artyom Luchnikov, 2017-07-31
@lu4nik

Judging by the code, you are passing in the filter of the CSaleBasket::GetPropsList method in BASKET_ID not the ID of the basket item, but the ID of the item. As a result, nothing is returned. In the filter, in the BASKET_ID key, it is necessary to pass exactly the ID of the basket element.
In general, I would advise you to do everything on D7. Here there are many examples implemented on D7, including working with a basket.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question