Skip to content

Commit b9a6495

Browse files
authored
Normalize Order History (#567)
* Normalize Order History * Updated order history to match pattern/casing used by Magento ("Order Placed on ...") * Fixed inconsistency between expected/actual cancellation notes * code review feedback
1 parent 6437db5 commit b9a6495

File tree

6 files changed

+16
-20
lines changed

6 files changed

+16
-20
lines changed

app/code/Meta/BusinessExtension/Helper/GraphAPIAdapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ public function cancelOrder($fbOrderId)
775775
// Magento doesn't support admin providing reason code or description for order cancellation
776776
$cancelReason = [
777777
'reason_code' => 'CUSTOMER_REQUESTED',
778-
'reason_description' => 'Cancelled from Magento',
778+
'reason_description' => 'Canceled from Magento',
779779
];
780780
$response = $this->callApi(
781781
'POST',

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ public function map(array $data, int $storeId): Order
139139
->setDebugMode($isDebugMode)
140140
->setAccessToken($accessToken);
141141

142-
$channel = ucfirst($data['channel']);
143142
$billingAddress = $this->getOrderBillingAddress($data);
144143
$shippingAddress = clone $billingAddress;
145144
$shippingAddress
@@ -174,7 +173,7 @@ public function map(array $data, int $storeId): Order
174173
$this->applyDiscountsToOrder($order, $data);
175174
$this->applyTotalsToOrder($order, $data, $storeId);
176175

177-
$order->addCommentToStatusHistory("Imported order #{$facebookOrderId} from {$channel}.");
176+
$order->addCommentToStatusHistory("Order Imported from Meta. Meta Order ID: #{$facebookOrderId}");
178177

179178
return $order;
180179
}

app/code/Meta/Sales/Model/Order/CreateCancellation.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class CreateCancellation
3838
/**
3939
* Constant for the cancellation note to be added to the order
4040
*/
41-
public const CANCELLATION_NOTE = 'Cancelled from Meta Commerce Manager';
41+
public const CANCELLATION_NOTE = 'Order Canceled from Meta.';
4242

4343
/**
4444
* @var OrderRepositoryInterface
@@ -115,17 +115,15 @@ public function execute(array $facebookOrderData, array $facebookCancellationDat
115115
$magentoOrder->setStatus(Order::STATE_CANCELED);
116116
}
117117
if (isset($facebookCancellationData['cancel_reason'])) {
118-
$concatenatedString = "";
118+
$concatenatedString = '';
119119
if (isset($facebookCancellationData['cancel_reason']['reason_code'])) {
120-
$concatenatedString .= 'Code: ' . $facebookCancellationData['cancel_reason']['reason_code'] . '. ';
120+
$concatenatedString .= ' Reason: ' . $facebookCancellationData['cancel_reason']['reason_code'];
121121
}
122122
if (isset($facebookCancellationData['cancel_reason']['reason_description'])) {
123-
$concatenatedString .= 'Description: ' .
123+
$concatenatedString .= ' Description: ' .
124124
$facebookCancellationData['cancel_reason']['reason_description'];
125125
}
126-
if (!empty($concatenatedString)) {
127-
$magentoOrder->addCommentToStatusHistory('Cancellation Details: ' . $concatenatedString);
128-
}
126+
$magentoOrder->addCommentToStatusHistory(self::CANCELLATION_NOTE . $concatenatedString);
129127
}
130128
$this->orderRepository->save($magentoOrder);
131129
}

app/code/Meta/Sales/Model/Order/Shipper.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,9 @@ public function markAsShipped(Shipment $shipment)
226226
);
227227

228228
if ($track) {
229-
$comment = "Marked order as shipped on Meta with {$track->getTitle()}. Tracking #: {$track->getNumber()}.";
229+
$comment = "Order Marked as Shipped on Meta for {$track->getTitle()}. Tracking #: {$track->getNumber()}";
230230
} else {
231-
$comment = "Marked order as shipped on Meta.";
231+
$comment = "Order Marked as Shipped on Meta";
232232
}
233233

234234
$order->addCommentToStatusHistory($comment)->save();
@@ -318,7 +318,7 @@ public function updateShipmentTracking(Shipment $shipment)
318318
$trackingInfo,
319319
);
320320

321-
$comment = "Updated shipment tracking on Meta for {$track->getTitle()}. Tracking #: {$track->getNumber()}.";
321+
$comment = "Order Shipment Tracking Updated on Meta for {$track->getTitle()}. Tracking #: {$track->getNumber()}";
322322
$order->addCommentToStatusHistory($comment)->save();
323323

324324
$fbOrder = $this->orderHelper->loadFacebookOrderFromMagentoId($order->getId());

app/code/Meta/Sales/Observer/Order/Cancel.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,10 @@ public function execute(Observer $observer)
8383
return;
8484
}
8585

86-
$statusHistory = $order->getStatusHistoryCollection();
87-
foreach ($statusHistory as $historyItem) {
88-
if ($historyItem->getComment() &&
89-
strpos($historyItem->getComment(), CreateCancellation::CANCELLATION_NOTE) !== false
90-
) {
86+
$historyItems = $order->getStatusHistoryCollection();
87+
foreach ($historyItems as $historyItem) {
88+
$comment = $historyItem->getComment();
89+
if ($comment && strpos($comment, CreateCancellation::CANCELLATION_NOTE) !== false) {
9190
// No-op if order was originally canceled on Facebook -- avoid infinite cancel loop.
9291
return;
9392
}
@@ -101,7 +100,7 @@ public function execute(Observer $observer)
101100

102101
$this->cancelOrder((int)$storeId, $facebookOrderId);
103102

104-
$order->addCommentToStatusHistory("Canceled order on Meta.");
103+
$order->addCommentToStatusHistory('Order Canceled on Meta');
105104
}
106105

107106
/**

app/code/Meta/Sales/Observer/Order/Refund.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public function execute(Observer $observer)
153153
$reasonText
154154
);
155155

156-
$payment->getOrder()->addCommentToStatusHistory('Refunded order on Meta.');
156+
$payment->getOrder()->addCommentToStatusHistory('Order Refunded on Meta');
157157
}
158158

159159
/**

0 commit comments

Comments
 (0)