本文整理汇总了PHP中Magento\Framework\Api\FilterBuilder::create方法的典型用法代码示例。如果您正苦于以下问题:PHP FilterBuilder::create方法的具体用法?PHP FilterBuilder::create怎么用?PHP FilterBuilder::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Api\FilterBuilder
的用法示例。
在下文中一共展示了FilterBuilder::create方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _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();
}
示例2: addRangeAttributeToSearch
/**
* Add attributes that have a range (from,to) to the SearchCriteriaBuilder.
*
* @param string $attributeCode
* @param array|string $attributeValue
* @return void
*/
private function addRangeAttributeToSearch($attributeCode, $attributeValue)
{
if (isset($attributeValue['from']) && '' !== $attributeValue['from']) {
$this->filterBuilder->setField("{$attributeCode}.from")->setValue($attributeValue['from']);
$this->searchCriteriaBuilder->addFilter($this->filterBuilder->create());
}
if (isset($attributeValue['to']) && '' !== $attributeValue['to']) {
$this->filterBuilder->setField("{$attributeCode}.to")->setValue($attributeValue['to']);
$this->searchCriteriaBuilder->addFilter($this->filterBuilder->create());
}
}
示例3: createFilterData
/**
* Creates a filter DTO for given field/condition
*
* @param string $field Field for new filter
* @param string|array $condition Condition for new filter.
* @return Filter
*/
protected function createFilterData($field, $condition)
{
$this->filterBuilder->setField($field);
if (is_array($condition)) {
$this->filterBuilder->setValue(reset($condition));
$this->filterBuilder->setConditionType(key($condition));
} else {
// not an array, just use eq as condition type and given value
$this->filterBuilder->setConditionType('eq');
$this->filterBuilder->setValue($condition);
}
return $this->filterBuilder->create();
}
示例4: applySelectionOnTargetProvider
/**
* Apply selection by Excluded Included to Search Result
*
* @throws LocalizedException
* @return void
*/
public function applySelectionOnTargetProvider()
{
$selected = $this->request->getParam(static::SELECTED_PARAM);
$excluded = $this->request->getParam(static::EXCLUDED_PARAM);
if ('false' === $excluded) {
return;
}
$component = $this->getComponent();
$this->prepareComponent($component);
$dataProvider = $component->getContext()->getDataProvider();
try {
if (is_array($excluded) && !empty($excluded)) {
$this->filterBuilder->setConditionType('nin')->setField($dataProvider->getPrimaryFieldName())->setValue($excluded);
$dataProvider->addFilter($this->filterBuilder->create());
} elseif (is_array($selected) && !empty($selected)) {
$this->filterBuilder->setConditionType('in')->setField($dataProvider->getPrimaryFieldName())->setValue($selected);
$dataProvider->addFilter($this->filterBuilder->create());
}
} catch (\Exception $e) {
throw new LocalizedException(__($e->getMessage()));
}
}
示例5: _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);
try {
$this->searchResult = $this->getSearch()->search($searchCriteria);
} catch (EmptyRequestDataException $e) {
/** @var \Magento\Framework\Api\Search\SearchResultInterface $searchResult */
$this->searchResult = $this->searchResultFactory->create()->setItems([]);
} catch (NonExistingRequestNameException $e) {
$this->_logger->error($e->getMessage());
throw new LocalizedException(__('Sorry, something went wrong. You can find out more in the error log.'));
}
$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();
}