Answer the question
In order to leave comments, you need to log in
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']
);
}
?>
Answer the question
In order to leave comments, you need to log in
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());
}
}
}
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);
}
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
)
)
<?$prop=CIBlockElement::GetByID(358)->GetNextElement()->GetProperties();
echo $prop[CML2_ARTICLE][VALUE]?>
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
)
)
It seems that CSaleBasket returns an object of type CDBResult, then it has methods:
$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 questionAsk a Question
731 491 924 answers to any question