E
E
Evgeny Nikolaev2019-05-17 10:49:57
API
Evgeny Nikolaev, 2019-05-17 10:49:57

Bitrix. How to specify the delivery address via the API?

There is a standard basket Bitrix component. But placing an order is written entirely in the API. (That is, starting from the checkout button, the internals of the component are not used)
Accordingly, the $order object is created, the current basket of the user $basket is passed to it.
Further, depending on what the user has chosen, delivery is created, namely like this:
if (($delivery == 2) or ($delivery == 3)) {
$service = Delivery\Services\Manager::getById($delivery);
$shipment->setFields(array(
"DELIVERY_ID" => $service["ID"],
"DELIVERY_NAME" => $service["NAME"],
));
$shipment->setBasePriceDelivery($deliveryCost);
} else {// Otherwise, create a service delivery
$service = Delivery\Services\Manager::getById(Delivery\Services\EmptyDeliveryService::getEmptyDeliveryServiceId());
$shipment->setFields(array(
"DELIVERY_ID" => $service["ID"],
"DELIVERY_NAME" => $service["NAME"],
));
}
How can I send and in what way the delivery address? Now it is not fixed in the order and therefore is not visible in the order from the admin panel.
Bitrix support has so far answered as follows:
"Delivery address" is an order property, its name can be obtained and updated $propertyValue->setField();
https://dev.1c-bitrix.ru/api_d7/bitrix/sale/techni...
https://dev.1c-bitrix.ru/api_d7/bitrix/sale/techni...
It's not clear what to apply setField to and what key to pass to it in order to set exactly the delivery address.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Nikolaev, 2019-05-20
@nikolaevevge

// A function to simplify work with order properties so that you don't write many lines for each property
function getPropertyByCode($propertyCollection, $code) {
foreach ($propertyCollection as $property) {
if($property->getField('CODE') = = $code) {
return $property;
}
}
}
$addressProperty = getPropertyByCode($propertyCollection, 'ADDRESS');
$addressProperty->setValue($deliveryAddress);// Set the address
Beforehand, if you did not set the demo data, you need to go to the store -> settings -> order properties and create the Delivery address property for each type of payer. It is necessary to check the box included in the profile and is the delivery address.
The list of standard property names and their codes (those that are installed with demo data) can be viewed at the link - https://dev.1c-bitrix.ru/support/forum/messages/fo...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question