|
5 | 5 | */
|
6 | 6 | namespace Magento\Customer\Controller\Adminhtml\Index;
|
7 | 7 |
|
| 8 | +use Magento\Customer\Api\AccountManagementInterface; |
| 9 | +use Magento\Customer\Api\AddressRepositoryInterface; |
| 10 | +use Magento\Customer\Api\CustomerRepositoryInterface; |
| 11 | +use Magento\Customer\Api\Data\AddressInterfaceFactory; |
| 12 | +use Magento\Customer\Api\Data\CustomerInterfaceFactory; |
| 13 | +use Magento\Customer\Model\Address\Mapper; |
| 14 | +use Magento\Framework\Api\DataObjectHelper; |
8 | 15 | use Magento\Framework\App\Action\HttpGetActionInterface;
|
9 | 16 | use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface;
|
10 | 17 | use Magento\Customer\Api\Data\CustomerInterface;
|
| 18 | +use Magento\Framework\App\ObjectManager; |
| 19 | +use Magento\Framework\DataObjectFactory as ObjectFactory; |
11 | 20 | use Magento\Framework\Message\Error;
|
12 | 21 | use Magento\Customer\Controller\Adminhtml\Index as CustomerAction;
|
| 22 | +use Magento\Store\Model\StoreManagerInterface; |
13 | 23 |
|
14 | 24 | /**
|
15 | 25 | * Class for validation of customer
|
16 | 26 | */
|
17 | 27 | class Validate extends CustomerAction implements HttpPostActionInterface, HttpGetActionInterface
|
18 | 28 | {
|
| 29 | + /** |
| 30 | + * @var StoreManagerInterface |
| 31 | + */ |
| 32 | + private $storeManager; |
| 33 | + |
| 34 | + /** |
| 35 | + * @param \Magento\Backend\App\Action\Context $context |
| 36 | + * @param \Magento\Framework\Registry $coreRegistry |
| 37 | + * @param \Magento\Framework\App\Response\Http\FileFactory $fileFactory |
| 38 | + * @param \Magento\Customer\Model\CustomerFactory $customerFactory |
| 39 | + * @param \Magento\Customer\Model\AddressFactory $addressFactory |
| 40 | + * @param \Magento\Customer\Model\Metadata\FormFactory $formFactory |
| 41 | + * @param \Magento\Newsletter\Model\SubscriberFactory $subscriberFactory |
| 42 | + * @param \Magento\Customer\Helper\View $viewHelper |
| 43 | + * @param \Magento\Framework\Math\Random $random |
| 44 | + * @param CustomerRepositoryInterface $customerRepository |
| 45 | + * @param \Magento\Framework\Api\ExtensibleDataObjectConverter $extensibleDataObjectConverter |
| 46 | + * @param Mapper $addressMapper |
| 47 | + * @param AccountManagementInterface $customerAccountManagement |
| 48 | + * @param AddressRepositoryInterface $addressRepository |
| 49 | + * @param CustomerInterfaceFactory $customerDataFactory |
| 50 | + * @param AddressInterfaceFactory $addressDataFactory |
| 51 | + * @param \Magento\Customer\Model\Customer\Mapper $customerMapper |
| 52 | + * @param \Magento\Framework\Reflection\DataObjectProcessor $dataObjectProcessor |
| 53 | + * @param DataObjectHelper $dataObjectHelper |
| 54 | + * @param ObjectFactory $objectFactory |
| 55 | + * @param \Magento\Framework\View\LayoutFactory $layoutFactory |
| 56 | + * @param \Magento\Framework\View\Result\LayoutFactory $resultLayoutFactory |
| 57 | + * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory |
| 58 | + * @param \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory |
| 59 | + * @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory |
| 60 | + * @param StoreManagerInterface|null $storeManager |
| 61 | + * @SuppressWarnings(PHPMD.ExcessiveParameterList) |
| 62 | + */ |
| 63 | + public function __construct( |
| 64 | + \Magento\Backend\App\Action\Context $context, |
| 65 | + \Magento\Framework\Registry $coreRegistry, |
| 66 | + \Magento\Framework\App\Response\Http\FileFactory $fileFactory, |
| 67 | + \Magento\Customer\Model\CustomerFactory $customerFactory, |
| 68 | + \Magento\Customer\Model\AddressFactory $addressFactory, |
| 69 | + \Magento\Customer\Model\Metadata\FormFactory $formFactory, |
| 70 | + \Magento\Newsletter\Model\SubscriberFactory $subscriberFactory, |
| 71 | + \Magento\Customer\Helper\View $viewHelper, |
| 72 | + \Magento\Framework\Math\Random $random, |
| 73 | + CustomerRepositoryInterface $customerRepository, |
| 74 | + \Magento\Framework\Api\ExtensibleDataObjectConverter $extensibleDataObjectConverter, |
| 75 | + Mapper $addressMapper, |
| 76 | + AccountManagementInterface $customerAccountManagement, |
| 77 | + AddressRepositoryInterface $addressRepository, |
| 78 | + CustomerInterfaceFactory $customerDataFactory, |
| 79 | + AddressInterfaceFactory $addressDataFactory, |
| 80 | + \Magento\Customer\Model\Customer\Mapper $customerMapper, |
| 81 | + \Magento\Framework\Reflection\DataObjectProcessor $dataObjectProcessor, |
| 82 | + DataObjectHelper $dataObjectHelper, |
| 83 | + ObjectFactory $objectFactory, |
| 84 | + \Magento\Framework\View\LayoutFactory $layoutFactory, |
| 85 | + \Magento\Framework\View\Result\LayoutFactory $resultLayoutFactory, |
| 86 | + \Magento\Framework\View\Result\PageFactory $resultPageFactory, |
| 87 | + \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory, |
| 88 | + \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory, |
| 89 | + ?StoreManagerInterface $storeManager = null |
| 90 | + ) { |
| 91 | + parent::__construct( |
| 92 | + $context, |
| 93 | + $coreRegistry, |
| 94 | + $fileFactory, |
| 95 | + $customerFactory, |
| 96 | + $addressFactory, |
| 97 | + $formFactory, |
| 98 | + $subscriberFactory, |
| 99 | + $viewHelper, |
| 100 | + $random, |
| 101 | + $customerRepository, |
| 102 | + $extensibleDataObjectConverter, |
| 103 | + $addressMapper, |
| 104 | + $customerAccountManagement, |
| 105 | + $addressRepository, |
| 106 | + $customerDataFactory, |
| 107 | + $addressDataFactory, |
| 108 | + $customerMapper, |
| 109 | + $dataObjectProcessor, |
| 110 | + $dataObjectHelper, |
| 111 | + $objectFactory, |
| 112 | + $layoutFactory, |
| 113 | + $resultLayoutFactory, |
| 114 | + $resultPageFactory, |
| 115 | + $resultForwardFactory, |
| 116 | + $resultJsonFactory |
| 117 | + ); |
| 118 | + |
| 119 | + $this->storeManager = $storeManager ?? ObjectManager::getInstance()->get(StoreManagerInterface::class); |
| 120 | + } |
| 121 | + |
19 | 122 | /**
|
20 | 123 | * Customer validation
|
21 | 124 | *
|
@@ -55,6 +158,11 @@ protected function _validateCustomer($response)
|
55 | 158 | $entity_id = $submittedData['entity_id'];
|
56 | 159 | $customer->setId($entity_id);
|
57 | 160 | }
|
| 161 | + if (isset($data['website_id'])) { |
| 162 | + $website = $this->storeManager->getWebsite($data['website_id']); |
| 163 | + $storeId = current($website->getStoreIds()); |
| 164 | + $this->storeManager->setCurrentStore($storeId); |
| 165 | + } |
58 | 166 | $errors = $this->customerAccountManagement->validate($customer)->getMessages();
|
59 | 167 | } catch (\Magento\Framework\Validator\Exception $exception) {
|
60 | 168 | /* @var $error Error */
|
|
0 commit comments