Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
recipientdataprovider.php
1<?php
2
4
10
17{
22 public static function getContact(Shipment $shipment): ?Contact
23 {
24 $event = new Event(
25 'sale',
27 ['SHIPMENT' => $shipment]
28 );
29
30 $event->send();
31 $eventResults = $event->getResults();
32 foreach ($eventResults as $eventResult)
33 {
34 if ($eventResult->getType() === EventResult::SUCCESS)
35 {
36 $recipientContact = $eventResult->getParameters();
37 if ($recipientContact instanceof Contact)
38 {
39 return $recipientContact;
40 }
41 }
42 }
43
44 $order = $shipment->getOrder();
45 if (!$order)
46 {
47 return null;
48 }
49
50 return self::getContactFromOrder($order);
51 }
52
57 private static function getContactFromOrder(Order $order): ?Contact
58 {
59 $contact = new Contact();
60
61 $buyerName = $order->getPropertyCollection()->getAttribute('IS_PAYER');
62 if ($buyerName)
63 {
64 $contact->setName((string)$buyerName->getValue());
65 }
66
67 $buyerPhone = $order->getPropertyCollection()->getAttribute('IS_PHONE');
68 if ($buyerPhone)
69 {
70 $contact->addPhone(new Phone('OTHER', (string)$buyerPhone->getValue()));
71 }
72
73 return $contact;
74 }
75}
const EVENT_ON_NEED_DELIVERY_RECIPIENT_CONTACT