Skip to content

Commit 5d5c3d3

Browse files
committed
MAGETWO-89990: Implement negative flow handling on backend (MAGETWO-85818)
1 parent e5a125b commit 5d5c3d3

File tree

13 files changed

+524
-50
lines changed

13 files changed

+524
-50
lines changed

app/code/Magento/Multishipping/Block/Checkout/Overview.php

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,7 @@ public function getPaymentHtml()
120120
*/
121121
public function getPayment()
122122
{
123-
if (!$this->hasData('payment')) {
124-
$payment = new \Magento\Framework\DataObject($this->getRequest()->getPost('payment'));
125-
$this->setData('payment', $payment);
126-
}
127-
return $this->_getData('payment');
123+
return $this->getCheckout()->getQuote()->getPayment();
128124
}
129125

130126
/**
@@ -309,16 +305,7 @@ public function getVirtualProductEditUrl()
309305
*/
310306
public function getVirtualItems()
311307
{
312-
$items = [];
313-
foreach ($this->getBillingAddress()->getItemsCollection() as $_item) {
314-
if ($_item->isDeleted()) {
315-
continue;
316-
}
317-
if ($_item->getProduct()->getIsVirtual() && !$_item->getParentItemId()) {
318-
$items[] = $_item;
319-
}
320-
}
321-
return $items;
308+
return $this->getBillingAddress()->getAllVisibleItems();
322309
}
323310

324311
/**

app/code/Magento/Multishipping/Block/Checkout/Success.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function __construct(
3636
*/
3737
public function getOrderIds()
3838
{
39-
$ids = $this->_session->getOrderIds(true);
39+
$ids = $this->_session->getOrderIds();
4040
if ($ids && is_array($ids)) {
4141
return $ids;
4242
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Multishipping\Block\DataProviders;
8+
9+
use Magento\Framework\Session\SessionManagerInterface;
10+
use Magento\Framework\View\Element\Block\ArgumentInterface;
11+
use Magento\Quote\Model\Quote\Address;
12+
13+
/**
14+
* Provides additional data for multishipping checkout overview step.
15+
*/
16+
class Overview implements ArgumentInterface
17+
{
18+
/**
19+
* @var SessionManagerInterface
20+
*/
21+
private $session;
22+
23+
/**
24+
* @var array
25+
*/
26+
private $addressErrors = [];
27+
28+
/**
29+
* @param SessionManagerInterface $session
30+
*/
31+
public function __construct(
32+
SessionManagerInterface $session
33+
) {
34+
$this->session = $session;
35+
}
36+
37+
/**
38+
* Returns address error.
39+
*
40+
* @param Address $address
41+
* @return string
42+
*/
43+
public function getAddressError(Address $address): string
44+
{
45+
if (empty($this->addressErrors)) {
46+
$this->addressErrors = $this->session->getAddressErrors(true);
47+
}
48+
49+
return $this->addressErrors[$address->getId()] ?? '';
50+
}
51+
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Multishipping\Block\DataProviders;
8+
9+
use Magento\Framework\Session\SessionManagerInterface;
10+
use Magento\Framework\View\Element\Block\ArgumentInterface;
11+
use Magento\Customer\Model\Address\Config as AddressConfig;
12+
use Magento\Multishipping\Model\Checkout\Type\Multishipping;
13+
use Magento\Quote\Model\Quote;
14+
use Magento\Quote\Model\Quote\Address;
15+
16+
/**
17+
* Provides additional data for multishipping checkout success step.
18+
*/
19+
class Success implements ArgumentInterface
20+
{
21+
/**
22+
* @var SessionManagerInterface
23+
*/
24+
private $session;
25+
26+
/**
27+
* @var Multishipping
28+
*/
29+
private $multishipping;
30+
31+
/**
32+
* @var AddressConfig
33+
*/
34+
private $addressConfig;
35+
36+
/**
37+
* @param SessionManagerInterface $session
38+
* @param Multishipping $multishipping
39+
* @param AddressConfig $addressConfig
40+
*/
41+
public function __construct(
42+
SessionManagerInterface $session,
43+
Multishipping $multishipping,
44+
AddressConfig $addressConfig
45+
) {
46+
$this->session = $session;
47+
$this->multishipping = $multishipping;
48+
$this->addressConfig = $addressConfig;
49+
}
50+
51+
/**
52+
* Returns shipping addresses from quote.
53+
*
54+
* @return array
55+
*/
56+
public function getShippingAddresses(): array
57+
{
58+
return $this->multishipping->getQuote()->getAllShippingAddresses();
59+
}
60+
61+
/**
62+
* Returns quote.
63+
*
64+
* @return Quote
65+
*/
66+
public function getQuote(): Quote
67+
{
68+
return $this->multishipping->getQuote();
69+
}
70+
71+
/**
72+
* Returns address error.
73+
*
74+
* @param Address $address
75+
* @return string
76+
*/
77+
public function getAddressError(Address $address): string
78+
{
79+
$errors = $this->session->getAddressErrors();
80+
81+
return $errors[$address->getId()] ?? '';
82+
}
83+
84+
/**
85+
* Get address formatted as html string.
86+
*
87+
* @param Address $address
88+
* @return string
89+
*/
90+
public function getAddressHtml(Address $address): string
91+
{
92+
$renderer = $this->addressConfig->getFormatByCode('html')->getRenderer();
93+
94+
return $renderer->renderArray($address->getData());
95+
}
96+
}

app/code/Magento/Multishipping/Controller/Checkout/Overview.php

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

9+
use Magento\Framework\Exception\LocalizedException;
910
use Magento\Multishipping\Model\Checkout\Type\Multishipping\State;
11+
use Magento\Payment\Model\Method\AbstractMethod;
12+
use Psr\Log\LoggerInterface;
1013

1114
class Overview extends \Magento\Multishipping\Controller\Checkout
1215
{
@@ -25,23 +28,24 @@ public function execute()
2528

2629
try {
2730
$payment = $this->getRequest()->getPost('payment', []);
28-
$payment['checks'] = [
29-
\Magento\Payment\Model\Method\AbstractMethod::CHECK_USE_FOR_COUNTRY,
30-
\Magento\Payment\Model\Method\AbstractMethod::CHECK_USE_FOR_CURRENCY,
31-
\Magento\Payment\Model\Method\AbstractMethod::CHECK_ORDER_TOTAL_MIN_MAX,
32-
\Magento\Payment\Model\Method\AbstractMethod::CHECK_ZERO_TOTAL,
33-
];
34-
$this->_getCheckout()->setPaymentMethod($payment);
35-
31+
if (!empty($payment)) {
32+
$payment['checks'] = [
33+
AbstractMethod::CHECK_USE_FOR_COUNTRY,
34+
AbstractMethod::CHECK_USE_FOR_CURRENCY,
35+
AbstractMethod::CHECK_ORDER_TOTAL_MIN_MAX,
36+
AbstractMethod::CHECK_ZERO_TOTAL,
37+
];
38+
$this->_getCheckout()->setPaymentMethod($payment);
39+
}
3640
$this->_getState()->setCompleteStep(State::STEP_BILLING);
3741

3842
$this->_view->loadLayout();
3943
$this->_view->renderLayout();
40-
} catch (\Magento\Framework\Exception\LocalizedException $e) {
44+
} catch (LocalizedException $e) {
4145
$this->messageManager->addError($e->getMessage());
4246
$this->_redirect('*/*/billing');
4347
} catch (\Exception $e) {
44-
$this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e);
48+
$this->_objectManager->get(LoggerInterface::class)->critical($e);
4549
$this->messageManager->addException($e, __('We cannot open the overview page.'));
4650
$this->_redirect('*/*/billing');
4751
}

app/code/Magento/Multishipping/Controller/Checkout/Success.php

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,56 @@
66
*/
77
namespace Magento\Multishipping\Controller\Checkout;
88

9+
use Magento\Framework\App\Action\Action;
10+
use Magento\Framework\App\Action\Context;
11+
use Magento\Multishipping\Model\Checkout\Type\Multishipping;
912
use Magento\Multishipping\Model\Checkout\Type\Multishipping\State;
1013

11-
class Success extends \Magento\Multishipping\Controller\Checkout
14+
/**
15+
* Multishipping checkout success controller.
16+
*/
17+
class Success extends Action
1218
{
19+
/**
20+
* @var State
21+
*/
22+
private $state;
23+
24+
/**
25+
* @var Multishipping
26+
*/
27+
private $multishipping;
28+
29+
/**
30+
* @param Context $context
31+
* @param State $state
32+
* @param Multishipping $multishipping
33+
*/
34+
public function __construct(
35+
Context $context,
36+
State $state,
37+
Multishipping $multishipping
38+
) {
39+
$this->state = $state;
40+
$this->multishipping = $multishipping;
41+
42+
parent::__construct($context);
43+
}
44+
1345
/**
1446
* Multishipping checkout success page
1547
*
1648
* @return void
1749
*/
1850
public function execute()
1951
{
20-
if (!$this->_getState()->getCompleteStep(State::STEP_OVERVIEW)) {
52+
if (!$this->state->getCompleteStep(State::STEP_OVERVIEW)) {
2153
$this->_redirect('*/*/addresses');
2254
return;
2355
}
2456

2557
$this->_view->loadLayout();
26-
$ids = $this->_getCheckout()->getOrderIds();
58+
$ids = $this->multishipping->getOrderIds();
2759
$this->_eventManager->dispatch('multishipping_checkout_controller_success_action', ['order_ids' => $ids]);
2860
$this->_view->renderLayout();
2961
}

0 commit comments

Comments
 (0)