当前位置: 首页>>代码示例>>PHP>>正文


PHP CustomerRepositoryInterface::getList方法代码示例

本文整理汇总了PHP中Magento\Customer\Api\CustomerRepositoryInterface::getList方法的典型用法代码示例。如果您正苦于以下问题:PHP CustomerRepositoryInterface::getList方法的具体用法?PHP CustomerRepositoryInterface::getList怎么用?PHP CustomerRepositoryInterface::getList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Magento\Customer\Api\CustomerRepositoryInterface的用法示例。


在下文中一共展示了CustomerRepositoryInterface::getList方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: load

 /**
  * Load search results
  *
  * @return $this
  */
 public function load()
 {
     $result = [];
     if (!$this->hasStart() || !$this->hasLimit() || !$this->hasQuery()) {
         $this->setResults($result);
         return $this;
     }
     $this->searchCriteriaBuilder->setCurrentPage($this->getStart());
     $this->searchCriteriaBuilder->setPageSize($this->getLimit());
     $searchFields = ['firstname', 'lastname', 'company'];
     $filters = [];
     foreach ($searchFields as $field) {
         $filters[] = $this->filterBuilder->setField($field)->setConditionType('like')->setValue($this->getQuery() . '%')->create();
     }
     $this->searchCriteriaBuilder->addFilters($filters);
     $searchCriteria = $this->searchCriteriaBuilder->create();
     $searchResults = $this->customerRepository->getList($searchCriteria);
     foreach ($searchResults->getItems() as $customer) {
         $customerAddresses = $customer->getAddresses();
         /** Look for a company name defined in default billing address */
         $company = null;
         foreach ($customerAddresses as $customerAddress) {
             if ($customerAddress->getId() == $customer->getDefaultBilling()) {
                 $company = $customerAddress->getCompany();
                 break;
             }
         }
         $result[] = ['id' => 'customer/1/' . $customer->getId(), 'type' => __('Customer'), 'name' => $this->_customerViewHelper->getCustomerName($customer), 'description' => $company, 'url' => $this->_adminhtmlData->getUrl('customer/index/edit', ['id' => $customer->getId()])];
     }
     $this->setResults($result);
     return $this;
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:37,代码来源:Customer.php

示例2: testSearchCustomersOrder

 /**
  * Test ordering
  *
  * @magentoDataFixture Magento/Customer/_files/three_customers.php
  * @magentoDbIsolation enabled
  */
 public function testSearchCustomersOrder()
 {
     /** @var \Magento\Framework\Api\SearchCriteriaBuilder $searchBuilder */
     $objectManager = Bootstrap::getObjectManager();
     $searchBuilder = $objectManager->create('Magento\\Framework\\Api\\SearchCriteriaBuilder');
     // Filter for 'firstname' like 'First'
     $filterBuilder = $objectManager->create('Magento\\Framework\\Api\\FilterBuilder');
     $firstnameFilter = $filterBuilder->setField('firstname')->setConditionType('like')->setValue('First%')->create();
     $searchBuilder->addFilters([$firstnameFilter]);
     // Search ascending order
     $sortOrderBuilder = $objectManager->create('Magento\\Framework\\Api\\SortOrderBuilder');
     $sortOrder = $sortOrderBuilder->setField('lastname')->setDirection(SearchCriteriaInterface::SORT_ASC)->create();
     $searchBuilder->addSortOrder($sortOrder);
     $searchResults = $this->customerRepository->getList($searchBuilder->create());
     $this->assertEquals(3, $searchResults->getTotalCount());
     $this->assertEquals('Lastname', $searchResults->getItems()[0]->getLastname());
     $this->assertEquals('Lastname2', $searchResults->getItems()[1]->getLastname());
     $this->assertEquals('Lastname3', $searchResults->getItems()[2]->getLastname());
     // Search descending order
     $sortOrder = $sortOrderBuilder->setField('lastname')->setDirection(SearchCriteriaInterface::SORT_DESC)->create();
     $searchBuilder->addSortOrder($sortOrder);
     $searchResults = $this->customerRepository->getList($searchBuilder->create());
     $this->assertEquals('Lastname3', $searchResults->getItems()[0]->getLastname());
     $this->assertEquals('Lastname2', $searchResults->getItems()[1]->getLastname());
     $this->assertEquals('Lastname', $searchResults->getItems()[2]->getLastname());
 }
开发者ID:vasiljok,项目名称:magento2,代码行数:32,代码来源:CustomerRepositoryTest.php

示例3: findCustomerByLoginAttribute

 /**
  * Find a customer
  *
  * @param string $attributeValue Attribute Value
  * @return bool|\Magento\Customer\Api\Data\CustomerInterface
  */
 private function findCustomerByLoginAttribute($attributeValue)
 {
     // Retrieve the customer login attribute and check if valid
     $loginAttribute = $this->advancedLoginConfigProvider->getLoginAttribute();
     if (false === $loginAttribute) {
         return false;
     }
     // Add website filter if customer accounts are shared per website
     $websiteIdFilter = false;
     if ($this->advancedLoginConfigProvider->getCustomerAccountShareScope() == Share::SHARE_WEBSITE) {
         $websiteIdFilter[] = $this->filterBuilder->setField('website_id')->setConditionType('eq')->setValue($this->storeManager->getStore()->getWebsiteId())->create();
     }
     // Add customer attribute filter
     $customerNumberFilter[] = $this->filterBuilder->setField('customer_number')->setConditionType('eq')->setValue($attributeValue)->create();
     // Build search criteria
     $searchCriteriaBuilder = $this->searchCriteriaBuilder->addFilters($customerNumberFilter);
     if ($websiteIdFilter) {
         $searchCriteriaBuilder->addFilters($websiteIdFilter);
     }
     $searchCriteria = $searchCriteriaBuilder->create();
     // Retrieve the customer collection and return customer if there was exactly one customer found
     $collection = $this->customerRepository->getList($searchCriteria);
     if ($collection->getTotalCount() == 1) {
         return $collection->getItems()[0];
     }
     return false;
 }
开发者ID:semaio,项目名称:magento2-advancedlogin,代码行数:33,代码来源:AccountManagement.php

示例4: getAllCustomers

 /**
  * @return \Magento\Customer\Api\Data\CustomerInterface[]
  */
 public function getAllCustomers()
 {
     $crit = $this->_manObj->create(\Magento\Framework\Api\SearchCriteriaInterface::class);
     /** @var \Magento\Customer\Api\Data\CustomerSearchResultsInterface $all */
     $all = $this->_repoCust->getList($crit);
     $result = $all->getItems();
     return $result;
 }
开发者ID:praxigento,项目名称:mobi_app_generic_mage2,代码行数:11,代码来源:SaleOrder.php


注:本文中的Magento\Customer\Api\CustomerRepositoryInterface::getList方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。