Answer the question
In order to leave comments, you need to log in
Purchase in one click, the letter goes to an anonymous mailbox?
I create a purchase in one click. The order is created, but the letter is sent not to the specified mailbox, but to the mailbox of an anonymous user....
// Создаем заказ и привязываем корзину, перерасчет происходит автоматически
$order = \Bitrix\Sale\Order::create(SITE_ID, ($USER->IsAuthorized()) ? $USER->GetID() : \CSaleUser::GetAnonymousUserID());
$order->setPersonTypeId(1); // Физ. лицо
$order->setBasket($basket);
// Создаём одну отгрузку и устанавливаем способ доставки - "Без доставки" (он служебный)
$shipmentCollection = $order->getShipmentCollection();
$shipment = $shipmentCollection->createItem();
$service = \Bitrix\Sale\Delivery\Services\Manager::getById(\Bitrix\Sale\Delivery\Services\EmptyDeliveryService::getEmptyDeliveryServiceId());
$shipment->setFields(array(
'DELIVERY_ID' => $service['ID'],
'DELIVERY_NAME' => $service['NAME'],
));
$shipmentItemCollection = $shipment->getShipmentItemCollection();
$arResult['basket'] = $basket;
foreach ($basket as $item) {
$shipmentItem = $shipmentItemCollection->createItem($item);
$shipmentItem->setQuantity($item->getQuantity());
}
// Создаём оплату
$paymentCollection = $order->getPaymentCollection();
$payment = $paymentCollection->createItem();
$paySystemService = \Bitrix\Sale\PaySystem\Manager::getObjectById(PAY_SYSTEM_ID);
$payment->setFields(array(
'PAY_SYSTEM_ID' => $paySystemService->getField("PAY_SYSTEM_ID"),
'PAY_SYSTEM_NAME' => $paySystemService->getField("NAME"),
));
// Устанавливаем свойства
$propertyCollection = $order->getPropertyCollection();
$nameProp = $propertyCollection->getPayerName();
$nameProp->setValue(htmlspecialcharsbx($name));
// $emailProp = $propertyCollection->getUserEmail();
// $emailProp->setValue(htmlspecialcharsbx($email));
$locProp = $propertyCollection->getDeliveryLocation();
$locProp->setValue(DEFAULT_LOCATION_ID);
function getPropertyByCode($propertyCollection, $code) {
foreach ($propertyCollection as $property)
{
if($property->getField('CODE') == $code)
return $property;
}
}
$phoneProperty = getPropertyByCode($propertyCollection, 'PHONE');
$phoneProperty->setValue($email);
// Сохраняем
$order->doFinalAction(true);
$order->setField('USER_DESCRIPTION', 'Быстрая покупака');
$order->save();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question