Example #1
0
 /**
  * @expectedException \Magento\Framework\Exception\LocalizedException
  * @exceptedExceptionMessage We can't find the quote item.
  */
 public function testCheckQuoteItemWithException()
 {
     $itemId = 2;
     $quoteMock = $this->getMockBuilder('Magento\\Quote\\Model\\Quote')->disableOriginalConstructor()->getMock();
     $quoteMock->expects($this->once())->method('getItemById')->with($itemId)->willReturn(null);
     $this->cartMock->expects($this->any())->method('getQuote')->willReturn($quoteMock);
     $this->sidebar->checkQuoteItem($itemId);
 }
Example #2
0
 /**
  * @return $this
  */
 public function executeInternal()
 {
     $itemId = (int) $this->getRequest()->getParam('item_id');
     try {
         $this->sidebar->checkQuoteItem($itemId);
         $this->sidebar->removeQuoteItem($itemId);
         return $this->jsonResponse();
     } catch (LocalizedException $e) {
         return $this->jsonResponse($e->getMessage());
     } catch (\Exception $e) {
         $this->logger->critical($e);
         return $this->jsonResponse($e->getMessage());
     }
 }
Example #3
0
 /**
  * @return $this
  */
 public function execute()
 {
     if (!$this->getFormKeyValidator()->validate($this->getRequest())) {
         return $this->resultRedirectFactory->create()->setPath('*/cart/');
     }
     $itemId = (int) $this->getRequest()->getParam('item_id');
     try {
         $this->sidebar->checkQuoteItem($itemId);
         $this->sidebar->removeQuoteItem($itemId);
         return $this->jsonResponse();
     } catch (\Magento\Framework\Exception\LocalizedException $e) {
         return $this->jsonResponse($e->getMessage());
     } catch (\Exception $e) {
         $this->logger->critical($e);
         return $this->jsonResponse($e->getMessage());
     }
 }