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


PHP SearchCriteriaBuilder::addFilter方法代码示例

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


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

示例1: getProductStatusMatchingSku

 /**
  * @param string $sku
  * @return string[]
  */
 public function getProductStatusMatchingSku($sku)
 {
     $this->validateSku($sku);
     $this->searchCriteriaBuilder->addFilter('sku', '%' . $sku . '%', 'like');
     $result = $this->productRepository->getList($this->searchCriteriaBuilder->create());
     return array_reduce($result->getItems(), function ($acc, ProductInterface $product) {
         return array_merge($acc, [$product->getSku() => $this->getStatusAsString($product)]);
     }, []);
 }
开发者ID:nhp,项目名称:MageTitans_ProductStatus,代码行数:13,代码来源:ProductStatusAdapter.php

示例2: getAttributes

 /**
  * Returns array of fields
  *
  * @param string $entityType
  * @return array
  * @throws \Exception
  */
 public function getAttributes($entityType)
 {
     $metadata = $this->metadataPool->getMetadata($entityType);
     $searchResult = $this->attributeRepository->getList($metadata->getEavEntityType(), $this->searchCriteriaBuilder->addFilter('attribute_set_id', null, 'neq')->create());
     $attributes = [];
     foreach ($searchResult->getItems() as $attribute) {
         $attributes[] = $attribute->getAttributeCode();
     }
     return $attributes;
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:17,代码来源:AttributeProvider.php

示例3: 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->addFilter($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:shabbirvividads,项目名称:magento2,代码行数:37,代码来源:Customer.php

示例4: isAssignedToObjects

 /**
  * {@inheritdoc}
  */
 public function isAssignedToObjects()
 {
     $searchCriteria = $this->searchCriteriaBuilder->addFilter([$this->filterBuilder->setField(CustomerGroup::TAX_CLASS_ID)->setValue($this->getId())->create()])->create();
     $result = $this->customerGroupRepository->getList($searchCriteria);
     $items = $result->getItems();
     return !empty($items);
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:10,代码来源:Customer.php

示例5: getStatusForProductsMatchingSku

 /**
  * @param string $sku
  * @return string[]
  */
 public function getStatusForProductsMatchingSku($sku)
 {
     $this->validateSku($sku);
     $this->searchCriteriaBuilder->addFilter('sku', $this->getLikeSkuExpression($sku), 'like');
     $productList = $this->productRepository->getList($this->searchCriteriaBuilder->create());
     return array_reduce($productList->getItems(), function (array $carry, ProductInterface $product) {
         return array_merge($carry, [$product->getSku() => $this->getStatusString($product)]);
     }, []);
 }
开发者ID:Vinai,项目名称:MM15PL_ProductStatus,代码行数:13,代码来源:ProductStatusAdapter.php

示例6: getApplicableAttributeCodes

 /**
  * Get applicable attributes
  *
  * @param array $documentIds
  * @return array
  */
 private function getApplicableAttributeCodes(array $documentIds)
 {
     $attributeSetIds = $this->attributeSetFinder->findAttributeSetIdsByProductIds($documentIds);
     $searchCriteria = $this->searchCriteriaBuilder->addFilter('attribute_set_id', $attributeSetIds, 'in')->create();
     $result = $this->productAttributeRepository->getList($searchCriteria);
     $attributeCodes = [];
     foreach ($result->getItems() as $attribute) {
         $attributeCodes[] = $attribute->getAttributeCode();
     }
     return $attributeCodes;
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:17,代码来源:AggregationResolver.php

示例7: execute

 /**
  * @return void
  */
 public function execute()
 {
     $filter = $this->filterBuilder->setField('parent_id')->setValue($this->_getCheckout()->getCustomer()->getId())->setConditionType('eq')->create();
     $addresses = (array) $this->addressRepository->getList($this->searchCriteriaBuilder->addFilter([$filter])->create())->getItems();
     /**
      * if we create first address we need reset emd init checkout
      */
     if (count($addresses) === 1) {
         $this->_getCheckout()->reset();
     }
     $this->_redirect('*/checkout/addresses');
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:15,代码来源:ShippingSaved.php

示例8: getByIdentifierNamespace

 /**
  * {@inheritdoc}
  */
 public function getByIdentifierNamespace($identifier, $namespace)
 {
     $this->searchCriteriaBuilder->addFilter([$this->filterBuilder->setField('user_id')->setConditionType('eq')->setValue($this->userContext->getUserId())->create(), $this->filterBuilder->setField('identifier')->setConditionType('eq')->setValue($identifier)->create(), $this->filterBuilder->setField('namespace')->setConditionType('eq')->setValue($namespace)->create()]);
     $searchCriteria = $this->searchCriteriaBuilder->create();
     $searchResults = $this->bookmarkRepository->getList($searchCriteria);
     if ($searchResults->getTotalCount() > 0) {
         foreach ($searchResults->getItems() as $searchResult) {
             $bookmark = $this->bookmarkRepository->getById($searchResult->getId());
             return $bookmark;
         }
     }
     return null;
 }
开发者ID:niranjanssiet,项目名称:magento2,代码行数:16,代码来源:BookmarkManagement.php

示例9: getAddress

 /**
  * Get a list of current customer addresses.
  *
  * @return \Magento\Customer\Api\Data\AddressInterface[]
  */
 public function getAddress()
 {
     $addresses = $this->getData('address_collection');
     if ($addresses === null) {
         try {
             $filter = $this->filterBuilder->setField('parent_id')->setValue($this->_multishipping->getCustomer()->getId())->setConditionType('eq')->create();
             $addresses = (array) $this->addressRepository->getList($this->searchCriteriaBuilder->addFilter([$filter])->create())->getItems();
         } catch (NoSuchEntityException $e) {
             return [];
         }
         $this->setData('address_collection', $addresses);
     }
     return $addresses;
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:19,代码来源:Select.php

示例10: getAllOptions

 /**
  * Retrieve all customer tax classes as an options array.
  *
  * @return array
  * @throws StateException
  */
 public function getAllOptions()
 {
     if (empty($this->_options)) {
         $options = [];
         $filter = $this->filterBuilder->setField(TaxClass::KEY_TYPE)->setValue(TaxClassManagementInterface::TYPE_CUSTOMER)->create();
         $searchCriteria = $this->searchCriteriaBuilder->addFilter([$filter])->create();
         $searchResults = $this->taxClassRepository->getList($searchCriteria);
         foreach ($searchResults->getItems() as $taxClass) {
             $options[] = ['value' => $taxClass->getClassId(), 'label' => $taxClass->getClassName()];
         }
         $this->_options = $options;
     }
     return $this->_options;
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:20,代码来源:Customer.php

示例11: get

 /**
  * load entity
  *
  * @param int $id
  * @return Transaction
  * @throws \Magento\Framework\Exception\NoSuchEntityException
  * @throws \Magento\Framework\Exception\InputException
  */
 public function get($id)
 {
     if (!$id) {
         throw new \Magento\Framework\Exception\InputException(__('ID required'));
     }
     if (!isset($this->registry[$id])) {
         $filter = $this->filterBuilder->setField('transaction_id')->setValue($id)->setConditionType('eq')->create();
         $this->searchCriteriaBuilder->addFilter([$filter]);
         $this->find($this->searchCriteriaBuilder->create());
         if (!isset($this->registry[$id])) {
             throw new \Magento\Framework\Exception\NoSuchEntityException(__('Requested entity doesn\'t exist'));
         }
     }
     return $this->registry[$id];
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:23,代码来源:TransactionRepository.php

示例12: getTaxClassId

 /**
  * {@inheritdoc}
  */
 public function getTaxClassId($taxClassKey, $taxClassType = self::TYPE_PRODUCT)
 {
     if (!empty($taxClassKey)) {
         switch ($taxClassKey->getType()) {
             case TaxClassKeyInterface::TYPE_ID:
                 return $taxClassKey->getValue();
             case TaxClassKeyInterface::TYPE_NAME:
                 $searchCriteria = $this->searchCriteriaBuilder->addFilter([$this->filterBuilder->setField(ClassModel::KEY_TYPE)->setValue($taxClassType)->create()])->addFilter([$this->filterBuilder->setField(ClassModel::KEY_NAME)->setValue($taxClassKey->getValue())->create()])->create();
                 $taxClasses = $this->classRepository->getList($searchCriteria)->getItems();
                 $taxClass = array_shift($taxClasses);
                 return null == $taxClass ? null : $taxClass->getClassId();
         }
     }
     return null;
 }
开发者ID:opexsw,项目名称:magento2,代码行数:18,代码来源:Management.php

示例13: getLoggedInGroups

 /**
  * {@inheritdoc}
  */
 public function getLoggedInGroups()
 {
     $notLoggedInFilter[] = $this->filterBuilder->setField(GroupInterface::ID)->setConditionType('neq')->setValue(self::NOT_LOGGED_IN_ID)->create();
     $groupAll[] = $this->filterBuilder->setField(GroupInterface::ID)->setConditionType('neq')->setValue(self::CUST_GROUP_ALL)->create();
     $searchCriteria = $this->searchCriteriaBuilder->addFilter($notLoggedInFilter)->addFilter($groupAll)->create();
     return $this->groupRepository->getList($searchCriteria)->getItems();
 }
开发者ID:opexsw,项目名称:magento2,代码行数:10,代码来源:GroupManagement.php

示例14: testSearchTaxClassMultipleFilterGroups

 /**
  * Test using multiple filters
  */
 public function testSearchTaxClassMultipleFilterGroups()
 {
     $productTaxClass = [ClassModel::KEY_NAME => 'Taxable Goods', ClassModel::KEY_TYPE => 'PRODUCT'];
     $customerTaxClass = [ClassModel::KEY_NAME => 'Retail Customer', ClassModel::KEY_TYPE => 'CUSTOMER'];
     $filter1 = $this->filterBuilder->setField(ClassModel::KEY_NAME)->setValue($productTaxClass[ClassModel::KEY_NAME])->create();
     $filter2 = $this->filterBuilder->setField(ClassModel::KEY_NAME)->setValue($customerTaxClass[ClassModel::KEY_NAME])->create();
     $filter3 = $this->filterBuilder->setField(ClassModel::KEY_TYPE)->setValue($productTaxClass[ClassModel::KEY_TYPE])->create();
     $filter4 = $this->filterBuilder->setField(ClassModel::KEY_TYPE)->setValue($customerTaxClass[ClassModel::KEY_TYPE])->create();
     /**
      * (class_name == 'Retail Customer' || class_name == 'Taxable Goods)
      * && ( class_type == 'CUSTOMER' || class_type == 'PRODUCT')
      */
     $this->searchCriteriaBuilder->addFilter([$filter1, $filter2]);
     $this->searchCriteriaBuilder->addFilter([$filter3, $filter4]);
     $searchCriteria = $this->searchCriteriaBuilder->setCurrentPage(1)->setPageSize(10)->create();
     $searchData = $searchCriteria->__toArray();
     $requestData = ['searchCriteria' => $searchData];
     $serviceInfo = ['rest' => ['resourcePath' => self::RESOURCE_PATH . '/search' . '?' . http_build_query($requestData), 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET], 'soap' => ['service' => self::SERVICE_NAME, 'serviceVersion' => self::SERVICE_VERSION, 'operation' => self::SERVICE_NAME . 'GetList']];
     $searchResults = $this->_webApiCall($serviceInfo, $requestData);
     $this->assertEquals(2, $searchResults['total_count']);
     $this->assertEquals($productTaxClass[ClassModel::KEY_NAME], $searchResults['items'][0][ClassModel::KEY_NAME]);
     $this->assertEquals($customerTaxClass[ClassModel::KEY_NAME], $searchResults['items'][1][ClassModel::KEY_NAME]);
     /** class_name == 'Retail Customer' && ( class_type == 'CUSTOMER' || class_type == 'PRODUCT') */
     $this->searchCriteriaBuilder->addFilter([$filter2]);
     $this->searchCriteriaBuilder->addFilter([$filter3, $filter4]);
     $searchCriteria = $this->searchCriteriaBuilder->create();
     $searchData = $searchCriteria->__toArray();
     $requestData = ['searchCriteria' => $searchData];
     $serviceInfo['rest']['resourcePath'] = self::RESOURCE_PATH . '/search' . '?' . http_build_query($requestData);
     $searchResults = $this->_webApiCall($serviceInfo, $requestData);
     $this->assertEquals(1, $searchResults['total_count']);
     $this->assertEquals($customerTaxClass[ClassModel::KEY_NAME], $searchResults['items'][0][ClassModel::KEY_NAME]);
 }
开发者ID:opexsw,项目名称:magento2,代码行数:36,代码来源:TaxClassRepositoryTest.php

示例15: testSearchCustomersMultipleFilterGroups

 /**
  * Test using multiple filters
  */
 public function testSearchCustomersMultipleFilterGroups()
 {
     $customerData1 = $this->_createCustomer();
     /** @var \Magento\Framework\Api\FilterBuilder $builder */
     $builder = Bootstrap::getObjectManager()->create('Magento\\Framework\\Api\\FilterBuilder');
     $filter1 = $builder->setField(Customer::EMAIL)->setValue($customerData1[Customer::EMAIL])->create();
     $filter2 = $builder->setField(Customer::MIDDLENAME)->setValue($customerData1[Customer::MIDDLENAME])->create();
     $filter3 = $builder->setField(Customer::MIDDLENAME)->setValue('invalid')->create();
     $filter4 = $builder->setField(Customer::LASTNAME)->setValue($customerData1[Customer::LASTNAME])->create();
     $this->searchCriteriaBuilder->addFilter([$filter1]);
     $this->searchCriteriaBuilder->addFilter([$filter2, $filter3]);
     $this->searchCriteriaBuilder->addFilter([$filter4]);
     $searchCriteria = $this->searchCriteriaBuilder->setCurrentPage(1)->setPageSize(10)->create();
     $searchData = $searchCriteria->__toArray();
     $requestData = ['searchCriteria' => $searchData];
     $serviceInfo = ['rest' => ['resourcePath' => self::RESOURCE_PATH . '/search' . '?' . http_build_query($requestData), 'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET], 'soap' => ['service' => self::SERVICE_NAME, 'serviceVersion' => self::SERVICE_VERSION, 'operation' => self::SERVICE_NAME . 'getList']];
     $searchResults = $this->_webApiCall($serviceInfo, $requestData);
     $this->assertEquals(1, $searchResults['total_count']);
     $this->assertEquals($customerData1[Customer::ID], $searchResults['items'][0][Customer::ID]);
     // Add an invalid And-ed data with multiple groups to yield no result
     $filter4 = $builder->setField(Customer::LASTNAME)->setValue('invalid')->create();
     $this->searchCriteriaBuilder->addFilter([$filter1]);
     $this->searchCriteriaBuilder->addFilter([$filter2, $filter3]);
     $this->searchCriteriaBuilder->addFilter([$filter4]);
     $searchCriteria = $this->searchCriteriaBuilder->create();
     $searchData = $searchCriteria->__toArray();
     $requestData = ['searchCriteria' => $searchData];
     $serviceInfo['rest']['resourcePath'] = self::RESOURCE_PATH . '/search' . '?' . http_build_query($requestData);
     $searchResults = $this->_webApiCall($serviceInfo, $requestData);
     $this->assertEquals(0, $searchResults['total_count']);
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:34,代码来源:CustomerRepositoryTest.php


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