Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Index.php
Go to the documentation of this file.
1 <?php
7 
11 use Magento\Customer\Api\Data\AddressInterfaceFactory;
12 use Magento\Customer\Api\Data\CustomerInterfaceFactory;
16 use Magento\Framework\DataObjectFactory as ObjectFactory;
18 
27 abstract class Index extends \Magento\Backend\App\Action
28 {
34  const ADMIN_RESOURCE = 'Magento_Customer::manage';
35 
40  protected $_validator;
41 
47  protected $_coreRegistry = null;
48 
52  protected $_fileFactory;
53 
58  protected $_customerFactory = null;
59 
64  protected $_addressFactory = null;
65 
70 
74  protected $_formFactory;
75 
80 
84  protected $_viewHelper;
85 
90  protected $_random;
91 
95  protected $_objectFactory;
96 
102 
106  protected $addressMapper;
107 
112 
117 
122 
127 
131  protected $customerMapper;
132 
138 
142  protected $dataObjectHelper;
143 
148  protected $layoutFactory;
149 
154 
159 
164 
169 
200  public function __construct(
201  \Magento\Backend\App\Action\Context $context,
202  \Magento\Framework\Registry $coreRegistry,
203  \Magento\Framework\App\Response\Http\FileFactory $fileFactory,
204  \Magento\Customer\Model\CustomerFactory $customerFactory,
205  \Magento\Customer\Model\AddressFactory $addressFactory,
206  \Magento\Customer\Model\Metadata\FormFactory $formFactory,
207  \Magento\Newsletter\Model\SubscriberFactory $subscriberFactory,
208  \Magento\Customer\Helper\View $viewHelper,
209  \Magento\Framework\Math\Random $random,
211  \Magento\Framework\Api\ExtensibleDataObjectConverter $extensibleDataObjectConverter,
215  CustomerInterfaceFactory $customerDataFactory,
216  AddressInterfaceFactory $addressDataFactory,
217  \Magento\Customer\Model\Customer\Mapper $customerMapper,
218  \Magento\Framework\Reflection\DataObjectProcessor $dataObjectProcessor,
220  ObjectFactory $objectFactory,
221  \Magento\Framework\View\LayoutFactory $layoutFactory,
222  \Magento\Framework\View\Result\LayoutFactory $resultLayoutFactory,
223  \Magento\Framework\View\Result\PageFactory $resultPageFactory,
224  \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory,
225  \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
226  ) {
227  $this->_coreRegistry = $coreRegistry;
228  $this->_fileFactory = $fileFactory;
229  $this->_customerFactory = $customerFactory;
230  $this->_addressFactory = $addressFactory;
231  $this->_formFactory = $formFactory;
232  $this->_subscriberFactory = $subscriberFactory;
233  $this->_viewHelper = $viewHelper;
234  $this->_random = $random;
235  $this->_customerRepository = $customerRepository;
236  $this->_extensibleDataObjectConverter = $extensibleDataObjectConverter;
237  $this->addressMapper = $addressMapper;
238  $this->customerAccountManagement = $customerAccountManagement;
239  $this->addressRepository = $addressRepository;
240  $this->customerDataFactory = $customerDataFactory;
241  $this->addressDataFactory = $addressDataFactory;
242  $this->customerMapper = $customerMapper;
243  $this->dataObjectProcessor = $dataObjectProcessor;
244  $this->_objectFactory = $objectFactory;
245  $this->dataObjectHelper = $dataObjectHelper;
246  $this->layoutFactory = $layoutFactory;
247  $this->resultLayoutFactory = $resultLayoutFactory;
248  $this->resultPageFactory = $resultPageFactory;
249  $this->resultForwardFactory = $resultForwardFactory;
250  $this->resultJsonFactory = $resultJsonFactory;
251  parent::__construct($context);
252  }
253 
259  protected function initCurrentCustomer()
260  {
261  $customerId = (int)$this->getRequest()->getParam('id');
262 
263  if ($customerId) {
264  $this->_coreRegistry->register(RegistryConstants::CURRENT_CUSTOMER_ID, $customerId);
265  }
266 
267  return $customerId;
268  }
269 
276  protected function prepareDefaultCustomerTitle(\Magento\Backend\Model\View\Result\Page $resultPage)
277  {
278  $resultPage->getConfig()->getTitle()->prepend(__('Customers'));
279  }
280 
289  protected function _addSessionErrorMessages($messages)
290  {
291  $messages = (array)$messages;
292  $session = $this->_getSession();
293 
294  $callback = function ($error) use ($session) {
295  if (!$error instanceof Error) {
296  $error = new Error($error);
297  }
298  $this->messageManager->addMessage($error);
299  };
300  array_walk_recursive($messages, $callback);
301  }
302 
311  protected function actUponMultipleCustomers(callable $singleAction, $customerIds)
312  {
313  if (!is_array($customerIds)) {
314  $this->messageManager->addError(__('Please select customer(s).'));
315  return 0;
316  }
317  $customersUpdated = 0;
318  foreach ($customerIds as $customerId) {
319  try {
320  $singleAction($customerId);
321  $customersUpdated++;
322  } catch (\Exception $exception) {
323  $this->messageManager->addError($exception->getMessage());
324  }
325  }
326  return $customersUpdated;
327  }
328 }
__construct(\Magento\Backend\App\Action\Context $context, \Magento\Framework\Registry $coreRegistry, \Magento\Framework\App\Response\Http\FileFactory $fileFactory, \Magento\Customer\Model\CustomerFactory $customerFactory, \Magento\Customer\Model\AddressFactory $addressFactory, \Magento\Customer\Model\Metadata\FormFactory $formFactory, \Magento\Newsletter\Model\SubscriberFactory $subscriberFactory, \Magento\Customer\Helper\View $viewHelper, \Magento\Framework\Math\Random $random, CustomerRepositoryInterface $customerRepository, \Magento\Framework\Api\ExtensibleDataObjectConverter $extensibleDataObjectConverter, Mapper $addressMapper, AccountManagementInterface $customerAccountManagement, AddressRepositoryInterface $addressRepository, CustomerInterfaceFactory $customerDataFactory, AddressInterfaceFactory $addressDataFactory, \Magento\Customer\Model\Customer\Mapper $customerMapper, \Magento\Framework\Reflection\DataObjectProcessor $dataObjectProcessor, DataObjectHelper $dataObjectHelper, ObjectFactory $objectFactory, \Magento\Framework\View\LayoutFactory $layoutFactory, \Magento\Framework\View\Result\LayoutFactory $resultLayoutFactory, \Magento\Framework\View\Result\PageFactory $resultPageFactory, \Magento\Backend\Model\View\Result\ForwardFactory $resultForwardFactory, \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory)
Definition: Index.php:200
__()
Definition: __.php:13
$customerRepository
$addressFactory
Definition: quote.php:20
prepareDefaultCustomerTitle(\Magento\Backend\Model\View\Result\Page $resultPage)
Definition: Index.php:276
actUponMultipleCustomers(callable $singleAction, $customerIds)
Definition: Index.php:311