Skip to content

Commit 1c09381

Browse files
committed
Merge branch 'MAGETWO-84587' into MPI-PR
2 parents 6bc1f18 + 4b5439f commit 1c09381

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+2792
-282
lines changed

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

Lines changed: 4 additions & 17 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
/**
@@ -200,9 +196,9 @@ public function formatPrice($price)
200196

201197
/**
202198
* @param Address $address
203-
* @return mixed
199+
* @return array
204200
*/
205-
public function getShippingAddressItems($address)
201+
public function getShippingAddressItems($address): array
206202
{
207203
return $address->getAllVisibleItems();
208204
}
@@ -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
/**
Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Multishipping\Block\Checkout;
7+
8+
use Magento\Framework\Exception\LocalizedException;
9+
use Magento\Framework\View\Element\Template\Context;
10+
use Magento\Multishipping\Model\Checkout\Type\Multishipping;
11+
use Magento\Sales\Api\OrderRepositoryInterface;
12+
use Magento\Customer\Model\Address\Config as AddressConfig;
13+
use Magento\Quote\Model\Quote\Address as QuoteAddress;
14+
use Magento\Sales\Model\Order\Address as OrderAddress;
15+
use Magento\Framework\Session\SessionManagerInterface;
16+
17+
/**
18+
* Multi-shipping checkout results information
19+
*
20+
* @api
21+
*/
22+
class Results extends Success
23+
{
24+
/**
25+
* @var AddressConfig
26+
*/
27+
private $addressConfig;
28+
29+
/**
30+
* @var OrderRepositoryInterface
31+
*/
32+
private $orderRepository;
33+
34+
/**
35+
* @var SessionManagerInterface
36+
*/
37+
private $session;
38+
39+
/**
40+
* @var Multishipping
41+
*/
42+
private $multishipping;
43+
44+
/**
45+
* @param Context $context
46+
* @param Multishipping $multishipping
47+
* @param AddressConfig $addressConfig
48+
* @param OrderRepositoryInterface $orderRepository
49+
* @param SessionManagerInterface $session
50+
* @param array $data
51+
*/
52+
public function __construct(
53+
Context $context,
54+
Multishipping $multishipping,
55+
AddressConfig $addressConfig,
56+
OrderRepositoryInterface $orderRepository,
57+
SessionManagerInterface $session,
58+
array $data = []
59+
) {
60+
parent::__construct($context, $multishipping, $data);
61+
62+
$this->multishipping = $multishipping;
63+
$this->addressConfig = $addressConfig;
64+
$this->orderRepository = $orderRepository;
65+
$this->session = $session;
66+
}
67+
68+
/**
69+
* Returns shipping addresses from quote.
70+
*
71+
* @return array
72+
*/
73+
public function getQuoteShippingAddresses(): array
74+
{
75+
return $this->multishipping->getQuote()->getAllShippingAddresses();
76+
}
77+
78+
/**
79+
* Returns all failed addresses from quote.
80+
*
81+
* @return array
82+
*/
83+
public function getFailedAddresses(): array
84+
{
85+
$addresses = $this->getQuoteShippingAddresses();
86+
if ($this->getAddressError($this->getQuoteBillingAddress())) {
87+
$addresses[] = $this->getQuoteBillingAddress();
88+
}
89+
return $addresses;
90+
}
91+
92+
/**
93+
* Retrieve order shipping address.
94+
*
95+
* @param int $orderId
96+
* @return OrderAddress|null
97+
*/
98+
public function getOrderShippingAddress(int $orderId)
99+
{
100+
return $this->orderRepository->get($orderId)->getShippingAddress();
101+
}
102+
103+
/**
104+
* Retrieve quote billing address.
105+
*
106+
* @return QuoteAddress
107+
*/
108+
public function getQuoteBillingAddress(): QuoteAddress
109+
{
110+
return $this->getCheckout()->getQuote()->getBillingAddress();
111+
}
112+
113+
/**
114+
* Returns formatted shipping address from placed order.
115+
*
116+
* @param OrderAddress $address
117+
* @return string
118+
*/
119+
public function formatOrderShippingAddress(OrderAddress $address): string
120+
{
121+
return $this->getAddressOneline($address->getData());
122+
}
123+
124+
/**
125+
* Returns formatted shipping address from quote.
126+
*
127+
* @param QuoteAddress $address
128+
* @return string
129+
*/
130+
public function formatQuoteShippingAddress(QuoteAddress $address): string
131+
{
132+
return $this->getAddressOneline($address->getData());
133+
}
134+
135+
/**
136+
* Checks if address type is shipping.
137+
*
138+
* @param QuoteAddress $address
139+
* @return bool
140+
*/
141+
public function isShippingAddress(QuoteAddress $address): bool
142+
{
143+
return $address->getAddressType() === QuoteAddress::ADDRESS_TYPE_SHIPPING;
144+
}
145+
146+
/**
147+
* Get unescaped address formatted as one line string.
148+
*
149+
* @param array $address
150+
* @return string
151+
*/
152+
private function getAddressOneline(array $address): string
153+
{
154+
$renderer = $this->addressConfig->getFormatByCode('oneline')->getRenderer();
155+
156+
return $renderer->renderArray($address);
157+
}
158+
159+
/**
160+
* Returns address error.
161+
*
162+
* @param QuoteAddress $address
163+
* @return string
164+
*/
165+
public function getAddressError(QuoteAddress $address): string
166+
{
167+
$errors = $this->session->getAddressErrors();
168+
169+
return $errors[$address->getId()] ?? '';
170+
}
171+
172+
/**
173+
* Add title to block head.
174+
*
175+
* @throws LocalizedException
176+
* @return Success
177+
*/
178+
protected function _prepareLayout(): Success
179+
{
180+
$pageTitle = $this->getLayout()->getBlock('page.main.title');
181+
if ($pageTitle) {
182+
$title = $this->getOrderIds() ? $pageTitle->getPartlySuccessTitle() : $pageTitle->getFailedTitle();
183+
$pageTitle->setPageTitle($title);
184+
}
185+
186+
return parent::_prepareLayout();
187+
}
188+
}

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: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Multishipping\Block\DataProviders;
7+
8+
use Magento\Framework\View\Element\Block\ArgumentInterface;
9+
use Magento\Checkout\Model\CompositeConfigProvider;
10+
use Magento\Customer\Model\Address\Config as AddressConfig;
11+
use Magento\Framework\Serialize\Serializer\Json as Serializer;
12+
use Magento\Quote\Model\Quote\Address;
13+
14+
/**
15+
* Provides additional data for multishipping checkout billing step
16+
*
17+
* @see \Magento\Multishipping\view\frontend\templates\checkout\billing.phtml
18+
*/
19+
class Billing implements ArgumentInterface
20+
{
21+
/**
22+
* @var AddressConfig
23+
*/
24+
private $addressConfig;
25+
26+
/**
27+
* @var CompositeConfigProvider
28+
*/
29+
private $configProvider;
30+
31+
/**
32+
* @var Serializer
33+
*/
34+
private $serializer;
35+
36+
/**
37+
* @param AddressConfig $addressConfig
38+
* @param CompositeConfigProvider $configProvider
39+
* @param Serializer $serializer
40+
*/
41+
public function __construct(
42+
AddressConfig $addressConfig,
43+
CompositeConfigProvider $configProvider,
44+
Serializer $serializer
45+
) {
46+
$this->addressConfig = $addressConfig;
47+
$this->configProvider = $configProvider;
48+
$this->serializer = $serializer;
49+
}
50+
51+
/**
52+
* Get address formatted as html string.
53+
*
54+
* @param Address $address
55+
* @return string
56+
*/
57+
public function getAddressHtml(Address $address): string
58+
{
59+
$renderer = $this->addressConfig->getFormatByCode('html')->getRenderer();
60+
61+
return $renderer->renderArray($address->getData());
62+
}
63+
64+
/**
65+
* Returns serialized checkout config.
66+
*
67+
* @return string
68+
* @throws \InvalidArgumentException
69+
*/
70+
public function getSerializedCheckoutConfigs(): string
71+
{
72+
return $this->serializer->serialize($this->configProvider->getConfig());
73+
}
74+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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+
$addressErrors = $this->getAddressErrors();
46+
47+
return $addressErrors[$address->getId()] ?? '';
48+
}
49+
50+
/**
51+
* Returns all stored errors.
52+
*
53+
* @return array
54+
*/
55+
public function getAddressErrors(): array
56+
{
57+
if (empty($this->addressErrors)) {
58+
$this->addressErrors = $this->session->getAddressErrors(true);
59+
}
60+
61+
return $this->addressErrors ?? [];
62+
}
63+
64+
/**
65+
* Creates anchor name for address Id.
66+
*
67+
* @param int $addressId
68+
* @return string
69+
*/
70+
public function getAddressAnchorName(int $addressId): string
71+
{
72+
return 'a' . $addressId;
73+
}
74+
}

0 commit comments

Comments
 (0)