2

Magento-2 we would like to filter the products from REST API

I have filtered product by price in the frontend please check the result in the below screenshot

(24-MB02 price and special price we set at admin end)

Screenshot:-

enter image description here

But API Level:-

the same product 24-MB02 is missing

Api Url:- /rest/V1/products/

http://10.0.0.55/ma221/rest/V1/products/?searchCriteria[filterGroups][0][filters][0][field]=category_id&searchCriteria[filterGroups][0][filters][0][value]=4&searchCriteriafilterGroups[filters][0][field]=price&searchCriteriafilterGroups[filters][0][value]=40&searchCriteriafilterGroups[filters][0][condition_type]=gteq&searchCriteriafilterGroups[filters][0][field]=price&searchCriteriafilterGroups[filters][0][value]=50&searchCriteriafilterGroups[filters][0][condition_type]=lteq

But result we are getting 4 products

enter image description here

output:-

enter image description here

Please help on this. Thanks. How to achieve this?

/vendor/magento/module-catalog/Model/ProductRepository.php

public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria)
    {
        /** @var \Magento\Catalog\Model\ResourceModel\Product\Collection $collection */
        $collection = $this->collectionFactory->create();
        $this->extensionAttributesJoinProcessor->process($collection);

        $collection->addAttributeToSelect('*');
        $collection->joinAttribute('status', 'catalog_product/status', 'entity_id', null, 'inner');
        $collection->joinAttribute('visibility', 'catalog_product/visibility', 'entity_id', null, 'inner');


        $this->collectionProcessor->process($searchCriteria, $collection);

        $collection->load();

        $collection->addCategoryIds();
        $searchResult = $this->searchResultsFactory->create();
        $searchResult->setSearchCriteria($searchCriteria);
        $searchResult->setItems($collection->getItems());
        $searchResult->setTotalCount($collection->getSize());

        foreach ($collection->getItems() as $product) {
            $this->cacheProduct(
                $this->getCacheKey(
                    [
                        false,
                        $product->hasData(\Magento\Catalog\Model\Product::STORE_ID) ? $product->getStoreId() : null
                    ]
                ),
                $product
            );
        }

        return $searchResult;
    }
  • Any updates on this. – Pushpendra Singh Jan 8 '18 at 11:25
  • @PushpendraSingh i didn't get any fix, still my issue exist, may i know whether u have any idea ? – Nagaraju K Jan 9 '18 at 11:03
  • I am facing same issue, unfortunately currently I have no Idea. – Pushpendra Singh Jan 9 '18 at 13:06
  • Hi @PushpendraSingh i am also trying same from my end, if u found any solution or fix please share me thanks – Nagaraju K Jan 9 '18 at 14:28
  • Any updates on this – shivashankar m Jan 18 '18 at 6:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.