Пример #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;
 }
Пример #3
0
 public function testSave()
 {
     $this->quoteRepositoryMock->expects($this->any())->method('get')->willReturn($this->quoteMock);
     $this->quoteMock->expects($this->once())->method('getItemsCount')->willReturn(1);
     $this->quoteMock->expects($this->once())->method('getIsVirtual')->willReturn(false);
     $customerMock = $this->getMock('Magento\\Customer\\Api\\Data\\CustomerInterface', [], [], '', false);
     $this->quoteMock->expects($this->once())->method('getCustomer')->willReturn($customerMock);
     $this->messageMock->expects($this->any())->method('setCustomerId');
     $this->messageMock->expects($this->any())->method('setGiftMessageId');
     $this->cacheMock->expects($this->once())->method('save');
     $this->assertTrue($this->cartRepository->save($this->cartId, $this->messageMock));
 }
Пример #4
0
 public function testSave()
 {
     $this->quoteRepositoryMock->expects($this->any())->method('get')->willReturn($this->quoteMock);
     $this->quoteItemMock->expects($this->once())->method('getItemId')->willReturn($this->itemId);
     $this->quoteItemMock->expects($this->once())->method('getProductType')->willReturn(\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE);
     $customerMock = $this->getMock('Magento\\Customer\\Api\\Data\\CustomerInterface', [], [], '', false);
     $this->quoteMock->expects($this->once())->method('getCustomer')->willReturn($customerMock);
     $this->messageMock->expects($this->any())->method('setCustomerId');
     $this->messageMock->expects($this->any())->method('setGiftMessageId');
     $this->cacheMock->expects($this->once())->method('save');
     $this->assertTrue($this->itemRepository->save($this->cartId, $this->messageMock, $this->itemId));
 }
 /**
  * @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);
 }