Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function getSectionData()
 {
     $messages = $this->messageManager->getMessages(true);
     return ['messages' => array_reduce($messages->getItems(), function (array $result, MessageInterface $message) {
         $result[] = ['type' => $message->getType(), 'text' => $this->interpretationStrategy->interpret($message)];
         return $result;
     }, [])];
 }
Ejemplo n.º 2
0
 /**
  * Return messages array and clean message manager messages
  *
  * @return array
  */
 protected function getMessages()
 {
     $messages = $this->getCookiesMessages();
     /** @var MessageInterface $message */
     foreach ($this->messageManager->getMessages(true)->getItems() as $message) {
         $messages[] = ['type' => $message->getType(), 'text' => $this->interpretationStrategy->interpret($message)];
     }
     return $messages;
 }
Ejemplo n.º 3
0
 /**
  * Render messages in HTML format grouped by type
  *
  * @return string
  */
 protected function _renderMessagesByType()
 {
     $html = '';
     foreach ($this->getMessageTypes() as $type) {
         if ($messages = $this->getMessagesByType($type)) {
             if (!$html) {
                 $html .= '<' . $this->firstLevelTagName . ' class="messages">';
             }
             foreach ($messages as $message) {
                 $html .= '<' . $this->secondLevelTagName . ' class="message ' . 'message-' . $type . ' ' . $type . '">';
                 $html .= '<' . $this->contentWrapTagName . $this->getUiId('message', $type) . '>';
                 $html .= $this->interpretationStrategy->interpret($message);
                 $html .= '</' . $this->contentWrapTagName . '>';
                 $html .= '</' . $this->secondLevelTagName . '>';
             }
         }
     }
     if ($html) {
         $html .= '</' . $this->firstLevelTagName . '>';
     }
     return $html;
 }
Ejemplo n.º 4
0
 /**
  * Retrieve item messages
  * Return array with keys
  *
  * text => the message text
  * type => type of a message
  *
  * @return array
  */
 public function getMessages()
 {
     $messages = [];
     $quoteItem = $this->getItem();
     // Add basic messages occurring during this page load
     $baseMessages = $quoteItem->getMessage(false);
     if ($baseMessages) {
         foreach ($baseMessages as $message) {
             $messages[] = ['text' => $message, 'type' => $quoteItem->getHasError() ? 'error' : 'notice'];
         }
     }
     /* @var $collection \Magento\Framework\Message\Collection */
     $collection = $this->messageManager->getMessages(true, 'quote_item' . $quoteItem->getId());
     if ($collection) {
         $additionalMessages = $collection->getItems();
         foreach ($additionalMessages as $message) {
             /* @var $message \Magento\Framework\Message\MessageInterface */
             $messages[] = ['text' => $this->messageInterpretationStrategy->interpret($message), 'type' => $message->getType()];
         }
     }
     $this->messageManager->getMessages(true, 'quote_item' . $quoteItem->getId())->clear();
     return $messages;
 }