/** * {@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; }
/** * {@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; }