Skip to content

Commit 3f41b05

Browse files
author
Yuri Kovsher
committed
Merge remote-tracking branch 'tango-ce/MAGETWO-33058' into MAGETWO-32571
2 parents 624f58e + 468c0b4 commit 3f41b05

32 files changed

+576
-471
lines changed

app/code/Magento/Checkout/Controller/Action.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,29 @@ abstract class Action extends \Magento\Framework\App\Action\Action
2929
*/
3030
protected $accountManagement;
3131

32+
/**
33+
* @var \Magento\Framework\Controller\Result\RedirectFactory
34+
*/
35+
protected $resultRedirectFactory;
36+
3237
/**
3338
* @param \Magento\Framework\App\Action\Context $context
3439
* @param \Magento\Customer\Model\Session $customerSession
3540
* @param CustomerRepositoryInterface $customerRepository
3641
* @param AccountManagementInterface $accountManagement
42+
* @param \Magento\Framework\Controller\Result\RedirectFactory $resultRedirectFactory
3743
*/
3844
public function __construct(
3945
\Magento\Framework\App\Action\Context $context,
4046
\Magento\Customer\Model\Session $customerSession,
4147
CustomerRepositoryInterface $customerRepository,
42-
AccountManagementInterface $accountManagement
48+
AccountManagementInterface $accountManagement,
49+
\Magento\Framework\Controller\Result\RedirectFactory $resultRedirectFactory
4350
) {
4451
$this->_customerSession = $customerSession;
4552
$this->customerRepository = $customerRepository;
4653
$this->accountManagement = $accountManagement;
54+
$this->resultRedirectFactory = $resultRedirectFactory;
4755
parent::__construct($context);
4856
}
4957

@@ -54,7 +62,7 @@ public function __construct(
5462
*
5563
* @param bool $redirect - stop dispatch and redirect?
5664
* @param bool $addErrors - add error messages?
57-
* @return bool
65+
* @return bool|\Magento\Framework\Controller\Result\Redirect
5866
*/
5967
protected function _preDispatchValidateCustomer($redirect = true, $addErrors = true)
6068
{
@@ -73,8 +81,8 @@ protected function _preDispatchValidateCustomer($redirect = true, $addErrors = t
7381
}
7482
}
7583
if ($redirect) {
76-
$this->_redirect('customer/account/edit');
7784
$this->_actionFlag->set('', self::FLAG_NO_DISPATCH, true);
85+
return $this->resultRedirectFactory->create()->setPath('customer/account/edit');
7886
}
7987
return false;
8088
}

app/code/Magento/Checkout/Controller/Cart.php

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
use Magento\Catalog\Controller\Product\View\ViewInterface;
99
use Magento\Checkout\Model\Cart as CustomerCart;
10+
use Magento\Framework\Store\ScopeInterface;
1011

1112
/**
1213
* Shopping cart controller
@@ -38,56 +39,62 @@ class Cart extends \Magento\Framework\App\Action\Action implements ViewInterface
3839
*/
3940
protected $cart;
4041

42+
/**
43+
* @var \Magento\Framework\Controller\Result\RedirectFactory
44+
*/
45+
protected $resultRedirectFactory;
46+
4147
/**
4248
* @param \Magento\Framework\App\Action\Context $context
4349
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
4450
* @param \Magento\Checkout\Model\Session $checkoutSession
4551
* @param \Magento\Framework\Store\StoreManagerInterface $storeManager
4652
* @param \Magento\Core\App\Action\FormKeyValidator $formKeyValidator
4753
* @param CustomerCart $cart
54+
* @param \Magento\Framework\Controller\Result\RedirectFactory $resultRedirectFactory
4855
*/
4956
public function __construct(
5057
\Magento\Framework\App\Action\Context $context,
5158
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
5259
\Magento\Checkout\Model\Session $checkoutSession,
5360
\Magento\Framework\Store\StoreManagerInterface $storeManager,
5461
\Magento\Core\App\Action\FormKeyValidator $formKeyValidator,
55-
CustomerCart $cart
62+
CustomerCart $cart,
63+
\Magento\Framework\Controller\Result\RedirectFactory $resultRedirectFactory
5664
) {
5765
$this->_formKeyValidator = $formKeyValidator;
5866
$this->_scopeConfig = $scopeConfig;
5967
$this->_checkoutSession = $checkoutSession;
6068
$this->_storeManager = $storeManager;
6169
$this->cart = $cart;
70+
$this->resultRedirectFactory = $resultRedirectFactory;
6271
parent::__construct($context);
6372
}
6473

6574
/**
6675
* Set back redirect url to response
6776
*
68-
* @return $this
77+
* @return \Magento\Framework\Controller\Result\Redirect
6978
*/
7079
protected function _goBack()
7180
{
7281
$returnUrl = $this->getRequest()->getParam('return_url');
82+
$resultRedirect = $this->resultRedirectFactory->create();
7383
if ($returnUrl && $this->_isInternalUrl($returnUrl)) {
7484
$this->messageManager->getMessages()->clear();
75-
$this->getResponse()->setRedirect($returnUrl);
76-
} elseif (!$this->_scopeConfig->getValue(
77-
'checkout/cart/redirect_to_cart',
78-
\Magento\Framework\Store\ScopeInterface::SCOPE_STORE
79-
) && !$this->getRequest()->getParam(
80-
'in_cart'
81-
) && ($backUrl = $this->_redirect->getRefererUrl())
85+
$resultRedirect->setUrl($returnUrl);
86+
} elseif (!$this->_scopeConfig->getValue('checkout/cart/redirect_to_cart', ScopeInterface::SCOPE_STORE)
87+
&& !$this->getRequest()->getParam('in_cart')
88+
&& ($backUrl = $this->_redirect->getRefererUrl())
8289
) {
83-
$this->getResponse()->setRedirect($backUrl);
90+
$resultRedirect->setUrl($backUrl);
8491
} else {
8592
if ($this->getRequest()->getActionName() == 'add' && !$this->getRequest()->getParam('in_cart')) {
8693
$this->_checkoutSession->setContinueShoppingUrl($this->_redirect->getRefererUrl());
8794
}
88-
$this->_redirect('checkout/cart');
95+
$resultRedirect->setPath('checkout/cart');
8996
}
90-
return $this;
97+
return $resultRedirect;
9198
}
9299

93100
/**

app/code/Magento/Checkout/Controller/Cart/Add.php

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class Add extends \Magento\Checkout\Controller\Cart
3030
* @param \Magento\Framework\Store\StoreManagerInterface $storeManager
3131
* @param \Magento\Core\App\Action\FormKeyValidator $formKeyValidator
3232
* @param CustomerCart $cart
33+
* @param \Magento\Framework\Controller\Result\RedirectFactory $resultRedirectFactory
3334
* @param ProductRepositoryInterface $productRepository
3435
*/
3536
public function __construct(
@@ -39,9 +40,18 @@ public function __construct(
3940
\Magento\Framework\Store\StoreManagerInterface $storeManager,
4041
\Magento\Core\App\Action\FormKeyValidator $formKeyValidator,
4142
CustomerCart $cart,
43+
\Magento\Framework\Controller\Result\RedirectFactory $resultRedirectFactory,
4244
ProductRepositoryInterface $productRepository
4345
) {
44-
parent::__construct($context, $scopeConfig, $checkoutSession, $storeManager, $formKeyValidator, $cart);
46+
parent::__construct(
47+
$context,
48+
$scopeConfig,
49+
$checkoutSession,
50+
$storeManager,
51+
$formKeyValidator,
52+
$cart,
53+
$resultRedirectFactory
54+
);
4555
$this->productRepository = $productRepository;
4656
}
4757

@@ -67,7 +77,7 @@ protected function _initProduct()
6777
/**
6878
* Add product to shopping cart action
6979
*
70-
* @return void
80+
* @return \Magento\Framework\Controller\Result\Redirect
7181
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
7282
*/
7383
public function execute()
@@ -88,8 +98,7 @@ public function execute()
8898
* Check product availability
8999
*/
90100
if (!$product) {
91-
$this->_goBack();
92-
return;
101+
return $this->_goBack();
93102
}
94103

95104
$this->cart->addProduct($product, $params);
@@ -117,7 +126,7 @@ public function execute()
117126
);
118127
$this->messageManager->addSuccess($message);
119128
}
120-
$this->_goBack();
129+
return $this->_goBack();
121130
}
122131
} catch (\Magento\Framework\Model\Exception $e) {
123132
if ($this->_checkoutSession->getUseNotice(true)) {
@@ -135,15 +144,15 @@ public function execute()
135144

136145
$url = $this->_checkoutSession->getRedirectUrl(true);
137146
if ($url) {
138-
$this->getResponse()->setRedirect($url);
147+
return $this->resultRedirectFactory->create()->setUrl($url);
139148
} else {
140149
$cartUrl = $this->_objectManager->get('Magento\Checkout\Helper\Cart')->getCartUrl();
141-
$this->getResponse()->setRedirect($this->_redirect->getRedirectUrl($cartUrl));
150+
return $this->resultRedirectFactory->create()->setUrl($this->_redirect->getRedirectUrl($cartUrl));
142151
}
143152
} catch (\Exception $e) {
144153
$this->messageManager->addException($e, __('We cannot add this item to your shopping cart'));
145154
$this->_objectManager->get('Psr\Log\LoggerInterface')->critical($e);
146-
$this->_goBack();
155+
return $this->_goBack();
147156
}
148157
}
149158
}

app/code/Magento/Checkout/Controller/Cart/Addgroup.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,16 @@
99
class Addgroup extends \Magento\Checkout\Controller\Cart
1010
{
1111
/**
12-
* @return void
12+
* @return \Magento\Framework\Controller\Result\Redirect
1313
*/
1414
public function execute()
1515
{
1616
$orderItemIds = $this->getRequest()->getParam('order_items', []);
1717
if (is_array($orderItemIds)) {
18-
$itemsCollection = $this->_objectManager->create(
19-
'Magento\Sales\Model\Order\Item'
20-
)->getCollection()->addIdFilter(
21-
$orderItemIds
22-
)->load();
18+
$itemsCollection = $this->_objectManager->create('Magento\Sales\Model\Order\Item')
19+
->getCollection()
20+
->addIdFilter($orderItemIds)
21+
->load();
2322
/* @var $itemsCollection \Magento\Sales\Model\Resource\Order\Item\Collection */
2423
foreach ($itemsCollection as $item) {
2524
try {
@@ -33,12 +32,12 @@ public function execute()
3332
} catch (\Exception $e) {
3433
$this->messageManager->addException($e, __('We cannot add this item to your shopping cart'));
3534
$this->_objectManager->get('Psr\Log\LoggerInterface')->critical($e);
36-
$this->_goBack();
35+
return $this->_goBack();
3736
}
3837
}
3938
$this->cart->save();
4039
$this->_checkoutSession->setCartWasUpdated(true);
4140
}
42-
$this->_goBack();
41+
return $this->_goBack();
4342
}
4443
}

app/code/Magento/Checkout/Controller/Cart/Configure.php

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
*/
77
namespace Magento\Checkout\Controller\Cart;
88

9+
use Magento\Framework;
10+
911
class Configure extends \Magento\Checkout\Controller\Cart
1012
{
1113
/**
@@ -20,25 +22,35 @@ class Configure extends \Magento\Checkout\Controller\Cart
2022
* @param \Magento\Framework\Store\StoreManagerInterface $storeManager
2123
* @param \Magento\Core\App\Action\FormKeyValidator $formKeyValidator
2224
* @param \Magento\Checkout\Model\Cart $cart
25+
* @param \Magento\Framework\Controller\Result\RedirectFactory $resultRedirectFactory
2326
* @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
2427
*/
2528
public function __construct(
26-
\Magento\Framework\App\Action\Context $context,
27-
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
29+
Framework\App\Action\Context $context,
30+
Framework\App\Config\ScopeConfigInterface $scopeConfig,
2831
\Magento\Checkout\Model\Session $checkoutSession,
29-
\Magento\Framework\Store\StoreManagerInterface $storeManager,
32+
Framework\Store\StoreManagerInterface $storeManager,
3033
\Magento\Core\App\Action\FormKeyValidator $formKeyValidator,
3134
\Magento\Checkout\Model\Cart $cart,
32-
\Magento\Framework\View\Result\PageFactory $resultPageFactory
35+
Framework\Controller\Result\RedirectFactory $resultRedirectFactory,
36+
Framework\View\Result\PageFactory $resultPageFactory
3337
) {
34-
parent::__construct($context, $scopeConfig, $checkoutSession, $storeManager, $formKeyValidator, $cart);
38+
parent::__construct(
39+
$context,
40+
$scopeConfig,
41+
$checkoutSession,
42+
$storeManager,
43+
$formKeyValidator,
44+
$cart,
45+
$resultRedirectFactory
46+
);
3547
$this->resultPageFactory = $resultPageFactory;
3648
}
3749

3850
/**
3951
* Action to reconfigure cart item
4052
*
41-
* @return \Magento\Framework\View\Result\Page
53+
* @return \Magento\Framework\View\Result\Page|\Magento\Framework\Controller\Result\Redirect
4254
*/
4355
public function execute()
4456
{
@@ -53,8 +65,7 @@ public function execute()
5365
try {
5466
if (!$quoteItem || $productId != $quoteItem->getProduct()->getId()) {
5567
$this->messageManager->addError(__("We can't find the quote item."));
56-
$this->_redirect('checkout/cart');
57-
return;
68+
return $this->resultRedirectFactory->create()->setPath('checkout/cart');
5869
}
5970

6071
$params = new \Magento\Framework\Object();
@@ -74,8 +85,7 @@ public function execute()
7485
} catch (\Exception $e) {
7586
$this->messageManager->addError(__('We cannot configure the product.'));
7687
$this->_objectManager->get('Psr\Log\LoggerInterface')->critical($e);
77-
$this->_goBack();
78-
return;
88+
return $this->_goBack();
7989
}
8090
}
8191
}

0 commit comments

Comments
 (0)