-
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 #3538 from magento-performance/MAGETWO-97151
Fixed issues: - MAGETWO-97151 [Backport][MC-5683] Implement handling of large number of addresses on admin order creation page
- Loading branch information
Showing
7 changed files
with
219 additions
and
12 deletions.
There are no files selected for viewing
131 changes: 131 additions & 0 deletions
131
app/code/Magento/Sales/ViewModel/Customer/AddressFormatter.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,131 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\Sales\ViewModel\Customer; | ||
|
||
use Magento\Framework\View\Element\Block\ArgumentInterface; | ||
|
||
/** | ||
* Customer address formatter | ||
*/ | ||
class AddressFormatter implements ArgumentInterface | ||
{ | ||
/** | ||
* Customer form factory | ||
* | ||
* @var \Magento\Customer\Model\Metadata\FormFactory | ||
*/ | ||
private $customerFormFactory; | ||
|
||
/** | ||
* Address format helper | ||
* | ||
* @var \Magento\Customer\Helper\Address | ||
*/ | ||
private $addressFormatHelper; | ||
|
||
/** | ||
* Directory helper | ||
* | ||
* @var \Magento\Directory\Helper\Data | ||
*/ | ||
private $directoryHelper; | ||
|
||
/** | ||
* Session quote | ||
* | ||
* @var \Magento\Backend\Model\Session\Quote | ||
*/ | ||
private $session; | ||
|
||
/** | ||
* Json encoder | ||
* | ||
* @var \Magento\Framework\Serialize\Serializer\Json | ||
*/ | ||
private $jsonEncoder; | ||
|
||
/** | ||
* Customer address | ||
* | ||
* @param \Magento\Customer\Model\Metadata\FormFactory $customerFormFactory | ||
* @param \Magento\Customer\Helper\Address $addressFormatHelper | ||
* @param \Magento\Directory\Helper\Data $directoryHelper | ||
* @param \Magento\Backend\Model\Session\Quote $session | ||
* @param \Magento\Framework\Serialize\Serializer\Json $jsonEncoder | ||
*/ | ||
public function __construct( | ||
\Magento\Customer\Model\Metadata\FormFactory $customerFormFactory, | ||
\Magento\Customer\Helper\Address $addressFormatHelper, | ||
\Magento\Directory\Helper\Data $directoryHelper, | ||
\Magento\Backend\Model\Session\Quote $session, | ||
\Magento\Framework\Serialize\Serializer\Json $jsonEncoder | ||
) { | ||
$this->customerFormFactory = $customerFormFactory; | ||
$this->addressFormatHelper = $addressFormatHelper; | ||
$this->directoryHelper = $directoryHelper; | ||
$this->session = $session; | ||
$this->jsonEncoder = $jsonEncoder; | ||
} | ||
|
||
/** | ||
* Return customer address array as JSON | ||
* | ||
* @param array $addressArray | ||
* | ||
* @return string | ||
*/ | ||
public function getAddressesJson(array $addressArray) | ||
{ | ||
$data = $this->getEmptyAddressForm(); | ||
foreach ($addressArray as $addressId => $address) { | ||
$addressForm = $this->customerFormFactory->create( | ||
'customer_address', | ||
'adminhtml_customer_address', | ||
$address | ||
); | ||
$data[$addressId] = $addressForm->outputData( | ||
\Magento\Eav\Model\AttributeDataFactory::OUTPUT_FORMAT_JSON | ||
); | ||
} | ||
|
||
return $this->jsonEncoder->serialize($data); | ||
} | ||
|
||
/** | ||
* Represent customer address in 'online' format. | ||
* | ||
* @param array $address | ||
* @return string | ||
*/ | ||
public function getAddressAsString(array $address) | ||
{ | ||
$formatTypeRenderer = $this->addressFormatHelper->getFormatTypeRenderer('oneline'); | ||
$result = ''; | ||
if ($formatTypeRenderer) { | ||
$result = $formatTypeRenderer->renderArray($address); | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
/** | ||
* Return empty address address form | ||
* | ||
* @return array | ||
*/ | ||
private function getEmptyAddressForm() | ||
{ | ||
$defaultCountryId = $this->directoryHelper->getDefaultCountry($this->session->getStore()); | ||
$emptyAddressForm = $this->customerFormFactory->create( | ||
'customer_address', | ||
'adminhtml_customer_address', | ||
[\Magento\Customer\Api\Data\AddressInterface::COUNTRY_ID => $defaultCountryId] | ||
); | ||
|
||
return [0 => $emptyAddressForm->outputData(\Magento\Eav\Model\AttributeDataFactory::OUTPUT_FORMAT_JSON)]; | ||
} | ||
} |
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
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
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
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
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
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