C
C
ChertyakaNUB2020-09-15 20:46:11
1C-Bitrix
ChertyakaNUB, 2020-09-15 20:46:11

How to overcome the error Call to a member function GetProperties() on boolean (0)?

Hello!

I tried to create a product without sections with a price of 0 and made an entry in the cart template:

$Cart = Sale\Basket::loadItemsForFUser(Sale\Fuser::getId(), Bitrix\Main\Context::getCurrent()->getSite());
$item = $Cart->createItem('catalog', 666); 
        $item->setFields(array(
          'PRODUCT_PRICE_ID' => 0,
          'PRICE' => -(int)$Price,
          'CURRENCY' => 'RUB',
          'QUANTITY' => 1,
          'LID' => Bitrix\Main\Context::getCurrent()->getSite(),
          'CUSTOM_PRICE' => 'Y',
          'NAME' => 'Скидон - '.$Price,
        ));
        $Cart->save();

When adding a product, an error pops up:
[Error] 
Call to a member function GetProperties() on boolean (0)
/var/www/....php:17

With the indication of the file and the line with the code:
17 строка: $articul= CIBlockElement::GetByID($mxResult['ID'])->GetNextElement()->GetProperties();


The people, who can tell how to solve this problem? When adding a product, the cart falls and the error that is indicated above appears. But if you hover over the basket in the menu, a list of products in the basket will drop out, and there will be an added product, only without a name, but with a price.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
PetrPo, 2020-09-16
@ChertyakaNUB

In line

$articul= CIBlockElement::GetByID($mxResult['ID'])->GetNextElement()->GetProperties();

error, since the GetNextElement method returns false, you need to add a check
$articul = [];

$dbRes = CIBlockElement::GetByID($mxResult['ID']);
if($ob = $dbRes->GetNextElement()) {
  $articul = $ob->GetProperties();
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question