Skip to content

Commit fb2ec38

Browse files
authored
Custom shipping method labels (#319)
* Custom shipping method labels * add return type to param
1 parent cf6baca commit fb2ec38

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

app/code/Meta/BusinessExtension/Model/System/Config.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ class Config
6565
private const XML_PATH_FACEBOOK_SHIPPING_METHODS_STANDARD = 'facebook/shipping_methods/standard';
6666
private const XML_PATH_FACEBOOK_SHIPPING_METHODS_EXPEDITED = 'facebook/shipping_methods/expedited';
6767
private const XML_PATH_FACEBOOK_SHIPPING_METHODS_RUSH = 'facebook/shipping_methods/rush';
68+
private const XML_PATH_FACEBOOK_SHIPPING_METHODS_LABEL_STANDARD = 'facebook/shipping_methods/label_standard';
69+
private const XML_PATH_FACEBOOK_SHIPPING_METHODS_LABEL_EXPEDITED = 'facebook/shipping_methods/label_expedited';
70+
private const XML_PATH_FACEBOOK_SHIPPING_METHODS_LABEL_RUSH = 'facebook/shipping_methods/label_rush';
6871

6972
public const XML_PATH_FACEBOOK_BUSINESS_EXTENSION_ACCESS_TOKEN = 'facebook/business_extension/access_token';
7073
public const XML_PATH_FACEBOOK_BUSINESS_EXTENSION_PAGE_ACCESS_TOKEN =
@@ -708,6 +711,21 @@ public function getShippingMethodsMap($storeId = null): array
708711
];
709712
}
710713

714+
/**
715+
* Get shipping methods label map
716+
*
717+
* @param int|null $storeId
718+
* @return array|null
719+
*/
720+
public function getShippingMethodsLabelMap($storeId = null): array
721+
{
722+
return [
723+
'standard' => $this->getConfig(self::XML_PATH_FACEBOOK_SHIPPING_METHODS_LABEL_STANDARD, $storeId),
724+
'expedited' => $this->getConfig(self::XML_PATH_FACEBOOK_SHIPPING_METHODS_LABEL_EXPEDITED, $storeId),
725+
'rush' => $this->getConfig(self::XML_PATH_FACEBOOK_SHIPPING_METHODS_LABEL_RUSH, $storeId),
726+
];
727+
}
728+
711729
/**
712730
* Is catalog sync enabled
713731
*

app/code/Meta/Sales/Model/Mapper/OrderMapper.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,12 @@ public function map(array $data, int $storeId): Order
147147
$this->applyTotalsToOrder($order, $data, $storeId);
148148

149149
$shippingMethod = $this->getShippingMethod($shippingOptionName, $storeId);
150+
$shippingDescription = $this->getShippingMethodLabel($shippingOptionName, $storeId);
151+
150152
$order->setStoreId($storeId)
151153
// @todo have to set shipping method like this
152154
->setShippingMethod($shippingMethod)
153-
->setShippingDescription($shippingOptionName . " / {$shippingMethod}")
155+
->setShippingDescription($shippingDescription ?? $shippingOptionName . " / {$shippingMethod}")
154156
->setPayment($payment);
155157

156158
// @todo implement paging and tax for order items
@@ -187,6 +189,24 @@ private function getShippingMethod(string $shippingOptionName, int $storeId): ?s
187189
);
188190
}
189191

192+
/**
193+
* Get custom shipping method label
194+
*
195+
* @param string $shippingOptionName
196+
* @param int $storeId
197+
* @return string|null
198+
*/
199+
private function getShippingMethodLabel(string $shippingOptionName, int $storeId): ?string
200+
{
201+
$map = $this->systemConfig->getShippingMethodsLabelMap($storeId);
202+
foreach (['standard', 'expedited', 'rush'] as $item) {
203+
if (stripos($shippingOptionName, $item) !== false && isset($map[$item])) {
204+
return $map[$item];
205+
}
206+
}
207+
return null;
208+
}
209+
190210
/**
191211
* Create a magento order billing address from facebook order data
192212
*

0 commit comments

Comments
 (0)