forked from magento/magento2
-
Notifications
You must be signed in to change notification settings - Fork 0
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 magento#3524 from magento-panda/MAGETWO-94346
Fixed issues: - MAGETWO-95249: [Part 1] Implement handling of large number of addresses on admin edit customer page - MAGETWO-96212: [Part 2] Implement handling of large number of addresses on admin edit customer page - MAGETWO-96906: [MAGETWO-94346] PR stabilization
- Loading branch information
Showing
87 changed files
with
6,266 additions
and
1,236 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
42 changes: 42 additions & 0 deletions
42
app/code/Magento/Customer/Block/Adminhtml/Edit/Address/CancelButton.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,42 @@ | ||
<?php | ||
declare(strict_types=1); | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Customer\Block\Adminhtml\Edit\Address; | ||
|
||
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface; | ||
use Magento\Customer\Block\Adminhtml\Edit\GenericButton; | ||
|
||
/** | ||
* Class CancelButton | ||
*/ | ||
class CancelButton extends GenericButton implements ButtonProviderInterface | ||
{ | ||
/** | ||
* @inheritdoc | ||
* | ||
* @return array | ||
*/ | ||
public function getButtonData() | ||
{ | ||
return [ | ||
'label' => __('Cancel'), | ||
'on_click' => '', | ||
'data_attribute' => [ | ||
'mage-init' => [ | ||
'Magento_Ui/js/form/button-adapter' => [ | ||
'actions' => [ | ||
[ | ||
'targetName' => 'customer_form.areas.address.address.customer_address_update_modal', | ||
'actionName' => 'closeModal' | ||
], | ||
], | ||
], | ||
], | ||
], | ||
'sort_order' => 20 | ||
]; | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
app/code/Magento/Customer/Block/Adminhtml/Edit/Address/DeleteButton.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,65 @@ | ||
<?php | ||
declare(strict_types=1); | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Customer\Block\Adminhtml\Edit\Address; | ||
|
||
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface; | ||
use Magento\Customer\Ui\Component\Listing\Address\Column\Actions; | ||
|
||
/** | ||
* Delete button on edit customer address form | ||
*/ | ||
class DeleteButton extends GenericButton implements ButtonProviderInterface | ||
{ | ||
/** | ||
* Get delete button data. | ||
* | ||
* @return array | ||
* @throws \Magento\Framework\Exception\LocalizedException | ||
*/ | ||
public function getButtonData() | ||
{ | ||
$data = []; | ||
if ($this->getAddressId()) { | ||
$data = [ | ||
'label' => __('Delete'), | ||
'on_click' => '', | ||
'data_attribute' => [ | ||
'mage-init' => [ | ||
'Magento_Ui/js/form/button-adapter' => [ | ||
'actions' => [ | ||
[ | ||
'targetName' => 'customer_address_form.customer_address_form', | ||
'actionName' => 'deleteAddress', | ||
'params' => [ | ||
$this->getDeleteUrl(), | ||
], | ||
|
||
] | ||
], | ||
], | ||
], | ||
], | ||
'sort_order' => 20 | ||
]; | ||
} | ||
return $data; | ||
} | ||
|
||
/** | ||
* Get delete button url. | ||
* | ||
* @return string | ||
* @throws \Magento\Framework\Exception\LocalizedException | ||
*/ | ||
private function getDeleteUrl(): string | ||
{ | ||
return $this->getUrl( | ||
Actions::CUSTOMER_ADDRESS_PATH_DELETE, | ||
['parent_id' => $this->getCustomerId(), 'id' => $this->getAddressId()] | ||
); | ||
} | ||
} |
110 changes: 110 additions & 0 deletions
110
app/code/Magento/Customer/Block/Adminhtml/Edit/Address/GenericButton.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,110 @@ | ||
<?php | ||
declare(strict_types=1); | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Customer\Block\Adminhtml\Edit\Address; | ||
|
||
use Magento\Customer\Model\AddressFactory; | ||
use Magento\Framework\App\RequestInterface; | ||
use Magento\Framework\UrlInterface; | ||
use Magento\Customer\Model\ResourceModel\Address; | ||
use Magento\Customer\Model\ResourceModel\AddressRepository; | ||
|
||
/** | ||
* Class for common code for buttons on the create/edit address form | ||
*/ | ||
class GenericButton | ||
{ | ||
/** | ||
* @var AddressFactory | ||
*/ | ||
private $addressFactory; | ||
|
||
/** | ||
* @var UrlInterface | ||
*/ | ||
private $urlBuilder; | ||
|
||
/** | ||
* @var Address | ||
*/ | ||
private $addressResourceModel; | ||
|
||
/** | ||
* @var RequestInterface | ||
*/ | ||
private $request; | ||
|
||
/** | ||
* @var AddressRepository | ||
*/ | ||
private $addressRepository; | ||
|
||
/** | ||
* @param AddressFactory $addressFactory | ||
* @param UrlInterface $urlBuilder | ||
* @param Address $addressResourceModel | ||
* @param RequestInterface $request | ||
* @param AddressRepository $addressRepository | ||
*/ | ||
public function __construct( | ||
AddressFactory $addressFactory, | ||
UrlInterface $urlBuilder, | ||
Address $addressResourceModel, | ||
RequestInterface $request, | ||
AddressRepository $addressRepository | ||
) { | ||
$this->addressFactory = $addressFactory; | ||
$this->urlBuilder = $urlBuilder; | ||
$this->addressResourceModel = $addressResourceModel; | ||
$this->request = $request; | ||
$this->addressRepository = $addressRepository; | ||
} | ||
|
||
/** | ||
* Return address Id. | ||
* | ||
* @return int|null | ||
*/ | ||
public function getAddressId() | ||
{ | ||
$address = $this->addressFactory->create(); | ||
|
||
$entityId = $this->request->getParam('entity_id'); | ||
$this->addressResourceModel->load( | ||
$address, | ||
$entityId | ||
); | ||
|
||
return $address->getEntityId() ?: null; | ||
} | ||
|
||
/** | ||
* Get customer id. | ||
* | ||
* @return int|null | ||
* @throws \Magento\Framework\Exception\LocalizedException | ||
*/ | ||
public function getCustomerId() | ||
{ | ||
$addressId = $this->request->getParam('entity_id'); | ||
|
||
$address = $this->addressRepository->getById($addressId); | ||
|
||
return $address->getCustomerId() ?: null; | ||
} | ||
|
||
/** | ||
* Generate url by route and parameters | ||
* | ||
* @param string $route | ||
* @param array $params | ||
* @return string | ||
*/ | ||
public function getUrl($route = '', array $params = []): string | ||
{ | ||
return $this->urlBuilder->getUrl($route, $params); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
app/code/Magento/Customer/Block/Adminhtml/Edit/Address/SaveButton.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,34 @@ | ||
<?php | ||
declare(strict_types=1); | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Customer\Block\Adminhtml\Edit\Address; | ||
|
||
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface; | ||
use Magento\Customer\Block\Adminhtml\Edit\GenericButton; | ||
|
||
/** | ||
* Class SaveButton | ||
*/ | ||
class SaveButton extends GenericButton implements ButtonProviderInterface | ||
{ | ||
/** | ||
* @inheritdoc | ||
* | ||
* @return array | ||
*/ | ||
public function getButtonData() | ||
{ | ||
return [ | ||
'label' => __('Save'), | ||
'class' => 'save primary', | ||
'data_attribute' => [ | ||
'mage-init' => ['button' => ['event' => 'save']], | ||
'form-role' => 'save', | ||
], | ||
'sort_order' => 10 | ||
]; | ||
} | ||
} |
109 changes: 109 additions & 0 deletions
109
app/code/Magento/Customer/Controller/Adminhtml/Address/DefaultBillingAddress.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,109 @@ | ||
<?php | ||
declare(strict_types=1); | ||
/** | ||
* | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
namespace Magento\Customer\Controller\Adminhtml\Address; | ||
|
||
use Magento\Backend\App\Action; | ||
use Magento\Customer\Api\Data\AddressInterface; | ||
use Magento\Customer\Api\AddressRepositoryInterface; | ||
use Magento\Framework\App\Action\HttpPostActionInterface; | ||
use Magento\Framework\Controller\Result\Json; | ||
use Magento\Framework\Controller\Result\JsonFactory; | ||
use Psr\Log\LoggerInterface; | ||
|
||
/** | ||
* Class to process set default billing address action | ||
*/ | ||
class DefaultBillingAddress extends Action implements HttpPostActionInterface | ||
{ | ||
/** | ||
* Authorization level of a basic admin session | ||
* | ||
* @see _isAllowed() | ||
*/ | ||
public const ADMIN_RESOURCE = 'Magento_Customer::manage'; | ||
|
||
/** | ||
* @var AddressRepositoryInterface | ||
*/ | ||
private $addressRepository; | ||
|
||
/** | ||
* @var LoggerInterface | ||
*/ | ||
private $logger; | ||
|
||
/** | ||
* @var JsonFactory | ||
*/ | ||
private $resultJsonFactory; | ||
|
||
/** | ||
* @param Action\Context $context | ||
* @param AddressRepositoryInterface $addressRepository | ||
* @param LoggerInterface $logger | ||
* @param JsonFactory $resultJsonFactory | ||
*/ | ||
public function __construct( | ||
Action\Context $context, | ||
AddressRepositoryInterface $addressRepository, | ||
LoggerInterface $logger, | ||
JsonFactory $resultJsonFactory | ||
) { | ||
parent::__construct($context); | ||
$this->addressRepository = $addressRepository; | ||
$this->logger = $logger; | ||
$this->resultJsonFactory = $resultJsonFactory; | ||
} | ||
|
||
/** | ||
* Execute action to set customer default billing address | ||
* | ||
* @return Json | ||
*/ | ||
public function execute(): Json | ||
{ | ||
$customerId = $this->getRequest()->getParam('parent_id', false); | ||
$addressId = $this->getRequest()->getParam('id', false); | ||
$error = true; | ||
$message = __('There is no address id in setting default billing address.'); | ||
|
||
if ($addressId) { | ||
try { | ||
$address = $this->addressRepository->getById($addressId)->setCustomerId($customerId); | ||
$this->setAddressAsDefault($address); | ||
$this->addressRepository->save($address); | ||
$message = __('Default billing address has been changed.'); | ||
$error = false; | ||
} catch (\Exception $e) { | ||
$message = __('We can\'t change default billing address right now.'); | ||
$this->logger->critical($e); | ||
} | ||
} | ||
|
||
$resultJson = $this->resultJsonFactory->create(); | ||
$resultJson->setData( | ||
[ | ||
'message' => $message, | ||
'error' => $error, | ||
] | ||
); | ||
|
||
return $resultJson; | ||
} | ||
|
||
/** | ||
* Set address as default billing address | ||
* | ||
* @param AddressInterface $address | ||
* @return void | ||
*/ | ||
private function setAddressAsDefault(AddressInterface $address): void | ||
{ | ||
$address->setIsDefaultBilling(true); | ||
} | ||
} |
Oops, something went wrong.