Как получить отмеченные доп. услуги доставки в заказе? (habr)
Вопрос:
При отправке почтового шаблона нужно в письмо добавить отмеченные при оформлении заказа доп. услуги доставки. Не нашел, как это можно сделать?
Ответ 1:
Простым способом этого сделать не удалось. Описания \Bitrix\Sale\Delivery\ExtraServices вообще нет не знаю насколько это решение верное, но кое-как реализовал:
$order = \Bitrix\Sale\Order::load($arOrder['ID']);
$shipmentCollection = $order->getShipmentCollection();
$stores = \Bitrix\Sale\Delivery\ExtraServices\Manager::getExtraServicesList($arOrder['DELIVERY_ID']);
foreach ($shipmentCollection as $shipment){
$extra = $shipment->getExtraServices(); //массив значений доп.услуги, типа array([10]=>'Y')
if(!empty($extra)){
foreach($extra as $key => $value){
if($value == 'Y')
echo $stores[$key]['NAME']; // получаем наименование доп. услуги
}
}
}
Ответ 2:
еще вариант костыля
if (!\Bitrix\Main\Loader::IncludeModule('iblock'))
die();
if (!\Bitrix\Main\Loader::IncludeModule('sale'))
die();
if (!\Bitrix\Main\Loader::IncludeModule('catalog'))
die();
global $APPLICATION, $USER;
//объект заказа
$order = \Bitrix\Sale\Order::load($orderID);
//скидки
$discountData = $order->getDiscount()->getApplyResult(); //скидки
$discount = $discountData['PRICES']['BASKET'];
//корзина
$basket = $order->getBasket();
$arBasket = $basket->getListOfFormatText();
foreach( $arBasket as $kBastetItem=>$vBastetItem)
{
$tmp = $discount[$kBastetItem];
if(isset($tmp['DISCOUNT']) && (int)$tmp['DISCOUNT'] > 0)
$arBasket[$kBastetItem] .= '(скидка '.SaleFormatCurrency($tmp['DISCOUNT'], "RUB") . ')';
}
//доставка
$dilevery = array('Служба доставки: ');
//отгрузки
$shipmentCollection = $order->getShipmentCollection();
foreach($shipmentCollection as $shipment) {
$shipment_id = $shipment->getId();
if ($shipment->isSystem())
continue;
$dilevery[0] .= $shipment->getField("DELIVERY_NAME");
$dileveryId = $shipment->getField("DELIVERY_ID");
$dileveryPrice = $order->getDeliveryPrice();
if((float)$dileveryPrice > 0)
$dilevery[0] .= ' ('.SaleFormatCurrency($dileveryPrice , "RUB") . ')';
$ExtraServices = \Bitrix\Sale\Delivery\ExtraServices\Manager::getExtraServicesList($dileveryId);
if(!empty($ExtraServices)){
$shipmentExtraServices = \Bitrix\Sale\Delivery\ExtraServices\Manager::getValuesForShipment($shipment_id,$dileveryId);
foreach($ExtraServices as $k => $v) {
$dilevery[1] = $v["PARAMS"]["PRICES"][$shipmentExtraServices[$k]]['TITLE'];
}
}
}
//св-ва заказа
$arProp = array();
$propertyCollection = $order->getPropertyCollection();
foreach ($propertyCollection as $k => $property)
{
$v = $property ->getValue();
if(!empty($v)){
$tmp = $property -> getProperty();
if( $tmp['CODE'] == 'KURERDOSTAVKA')
continue;
if($tmp['CODE'] == 'PUNCKTVIDACHI'){
$dilevery[1] = $tmp['NAME'].': '.$dilevery[1];
}
else
{
$arProp[$tmp['NAME']] = $v;
}
}
}
//Платежная система
$paymentCollection = $order->getPaymentCollection();
foreach ($paymentCollection as $payment) {
$psID = $payment->getPaymentSystemId(); // ID платежной системы
$psName = $payment->getPaymentSystemName();
}
//массив результатов
$arResult = array_values($arBasket);
$arResult[] = '';
$arResult = array_merge($arResult,$dilevery);
$arResult[] = 'Способ оплаты: '. ($psID == 11 ? "Оплата картой" : $psName);
$arResult[] = '';
foreach($arProp as $k=>$v)
{
$arResult[] = $k.': '.$v;
}
//комментарий к заказу
$USER_DESCRIPTION = $order->getField("USER_DESCRIPTION");
if(!empty( $USER_DESCRIPTION )){
$arResult[] = '';
$arResult[] = 'Комментарий к заказу:';
$arResult[] = $USER_DESCRIPTION;
}
//$arResult[] = '';
//$arResult[] = 'Сумма заказа: '.SaleFormatCurrency($order->getField('PRICE') , "RUB");
$arFields['ORDER_LIST'] = implode("<br>", $arResult);
Ответ 3:
Я вот так вывел доп услуги в последнем шаге sale.order.ajax — confirm.php
$order = \Bitrix\Sale\Order::load($arResult['ORDER']['ID']);
$shipmentCollection = $order->getShipmentCollection();
foreach ($shipmentCollection as $shipment)
{
if ($shipment->isSystem())
continue;
$shipment_id = $shipment->getId();
$dileveryId = $shipment->getField("DELIVERY_ID");
$extraValues = $shipment->getExtraServices();
$extraServicesManager = new \Bitrix\Sale\Delivery\ExtraServices\Manager($dileveryId, "", $extraValues);
$extraServices = $extraServicesManager->getItems();
foreach($extraServices as $extra)
{
$cost = $extra->getCost();
$name = $extra->getName();
}
}
Источник: https://qna.habr.com/q/435332