Skip to content

Commit 54eeaaa

Browse files
author
Sergey Semenov
committed
Merge remote-tracking branch 'origin/MAGETWO-21349' into MAGETWO-21349
2 parents c1e6fba + 54bfe29 commit 54eeaaa

File tree

2 files changed

+27
-42
lines changed

2 files changed

+27
-42
lines changed

app/code/Magento/Checkout/Controller/Sidebar/UpdateItemQty.php

Lines changed: 25 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,55 +5,47 @@
55
*/
66
namespace Magento\Checkout\Controller\Sidebar;
77

8-
use Magento\Checkout\Controller\Cart;
9-
use Magento\Checkout\Model\Cart as CustomerCart;
10-
use Magento\Checkout\Model\Session;
118
use Magento\Checkout\Model\Sidebar;
9+
use Magento\Framework\App\Action\Action;
1210
use Magento\Framework\App\Action\Context;
13-
use Magento\Framework\App\Config\ScopeConfigInterface;
1411
use Magento\Framework\App\Response\Http;
15-
use Magento\Framework\Controller\Result\RedirectFactory;
16-
use Magento\Framework\Data\Form\FormKey\Validator;
1712
use Magento\Framework\Exception\LocalizedException;
18-
use Magento\Store\Model\StoreManagerInterface;
13+
use Magento\Framework\Json\Helper\Data;
14+
use Psr\Log\LoggerInterface;
1915

20-
class UpdateItemQty extends Cart
16+
class UpdateItemQty extends Action
2117
{
2218
/**
2319
* @var Sidebar
2420
*/
2521
protected $sidebar;
2622

23+
/**
24+
* @var LoggerInterface
25+
*/
26+
protected $logger;
27+
28+
/**
29+
* @var Data
30+
*/
31+
protected $jsonHelper;
32+
2733
/**
2834
* @param Context $context
29-
* @param ScopeConfigInterface $scopeConfig
30-
* @param Session $checkoutSession
31-
* @param StoreManagerInterface $storeManager
32-
* @param Validator $formKeyValidator
33-
* @param CustomerCart $cart
34-
* @param RedirectFactory $resultRedirectFactory
3535
* @param Sidebar $sidebar
36+
* @param LoggerInterface $logger
37+
* @param Data $jsonHelper
3638
*/
3739
public function __construct(
3840
Context $context,
39-
ScopeConfigInterface $scopeConfig,
40-
Session $checkoutSession,
41-
StoreManagerInterface $storeManager,
42-
Validator $formKeyValidator,
43-
CustomerCart $cart,
44-
RedirectFactory $resultRedirectFactory,
45-
Sidebar $sidebar
41+
Sidebar $sidebar,
42+
LoggerInterface $logger,
43+
Data $jsonHelper
4644
) {
4745
$this->sidebar = $sidebar;
48-
parent::__construct(
49-
$context,
50-
$scopeConfig,
51-
$checkoutSession,
52-
$storeManager,
53-
$formKeyValidator,
54-
$cart,
55-
$resultRedirectFactory
56-
);
46+
$this->logger = $logger;
47+
$this->jsonHelper = $jsonHelper;
48+
parent::__construct($context);
5749
}
5850

5951
/**
@@ -71,7 +63,7 @@ public function execute()
7163
} catch (LocalizedException $e) {
7264
return $this->jsonResponse($e->getMessage());
7365
} catch (\Exception $e) {
74-
$this->_objectManager->get('Psr\Log\LoggerInterface')->critical($e);
66+
$this->logger->critical($e);
7567
return $this->jsonResponse($e->getMessage());
7668
}
7769
}
@@ -82,11 +74,10 @@ public function execute()
8274
* @param string $error
8375
* @return Http
8476
*/
85-
public function jsonResponse($error = '')
77+
protected function jsonResponse($error = '')
8678
{
8779
return $this->getResponse()->representJson(
88-
$this->_objectManager->get('Magento\Framework\Json\Helper\Data')
89-
->jsonEncode($this->sidebar->getResponseData($error))
80+
$this->jsonHelper->jsonEncode($this->sidebar->getResponseData($error))
9081
);
9182
}
9283
}

app/code/Magento/Checkout/Model/Sidebar.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,8 @@ public function removeQuoteItem($itemId)
115115
*/
116116
public function updateQuoteItem($itemId, $itemQty)
117117
{
118-
$item = $this->cart->updateItem($itemId, $this->normalize($itemQty));
119-
if (is_string($item)) {
120-
throw new LocalizedException(__($item));
121-
}
122-
if ($item->getHasError()) {
123-
throw new LocalizedException(__($item->getMessage()));
124-
}
125-
$this->cart->save();
118+
$itemData = [$itemId => ['qty' => $this->normalize($itemQty)]];
119+
$this->cart->updateItems($itemData)->save();
126120
return $this;
127121
}
128122

0 commit comments

Comments
 (0)