/** * Indicates that block can display gift messages form * * @return boolean */ public function canDisplayGiftMessage() { $item = $this->getItem(); if (!$item) { return false; } return $this->_messageHelper->isMessagesAllowed('item', $item, $item->getStoreId()); }
/** * @param \Magento\Quote\Model\Quote\Item\ToOrderItem $subject * @param callable $proceed * @param \Magento\Quote\Model\Quote\Item\AbstractItem $item * @param array $additional * @return Item * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function aroundConvert(\Magento\Quote\Model\Quote\Item\ToOrderItem $subject, Closure $proceed, \Magento\Quote\Model\Quote\Item\AbstractItem $item, $additional = []) { /** @var $orderItem Item */ $orderItem = $proceed($item, $additional); $isAvailable = $this->_helper->isMessagesAllowed('item', $item, $item->getStoreId()); $orderItem->setGiftMessageId($item->getGiftMessageId()); $orderItem->setGiftMessageAvailable($isAvailable); return $orderItem; }
/** * Retrieve items allowed for gift messages. * * If no items available return false. * * @return array|false */ public function getItems() { $items = []; $allItems = $this->getQuote()->getAllItems(); foreach ($allItems as $item) { if ($this->_getGiftmessageSaveModel()->getIsAllowedQuoteItem($item) && $this->_messageHelper->isMessagesAllowed('item', $item, $this->getStore())) { // if item allowed $items[] = $item; } } if (sizeof($items)) { return $items; } return false; }
/** * Check gift messages availability * * @param Item|null $item * @return bool|null|string */ public function isGiftMessagesAvailable($item = null) { if ($item === null) { return $this->_messageHelper->isMessagesAllowed('items', $this->getQuote(), $this->getStore()); } return $this->_messageHelper->isMessagesAllowed('item', $item, $this->getStore()); }
/** * {@inheritDoc} */ public function save($orderId, \Magento\GiftMessage\Api\Data\MessageInterface $giftMessage) { /** @var \Magento\Sales\Api\Data\OrderInterface $order */ $order = $this->orderFactory->create()->load($orderId); if (!$order->getEntityId()) { throw new NoSuchEntityException(__('There is no order with provided id')); } if (0 == $order->getTotalItemCount()) { throw new InputException(__('Gift Messages is not applicable for empty order')); } if ($order->getIsVirtual()) { throw new InvalidTransitionException(__('Gift Messages is not applicable for virtual products')); } if (!$this->helper->isMessagesAllowed('order', $order, $this->storeManager->getStore())) { throw new CouldNotSaveException(__('Gift Message is not available')); } $message = []; $message[$orderId] = ['type' => 'order', $giftMessage::CUSTOMER_ID => $giftMessage->getCustomerId(), $giftMessage::SENDER => $giftMessage->getSender(), $giftMessage::RECIPIENT => $giftMessage->getRecipient(), $giftMessage::MESSAGE => $giftMessage->getMessage()]; $this->giftMessageSaveModel->setGiftmessages($message); try { $this->giftMessageSaveModel->saveAllInOrder(); } catch (\Exception $e) { throw new CouldNotSaveException(__('Could not add gift message to order: "%1"', $e->getMessage()), $e); } return true; }
/** * Duplicates giftmessage from order to quote on import or reorder * * @param \Magento\Framework\Event\Observer $observer * @return $this */ public function execute(\Magento\Framework\Event\Observer $observer) { $order = $observer->getEvent()->getOrder(); // Do not import giftmessage data if order is reordered if ($order->getReordered()) { return $this; } if (!$this->_giftMessageMessage->isMessagesAllowed('order', $order, $order->getStore())) { return $this; } $giftMessageId = $order->getGiftMessageId(); if ($giftMessageId) { $giftMessage = $this->_messageFactory->create()->load($giftMessageId)->setId(null)->save(); $observer->getEvent()->getQuote()->setGiftMessageId($giftMessage->getId()); } return $this; }
/** * Duplicates giftmessage from order item to quote item on import or reorder * * @param \Magento\Framework\Event\Observer $observer * @return $this */ public function execute(\Magento\Framework\Event\Observer $observer) { /** @var $orderItem \Magento\Sales\Model\Order\Item */ $orderItem = $observer->getEvent()->getOrderItem(); // Do not import giftmessage data if order is reordered $order = $orderItem->getOrder(); if ($order && $order->getReordered()) { return $this; } $isAvailable = $this->_giftMessageMessage->isMessagesAllowed('order_item', $orderItem, $orderItem->getStoreId()); if (!$isAvailable) { return $this; } /** @var $quoteItem \Magento\Quote\Model\Quote\Item */ $quoteItem = $observer->getEvent()->getQuoteItem(); if ($giftMessageId = $orderItem->getGiftMessageId()) { $giftMessage = $this->_messageFactory->create()->load($giftMessageId)->setId(null)->save(); $quoteItem->setGiftMessageId($giftMessage->getId()); } return $this; }
/** * {@inheritDoc} */ public function save($cartId, \Magento\GiftMessage\Api\Data\MessageInterface $giftMessage, $itemId) { /** * Quote. * * @var \Magento\Quote\Model\Quote $quote */ $quote = $this->quoteRepository->getActive($cartId); if (!($item = $quote->getItemById($itemId))) { throw new NoSuchEntityException(__('There is no product with provided itemId: %1 in the cart', $itemId)); } if ($item->getIsVirtual()) { throw new InvalidTransitionException(__('Gift Messages is not applicable for virtual products')); } if (!$this->helper->isMessagesAllowed('items', $quote, $this->storeManager->getStore())) { throw new CouldNotSaveException(__('Gift Message is not available')); } $this->giftMessageManager->setMessage($quote, 'quote_item', $giftMessage, $itemId); return true; }
/** * {@inheritDoc} */ public function save($cartId, \Magento\GiftMessage\Api\Data\MessageInterface $giftMessage) { /** * Quote. * * @var \Magento\Quote\Model\Quote $quote */ $quote = $this->quoteRepository->getActive($cartId); if (0 == $quote->getItemsCount()) { throw new InputException(__('Gift Messages is not applicable for empty cart')); } if ($quote->isVirtual()) { throw new InvalidTransitionException(__('Gift Messages is not applicable for virtual products')); } if (!$this->helper->isMessagesAllowed('quote', $quote, $this->storeManager->getStore())) { throw new CouldNotSaveException(__('Gift Message is not available')); } $this->giftMessageManager->setMessage($quote, 'quote', $giftMessage); return true; }
/** * {@inheritDoc} */ public function save($orderId, $orderItemId, \Magento\GiftMessage\Api\Data\MessageInterface $giftMessage) { /** @var \Magento\Sales\Api\Data\OrderInterface $order */ $order = $this->orderFactory->create()->load($orderId); /** @var \Magento\Sales\Api\Data\OrderItemInterface $orderItem */ if (!($orderItem = $this->getItemById($orderId, $orderItemId))) { throw new NoSuchEntityException(__('There is no item with provided id in the order')); } if ($order->getIsVirtual()) { throw new InvalidTransitionException(__('Gift Messages is not applicable for virtual products')); } if (!$this->helper->isMessagesAllowed('order_item', $orderItem, $this->storeManager->getStore())) { throw new CouldNotSaveException(__('Gift Message is not available')); } $message = []; $message[$orderItemId] = ['type' => 'order_item', 'sender' => $giftMessage->getSender(), 'recipient' => $giftMessage->getRecipient(), 'message' => $giftMessage->getMessage()]; $this->giftMessageSaveModel->setGiftmessages($message); try { $this->giftMessageSaveModel->saveAllInOrder(); } catch (\Exception $e) { throw new CouldNotSaveException(__('Could not add gift message to order: "%1"', $e->getMessage()), $e); } return true; }
/** * Retrieve is gift message available for item (product) * * @param \Magento\Framework\Object $item * @return bool */ public function isGiftMessagesAvailable($item) { return $this->_giftMessageMessage->isMessagesAllowed('item', $item, $item->getStore()); }
/** * Indicates that block can display giftmessages form * * @return bool */ public function canDisplayGiftmessage() { return $this->_messageHelper->isMessagesAllowed('order_item', $this->getItem(), $this->getItem()->getOrder()->getStoreId()); }
/** * Indicates that block can display gift message form * * @return bool */ public function canDisplayGiftmessageForm() { $quote = $this->_sessionQuote->getQuote(); return $this->_messageHelper->isMessagesAllowed('items', $quote, $quote->getStore()); }
/** * Indicates that block can display giftmessages form * * @return bool */ public function canDisplayGiftmessage() { return $this->_messageHelper->isMessagesAllowed('order', $this->getEntity(), $this->getEntity()->getStoreId()); }
/** * Check availability of giftmessages for specified entity item * * @param \Magento\Framework\Object $item * @return bool */ public function isItemMessagesAvailable($item) { $type = substr($this->getType(), 0, 5) == 'multi' ? 'address_item' : 'item'; return $this->_giftMessageMessage->isMessagesAllowed($type, $item); }