예제 #1
0
 /**
  * {@inheritDoc}
  */
 public function save($cartId, \Magento\GiftMessage\Api\Data\MessageInterface $giftMessage, $itemId)
 {
     $quote = $this->quoteRepository->get($cartId);
     /** @var CartItemInterface $item */
     $item = $this->getQuoteItem($cartId, $itemId);
     if ($item->getProductType() == \Magento\Catalog\Model\Product\Type::TYPE_VIRTUAL) {
         throw new InvalidTransitionException(__('Gift Messages is not applicable for virtual products'));
     }
     $giftMessage->setCustomerId($quote->getCustomer()->getId());
     $giftMessage->setGiftMessageId(rand());
     $msgCacheId = $itemId . self::CACHE_ID_POSTFIX;
     $this->cache->save(serialize($giftMessage), $msgCacheId);
     return true;
 }
예제 #2
0
 /**
  * {@inheritDoc}
  */
 public function save($cartId, \Magento\GiftMessage\Api\Data\MessageInterface $giftMessage)
 {
     /** @var CartInterface $quote */
     $quote = $this->quoteRepository->get($cartId);
     if (0 == $quote->getItemsCount()) {
         throw new InputException(__('Gift Messages is not applicable for empty cart'));
     }
     if ($quote->getIsVirtual()) {
         throw new InvalidTransitionException(__('Gift Messages is not applicable for virtual products'));
     }
     $giftMessage->setCustomerId($quote->getCustomer()->getId());
     $giftMessage->setGiftMessageId(rand());
     $msgCacheId = $cartId . self::CACHE_ID_POSTFIX;
     $this->cache->save(serialize($giftMessage), $msgCacheId);
     return true;
 }
 /**
  * @expectedExcpetion \Magento\Framework\Exception\NoSuchEntityException
  * @expectedExceptionMessage No such entity with cartId = 15
  */
 public function testGetWithExceptionByIsActive()
 {
     $cartId = 15;
     $this->quoteFactoryMock->expects($this->once())->method('create')->willReturn($this->quoteMock);
     $this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($this->storeMock);
     $this->storeMock->expects($this->once())->method('getId')->willReturn($this->storeMock);
     $this->quoteMock->expects($this->never())->method('setSharedStoreIds');
     $this->quoteMock->expects($this->once())->method('load')->with($cartId)->willReturn($this->storeMock);
     $this->quoteMock->expects($this->once())->method('getId')->willReturn($cartId);
     $this->quoteMock->expects($this->once())->method('getIsActive')->willReturn(0);
     $this->model->get($cartId);
 }