/**
  * @return array
  */
 public function getList()
 {
     if (!$this->attributes) {
         $this->attributes = $this->getListForEntity($this->customerMetadata->getAllAttributesMetadata(), CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER, $this->customerMetadataManagement);
         $this->attributes = array_merge($this->attributes, $this->getListForEntity($this->addressMetadata->getAllAttributesMetadata(), AddressMetadataInterface::ENTITY_TYPE_ADDRESS, $this->addressMetadataManagement));
     }
     return $this->attributeFilter->filter($this->attributes);
 }
 /**
  * {@inheritdoc}
  */
 public function getList(SearchCriteriaInterface $searchCriteria)
 {
     $searchResults = $this->searchResultsFactory->create();
     $searchResults->setSearchCriteria($searchCriteria);
     /** @var \Magento\Customer\Model\Resource\Customer\Collection $collection */
     $collection = $this->customerFactory->create()->getCollection();
     // This is needed to make sure all the attributes are properly loaded
     foreach ($this->customerMetadata->getAllAttributesMetadata() as $metadata) {
         $collection->addAttributeToSelect($metadata->getAttributeCode());
     }
     // Needed to enable filtering on name as a whole
     $collection->addNameToSelect();
     // Needed to enable filtering based on billing address attributes
     $collection->joinAttribute('billing_postcode', 'customer_address/postcode', 'default_billing', null, 'left')->joinAttribute('billing_city', 'customer_address/city', 'default_billing', null, 'left')->joinAttribute('billing_telephone', 'customer_address/telephone', 'default_billing', null, 'left')->joinAttribute('billing_region', 'customer_address/region', 'default_billing', null, 'left')->joinAttribute('billing_country_id', 'customer_address/country_id', 'default_billing', null, 'left')->joinAttribute('company', 'customer_address/company', 'default_billing', null, 'left');
     //Add filters from root filter group to the collection
     foreach ($searchCriteria->getFilterGroups() as $group) {
         $this->addFilterGroupToCollection($group, $collection);
     }
     $searchResults->setTotalCount($collection->getSize());
     $sortOrders = $searchCriteria->getSortOrders();
     if ($sortOrders) {
         foreach ($searchCriteria->getSortOrders() as $sortOrder) {
             $collection->addOrder($sortOrder->getField(), $sortOrder->getDirection() == SearchCriteriaInterface::SORT_ASC ? 'ASC' : 'DESC');
         }
     }
     $collection->setCurPage($searchCriteria->getCurrentPage());
     $collection->setPageSize($searchCriteria->getPageSize());
     $customers = [];
     /** @var \Magento\Customer\Model\Customer $customerModel */
     foreach ($collection as $customerModel) {
         $customers[] = $customerModel->getDataModel();
     }
     $searchResults->setItems($customers);
     return $searchResults;
 }
Example #3
0
 /**
  * Return array of additional account data
  * Value is option style array
  *
  * @return array
  */
 public function getCustomerAccountData()
 {
     $accountData = [];
     $entityType = 'customer';
     /* @var \Magento\Customer\Api\Data\AttributeMetadataInterface $attribute */
     foreach ($this->metadata->getAllAttributesMetadata($entityType) as $attribute) {
         if (!$attribute->isVisible() || $attribute->isSystem()) {
             continue;
         }
         $orderKey = sprintf('customer_%s', $attribute->getAttributeCode());
         $orderValue = $this->getOrder()->getData($orderKey);
         if ($orderValue != '') {
             $metadataElement = $this->_metadataElementFactory->create($attribute, $orderValue, $entityType);
             $value = $metadataElement->outputValue(AttributeDataFactory::OUTPUT_FORMAT_HTML);
             $sortOrder = $attribute->getSortOrder() + $attribute->isUserDefined() ? 200 : 0;
             $sortOrder = $this->_prepareAccountDataSortOrder($accountData, $sortOrder);
             $accountData[$sortOrder] = ['label' => $attribute->getFrontendLabel(), 'value' => $this->escapeHtml($value, ['br'])];
         }
     }
     ksort($accountData, SORT_NUMERIC);
     return $accountData;
 }