Пример #1
0
 /**
  * Indicates that block can display gift messages form
  *
  * @return boolean
  */
 public function canDisplayGiftMessage()
 {
     $item = $this->getItem();
     if (!$item) {
         return false;
     }
     return $this->_messageHelper->getIsMessagesAvailable('item', $item, $item->getStoreId());
 }
Пример #2
0
 /**
  * Retrieve items allowed for gift messages.
  *
  * If no items available return false.
  *
  * @return array|false
  */
 public function getItems()
 {
     $items = array();
     $allItems = $this->getQuote()->getAllItems();
     foreach ($allItems as $item) {
         if ($this->_getGiftmessageSaveModel()->getIsAllowedQuoteItem($item) && $this->_messageHelper->getIsMessagesAvailable('item', $item, $this->getStore())) {
             // if item allowed
             $items[] = $item;
         }
     }
     if (sizeof($items)) {
         return $items;
     }
     return false;
 }
Пример #3
0
 /**
  * Check gift messages availability
  *
  * @param Item|null $item
  * @return bool|null|string
  */
 public function isGiftMessagesAvailable($item = null)
 {
     if (is_null($item)) {
         return $this->_messageHelper->getIsMessagesAvailable('items', $this->getQuote(), $this->getStore());
     }
     return $this->_messageHelper->getIsMessagesAvailable('item', $item, $this->getStore());
 }
Пример #4
0
 /**
  * Set gift message to item or quote
  *
  * @param \Magento\Sales\Model\Quote $quote
  * @param string $type
  * @param \Magento\GiftMessage\Service\V1\Data\Message $giftMessage
  * @param null|int $entityId
  * @return void
  * @throws \Magento\Framework\Exception\CouldNotSaveException
  * @throws \Magento\Framework\Exception\State\InvalidTransitionException
  */
 protected function setMessage(\Magento\Sales\Model\Quote $quote, $type, $giftMessage, $entityId = null)
 {
     if (is_null($quote->getBillingAddress()->getCountryId())) {
         throw new InvalidTransitionException('Billing address is not set');
     }
     // check if shipping address is set
     if (is_null($quote->getShippingAddress()->getCountryId())) {
         throw new InvalidTransitionException('Shipping address is not set');
     }
     $configType = $type == 'quote' ? '' : 'items';
     if (!$this->helper->getIsMessagesAvailable($configType, $quote, $this->storeManager->getStore())) {
         throw new CouldNotSaveException('Gift Message is not available');
     }
     $message[$type][$entityId] = ['from' => $giftMessage->getSender(), 'to' => $giftMessage->getRecipient(), 'message' => $giftMessage->getMessage()];
     try {
         $this->giftMessageManager->add($message, $quote);
     } catch (\Exception $e) {
         throw new CouldNotSaveException('Could not add gift message to shopping cart');
     }
 }
Пример #5
0
 /**
  * Retrieve is gift message available for item (product)
  *
  * @param \Magento\Framework\Object $item
  * @return bool
  */
 public function isGiftMessagesAvailable($item)
 {
     return $this->_giftMessageMessage->getIsMessagesAvailable('item', $item, $item->getStore());
 }
Пример #6
0
 /**
  * Indicates that block can display giftmessages form
  *
  * @return bool
  */
 public function canDisplayGiftmessage()
 {
     return $this->_messageHelper->getIsMessagesAvailable('order_item', $this->getItem(), $this->getItem()->getOrder()->getStoreId());
 }
Пример #7
0
 /**
  * Indicates that block can display giftmessages form
  *
  * @return bool
  */
 public function canDisplayGiftmessage()
 {
     return $this->_messageHelper->getIsMessagesAvailable('order', $this->getEntity(), $this->getEntity()->getStoreId());
 }
Пример #8
0
 /**
  * Indicates that block can display gift message form
  *
  * @return bool
  */
 public function canDisplayGiftmessageForm()
 {
     $quote = $this->_sessionQuote->getQuote();
     return $this->_messageHelper->getIsMessagesAvailable('items', $quote, $quote->getStore());
 }