Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit d7352dd

Browse files
author
Alexander Akimov
authored
Merge pull request #2369 from magento-tsg/2.3-develop-pr11
[TSG] Upporting for 2.3 (pr11) (2.3.0)
2 parents eab1b2d + fab2efb commit d7352dd

Some content is hidden

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

50 files changed

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

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

0 commit comments

Comments
 (0)