Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria)
 {
     /** @var \Magento\Catalog\Model\ResourceModel\Product\Collection $collection */
     $collection = $this->collectionFactory->create();
     $this->extensionAttributesJoinProcessor->process($collection);
     foreach ($this->metadataService->getList($this->searchCriteriaBuilder->create())->getItems() as $metadata) {
         $collection->addAttributeToSelect($metadata->getAttributeCode());
     }
     $collection->joinAttribute('status', 'catalog_product/status', 'entity_id', null, 'inner');
     $collection->joinAttribute('visibility', 'catalog_product/visibility', 'entity_id', null, 'inner');
     //Add filters from root filter group to the collection
     foreach ($searchCriteria->getFilterGroups() as $group) {
         $this->addFilterGroupToCollection($group, $collection);
     }
     /** @var SortOrder $sortOrder */
     foreach ((array) $searchCriteria->getSortOrders() as $sortOrder) {
         $field = $sortOrder->getField();
         $collection->addOrder($field, $sortOrder->getDirection() == SortOrder::SORT_ASC ? 'ASC' : 'DESC');
     }
     $collection->setCurPage($searchCriteria->getCurrentPage());
     $collection->setPageSize($searchCriteria->getPageSize());
     $collection->load();
     $searchResult = $this->searchResultsFactory->create();
     $searchResult->setSearchCriteria($searchCriteria);
     $searchResult->setItems($collection->getItems());
     $searchResult->setTotalCount($collection->getSize());
     return $searchResult;
 }
 /**
  * {@inheritdoc}
  */
 public function getList($entityTypeCode, \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria)
 {
     if (!$entityTypeCode) {
         throw InputException::requiredField('entity_type_code');
     }
     /** @var \Magento\Eav\Model\Resource\Entity\Attribute\Collection $attributeCollection */
     $attributeCollection = $this->attributeCollectionFactory->create();
     $attributeCollection->addFieldToFilter('entity_type_code', ['eq' => $entityTypeCode]);
     $attributeCollection->join(['entity_type' => $attributeCollection->getTable('eav_entity_type')], 'main_table.entity_type_id = entity_type.entity_type_id', []);
     $attributeCollection->join(['eav_entity_attribute' => $attributeCollection->getTable('eav_entity_attribute')], 'main_table.attribute_id = eav_entity_attribute.attribute_id', []);
     $attributeCollection->join(['additional_table' => $attributeCollection->getTable('catalog_eav_attribute')], 'main_table.attribute_id = additional_table.attribute_id', []);
     //Add filters from root filter group to the collection
     foreach ($searchCriteria->getFilterGroups() as $group) {
         $this->addFilterGroupToCollection($group, $attributeCollection);
     }
     /** @var \Magento\Framework\Api\SortOrder $sortOrder */
     foreach ((array) $searchCriteria->getSortOrders() as $sortOrder) {
         $attributeCollection->addOrder($sortOrder->getField(), $sortOrder->getDirection() == SearchCriteriaInterface::SORT_ASC ? 'ASC' : 'DESC');
     }
     $totalCount = $attributeCollection->getSize();
     // Group attributes by id to prevent duplicates with different attribute sets
     $attributeCollection->addAttributeGrouping();
     $attributeCollection->setCurPage($searchCriteria->getCurrentPage());
     $attributeCollection->setPageSize($searchCriteria->getPageSize());
     $attributes = [];
     /** @var \Magento\Eav\Api\Data\AttributeInterface $attribute */
     foreach ($attributeCollection as $attribute) {
         $attributes[] = $this->get($entityTypeCode, $attribute->getAttributeCode());
     }
     $searchResults = $this->searchResultsFactory->create();
     $searchResults->setSearchCriteria($searchCriteria);
     $searchResults->setItems($attributes);
     $searchResults->setTotalCount($totalCount);
     return $searchResults;
 }
Exemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria)
 {
     /** @var \Magento\Tax\Model\Resource\Calculation\Rate\Collection $collection */
     $collection = $this->rateFactory->create()->getCollection();
     $collection->joinRegionTable();
     //Add filters from root filter group to the collection
     foreach ($searchCriteria->getFilterGroups() as $group) {
         $this->addFilterGroupToCollection($group, $collection);
     }
     $sortOrders = $searchCriteria->getSortOrders();
     /** @var SortOrder $sortOrder */
     if ($sortOrders) {
         foreach ($sortOrders as $sortOrder) {
             $collection->addOrder($this->translateField($sortOrder->getField()), $sortOrder->getDirection() == SearchCriteria::SORT_ASC ? 'ASC' : 'DESC');
         }
     }
     $collection->setCurPage($searchCriteria->getCurrentPage());
     $collection->setPageSize($searchCriteria->getPageSize());
     $taxRate = [];
     /** @var \Magento\Tax\Model\Calculation\Rate $taxRateModel */
     foreach ($collection as $taxRateModel) {
         $taxRate[] = $taxRateModel;
     }
     return $this->taxRateSearchResultsFactory->create()->setItems($taxRate)->setTotalCount($collection->getSize())->setSearchCriteria($searchCriteria);
 }
Exemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria)
 {
     /** @var \Magento\Catalog\Model\Resource\Product\Collection $collection */
     $collection = $this->collectionFactory->create();
     $defaultAttributeSetId = $this->eavConfig->getEntityType(\Magento\Catalog\Api\Data\ProductAttributeInterface::ENTITY_TYPE_CODE)->getDefaultAttributeSetId();
     $extendedSearchCriteria = $this->searchCriteriaBuilder->addFilter([$this->filterBuilder->setField('attribute_set_id')->setValue($defaultAttributeSetId)->create()]);
     foreach ($this->metadataService->getList($extendedSearchCriteria->create())->getItems() as $metadata) {
         $collection->addAttributeToSelect($metadata->getAttributeCode());
     }
     $collection->joinAttribute('status', 'catalog_product/status', 'entity_id', null, 'inner');
     $collection->joinAttribute('visibility', 'catalog_product/visibility', 'entity_id', null, 'inner');
     //Add filters from root filter group to the collection
     foreach ($searchCriteria->getFilterGroups() as $group) {
         $this->addFilterGroupToCollection($group, $collection);
     }
     /** @var SortOrder $sortOrder */
     foreach ((array) $searchCriteria->getSortOrders() as $sortOrder) {
         $field = $sortOrder->getField();
         $collection->addOrder($field, $sortOrder->getDirection() == SearchCriteriaInterface::SORT_ASC ? 'ASC' : 'DESC');
     }
     $collection->setCurPage($searchCriteria->getCurrentPage());
     $collection->setPageSize($searchCriteria->getPageSize());
     $collection->load();
     $searchResult = $this->searchResultsFactory->create();
     $searchResult->setSearchCriteria($searchCriteria);
     $searchResult->setItems($collection->getItems());
     $searchResult->setTotalCount($collection->getSize());
     return $searchResult;
 }
Exemplo n.º 5
0
 /**
  * Retrieve customers addresses matching the specified criteria.
  *
  * @param SearchCriteriaInterface $searchCriteria
  * @return \Magento\Customer\Api\Data\AddressSearchResultsInterface
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function getList(SearchCriteriaInterface $searchCriteria)
 {
     $searchResults = $this->addressSearchResultsFactory->create();
     /** @var Collection $collection */
     $collection = $this->addressCollectionFactory->create();
     $this->extensionAttributesJoinProcessor->process($collection, 'Magento\\Customer\\Api\\Data\\AddressInterface');
     // Add filters from root filter group to the collection
     foreach ($searchCriteria->getFilterGroups() as $group) {
         $this->addFilterGroupToCollection($group, $collection);
     }
     $searchResults->setTotalCount($collection->getSize());
     /** @var SortOrder $sortOrder */
     foreach ((array) $searchCriteria->getSortOrders() as $sortOrder) {
         $field = $sortOrder->getField();
         $collection->addOrder($field, $sortOrder->getDirection() == SearchCriteriaInterface::SORT_ASC ? 'ASC' : 'DESC');
     }
     $collection->setCurPage($searchCriteria->getCurrentPage());
     $collection->setPageSize($searchCriteria->getPageSize());
     /** @var \Magento\Customer\Api\Data\AddressInterface[] $addresses */
     $addresses = [];
     /** @var \Magento\Customer\Model\Address $address */
     foreach ($collection->getItems() as $address) {
         $addresses[] = $this->getById($address->getId());
     }
     $searchResults->setItems($addresses);
     $searchResults->setSearchCriteria($searchCriteria);
     return $searchResults;
 }
 /**
  * Retrieve coupon.
  *
  * @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria
  * @return \Magento\SalesRule\Api\Data\CouponSearchResultInterface
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria)
 {
     /** @var \Magento\SalesRule\Model\ResourceModel\Coupon\Collection $collection */
     $collection = $this->collectionFactory->create();
     $couponInterfaceName = 'Magento\\SalesRule\\Api\\Data\\CouponInterface';
     $this->extensionAttributesJoinProcessor->process($collection, $couponInterfaceName);
     //Add filters from root filter group to the collection
     /** @var FilterGroup $group */
     foreach ($searchCriteria->getFilterGroups() as $group) {
         $this->addFilterGroupToCollection($group, $collection);
     }
     $sortOrders = $searchCriteria->getSortOrders();
     if ($sortOrders === null) {
         $sortOrders = [];
     }
     /** @var \Magento\Framework\Api\SortOrder $sortOrder */
     foreach ($sortOrders as $sortOrder) {
         $field = $sortOrder->getField();
         $collection->addOrder($field, $sortOrder->getDirection() == SortOrder::SORT_ASC ? 'ASC' : 'DESC');
     }
     $collection->setCurPage($searchCriteria->getCurrentPage());
     $collection->setPageSize($searchCriteria->getPageSize());
     $coupons = [];
     /** @var \Magento\SalesRule\Model\Coupon $couponModel */
     foreach ($collection->getItems() as $couponModel) {
         $coupons[] = $couponModel->getData();
     }
     $searchResults = $this->searchResultFactory->create();
     $searchResults->setSearchCriteria($searchCriteria);
     $searchResults->setItems($coupons);
     $searchResults->setTotalCount($collection->getSize());
     return $searchResults;
 }
 /**
  * @param SearchCriteriaInterface $searchCriteria
  * @param FeaturetoggleCollection     $collection
  */
 private function setCurrentPage(SearchCriteriaInterface $searchCriteria, $collection)
 {
     if ($searchCriteria->getCurrentPage()) {
         $collection->setCurPage($searchCriteria->getCurrentPage());
     }
 }
Exemplo n.º 8
-1
 /**
  * {@inheritdoc}
  */
 public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria)
 {
     $this->searchCriteriaBuilder->addFilter([$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());
 }