32
32
use Meta \BusinessExtension \Helper \GraphAPIAdapter ;
33
33
use Meta \BusinessExtension \Model \System \Config as SystemConfig ;
34
34
use Meta \Sales \Plugin \ShippingMethodTypes ;
35
+ use Meta \Sales \Helper \ShippingHelper ;
35
36
36
37
/**
37
38
* Map facebook order data to magento order
@@ -74,6 +75,11 @@ class OrderMapper
74
75
*/
75
76
private OrderItemMapper $ orderItemMapper ;
76
77
78
+ /**
79
+ * @var ShippingHelper
80
+ */
81
+ private ShippingHelper $ shippingHelper ;
82
+
77
83
/**
78
84
* @param StoreManagerInterface $storeManager
79
85
* @param GraphAPIAdapter $graphAPIAdapter
@@ -82,6 +88,7 @@ class OrderMapper
82
88
* @param OrderPaymentInterfaceFactory $paymentFactory
83
89
* @param OrderAddressInterfaceFactory $orderAddressFactory
84
90
* @param OrderItemMapper $orderItemMapper
91
+ * @param ShippingHelper $shippingHelper
85
92
*/
86
93
public function __construct (
87
94
StoreManagerInterface $ storeManager ,
@@ -90,7 +97,8 @@ public function __construct(
90
97
OrderInterfaceFactory $ orderFactory ,
91
98
OrderPaymentInterfaceFactory $ paymentFactory ,
92
99
OrderAddressInterfaceFactory $ orderAddressFactory ,
93
- OrderItemMapper $ orderItemMapper
100
+ OrderItemMapper $ orderItemMapper ,
101
+ ShippingHelper $ shippingHelper
94
102
) {
95
103
$ this ->storeManager = $ storeManager ;
96
104
$ this ->graphAPIAdapter = $ graphAPIAdapter ;
@@ -99,6 +107,7 @@ public function __construct(
99
107
$ this ->paymentFactory = $ paymentFactory ;
100
108
$ this ->orderAddressFactory = $ orderAddressFactory ;
101
109
$ this ->orderItemMapper = $ orderItemMapper ;
110
+ $ this ->shippingHelper = $ shippingHelper ;
102
111
}
103
112
104
113
/**
@@ -183,8 +192,8 @@ public function map(array $data, int $storeId): Order
183
192
private function getShippingMethod (string $ shippingOptionName , string $ shippingReferenceId , int $ storeId ): ?string
184
193
{
185
194
$ static_shipping_options = [ShippingMethodTypes::FREE_SHIPPING ,
186
- ShippingMethodTypes::FLAT_RATE ,
187
- ShippingMethodTypes::TABLE_RATE ];
195
+ ShippingMethodTypes::FLAT_RATE ,
196
+ ShippingMethodTypes::TABLE_RATE ];
188
197
if (in_array ($ shippingReferenceId , $ static_shipping_options )) {
189
198
return $ shippingReferenceId ;
190
199
}
@@ -229,8 +238,13 @@ private function getOrderBillingAddress(array $data): Order\Address
229
238
? [$ data ['shipping_address ' ]['street1 ' ], $ data ['shipping_address ' ]['street2 ' ]]
230
239
: $ data ['shipping_address ' ]['street1 ' ];
231
240
241
+ $ regionName = $ this ->shippingHelper ->getRegionNameFromCode (
242
+ $ data ['shipping_address ' ]['state ' ],
243
+ $ data ['shipping_address ' ]['country ' ]
244
+ );
245
+
232
246
$ addressData = [
233
- 'region ' => $ data [ ' shipping_address ' ][ ' state ' ] ?? null ,
247
+ 'region ' => $ regionName ,
234
248
'postcode ' => $ data ['shipping_address ' ]['postal_code ' ],
235
249
'firstname ' => $ data ['shipping_address ' ]['first_name ' ],
236
250
'lastname ' => $ data ['shipping_address ' ]['last_name ' ],
0 commit comments