Skip to content

Commit

Permalink
Merge pull request #2369 from magento-tsg/2.3-develop-pr11
Browse files Browse the repository at this point in the history
[TSG] Upporting for 2.3 (pr11) (2.3.0)
  • Loading branch information
Alexander Akimov authored Apr 12, 2018
2 parents eab1b2d + fab2efb commit d7352dd
Show file tree
Hide file tree
Showing 50 changed files with 2,861 additions and 287 deletions.
21 changes: 4 additions & 17 deletions app/code/Magento/Multishipping/Block/Checkout/Overview.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,7 @@ public function getPaymentHtml()
*/
public function getPayment()
{
if (!$this->hasData('payment')) {
$payment = new \Magento\Framework\DataObject($this->getRequest()->getPost('payment'));
$this->setData('payment', $payment);
}
return $this->_getData('payment');
return $this->getCheckout()->getQuote()->getPayment();
}

/**
Expand Down Expand Up @@ -200,9 +196,9 @@ public function formatPrice($price)

/**
* @param Address $address
* @return mixed
* @return array
*/
public function getShippingAddressItems($address)
public function getShippingAddressItems($address): array
{
return $address->getAllVisibleItems();
}
Expand Down Expand Up @@ -309,16 +305,7 @@ public function getVirtualProductEditUrl()
*/
public function getVirtualItems()
{
$items = [];
foreach ($this->getBillingAddress()->getItemsCollection() as $_item) {
if ($_item->isDeleted()) {
continue;
}
if ($_item->getProduct()->getIsVirtual() && !$_item->getParentItemId()) {
$items[] = $_item;
}
}
return $items;
return $this->getBillingAddress()->getAllVisibleItems();
}

/**
Expand Down
186 changes: 186 additions & 0 deletions app/code/Magento/Multishipping/Block/Checkout/Results.php
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();
}
}
2 changes: 1 addition & 1 deletion app/code/Magento/Multishipping/Block/Checkout/Success.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function __construct(
*/
public function getOrderIds()
{
$ids = $this->_session->getOrderIds(true);
$ids = $this->_session->getOrderIds();
if ($ids && is_array($ids)) {
return $ids;
}
Expand Down
76 changes: 76 additions & 0 deletions app/code/Magento/Multishipping/Block/DataProviders/Billing.php
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 app/code/Magento/Multishipping/Block/DataProviders/Overview.php
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;
}
}
Loading

0 comments on commit d7352dd

Please sign in to comment.