PluginProbe
PostNL for WooCommerce / 4.4.0
PostNL for WooCommerce v4.4.0
5.9.12 5.9.11 5.9.10 5.9.9 5.9.8 5.9.7 5.9.6 trunk 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 3.1.4 3.1.5 3.1.6 3.1.7 4.0.0 4.0.1 4.0.2 4.3.2 4.3.3 4.4.0 4.4.1 All 72 releases
woo-postnl / vendor / myparcelnl / sdk / src / Concerns / HasCheckoutFields.php

HasCheckoutFields.php in PostNL for WooCommerce 4.4.0, at vendor/myparcelnl/sdk/src/Concerns/HasCheckoutFields.php

128 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php declare(strict_types=1);
2 /**
3 * @author Reindert Vetter <[email protected]>
4 */
5
6 namespace MyParcelNL\Sdk\src\Concerns;
7
8 use MyParcelNL\Sdk\src\Exception\MissingFieldException;
9 use MyParcelNL\Sdk\src\Helper\CheckoutFields;
10 use MyParcelNL\Sdk\src\Model\Consignment\AbstractConsignment;
11
12 /**
13 * @deprecated
14 */
15 trait HasCheckoutFields
16 {
17 /**
18 * Get delivery type from checkout
19 *
20 * You can use this if you use the following code in your checkout: https://github.com/myparcelnl/checkout
21 *
22 * @param string $checkoutData
23 *
24 * @return int
25 * @throws \Exception
26 * @deprecated
27 *
28 */
29 public function getDeliveryTypeFromCheckout($checkoutData)
30 {
31 $helper = new CheckoutFields();
32
33 return $helper->getDeliveryType($checkoutData);
34 }
35
36 /**
37 * Convert delivery date from checkout
38 *
39 * You can use this if you use the following code in your checkout: https://github.com/myparcelnl/checkout
40 *
41 * @param string $checkoutData
42 *
43 * @return $this
44 * @throws \Exception
45 * @deprecated
46 *
47 */
48 public function setDeliveryDateFromCheckout(?string $checkoutData)
49 {
50 if (! $checkoutData) {
51 return $this;
52 }
53
54 $aCheckoutData = json_decode($checkoutData, true);
55
56 if (
57 ! is_array($aCheckoutData) ||
58 ! key_exists('date', $aCheckoutData)
59 ) {
60 return $this;
61 }
62
63 if ($this->getDeliveryDate() == null) {
64 $this->setDeliveryDate($aCheckoutData['date']);
65 }
66
67 return $this;
68 }
69
70 /**
71 * Convert pickup data from checkout
72 *
73 * You can use this if you use the following code in your checkout: https://github.com/myparcelnl/checkout
74 *
75 * @param string $checkoutData
76 *
77 * @return $this
78 * @throws \MyParcelNL\Sdk\src\Exception\MissingFieldException
79 * @deprecated
80 *
81 */
82 public function setPickupAddressFromCheckout(?string $checkoutData)
83 {
84 if ($this->getCountry() !== AbstractConsignment::CC_NL && $this->getCountry() !== AbstractConsignment::CC_BE) {
85 return $this;
86 }
87
88 if (! $checkoutData) {
89 return $this;
90 }
91
92 $aCheckoutData = json_decode($checkoutData, true);
93
94 if (! is_array($aCheckoutData) ||
95 ! key_exists('location', $aCheckoutData)
96 ) {
97 return $this;
98 }
99
100 if ($this->getDeliveryDate() == null) {
101 $this->setDeliveryDate($aCheckoutData['date']);
102 }
103
104 if ($aCheckoutData['price_comment'] == 'retail') {
105 $this->setDeliveryType(AbstractConsignment::DELIVERY_TYPE_PICKUP);
106
107 } else if ($aCheckoutData['price_comment'] == 'retailexpress') {
108 $this->setDeliveryType(AbstractConsignment::DELIVERY_TYPE_PICKUP_EXPRESS);
109 } else {
110 throw new MissingFieldException('No PostNL location found in checkout data: ' . $checkoutData);
111 }
112 $this
113 ->setPickupPostalCode($aCheckoutData['postal_code'])
114 ->setPickupStreet($aCheckoutData['street'])
115 ->setPickupCity($aCheckoutData['city'])
116 ->setPickupNumber($aCheckoutData['number'])
117 ->setPickupCountry($aCheckoutData['cc'])
118 ->setPickupLocationName($aCheckoutData['location'])
119 ->setPickupLocationCode($aCheckoutData['location_code']);
120
121 if (isset($aCheckoutData['retail_network_id'])) {
122 $this->setRetailNetworkId($aCheckoutData['retail_network_id']);
123 }
124
125 return $this;
126 }
127 }
128