-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2369 from magento-tsg/2.3-develop-pr11
[TSG] Upporting for 2.3 (pr11) (2.3.0)
- Loading branch information
Showing
50 changed files
with
2,861 additions
and
287 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
186 changes: 186 additions & 0 deletions
186
app/code/Magento/Multishipping/Block/Checkout/Results.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,186 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\Multishipping\Block\Checkout; | ||
|
||
use Magento\Customer\Model\Address\Config as AddressConfig; | ||
use Magento\Framework\Exception\LocalizedException; | ||
use Magento\Framework\Session\SessionManagerInterface; | ||
use Magento\Framework\View\Element\Template\Context; | ||
use Magento\Multishipping\Model\Checkout\Type\Multishipping; | ||
use Magento\Quote\Model\Quote\Address as QuoteAddress; | ||
use Magento\Sales\Api\OrderRepositoryInterface; | ||
use Magento\Sales\Model\Order\Address as OrderAddress; | ||
use Magento\Theme\Block\Html\Title; | ||
|
||
/** | ||
* Multi-shipping checkout results information | ||
* | ||
* @api | ||
*/ | ||
class Results extends Success | ||
{ | ||
/** | ||
* @var AddressConfig | ||
*/ | ||
private $addressConfig; | ||
|
||
/** | ||
* @var OrderRepositoryInterface | ||
*/ | ||
private $orderRepository; | ||
|
||
/** | ||
* @var SessionManagerInterface | ||
*/ | ||
private $session; | ||
|
||
/** | ||
* @param Context $context | ||
* @param Multishipping $multishipping | ||
* @param AddressConfig $addressConfig | ||
* @param OrderRepositoryInterface $orderRepository | ||
* @param SessionManagerInterface $session | ||
* @param array $data | ||
*/ | ||
public function __construct( | ||
Context $context, | ||
Multishipping $multishipping, | ||
AddressConfig $addressConfig, | ||
OrderRepositoryInterface $orderRepository, | ||
SessionManagerInterface $session, | ||
array $data = [] | ||
) { | ||
parent::__construct($context, $multishipping, $data); | ||
|
||
$this->addressConfig = $addressConfig; | ||
$this->orderRepository = $orderRepository; | ||
$this->session = $session; | ||
} | ||
|
||
/** | ||
* Returns shipping addresses from quote. | ||
* | ||
* @return array | ||
*/ | ||
public function getQuoteShippingAddresses(): array | ||
{ | ||
return $this->_multishipping->getQuote()->getAllShippingAddresses(); | ||
} | ||
|
||
/** | ||
* Returns all failed addresses from quote. | ||
* | ||
* @return array | ||
*/ | ||
public function getFailedAddresses(): array | ||
{ | ||
$addresses = $this->getQuoteShippingAddresses(); | ||
if ($this->getAddressError($this->getQuoteBillingAddress())) { | ||
$addresses[] = $this->getQuoteBillingAddress(); | ||
} | ||
return $addresses; | ||
} | ||
|
||
/** | ||
* Retrieve order shipping address. | ||
* | ||
* @param int $orderId | ||
* @return OrderAddress|null | ||
*/ | ||
public function getOrderShippingAddress(int $orderId) | ||
{ | ||
return $this->orderRepository->get($orderId)->getShippingAddress(); | ||
} | ||
|
||
/** | ||
* Retrieve quote billing address. | ||
* | ||
* @return QuoteAddress | ||
*/ | ||
public function getQuoteBillingAddress(): QuoteAddress | ||
{ | ||
return $this->getCheckout()->getQuote()->getBillingAddress(); | ||
} | ||
|
||
/** | ||
* Returns formatted shipping address from placed order. | ||
* | ||
* @param OrderAddress $address | ||
* @return string | ||
*/ | ||
public function formatOrderShippingAddress(OrderAddress $address): string | ||
{ | ||
return $this->getAddressOneline($address->getData()); | ||
} | ||
|
||
/** | ||
* Returns formatted shipping address from quote. | ||
* | ||
* @param QuoteAddress $address | ||
* @return string | ||
*/ | ||
public function formatQuoteShippingAddress(QuoteAddress $address): string | ||
{ | ||
return $this->getAddressOneline($address->getData()); | ||
} | ||
|
||
/** | ||
* Checks if address type is shipping. | ||
* | ||
* @param QuoteAddress $address | ||
* @return bool | ||
*/ | ||
public function isShippingAddress(QuoteAddress $address): bool | ||
{ | ||
return $address->getAddressType() === QuoteAddress::ADDRESS_TYPE_SHIPPING; | ||
} | ||
|
||
/** | ||
* Get unescaped address formatted as one line string. | ||
* | ||
* @param array $address | ||
* @return string | ||
*/ | ||
private function getAddressOneline(array $address): string | ||
{ | ||
$renderer = $this->addressConfig->getFormatByCode('oneline')->getRenderer(); | ||
|
||
return $renderer->renderArray($address); | ||
} | ||
|
||
/** | ||
* Returns address error. | ||
* | ||
* @param QuoteAddress $address | ||
* @return string | ||
*/ | ||
public function getAddressError(QuoteAddress $address): string | ||
{ | ||
$errors = $this->session->getAddressErrors(); | ||
|
||
return $errors[$address->getId()] ?? ''; | ||
} | ||
|
||
/** | ||
* Add title to block head. | ||
* | ||
* @throws LocalizedException | ||
* @return Success | ||
*/ | ||
protected function _prepareLayout(): Success | ||
{ | ||
/** @var Title $pageTitle */ | ||
$pageTitle = $this->getLayout()->getBlock('page.main.title'); | ||
if ($pageTitle) { | ||
$title = $this->getOrderIds() ? $pageTitle->getPartlySuccessTitle() : $pageTitle->getFailedTitle(); | ||
$pageTitle->setPageTitle($title); | ||
} | ||
|
||
return parent::_prepareLayout(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
app/code/Magento/Multishipping/Block/DataProviders/Billing.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\Multishipping\Block\DataProviders; | ||
|
||
use Magento\Framework\View\Element\Block\ArgumentInterface; | ||
use Magento\Checkout\Model\CompositeConfigProvider; | ||
use Magento\Customer\Model\Address\Config as AddressConfig; | ||
use Magento\Framework\Serialize\Serializer\Json as Serializer; | ||
use Magento\Quote\Model\Quote\Address; | ||
|
||
/** | ||
* Provides additional data for multishipping checkout billing step | ||
* | ||
* @see \Magento\Multishipping\view\frontend\templates\checkout\billing.phtml | ||
*/ | ||
class Billing implements ArgumentInterface | ||
{ | ||
/** | ||
* @var AddressConfig | ||
*/ | ||
private $addressConfig; | ||
|
||
/** | ||
* @var CompositeConfigProvider | ||
*/ | ||
private $configProvider; | ||
|
||
/** | ||
* @var Serializer | ||
*/ | ||
private $serializer; | ||
|
||
/** | ||
* @param AddressConfig $addressConfig | ||
* @param CompositeConfigProvider $configProvider | ||
* @param Serializer $serializer | ||
*/ | ||
public function __construct( | ||
AddressConfig $addressConfig, | ||
CompositeConfigProvider $configProvider, | ||
Serializer $serializer | ||
) { | ||
$this->addressConfig = $addressConfig; | ||
$this->configProvider = $configProvider; | ||
$this->serializer = $serializer; | ||
} | ||
|
||
/** | ||
* Get address formatted as html string. | ||
* | ||
* @param Address $address | ||
* @return string | ||
*/ | ||
public function getAddressHtml(Address $address): string | ||
{ | ||
$renderer = $this->addressConfig->getFormatByCode('html')->getRenderer(); | ||
|
||
return $renderer->renderArray($address->getData()); | ||
} | ||
|
||
/** | ||
* Returns serialized checkout config. | ||
* | ||
* @return string | ||
* @throws \InvalidArgumentException | ||
*/ | ||
public function getSerializedCheckoutConfigs(): string | ||
{ | ||
return $this->serializer->serialize($this->configProvider->getConfig()); | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
app/code/Magento/Multishipping/Block/DataProviders/Overview.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\Multishipping\Block\DataProviders; | ||
|
||
use Magento\Framework\Session\SessionManagerInterface; | ||
use Magento\Framework\View\Element\Block\ArgumentInterface; | ||
use Magento\Quote\Model\Quote\Address; | ||
|
||
/** | ||
* Provides additional data for multishipping checkout overview step. | ||
*/ | ||
class Overview implements ArgumentInterface | ||
{ | ||
/** | ||
* @var SessionManagerInterface | ||
*/ | ||
private $session; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private $addressErrors = []; | ||
|
||
/** | ||
* @param SessionManagerInterface $session | ||
*/ | ||
public function __construct( | ||
SessionManagerInterface $session | ||
) { | ||
$this->session = $session; | ||
} | ||
|
||
/** | ||
* Returns address error. | ||
* | ||
* @param Address $address | ||
* @return string | ||
*/ | ||
public function getAddressError(Address $address): string | ||
{ | ||
$addressErrors = $this->getAddressErrors(); | ||
|
||
return $addressErrors[$address->getId()] ?? ''; | ||
} | ||
|
||
/** | ||
* Returns all stored errors. | ||
* | ||
* @return array | ||
*/ | ||
public function getAddressErrors(): array | ||
{ | ||
if (empty($this->addressErrors)) { | ||
$this->addressErrors = $this->session->getAddressErrors(true); | ||
} | ||
|
||
return $this->addressErrors ?? []; | ||
} | ||
|
||
/** | ||
* Creates anchor name for address Id. | ||
* | ||
* @param int $addressId | ||
* @return string | ||
*/ | ||
public function getAddressAnchorName(int $addressId): string | ||
{ | ||
return 'a' . $addressId; | ||
} | ||
} |
Oops, something went wrong.