本文整理汇总了PHP中Magento\Framework\Api\SearchCriteriaBuilder::addFilters方法的典型用法代码示例。如果您正苦于以下问题:PHP SearchCriteriaBuilder::addFilters方法的具体用法?PHP SearchCriteriaBuilder::addFilters怎么用?PHP SearchCriteriaBuilder::addFilters使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Api\SearchCriteriaBuilder
的用法示例。
在下文中一共展示了SearchCriteriaBuilder::addFilters方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getList
/**
* {@inheritdoc}
*/
public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria)
{
$this->searchCriteriaBuilder->addFilters([$this->filterBuilder->setField('entity_type_code')->setValue(\Magento\Catalog\Api\Data\ProductAttributeInterface::ENTITY_TYPE_CODE)->setConditionType('eq')->create()]);
$this->searchCriteriaBuilder->setCurrentPage($searchCriteria->getCurrentPage());
$this->searchCriteriaBuilder->setPageSize($searchCriteria->getPageSize());
return $this->attributeSetRepository->getList($this->searchCriteriaBuilder->create());
}
示例2: isAssignedToObjects
/**
* {@inheritdoc}
*/
public function isAssignedToObjects()
{
$searchCriteria = $this->searchCriteriaBuilder->addFilters([$this->filterBuilder->setField(CustomerGroup::TAX_CLASS_ID)->setValue($this->getId())->create()])->create();
$result = $this->customerGroupRepository->getList($searchCriteria);
$items = $result->getItems();
return !empty($items);
}
示例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->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;
}
示例4: 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');
}
示例5: 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;
}
示例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: 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(ClassModel::KEY_TYPE)->setValue(TaxClassManagementInterface::TYPE_CUSTOMER)->create();
$searchCriteria = $this->searchCriteriaBuilder->addFilters([$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;
}
示例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: getSearchCriteria
/**
* Creates a search criteria DTO based on the array of field filters.
*
* @return SearchCriteria
*/
protected function getSearchCriteria()
{
foreach ($this->fieldFilters as $filter) {
// array of fields, put filters in array to use 'or' group
/** @var Filter[] $filterGroup */
$filterGroup = [];
if (!is_array($filter['field'])) {
// just one field
$filterGroup = [$this->createFilterData($filter['field'], $filter['condition'])];
} else {
foreach ($filter['field'] as $index => $field) {
$filterGroup[] = $this->createFilterData($field, $filter['condition'][$index]);
}
}
$this->searchCriteriaBuilder->addFilters($filterGroup);
}
foreach ($this->_orders as $field => $direction) {
/** @var SortOrder $sortOrder */
/** @var string $direction */
$direction = $direction == 'ASC' ? SortOrder::SORT_ASC : SortOrder::SORT_DESC;
$sortOrder = $this->sortOrderBuilder->setField($field)->setDirection($direction)->create();
$this->searchCriteriaBuilder->addSortOrder($sortOrder);
}
$this->searchCriteriaBuilder->setCurrentPage($this->_curPage);
$this->searchCriteriaBuilder->setPageSize($this->_pageSize);
return $this->searchCriteriaBuilder->create();
}
示例11: 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;
}
示例12: 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->addFilters($notLoggedInFilter)->addFilters($groupAll)->create();
return $this->groupRepository->getList($searchCriteria)->getItems();
}
示例13: 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('.');
}
}
示例14: 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;
}
示例15: 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]];
}