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


PHP FilterBuilder::setField方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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->addFilters([$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:pradeep-wagento,项目名称:magento2,代码行数:15,代码来源:ShippingSaved.php

示例4: getByIdentifierNamespace

 /**
  * {@inheritdoc}
  */
 public function getByIdentifierNamespace($identifier, $namespace)
 {
     $this->searchCriteriaBuilder->addFilters([$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:pradeep-wagento,项目名称:magento2,代码行数:16,代码来源:BookmarkManagement.php

示例5: 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

示例6: 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->addFilters([$filter])->create())->getItems();
         } catch (NoSuchEntityException $e) {
             return [];
         }
         $this->setData('address_collection', $addresses);
     }
     return $addresses;
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:19,代码来源:Select.php

示例7: getDataSourceData

 /**
  * {@inheritdoc}
  */
 public function getDataSourceData()
 {
     $dataSource = [];
     $id = $this->getContext()->getRequestParam($this->getContext()->getDataProvider()->getRequestFieldName());
     if ($id) {
         $filter = $this->filterBuilder->setField($this->getContext()->getDataProvider()->getPrimaryFieldName())->setValue($id)->create();
         $this->getContext()->getDataProvider()->addFilter($filter);
         $data = $this->getContext()->getDataProvider()->getData();
         if (isset($data[$id])) {
             $dataSource = ['data' => $data[$id]];
         }
     }
     return $dataSource;
 }
开发者ID:vv-team,项目名称:foodo,代码行数:17,代码来源:Form.php

示例8: 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->addFilters([$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:nja78,项目名称:magento2,代码行数:23,代码来源:TransactionRepository.php

示例9: 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->addFilters([$this->filterBuilder->setField(ClassModel::KEY_TYPE)->setValue($taxClassType)->create()])->addFilters([$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:kidaa30,项目名称:magento2-platformsh,代码行数:18,代码来源:Management.php

示例10: _renderFiltersBefore

 /**
  * @inheritdoc
  */
 protected function _renderFiltersBefore()
 {
     $this->getSearchCriteriaBuilder();
     $this->getFilterBuilder();
     $this->getSearch();
     if ($this->queryText) {
         $this->filterBuilder->setField('search_term');
         $this->filterBuilder->setValue($this->queryText);
         $this->searchCriteriaBuilder->addFilter($this->filterBuilder->create());
     }
     $priceRangeCalculation = $this->_scopeConfig->getValue(\Magento\Catalog\Model\Layer\Filter\Dynamic\AlgorithmFactory::XML_PATH_RANGE_CALCULATION, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
     if ($priceRangeCalculation) {
         $this->filterBuilder->setField('price_dynamic_algorithm');
         $this->filterBuilder->setValue($priceRangeCalculation);
         $this->searchCriteriaBuilder->addFilter($this->filterBuilder->create());
     }
     $searchCriteria = $this->searchCriteriaBuilder->create();
     $searchCriteria->setRequestName($this->searchRequestName);
     $this->searchResult = $this->search->search($searchCriteria);
     $temporaryStorage = $this->temporaryStorageFactory->create();
     $table = $temporaryStorage->storeApiDocuments($this->searchResult->getItems());
     $this->getSelect()->joinInner(['search_result' => $table->getName()], 'e.entity_id = search_result.' . TemporaryStorage::FIELD_ENTITY_ID, []);
     $this->_totalRecords = $this->searchResult->getTotalCount();
     if ($this->order && 'relevance' === $this->order['field']) {
         $this->getSelect()->order('search_result.' . TemporaryStorage::FIELD_SCORE . ' ' . $this->order['dir']);
     }
     return parent::_renderFiltersBefore();
 }
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:31,代码来源:Collection.php

示例11: run

 /**
  * {@inheritdoc}
  */
 public function run()
 {
     $this->logger->log('Installing taxes:');
     $fixtureFile = 'Tax/tax_rate.csv';
     $fixtureFilePath = $this->fixtureHelper->getPath($fixtureFile);
     /** @var \Magento\SampleData\Helper\Csv\Reader $csvReader */
     $csvReader = $this->csvReaderFactory->create(['fileName' => $fixtureFilePath, 'mode' => 'r']);
     foreach ($csvReader as $data) {
         if ($this->rateFactory->create()->loadByCode($data['code'])->getId()) {
             continue;
         }
         $taxRate = $this->rateFactory->create();
         $taxRate->setCode($data['code'])->setTaxCountryId($data['tax_country_id'])->setTaxRegionId($data['tax_region_id'])->setTaxPostcode($data['tax_postcode'])->setRate($data['rate']);
         $this->taxRateRepository->save($taxRate);
         $this->logger->logInline('.');
     }
     $fixtureFile = 'Tax/tax_rule.csv';
     $fixtureFilePath = $this->fixtureHelper->getPath($fixtureFile);
     /** @var \Magento\SampleData\Helper\Csv\Reader $csvReader */
     $csvReader = $this->csvReaderFactory->create(['fileName' => $fixtureFilePath, 'mode' => 'r']);
     foreach ($csvReader as $data) {
         $filter = $this->filterBuilder->setField('code')->setConditionType('=')->setValue($data['code'])->create();
         $criteria = $this->criteriaBuilder->addFilters([$filter])->create();
         $existingRates = $this->taxRuleRepository->getList($criteria)->getItems();
         if (!empty($existingRates)) {
             continue;
         }
         $taxRate = $this->taxRateFactory->create()->loadByCode($data['tax_rate']);
         $taxRule = $this->ruleFactory->create();
         $taxRule->setCode($data['code'])->setTaxRateIds([$taxRate->getId()])->setCustomerTaxClassIds([$data['tax_customer_class']])->setProductTaxClassIds([$data['tax_product_class']])->setPriority($data['priority'])->setCalculateSubtotal($data['calculate_subtotal'])->setPosition($data['position']);
         $this->taxRuleRepository->save($taxRule);
         $this->logger->logInline('.');
     }
 }
开发者ID:vinai-drive-by-commits,项目名称:magento2-sample-data,代码行数:37,代码来源:Tax.php

示例12: 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

示例13: getConfig

 /**
  * Retrieve assoc array of checkout configuration
  *
  * @return array
  */
 public function getConfig()
 {
     $vaultPayments = [];
     $customerId = $this->session->getCustomerId();
     if (!$customerId) {
         return $vaultPayments;
     }
     $storeId = $this->storeManager->getStore()->getId();
     if (!$this->vaultPayment->isActive($storeId)) {
         return $vaultPayments;
     }
     $vaultProviderCode = $this->vaultPayment->getProviderCode($storeId);
     $componentProvider = $this->getComponentProvider($vaultProviderCode);
     if (null === $componentProvider) {
         return $vaultPayments;
     }
     $filters[] = $this->filterBuilder->setField(PaymentTokenInterface::CUSTOMER_ID)->setValue($customerId)->create();
     $filters[] = $this->filterBuilder->setField(PaymentTokenInterface::IS_VISIBLE)->setValue(1)->create();
     $filters[] = $this->filterBuilder->setField(PaymentTokenInterface::PAYMENT_METHOD_CODE)->setValue($vaultProviderCode)->create();
     $searchCriteria = $this->searchCriteriaBuilder->addFilters($filters)->create();
     foreach ($this->paymentTokenRepository->getList($searchCriteria)->getItems() as $index => $token) {
         $component = $componentProvider->getComponentForToken($token);
         $vaultPayments[VaultPaymentInterface::CODE . '_item_' . $index] = ['config' => $component->getConfig(), 'component' => $component->getName()];
     }
     return ['payment' => [VaultPaymentInterface::CODE => $vaultPayments]];
 }
开发者ID:uibar,项目名称:lavinia2,代码行数:31,代码来源:TokensConfigProvider.php

示例14: getTokensComponents

 /**
  * @param string $vaultPaymentCode
  * @return TokenUiComponentInterface[]
  */
 public function getTokensComponents($vaultPaymentCode)
 {
     $result = [];
     $customerId = $this->session->getCustomerId();
     if (!$customerId) {
         return $result;
     }
     $vaultPayment = $this->getVaultPayment($vaultPaymentCode);
     if ($vaultPayment === null) {
         return $result;
     }
     $vaultProviderCode = $vaultPayment->getProviderCode();
     $componentProvider = $this->getComponentProvider($vaultProviderCode);
     if ($componentProvider === null) {
         return $result;
     }
     $filters[] = $this->filterBuilder->setField(PaymentTokenInterface::CUSTOMER_ID)->setValue($customerId)->create();
     $filters[] = $this->filterBuilder->setField(PaymentTokenInterface::PAYMENT_METHOD_CODE)->setValue($vaultProviderCode)->create();
     $filters[] = $this->filterBuilder->setField(PaymentTokenInterface::IS_ACTIVE)->setValue(1)->create();
     $filters[] = $this->filterBuilder->setField(PaymentTokenInterface::EXPIRES_AT)->setConditionType('gt')->setValue($this->dateTimeFactory->create('now', new \DateTimeZone('UTC'))->format('Y-m-d 00:00:00'))->create();
     $searchCriteria = $this->searchCriteriaBuilder->addFilters($filters)->create();
     foreach ($this->paymentTokenRepository->getList($searchCriteria)->getItems() as $token) {
         $result[] = $componentProvider->getComponentForToken($token);
     }
     return $result;
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:30,代码来源:TokensConfigProvider.php

示例15: 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->addFilters([$filter1, $filter2]);
     $this->searchCriteriaBuilder->addFilters([$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->addFilters([$filter2]);
     $this->searchCriteriaBuilder->addFilters([$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:kidaa30,项目名称:magento2-platformsh,代码行数:36,代码来源:TaxClassRepositoryTest.php


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