Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
UpdateItemQty.php
Go to the documentation of this file.
1 <?php
7 
14 use Psr\Log\LoggerInterface;
15 
16 class UpdateItemQty extends Action
17 {
21  protected $sidebar;
22 
26  protected $logger;
27 
31  protected $jsonHelper;
32 
40  public function __construct(
41  Context $context,
43  LoggerInterface $logger,
45  ) {
46  $this->sidebar = $sidebar;
47  $this->logger = $logger;
48  $this->jsonHelper = $jsonHelper;
49  parent::__construct($context);
50  }
51 
55  public function execute()
56  {
57  $itemId = (int)$this->getRequest()->getParam('item_id');
58  $itemQty = $this->getRequest()->getParam('item_qty') * 1;
59 
60  try {
61  $this->sidebar->checkQuoteItem($itemId);
62  $this->sidebar->updateQuoteItem($itemId, $itemQty);
63  return $this->jsonResponse();
64  } catch (LocalizedException $e) {
65  return $this->jsonResponse($e->getMessage());
66  } catch (\Exception $e) {
67  $this->logger->critical($e);
68  return $this->jsonResponse($e->getMessage());
69  }
70  }
71 
78  protected function jsonResponse($error = '')
79  {
80  return $this->getResponse()->representJson(
81  $this->jsonHelper->jsonEncode($this->sidebar->getResponseData($error))
82  );
83  }
84 }
__construct(Context $context, Sidebar $sidebar, LoggerInterface $logger, Data $jsonHelper)