Skip to content

Commit 022bd3d

Browse files
committed
MAGETWO-35610: Merge and Fix Tests
- fix. added additional check during saving gift messages
1 parent b0ca9ca commit 022bd3d

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

app/code/Magento/GiftMessage/Model/Plugin/OrderSave.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,21 @@ public function aroundSave(
6161
*/
6262
protected function saveOrderGiftMessage(\Magento\Sales\Api\Data\OrderInterface $order)
6363
{
64-
if (null !== ($order->getExtensionAttributes())) {
64+
if (
65+
null !== $order->getExtensionAttributes() &&
66+
null !== $order->getExtensionAttributes()->getGiftMessage()
67+
) {
6568
/* @var \Magento\GiftMessage\Api\Data\MessageInterface $giftMessage */
6669
$giftMessage = $order->getExtensionAttributes()->getGiftMessage();
67-
try {
68-
$this->giftMessageOrderRepository->save($order->getEntityId(), $giftMessage);
69-
} catch (\Exception $e) {
70-
throw new CouldNotSaveException(__('Could not add gift message to order: "%1"', $e->getMessage()), $e);
70+
if (null !== $giftMessage) {
71+
try {
72+
$this->giftMessageOrderRepository->save($order->getEntityId(), $giftMessage);
73+
} catch (\Exception $e) {
74+
throw new CouldNotSaveException(
75+
__('Could not add gift message to order: "%1"', $e->getMessage()),
76+
$e
77+
);
78+
}
7179
}
7280
}
7381
return $order;
@@ -84,7 +92,10 @@ protected function saveOrderItemGiftMessage(\Magento\Sales\Api\Data\OrderInterfa
8492
if (null !== $order->getItems()) {
8593
/** @var \Magento\Sales\Api\Data\OrderItemInterface $orderItem */
8694
foreach ($order->getItems() as $orderItem) {
87-
if (null !== ($orderItem->getExtensionAttributes())) {
95+
if (
96+
null !== $orderItem->getExtensionAttributes() &&
97+
null !== $orderItem->getExtensionAttributes()->getGiftMessage()
98+
) {
8899
/* @var \Magento\GiftMessage\Api\Data\MessageInterface $giftMessage */
89100
$giftMessage = $orderItem->getExtensionAttributes()->getGiftMessage();
90101
try {

0 commit comments

Comments
 (0)