/**
  * @expectedException \Magento\Framework\Exception\CouldNotSaveException
  * @expectedExceptionMessage Could not add gift message to shopping cart
  */
 public function testSetMessageCouldNotAddGiftMessageException()
 {
     $this->giftMessageMock->expects($this->once())->method('getSender')->will($this->returnValue('sender'));
     $this->giftMessageMock->expects($this->once())->method('getRecipient')->will($this->returnValue('recipient'));
     $this->giftMessageMock->expects($this->once())->method('getMessage')->will($this->returnValue('Message'));
     $this->messageFactoryMock->expects($this->once())->method('create')->willThrowException(new \Exception());
     $this->model->setMessage($this->quoteMock, 'item', $this->giftMessageMock);
 }
Exemplo n.º 2
0
 /**
  * {@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;
 }
Exemplo n.º 3
0
 /**
  * {@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;
 }