Skip to content

Commit b8892f0

Browse files
authored
Merge pull request #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
2 parents 5f89b03 + 020dd1c commit b8892f0

File tree

87 files changed

+6266
-1236
lines changed

Some content is hidden

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

87 files changed

+6266
-1236
lines changed

app/code/Magento/Braintree/Test/Mftf/Data/NewCustomerData.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<data key="City">Yerevan</data>
1919
<data key="Zip">9999</data>
2020
<data key="PhoneNumber">9999</data>
21+
<data key="Country">Armenia</data>
2122
</entity>
2223

2324
</entities>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
declare(strict_types=1);
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
namespace Magento\Customer\Block\Adminhtml\Edit\Address;
8+
9+
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
10+
use Magento\Customer\Block\Adminhtml\Edit\GenericButton;
11+
12+
/**
13+
* Class CancelButton
14+
*/
15+
class CancelButton extends GenericButton implements ButtonProviderInterface
16+
{
17+
/**
18+
* @inheritdoc
19+
*
20+
* @return array
21+
*/
22+
public function getButtonData()
23+
{
24+
return [
25+
'label' => __('Cancel'),
26+
'on_click' => '',
27+
'data_attribute' => [
28+
'mage-init' => [
29+
'Magento_Ui/js/form/button-adapter' => [
30+
'actions' => [
31+
[
32+
'targetName' => 'customer_form.areas.address.address.customer_address_update_modal',
33+
'actionName' => 'closeModal'
34+
],
35+
],
36+
],
37+
],
38+
],
39+
'sort_order' => 20
40+
];
41+
}
42+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
declare(strict_types=1);
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
namespace Magento\Customer\Block\Adminhtml\Edit\Address;
8+
9+
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
10+
use Magento\Customer\Ui\Component\Listing\Address\Column\Actions;
11+
12+
/**
13+
* Delete button on edit customer address form
14+
*/
15+
class DeleteButton extends GenericButton implements ButtonProviderInterface
16+
{
17+
/**
18+
* Get delete button data.
19+
*
20+
* @return array
21+
* @throws \Magento\Framework\Exception\LocalizedException
22+
*/
23+
public function getButtonData()
24+
{
25+
$data = [];
26+
if ($this->getAddressId()) {
27+
$data = [
28+
'label' => __('Delete'),
29+
'on_click' => '',
30+
'data_attribute' => [
31+
'mage-init' => [
32+
'Magento_Ui/js/form/button-adapter' => [
33+
'actions' => [
34+
[
35+
'targetName' => 'customer_address_form.customer_address_form',
36+
'actionName' => 'deleteAddress',
37+
'params' => [
38+
$this->getDeleteUrl(),
39+
],
40+
41+
]
42+
],
43+
],
44+
],
45+
],
46+
'sort_order' => 20
47+
];
48+
}
49+
return $data;
50+
}
51+
52+
/**
53+
* Get delete button url.
54+
*
55+
* @return string
56+
* @throws \Magento\Framework\Exception\LocalizedException
57+
*/
58+
private function getDeleteUrl(): string
59+
{
60+
return $this->getUrl(
61+
Actions::CUSTOMER_ADDRESS_PATH_DELETE,
62+
['parent_id' => $this->getCustomerId(), 'id' => $this->getAddressId()]
63+
);
64+
}
65+
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
<?php
2+
declare(strict_types=1);
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
namespace Magento\Customer\Block\Adminhtml\Edit\Address;
8+
9+
use Magento\Customer\Model\AddressFactory;
10+
use Magento\Framework\App\RequestInterface;
11+
use Magento\Framework\UrlInterface;
12+
use Magento\Customer\Model\ResourceModel\Address;
13+
use Magento\Customer\Model\ResourceModel\AddressRepository;
14+
15+
/**
16+
* Class for common code for buttons on the create/edit address form
17+
*/
18+
class GenericButton
19+
{
20+
/**
21+
* @var AddressFactory
22+
*/
23+
private $addressFactory;
24+
25+
/**
26+
* @var UrlInterface
27+
*/
28+
private $urlBuilder;
29+
30+
/**
31+
* @var Address
32+
*/
33+
private $addressResourceModel;
34+
35+
/**
36+
* @var RequestInterface
37+
*/
38+
private $request;
39+
40+
/**
41+
* @var AddressRepository
42+
*/
43+
private $addressRepository;
44+
45+
/**
46+
* @param AddressFactory $addressFactory
47+
* @param UrlInterface $urlBuilder
48+
* @param Address $addressResourceModel
49+
* @param RequestInterface $request
50+
* @param AddressRepository $addressRepository
51+
*/
52+
public function __construct(
53+
AddressFactory $addressFactory,
54+
UrlInterface $urlBuilder,
55+
Address $addressResourceModel,
56+
RequestInterface $request,
57+
AddressRepository $addressRepository
58+
) {
59+
$this->addressFactory = $addressFactory;
60+
$this->urlBuilder = $urlBuilder;
61+
$this->addressResourceModel = $addressResourceModel;
62+
$this->request = $request;
63+
$this->addressRepository = $addressRepository;
64+
}
65+
66+
/**
67+
* Return address Id.
68+
*
69+
* @return int|null
70+
*/
71+
public function getAddressId()
72+
{
73+
$address = $this->addressFactory->create();
74+
75+
$entityId = $this->request->getParam('entity_id');
76+
$this->addressResourceModel->load(
77+
$address,
78+
$entityId
79+
);
80+
81+
return $address->getEntityId() ?: null;
82+
}
83+
84+
/**
85+
* Get customer id.
86+
*
87+
* @return int|null
88+
* @throws \Magento\Framework\Exception\LocalizedException
89+
*/
90+
public function getCustomerId()
91+
{
92+
$addressId = $this->request->getParam('entity_id');
93+
94+
$address = $this->addressRepository->getById($addressId);
95+
96+
return $address->getCustomerId() ?: null;
97+
}
98+
99+
/**
100+
* Generate url by route and parameters
101+
*
102+
* @param string $route
103+
* @param array $params
104+
* @return string
105+
*/
106+
public function getUrl($route = '', array $params = []): string
107+
{
108+
return $this->urlBuilder->getUrl($route, $params);
109+
}
110+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
declare(strict_types=1);
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
namespace Magento\Customer\Block\Adminhtml\Edit\Address;
8+
9+
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
10+
use Magento\Customer\Block\Adminhtml\Edit\GenericButton;
11+
12+
/**
13+
* Class SaveButton
14+
*/
15+
class SaveButton extends GenericButton implements ButtonProviderInterface
16+
{
17+
/**
18+
* @inheritdoc
19+
*
20+
* @return array
21+
*/
22+
public function getButtonData()
23+
{
24+
return [
25+
'label' => __('Save'),
26+
'class' => 'save primary',
27+
'data_attribute' => [
28+
'mage-init' => ['button' => ['event' => 'save']],
29+
'form-role' => 'save',
30+
],
31+
'sort_order' => 10
32+
];
33+
}
34+
}
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
<?php
2+
declare(strict_types=1);
3+
/**
4+
*
5+
* Copyright © Magento, Inc. All rights reserved.
6+
* See COPYING.txt for license details.
7+
*/
8+
namespace Magento\Customer\Controller\Adminhtml\Address;
9+
10+
use Magento\Backend\App\Action;
11+
use Magento\Customer\Api\Data\AddressInterface;
12+
use Magento\Customer\Api\AddressRepositoryInterface;
13+
use Magento\Framework\App\Action\HttpPostActionInterface;
14+
use Magento\Framework\Controller\Result\Json;
15+
use Magento\Framework\Controller\Result\JsonFactory;
16+
use Psr\Log\LoggerInterface;
17+
18+
/**
19+
* Class to process set default billing address action
20+
*/
21+
class DefaultBillingAddress extends Action implements HttpPostActionInterface
22+
{
23+
/**
24+
* Authorization level of a basic admin session
25+
*
26+
* @see _isAllowed()
27+
*/
28+
public const ADMIN_RESOURCE = 'Magento_Customer::manage';
29+
30+
/**
31+
* @var AddressRepositoryInterface
32+
*/
33+
private $addressRepository;
34+
35+
/**
36+
* @var LoggerInterface
37+
*/
38+
private $logger;
39+
40+
/**
41+
* @var JsonFactory
42+
*/
43+
private $resultJsonFactory;
44+
45+
/**
46+
* @param Action\Context $context
47+
* @param AddressRepositoryInterface $addressRepository
48+
* @param LoggerInterface $logger
49+
* @param JsonFactory $resultJsonFactory
50+
*/
51+
public function __construct(
52+
Action\Context $context,
53+
AddressRepositoryInterface $addressRepository,
54+
LoggerInterface $logger,
55+
JsonFactory $resultJsonFactory
56+
) {
57+
parent::__construct($context);
58+
$this->addressRepository = $addressRepository;
59+
$this->logger = $logger;
60+
$this->resultJsonFactory = $resultJsonFactory;
61+
}
62+
63+
/**
64+
* Execute action to set customer default billing address
65+
*
66+
* @return Json
67+
*/
68+
public function execute(): Json
69+
{
70+
$customerId = $this->getRequest()->getParam('parent_id', false);
71+
$addressId = $this->getRequest()->getParam('id', false);
72+
$error = true;
73+
$message = __('There is no address id in setting default billing address.');
74+
75+
if ($addressId) {
76+
try {
77+
$address = $this->addressRepository->getById($addressId)->setCustomerId($customerId);
78+
$this->setAddressAsDefault($address);
79+
$this->addressRepository->save($address);
80+
$message = __('Default billing address has been changed.');
81+
$error = false;
82+
} catch (\Exception $e) {
83+
$message = __('We can\'t change default billing address right now.');
84+
$this->logger->critical($e);
85+
}
86+
}
87+
88+
$resultJson = $this->resultJsonFactory->create();
89+
$resultJson->setData(
90+
[
91+
'message' => $message,
92+
'error' => $error,
93+
]
94+
);
95+
96+
return $resultJson;
97+
}
98+
99+
/**
100+
* Set address as default billing address
101+
*
102+
* @param AddressInterface $address
103+
* @return void
104+
*/
105+
private function setAddressAsDefault(AddressInterface $address): void
106+
{
107+
$address->setIsDefaultBilling(true);
108+
}
109+
}

0 commit comments

Comments
 (0)