1 <?php
2 3 4
5 namespace Team3\PayU\Order\Transformer\UserOrder\Strategy;
6
7 use Team3\PayU\Order\Model\Buyer\DeliveryInterface;
8 use Team3\PayU\Order\Model\OrderInterface;
9 use Team3\PayU\Order\Transformer\UserOrder\TransformerProperties;
10 use Team3\PayU\Order\Transformer\UserOrder\TransformerPropertiesRegExp;
11 use Team3\PayU\PropertyExtractor\ExtractorResult;
12
13 class DeliveryTransformer implements UserOrderTransformerStrategyInterface
14 {
15 16 17
18 public function transform(
19 OrderInterface $order,
20 ExtractorResult $extractorResult
21 ) {
22 $this->copyValue(
23 $order->getBuyer()->getDelivery(),
24 $extractorResult
25 );
26 }
27
28 29 30
31 public function supports($propertyName)
32 {
33 return 1 === preg_match(
34 TransformerPropertiesRegExp::DELIVERY_REGEXP,
35 $propertyName
36 );
37 }
38
39 40 41 42
43 private function copyValue(
44 DeliveryInterface $delivery,
45 ExtractorResult $extractorResult
46 ) {
47 switch ($extractorResult->getPropertyName()) {
48 case TransformerProperties::DELIVERY_RECIPIENT_PHONE:
49 $delivery->setRecipientPhone($extractorResult->getValue());
50 break;
51 case TransformerProperties::DELIVERY_RECIPIENT_NAME:
52 $delivery->setRecipientName($extractorResult->getValue());
53 break;
54 case TransformerProperties::DELIVERY_RECIPIENT_EMAIL:
55 $delivery->setRecipientEmail($extractorResult->getValue());
56 break;
57 case TransformerProperties::DELIVERY_POSTAL_CODE:
58 $delivery->setPostalCode($extractorResult->getValue());
59 break;
60 case TransformerProperties::DELIVERY_CITY:
61 $delivery->setCity($extractorResult->getValue());
62 break;
63 case TransformerProperties::DELIVERY_COUNTRY_CODE:
64 $delivery->setCountryCode($extractorResult->getValue());
65 break;
66 case TransformerProperties::DELIVERY_NAME:
67 $delivery->setName($extractorResult->getValue());
68 break;
69 case TransformerProperties::DELIVERY_STREET:
70 $delivery->setStreet($extractorResult->getValue());
71 break;
72 default:
73 }
74 }
75 }
76