0

I'm trying to edit an associative array containing order info.

This array for our backend application gets created under sales_order_place_after event once the order is placed .Everything works as expected except when the order is placed with empty gift message.

Another event sales_order_save_after being used to only fetch the gift message fails when the order is placed without any optional gift message.

Order gets placed successfully, and the second observer class gets the control but fails when the execution reaches this line of code !empty($this->_orderGiftRepo->get($order->getId())) Any help/suggestion is greatly appreciated.

1 Answer 1

0

Several hours of research and experimenting resulted in resolving the issue with the order without a gift message on it. As I'm sure it would help those who may find this issue, I would answer my own question. The most useful information is that $this->_orderGiftRepo->get($order->getId())will throw an exception in case of orders placed with the empty gift message. To have handled this exception like try { // Magento\GiftMessage\Api\OrderRepositoryInterface $_orderGiftRepo $gift_object = $this->_orderGiftRepo->get($order->getId()); $gift_message = $gift_object->getMessage(); } catch (NoSuchEntityException $e) { // Do nothing. No gift message specified. Valid scenario. } catch (\Exception $e) { $this->_logger->debug("Empty Gift Message for this order: " . $e->getMessage()); } fixed the issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.