Example #1
0
 /**
  * Removes error statuses from quote and item, set by this observer
  *
  * @param \Magento\Sales\Model\Quote\Item $item
  * @param int $code
  * @return void
  */
 protected function _removeErrorsFromQuoteAndItem($item, $code)
 {
     if ($item->getHasError()) {
         $params = array('origin' => 'cataloginventory', 'code' => $code);
         $item->removeErrorInfosByParams($params);
     }
     $quote = $item->getQuote();
     $quoteItems = $quote->getItemsCollection();
     $canRemoveErrorFromQuote = true;
     foreach ($quoteItems as $quoteItem) {
         if ($quoteItem->getItemId() == $item->getItemId()) {
             continue;
         }
         $errorInfos = $quoteItem->getErrorInfos();
         foreach ($errorInfos as $errorInfo) {
             if ($errorInfo['code'] == $code) {
                 $canRemoveErrorFromQuote = false;
                 break;
             }
         }
         if (!$canRemoveErrorFromQuote) {
             break;
         }
     }
     if ($quote->getHasError() && $canRemoveErrorFromQuote) {
         $params = array('origin' => 'cataloginventory', 'code' => $code);
         $quote->removeErrorInfosByParams(null, $params);
     }
 }