есть два метода для получения список доставок
1) [CODE]$deliveryList = \Bitrix\Sale\Delivery\Services\Manager::getRestrictedList($shipment,\Bitrix\Sale\Services\Base\RestrictionManager::MODE_CLIENT);[/CODE]
2) [CODE]$deliveryList = \Bitrix\Sale\Delivery\Services\Manager::getRestrictedObjectsList($shipment);[/CODE]
Дело в том что первый метод возвращает 3 доступные доставки учитывая ограничение по местоположению (но не позволяет рассчитать скидки на стоимость доставки)
Второй метод возвращает только одну доставку (почему неизвестно) но позволяет рассчитать стоимость доставки с учетом скидок
весь код получения списка доставок
[CODE]private function getDelivery(){
Loader::includeModule('sale');
Loader::includeModule('iblock');
$order = $this->order;
$propertyCollection = $order->getPropertyCollection();
/** @var PropertyValueBase $prop */
global $USER;
if($USER->IsAdmin()){
$shipmentCollection = $order->getShipmentCollection();
$shipment = $shipmentCollection->createItem();
$propertyCollection = $order->getPropertyCollection();
$propertyLocation = $propertyCollection->getDeliveryLocation();
foreach ($propertyCollection as $prop) {
$propCode = $prop->getField('CODE');
if ($propCode === 'CITY') {
$prop->setValue($cityCode);
$propertyLocation->setField('VALUE', $cityCode);
break;
}
}
}
/** @var ShipmentCollection $shipmentCollection */
$shipmentCollection = $order->getShipmentCollection();
$shipment = $shipmentCollection->createItem();
$shipmentItemCollection = $shipment->getShipmentItemCollection();
/** @var $shipmentItemCollection ShipmentItemCollection */
foreach ($this->basket as $basketItem) {
/**
* @var $basketItem BasketItem
* @var $shipmentItem ShipmentItem
*/
$shipmentItem = $shipmentItemCollection->createItem($basketItem);
$shipmentItem->setQuantity($basketItem->getQuantity());
}
/** @var \Bitrix\Sale\Delivery\Services\Base[] $delivery */
if($USER->IsAdmin()){
$deliveryList = \Bitrix\Sale\Delivery\Services\Manager::getRestrictedList($shipment,\Bitrix\Sale\Services\Base\RestrictionManager::MODE_CLIENT);
}else{
$deliveryList = \Bitrix\Sale\Delivery\Services\Manager::getRestrictedObjectsList($shipment);
}
dump($deliveryList,1);
$resultDelivery = [];
foreach ($deliveryList as $delivery) {
$calculationResult = $delivery->calculate($shipment);
$shipment->setBasePriceDelivery($calculationResult->getPrice());
if ($calculationResult->isSuccess()) {
$shipment->setBasePriceDelivery($calculationResult->getPrice());
$arShowPrices = $order->getDiscount()
->getShowPrices();
$data = $calculationResult->getData();
$data['DISCOUNT_DATA'] = $arShowPrices['DELIVERY'];
$calculationResult->setData($data);
}
$calcResult = $delivery->calculate();
$price = \Bitrix\Sale\PriceMaths::roundPrecision($calcResult->getPrice());
$resultDelivery[] = [
'ID' => $delivery->getId(),
'NAME' => $delivery->getName(),
'TEXT' => $delivery->getDescription(),
'PRICE' => $price,
'PRICE_FORMATED' => SaleFormatCurrency($price, 'RUB'),
'CALC' => $calculationResult->getData()
];
}
return $resultDelivery;
}[/CODE]
Подскажите как правильно сделать что бы получить все доставки и с расчетом скидок?
И в чем разница этих методов?
1) [CODE]$deliveryList = \Bitrix\Sale\Delivery\Services\Manager::getRestrictedList($shipment,\Bitrix\Sale\Services\Base\RestrictionManager::MODE_CLIENT);[/CODE]
2) [CODE]$deliveryList = \Bitrix\Sale\Delivery\Services\Manager::getRestrictedObjectsList($shipment);[/CODE]
Дело в том что первый метод возвращает 3 доступные доставки учитывая ограничение по местоположению (но не позволяет рассчитать скидки на стоимость доставки)
Второй метод возвращает только одну доставку (почему неизвестно) но позволяет рассчитать стоимость доставки с учетом скидок
весь код получения списка доставок
[CODE]private function getDelivery(){
Loader::includeModule('sale');
Loader::includeModule('iblock');
$order = $this->order;
$propertyCollection = $order->getPropertyCollection();
/** @var PropertyValueBase $prop */
global $USER;
if($USER->IsAdmin()){
$shipmentCollection = $order->getShipmentCollection();
$shipment = $shipmentCollection->createItem();
$propertyCollection = $order->getPropertyCollection();
$propertyLocation = $propertyCollection->getDeliveryLocation();
foreach ($propertyCollection as $prop) {
$propCode = $prop->getField('CODE');
if ($propCode === 'CITY') {
$prop->setValue($cityCode);
$propertyLocation->setField('VALUE', $cityCode);
break;
}
}
}
/** @var ShipmentCollection $shipmentCollection */
$shipmentCollection = $order->getShipmentCollection();
$shipment = $shipmentCollection->createItem();
$shipmentItemCollection = $shipment->getShipmentItemCollection();
/** @var $shipmentItemCollection ShipmentItemCollection */
foreach ($this->basket as $basketItem) {
/**
* @var $basketItem BasketItem
* @var $shipmentItem ShipmentItem
*/
$shipmentItem = $shipmentItemCollection->createItem($basketItem);
$shipmentItem->setQuantity($basketItem->getQuantity());
}
/** @var \Bitrix\Sale\Delivery\Services\Base[] $delivery */
if($USER->IsAdmin()){
$deliveryList = \Bitrix\Sale\Delivery\Services\Manager::getRestrictedList($shipment,\Bitrix\Sale\Services\Base\RestrictionManager::MODE_CLIENT);
}else{
$deliveryList = \Bitrix\Sale\Delivery\Services\Manager::getRestrictedObjectsList($shipment);
}
dump($deliveryList,1);
$resultDelivery = [];
foreach ($deliveryList as $delivery) {
$calculationResult = $delivery->calculate($shipment);
$shipment->setBasePriceDelivery($calculationResult->getPrice());
if ($calculationResult->isSuccess()) {
$shipment->setBasePriceDelivery($calculationResult->getPrice());
$arShowPrices = $order->getDiscount()
->getShowPrices();
$data = $calculationResult->getData();
$data['DISCOUNT_DATA'] = $arShowPrices['DELIVERY'];
$calculationResult->setData($data);
}
$calcResult = $delivery->calculate();
$price = \Bitrix\Sale\PriceMaths::roundPrecision($calcResult->getPrice());
$resultDelivery[] = [
'ID' => $delivery->getId(),
'NAME' => $delivery->getName(),
'TEXT' => $delivery->getDescription(),
'PRICE' => $price,
'PRICE_FORMATED' => SaleFormatCurrency($price, 'RUB'),
'CALC' => $calculationResult->getData()
];
}
return $resultDelivery;
}[/CODE]
Подскажите как правильно сделать что бы получить все доставки и с расчетом скидок?
И в чем разница этих методов?