31
31
use Magento \Store \Model \StoreManagerInterface ;
32
32
use Meta \BusinessExtension \Helper \GraphAPIAdapter ;
33
33
use Meta \BusinessExtension \Model \System \Config as SystemConfig ;
34
+ use Meta \Sales \Plugin \ShippingMethodTypes ;
34
35
35
36
/**
36
37
* Map facebook order data to magento order
38
+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
37
39
*/
38
40
class OrderMapper
39
41
{
@@ -120,6 +122,7 @@ public function map(array $data, int $storeId): Order
120
122
121
123
$ channel = ucfirst ($ data ['channel ' ]);
122
124
$ shippingOptionName = $ data ['selected_shipping_option ' ]['name ' ];
125
+ $ shippingReferenceId = $ data ['selected_shipping_option ' ]['reference_id ' ];
123
126
$ billingAddress = $ this ->getOrderBillingAddress ($ data );
124
127
$ shippingAddress = clone $ billingAddress ;
125
128
$ shippingAddress
@@ -146,7 +149,7 @@ public function map(array $data, int $storeId): Order
146
149
147
150
$ this ->applyTotalsToOrder ($ order , $ data , $ storeId );
148
151
149
- $ shippingMethod = $ this ->getShippingMethod ($ shippingOptionName , $ storeId );
152
+ $ shippingMethod = $ this ->getShippingMethod ($ shippingOptionName , $ shippingReferenceId , $ storeId );
150
153
$ shippingDescription = $ this ->getShippingMethodLabel ($ shippingOptionName , $ storeId );
151
154
152
155
$ order ->setStoreId ($ storeId )
@@ -172,12 +175,19 @@ public function map(array $data, int $storeId): Order
172
175
* Get Magento shipping method code. For example: "flatrate_flatrate"
173
176
*
174
177
* @param string $shippingOptionName (possible values: "standard", "expedited", "rush")
178
+ * @param string $shippingReferenceId
175
179
* @param int $storeId
176
180
* @return string|null
177
181
* @throws LocalizedException
178
182
*/
179
- private function getShippingMethod (string $ shippingOptionName , int $ storeId ): ?string
183
+ private function getShippingMethod (string $ shippingOptionName , string $ shippingReferenceId , int $ storeId ): ?string
180
184
{
185
+ $ static_shipping_options = [ShippingMethodTypes::FREE_SHIPPING ,
186
+ ShippingMethodTypes::FLAT_RATE ,
187
+ ShippingMethodTypes::TABLE_RATE ];
188
+ if (in_array ($ shippingReferenceId , $ static_shipping_options )) {
189
+ return $ shippingReferenceId ;
190
+ }
181
191
$ map = $ this ->systemConfig ->getShippingMethodsMap ($ storeId );
182
192
foreach (['standard ' , 'expedited ' , 'rush ' ] as $ item ) {
183
193
if (stripos ($ shippingOptionName , $ item ) !== false && isset ($ map [$ item ])) {
0 commit comments