Z
Z
zekin3752020-10-27 01:55:45
1C-Bitrix
zekin375, 2020-10-27 01:55:45

Get item property from bitrix order?

Getting data about products using code

<?php
require($_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_before.php");
 $ORDER_ID='4455';
 CModule::IncludeModule('sale');
$res = CSaleBasket::GetList(array(), array("ORDER_ID" => $ORDER_ID)); 
$json_product=array();
while ($arItem = $res->Fetch()) {
var_dump($arItem);

$price_list[] = array(
  'name' => $arItem['NAME'],
  'id' => $arItem['PRODUCT_ID'],
  'price' => $arItem['PRICE'],
  'quantity' => $arItem['QUANTITY']
);
}
?>

$arItem does not contain product properties, help get property

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Alexey, 2020-10-28
@AlexeyCaTHaR

use Bitrix\Sale;

$basket = Sale\Order::load($orderId)->getBasket(); // получили корзину по $orderId

$basketItems = $basket->getBasketItems(); // получили товары корзины

foreach ($basketItems as $basketItem) {
$basketPropertyCollection = $item->getPropertyCollection(); // вот и  свойства товара

foreach ($basketPropertyCollection as $propertyItem) {
    if ($propertyItem->getField('CODE') == 'ARTICLE') {
        var_dump($propertyItem->getValue());
    }
}
}

here it is clearly written
https://mrcappuccino.ru/blog/post/work-with-order-...
https://mrcappuccino.ru/blog/post/work-with-basket...

A
Anton, 2020-10-27
@anton99zel

If the property is in the order, then

// получение списка свойств для заказа с ID 123
$dbRes = \Bitrix\Sale\PropertyValueCollection::getList([
    'select' => ['*'],
    'filter' => [
        '=ORDER_ID' => 123, 
    ]
]);

while ($item = $dbRes->fetch())
{
    var_dump($item);
}

Otherwise

Z
zekin375, 2020-10-27
@zekin375

In principle, I understand that you can get the product property using another code and add an array, but I don’t know how to do it.
There is an array $price_list

Array
(
    [0] => Array
        (
            [name] => Товар 1
            [id] => 358
            [price] => 90.0000
            [quantity] => 1
        )

    [1] => Array
        (
            [name] => Товар 2
            [id] => 5017
            [price] => 500.0000
            [quantity] => 1
        )

)

Get product property by id
<?$prop=CIBlockElement::GetByID(358)->GetNextElement()->GetProperties();
echo $prop[CML2_ARTICLE][VALUE]?>

Please help me to add the $price_list array with the article property
Array
(
    [0] => Array
        (
            [name] => Товар 1
            [id] => 358
            [price] => 90.0000
            [quantity] => 1
            [ARTICLE] => 122
        )

    [1] => Array
        (
            [name] => Товар 2
            [id] => 5017
            [price] => 500.0000
            [quantity] => 1
            [ARTICLE] => 123
        )

)

A
Andrey Chursin, 2020-10-27
@AndreyChursin

It seems that CSaleBasket returns an object of type CDBResult, then it has methods:

  1. fetch() - fetches an array from the result
  2. GetNextElement() - Gets the next result object
  3. GetFields() - retrieves an array from the result
  4. GetProperties() - Retrieves an array of result properties

Try code like:
$db_elemens = CSaleBasket::GetList(...);
while($obElement = $db_elemens->GetNextElement())
{
   $item= $obElement->GetFields();
   $item["PROPERTIES"] = $obElement->GetProperties();
   $arResult["ITEMS"][] = $item;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question