Answer the question
In order to leave comments, you need to log in
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
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);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question