简体   繁体   English

magento 2 rest api产品过滤器

[英]magento 2 rest api product filters

I am working on magento 2 api. 我正在研究magento 2 API。 I need products based on below filters 我需要基于以下过滤器的产品

  1. store id 商店编号
  2. by product name search 按产品名称搜索
  3. shorting by name 简称
  4. category id 类别编号
  5. add limit 增加限制

I have try with this api but no option available 我尝试使用此api,但没有可用的选项

index.php/rest/V1/categories/{id}/products index.php / rest / V1 / categories / {id} / products

Please someone suggest how to archive this. 请有人建议如何存档。

Thanks 谢谢

You are looking for the (GET) API /rest/V1/products . 您正在寻找(GET)API /rest/V1/products

  1. the store ID should be automatically detected by the store, because you can pass the store code in the URL before. 商店ID应该由商店自动检测,因为您可以在URL中之前传递商店代码。 If you have a store with code test , the API will start with GET /rest/test/V1/products/[...] . 如果您的商店具有代码test ,则API将以GET /rest/test/V1/products/[...]开头。
  2. You can use the like condition type. 您可以使用like条件类型。 Ex.: products with "sample" in their name: ?searchCriteria[filter_groups][0][filters][0][field]=name &searchCriteria[filter_groups][0][filters][0][value]=%sample% &searchCriteria[filter_groups][0][filters][0][condition_type]=like 例如:名称中带有“ sample”的产品: ?searchCriteria[filter_groups][0][filters][0][field]=name &searchCriteria[filter_groups][0][filters][0][value]=%sample% &searchCriteria[filter_groups][0][filters][0][condition_type]=like
  3. you are looking for the sortOrders . 您正在寻找sortOrders Ex.: searchCriteria[sortOrders][0][field]=name . 例如: searchCriteria[sortOrders][0][field]=name You can even add the sort direction, for example DESC, with searchCriteria[sortOrders][0][direction]=DESC . 您甚至可以使用searchCriteria[sortOrders][0][direction]=DESC添加排序方向,例如searchCriteria[sortOrders][0][direction]=DESC
  4. Use the category_id field and the eq condition type. 使用category_id字段和eq条件类型。 Ex.: if you want products from category 10: searchCriteria[filter_groups][0][filters][0][field]=category_id& searchCriteria[filter_groups][0][filters][0][value]=10& searchCriteria[filter_groups][0][filters][0][condition_type]=eq 例如:如果您要使用类别10中的产品: searchCriteria[filter_groups][0][filters][0][field]=category_id& searchCriteria[filter_groups][0][filters][0][value]=10& searchCriteria[filter_groups][0][filters][0][condition_type]=eq
  5. use searchCriteria[pageSize] . 使用searchCriteria[pageSize] Ex.: 20 products starting from the 40th, equivalent in SQL to LIMIT 20 OFFSET 40 : &searchCriteria[pageSize]=20&searchCriteria[currentPage]=3 例:从第40个开始的20种产品,在SQL中等效于LIMIT 20 OFFSET 40&searchCriteria[pageSize]=20&searchCriteria[currentPage]=3

Of course you can perform AND and OR operations with filters. 当然,您可以使用过滤器执行AND和OR运算。

[
    "filter_groups": [
        {
            "filters": [
                {
                    "field": "type_id",
                    "value": "simple",
                    "condition_type": "eq"
                }
            ]
        },
        {
            "filters": [
                {
                    "field": "category_id",
                    "value": "611",
                    "condition_type": "eq"
                }
            ]
        }
    ],
    "page_size": 100,
    "current_page": 1,
    "sort_orders": [
        {
            "field": "name",
            "direction": "ASC"
        }
    ]
]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM