Skip to content

Commit 3626e10

Browse files
committed
ACP2E-675: Telephone required on all websites when set to be optional on some
1 parent 141ad08 commit 3626e10

File tree

1 file changed

+17
-15
lines changed
  • app/code/Magento/Customer/Controller/Adminhtml/Address

1 file changed

+17
-15
lines changed

app/code/Magento/Customer/Controller/Adminhtml/Address/Validate.php

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Magento\Backend\App\Action;
1010
use Magento\Customer\Api\CustomerRepositoryInterface;
1111
use Magento\Customer\Model\Config\Share;
12+
use Magento\Customer\Model\CustomerRegistry;
1213
use Magento\Framework\App\Action\HttpGetActionInterface;
1314
use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface;
1415
use Magento\Framework\App\ObjectManager;
@@ -44,40 +45,40 @@ class Validate extends Action implements HttpPostActionInterface, HttpGetActionI
4445
private $shareConfig;
4546

4647
/**
47-
* @var CustomerRepositoryInterface
48+
* @var StoreManagerInterface
4849
*/
49-
private $customerRepository;
50+
private $storeManager;
5051

5152
/**
52-
* @var StoreManagerInterface
53+
* @var CustomerRegistry
5354
*/
54-
private $storeManager;
55+
private $customerRegistry;
5556

5657
/**
5758
* @param Action\Context $context
5859
* @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
5960
* @param \Magento\Customer\Model\Metadata\FormFactory $formFactory
6061
* @param Share|null $shareConfig
61-
* @param CustomerRepositoryInterface|null $customerRepository
6262
* @param StoreManagerInterface|null $storeManager
63+
* @param CustomerRegistry|null $customerRegistry
6364
*/
6465
public function __construct(
6566
Action\Context $context,
6667
\Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory,
6768
\Magento\Customer\Model\Metadata\FormFactory $formFactory,
6869
?Share $shareConfig = null,
69-
?CustomerRepositoryInterface $customerRepository = null,
70-
?StoreManagerInterface $storeManager = null
70+
?StoreManagerInterface $storeManager = null,
71+
?CustomerRegistry $customerRegistry = null
7172
) {
7273
parent::__construct($context);
7374
$this->resultJsonFactory = $resultJsonFactory;
7475
$this->formFactory = $formFactory;
7576
$this->shareConfig = $shareConfig
7677
?? ObjectManager::getInstance()->get(Share::class);
77-
$this->customerRepository = $customerRepository
78-
?? ObjectManager::getInstance()->get(CustomerRepositoryInterface::class);
7978
$this->storeManager = $storeManager
8079
?? ObjectManager::getInstance()->get(StoreManagerInterface::class);
80+
$this->customerRegistry = $customerRegistry
81+
?? ObjectManager::getInstance()->get(CustomerRegistry::class);
8182
}
8283

8384
/**
@@ -87,6 +88,13 @@ public function __construct(
8788
*/
8889
public function execute(): Json
8990
{
91+
$customerId = $this->getRequest()->getParam('parent_id');
92+
if ($customerId) {
93+
$customerModel = $this->customerRegistry->retrieve($customerId);
94+
if (!$this->shareConfig->isGlobalScope() && $customerModel->getStoreId()) {
95+
$this->storeManager->setCurrentStore($customerModel->getStoreId());
96+
}
97+
}
9098
/** @var \Magento\Framework\DataObject $response */
9199
$response = new \Magento\Framework\DataObject();
92100
$response->setError(false);
@@ -113,12 +121,6 @@ public function execute(): Json
113121
private function validateCustomerAddress(DataObject $response): DataObject
114122
{
115123
$addressForm = $this->formFactory->create('customer_address', 'adminhtml_customer_address');
116-
if ($this->getRequest()->getParam('parent_id')) {
117-
$customer = $this->customerRepository->getById($this->getRequest()->getParam('parent_id'));
118-
if (!$this->shareConfig->isGlobalScope() && $customer->getStoreId()) {
119-
$this->storeManager->setCurrentStore($customer->getStoreId());
120-
}
121-
}
122124
$formData = $addressForm->extractData($this->getRequest());
123125
$errors = $addressForm->validateData($formData);
124126
if ($errors !== true) {

0 commit comments

Comments
 (0)