本文整理汇总了PHP中Magento\Framework\Api\SearchCriteriaBuilder::create方法的典型用法代码示例。如果您正苦于以下问题:PHP SearchCriteriaBuilder::create方法的具体用法?PHP SearchCriteriaBuilder::create怎么用?PHP SearchCriteriaBuilder::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Api\SearchCriteriaBuilder
的用法示例。
在下文中一共展示了SearchCriteriaBuilder::create方法的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)]);
}, []);
}
示例2: init
/**
* {@inheritdoc}
*/
public function init($context)
{
foreach ($this->groupRepository->getList($this->searchCriteriaBuilder->create())->getItems() as $group) {
$this->customerGroups[$group->getId()] = true;
}
return parent::init($context);
}
示例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: getData
/**
* {@inheritdoc}
*/
public function getData(array $fieldsData)
{
$service = $this->getService();
$searchCriteria = $this->searchCriteriaBuilder->create();
/** @var SearchResults $list */
$list = $service->getList($searchCriteria);
return $this->getRequestedFields($list, $fieldsData);
}
示例5: toOptionArray
/**
* Retrieve all tax rates as an options array.
*
* @return array
*/
public function toOptionArray()
{
if (!$this->options) {
$searchCriteria = $this->searchCriteriaBuilder->create();
$searchResults = $this->sliderRepository->getList($searchCriteria);
$this->options = $this->converter->toOptionArray($searchResults->getItems(), Slider::ID, Slider::SLIDER_TITLE);
}
return $this->options;
}
示例6: 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)]);
}, []);
}
示例7: toOptionArray
/**
* Retrieve all tax rates as an options array.
*
* @return array
*/
public function toOptionArray()
{
if (!$this->options) {
$searchCriteria = $this->searchCriteriaBuilder->create();
$searchResults = $this->taxRateRepository->getList($searchCriteria);
$this->options = $this->converter->toOptionArray($searchResults->getItems(), Rate::KEY_ID, Rate::KEY_CODE);
}
return $this->options;
}
示例8: 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->create());
$attributes = [];
foreach ($searchResult->getItems() as $attribute) {
$attributes[] = $attribute->getAttributeCode();
}
return $attributes;
}
示例9: getAttributes
/**
* @param string $entityType
* @return \Magento\Eav\Api\Data\AttributeInterface[]
* @throws \Exception
*/
protected function getAttributes($entityType)
{
$attributes = $this->attributeCache->getAttributes($entityType);
if ($attributes) {
return $attributes;
}
$metadata = $this->metadataPool->getMetadata($entityType);
$searchResult = $this->attributeRepository->getList($metadata->getEavEntityType(), $this->searchCriteriaBuilder->create());
$attributes = $searchResult->getItems();
$this->attributeCache->saveAttributes($entityType, $attributes);
return $attributes;
}
示例10: getMetadataValues
/**
* Get metadata for sales rule form. It will be merged with form UI component declaration.
*
* @param Rule $rule
* @return array
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function getMetadataValues(\Magento\SalesRule\Model\Rule $rule)
{
$customerGroups = $this->groupRepository->getList($this->searchCriteriaBuilder->create())->getItems();
$applyOptions = [['label' => __('Percent of product price discount'), 'value' => Rule::BY_PERCENT_ACTION], ['label' => __('Fixed amount discount'), 'value' => Rule::BY_FIXED_ACTION], ['label' => __('Fixed amount discount for whole cart'), 'value' => Rule::CART_FIXED_ACTION], ['label' => __('Buy X get Y free (discount amount is Y)'), 'value' => Rule::BUY_X_GET_Y_ACTION]];
$couponTypesOptions = [];
$couponTypes = $this->salesRuleFactory->create()->getCouponTypes();
foreach ($couponTypes as $key => $couponType) {
$couponTypesOptions[] = ['label' => $couponType, 'value' => $key];
}
$labels = $rule->getStoreLabels();
return ['rule_information' => ['children' => ['website_ids' => ['arguments' => ['data' => ['config' => ['options' => $this->store->getWebsiteValuesForForm()]]]], 'is_active' => ['arguments' => ['data' => ['config' => ['options' => [['label' => __('Active'), 'value' => '1'], ['label' => __('Inactive'), 'value' => '0']]]]]], 'customer_group_ids' => ['arguments' => ['data' => ['config' => ['options' => $this->objectConverter->toOptionArray($customerGroups, 'id', 'code')]]]], 'coupon_type' => ['arguments' => ['data' => ['config' => ['options' => $couponTypesOptions]]]], 'is_rss' => ['arguments' => ['data' => ['config' => ['options' => [['label' => __('Yes'), 'value' => '1'], ['label' => __('No'), 'value' => '0']]]]]]]], 'actions' => ['children' => ['simple_action' => ['arguments' => ['data' => ['config' => ['options' => $applyOptions]]]], 'discount_amount' => ['arguments' => ['data' => ['config' => ['value' => '0']]]], 'discount_qty' => ['arguments' => ['data' => ['config' => ['value' => '0']]]], 'apply_to_shipping' => ['arguments' => ['data' => ['config' => ['options' => [['label' => __('Yes'), 'value' => '1'], ['label' => __('No'), 'value' => '0']]]]]], 'stop_rules_processing' => ['arguments' => ['data' => ['config' => ['options' => [['label' => __('Yes'), 'value' => '1'], ['label' => __('No'), 'value' => '0']]]]]]]], 'labels' => ['children' => ['store_labels[0]' => ['arguments' => ['data' => ['config' => ['value' => isset($labels[0]) ? $labels[0] : '']]]]]]];
}
示例11: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
// Get list of available records
$searchCriteria = $this->searchCriteriaBuilder->create();
$searchResult = $this->demoRepository->getList($searchCriteria);
$rows = [];
foreach ($searchResult->getItems() as $item) {
$rows[] = [$item->getId(), $item->getTitle()];
}
$table = $this->getHelper('table');
$table->setHeaders(array(__('ID'), __('Title')))->setRows($rows);
$table->render($output);
}
示例12: 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;
}
示例13: toOptionArray
/**
* Return array of customer groups
*
* @return array
*/
public function toOptionArray()
{
if (!$this->moduleManager->isEnabled('Magento_Customer')) {
return [];
}
$customerGroups = [['label' => __('ALL GROUPS'), 'value' => GroupInterface::CUST_GROUP_ALL]];
/** @var GroupInterface[] $groups */
$groups = $this->groupRepository->getList($this->searchCriteriaBuilder->create());
foreach ($groups->getItems() as $group) {
$customerGroups[] = ['label' => $group->getCode(), 'value' => $group->getId()];
}
return $customerGroups;
}
示例14: 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];
}
示例15: _getCustomerGroups
/**
* Retrieve allowed customer groups
*
* @param int $groupId return name by customer group id
* @return array|string
*/
protected function _getCustomerGroups($groupId = null)
{
if ($this->_customerGroups === null) {
$this->_customerGroups = [];
foreach ($this->groupRepository->getList($this->searchCriteriaBuilder->create())->getItems() as $item) {
$this->_customerGroups[$item->getId()] = $item->getCode();
}
$notLoggedInGroup = $this->groupManagement->getNotLoggedInGroup();
$this->_customerGroups[$notLoggedInGroup->getId()] = $notLoggedInGroup->getCode();
}
if ($groupId !== null) {
return isset($this->_customerGroups[$groupId]) ? $this->_customerGroups[$groupId] : null;
}
return $this->_customerGroups;
}