本文整理汇总了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);
}
示例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;
}
示例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');
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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];
}
示例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;
}
示例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();
}
示例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('.');
}
}
示例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;
}
示例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]];
}
示例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;
}
示例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]);
}