Skip to content

Commit fe415b2

Browse files
committed
Merge branch '2.2-develop' of github.com:magento/magento2ce into MAGETWO-75769
2 parents 6e82722 + 0839bd4 commit fe415b2

File tree

83 files changed

+4583
-676
lines changed

Some content is hidden

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

83 files changed

+4583
-676
lines changed

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

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

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

+1-1
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
}
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+
}
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)