Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SalesEventOrderToQuoteObserver.php
Go to the documentation of this file.
1 <?php
7 
9 
16 {
22  protected $_giftMessageMessage = null;
23 
27  protected $_messageFactory;
28 
33  public function __construct(
34  \Magento\GiftMessage\Model\MessageFactory $messageFactory,
35  \Magento\GiftMessage\Helper\Message $giftMessageMessage
36  ) {
37  $this->_messageFactory = $messageFactory;
38  $this->_giftMessageMessage = $giftMessageMessage;
39  }
40 
47  public function execute(\Magento\Framework\Event\Observer $observer)
48  {
49  $order = $observer->getEvent()->getOrder();
50  // Do not import giftmessage data if order is reordered
51  if ($order->getReordered()) {
52  return $this;
53  }
54 
55  if (!$this->_giftMessageMessage->isMessagesAllowed('order', $order, $order->getStore())) {
56  return $this;
57  }
58  $giftMessageId = $order->getGiftMessageId();
59  if ($giftMessageId) {
60  $giftMessage = $this->_messageFactory->create()->load($giftMessageId)->setId(null)->save();
61  $observer->getEvent()->getQuote()->setGiftMessageId($giftMessage->getId());
62  }
63 
64  return $this;
65  }
66 }
$giftMessage
Definition: items.phtml:47
$order
Definition: order.php:55
__construct(\Magento\GiftMessage\Model\MessageFactory $messageFactory, \Magento\GiftMessage\Helper\Message $giftMessageMessage)
$messageFactory
Definition: messages.php:10