Как получить все службы доставки, которые привязаны к местоположению?
подскажите как в битриксе получить все службы доставки, которые привязаны к местоположению? т.е есть locationId по нему я могу получить службы, но id выдаются странные вида:
Array(
[0] => 2
[1] => 3
[2] => new122:profile
[3] => new200:profile
)
первые две это ид службы а вторые профили видимо от служб, как правильно вытащить все службы по этим профилям? либо предложите еще какой вариант. Если CSaleDelivery::GetList передать эти профили я получу только два. 2 и 3, а new122:profile и new200:profile уже нет.
Ответы (2 шт):
Автор решения: Firsov36
→ Ссылка
Если без оптимизации кода, по-быстрому так сказать, то примерно так:
use Bitrix\Main\Loader;
Loader::includeModule('sale');
$locationCode = '2441'; // именно CODE! не ID.
$result = [];
$deliveries = Bitrix\Sale\Delivery\Services\Table::getList(
[
'select' => ['ID', 'NAME']
]
)->fetchAll();
foreach($deliveries as $delivery)
{
if(Bitrix\Sale\Delivery\Restrictions\ByLocation::check($locationCode,[],$delivery['ID']))
{
$result[] = $delivery;
}
}
\Bitrix\Main\Diag\Debug::dump($result);
Автор решения: Dev_Prod
→ Ссылка
если по ID можно так:
function getLocationDeliveryServices($locationId)
{
if (is_numeric($locationId)) {
$arLocationDeliveryServices = [];
$allDeliveries = CSaleDelivery::GetLocationList(
array(
'LOCATION_ID' => $locationId,
'LOCATION_TYPE' => 'L'
)
);
while ($location = $allDeliveries->Fetch()) {
if (is_numeric($location['DELIVERY_ID'])) {
//Записываем ID службы
$arLocationDeliveryServices[] = $location['DELIVERY_ID'];
} else {
//Записываем ID профиля службы
$profileDeliveryId = preg_replace("/[^0-9]/", '', $location['DELIVERY_ID']);
$arLocationDeliveryServices[] = $profileDeliveryId;
}
}
return (count($arLocationDeliveryServices) > 0) ? $arLocationDeliveryServices : false;
}
return false;
}
function getAllActiveDeliveryPricesByLocationIds($arLocationDeliveryServices)
{
try {
if (is_array($arLocationDeliveryServices) && count($arLocationDeliveryServices) > 0) {
$arAllDeliveryPrice = [];
$arActiveDelivery = \Bitrix\Sale\Delivery\Services\Manager::getActiveList();
if (count($arActiveDelivery) > 0) {
foreach ($arActiveDelivery as $id => $arDataDelivery) {
if (!empty($arDataDelivery['CONFIG']['MAIN']['DELIVERY_PRICE']) && in_array($arDataDelivery['ID'], $arLocationDeliveryServices)) {
$arAllDeliveryPrice[$id]['ID'] = $arDataDelivery['ID'];
$arAllDeliveryPrice[$id]['PARENT_ID'] = $arDataDelivery['PARENT_ID'];
$arAllDeliveryPrice[$id]['NAME'] = $arDataDelivery['NAME'];
$arAllDeliveryPrice[$id]['DESCRIPTION'] = $arDataDelivery['DESCRIPTION'];
$arAllDeliveryPrice[$id]['DELIVERY_PRICE'] = $arDataDelivery['CONFIG']['MAIN']['DELIVERY_PRICE'];
$arAllDeliveryPrice[$id]['PERIOD_TEXT'] = $arDataDelivery['CONFIG']['MAIN']['PERIOD_TEXT'];
}
}
return (count($arAllDeliveryPrice) > 0) ? $arAllDeliveryPrice : false;
}
}
} catch (\Bitrix\Main\ArgumentException $e) {
return false;
}
return false;
}
$arLocationDeliveryServices = getLocationDeliveryServices($LOCATION_ID);
$arAllActiveDeliveryPrices = getAllActiveDeliveryPricesByLocationIds($arLocationDeliveryServices);