E
E
Evgeny Nikolaev2019-07-03 14:24:46
1C-Bitrix
Evgeny Nikolaev, 2019-07-03 14:24:46

D7, Getting information about the products and offers in the shopping cart (no order), how to get the length, width and height?

It is required to obtain information about goods and trade offers of the bitrix basket not assigned to the order. How to get the weight is understandable. How to get width, length and height?
Now I do this:
<?php
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/header.php");
use Bitrix\Main\Context,
Bitrix\Currency\CurrencyManager,
Bitrix\Sale\Order,
Bitrix\Sale\Basket,
Bitrix\Sale\Delivery,
Bitrix\Sale\PaySystem,
YandexCheckout\Client;
$basket = \Bitrix\Sale\Basket::loadItemsForFUser(\Bitrix\Sale\Fuser::getId(CSaleBasket::GetBasketUserID()), \Bitrix\Main\Context::getCurrent()->getSite());
// [BEGINNING] Apply discounts to the goods in the received basket (required if the basket is not in the order)
$context = new \Bitrix\Sale\Discount\Context\Fuser($basket->getFUserId());
$discounts = \Bitrix\Sale\Discount::buildFromBasket($basket, $context);
$r = $discounts->calculate();
if ($r->isSuccess()) {
$result = $r->getData();
if (isset($result['BASKET_ITEMS'])) {
$basket->applyDiscount($result['BASKET_ITEMS']);
}
}
// [END] Apply discounts to goods in the received basket (required if the basket is not in the order)
$sumNoDiscont = 0;// sum of all goods without discounts
$sumDiscont = 0;// sum of all goods with a discount
foreach ($basket->getBasketItems() as $basketItem) {// loop through the items and offers in the basket
$priceBase = $basketItem->getBasePrice();
$priceDiscont = $basketItem->getPrice();
$weight = $basketItem->getWeight();
$length = $basketItem->how_get(?);
$width = $basketItem->how_get(?);
$height = $basketItem->how_get(?);

if ($priceBase != $priceDiscont) {
$sumDiscont += $priceDiscont;
} else {
$sumNoDiscont += $priceBase;
}
echo "$weight - $length - $width - $height" . $basketItem->getField("NAME") . "-" . $priceDiscount . "-" . $priceBase . "\n";// debugging
}
Question:
_________________________________
Note! What can be obtained like this CCatalogProduct::GetByID($_id_offer_offer);// an array is returned in which there is a length, width, height, I myself know. Whether interests it is possible directly from $basketItem-> as that to receive?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
MiXaLiN17, 2019-07-03
@MiXaLiN17

$basketItem->getField('NAME');// Any item field in the basket

N
Nikolay S., 2020-09-03
@Nikolays93

I don’t know about the documentation, but I noticed that the DIMENSIONS property stores serialized data about the size of the product.

<?php
// a:3:{s:5:"WIDTH";N;s:6:"HEIGHT";N;s:6:"LENGTH";N;}
$dimensions = $basketItem->getField('DIMENSIONS');
// @var array
$arDimensions = unserialize($dimensions);

print_r($arDimension);

Might be useful to someone

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question