P
P
Pavel Zagainov2020-09-16 08:33:08
1C-Bitrix
Pavel Zagainov, 2020-09-16 08:33:08

How to get the values ​​of the product properties in the cart?

I need to get product properties in order to create an excel document.

foreach ($basketItems as $basketItem) {
                    $item = $basketItem; //$basketItems = $basket->getBasketItems();
                    $name = $item->getField('NAME');
                    $price = $item->getPrice();
                    $price1 = $item->getFinalPrice();
                    $quantity = $item->getQuantity();
                    
                    $MODIFICATION = getBasketPropertyValue($item,'MODIFICATION');
                    $SERVICE_CODE = getBasketPropertyValue($item,'SERVICE_CODE');
                    $REESTR = getBasketPropertyValue($item,'REESTR');
                    $OTDEL = getBasketPropertyValue($item,'OTDEL');
                    $WITHOUT_NDS = getBasketPropertyValue($item,'WITHOUT_NDS');
                    
                    /*
                    $MODIFICATION = $item->getField('MODIFICATION');
                    $SERVICE_CODE = $item->getField('SERVICE_CODE');
                    $REESTR = $item->getField('REESTR');
                    $OTDEL = $item->getField('OTDEL');
                    $WITHOUT_NDS = $item->getField('WITHOUT_NDS');
                    
                    $MODIFICATION = $properties->getItemById(494);
                    $SERVICE_CODE = $properties->getItemById(495);
                    $REESTR = $properties->getItemById(496);
                    $OTDEL = $properties->getItemById(497);
                    $WITHOUT_NDS = $properties->getItemById(498);
                    */
}

function getBasketPropertyValue(\Bitrix\Sale\BasketItem $item,$code) {
    foreach ($item->getPropertyCollection() as $property) {
        if($property->getField('CODE')!=$code)
            continue;
        return $property->getField('VALUE');
    }
    return false;
}


These methods don't help.

Answer the question

In order to leave comments, you need to log in

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

$item->getPropertyCollection() is not an array

foreach ($basketItems as $basketItem) {
  $basketPropertyCollection = $basketItem->getPropertyCollection();
  $propertyValues = $basketPropertyCollection->getPropertyValues();
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question