cancel
Showing results for 
Search instead for 
Did you mean: 

Magento Filter - How can I filter by category_id and brand

Magento Filter - How can I filter by category_id and brand

Hi I was trying to filter by category and brand but I got as response all products from category instead of just an specific brand that category have in it.

 

{{BaseUrl}}/products/?searchCriteria[filterGroups][0][filters][0][field]=brand&searchCriteria[filterGroups][0][filters][0][value]=5856&searchCriteria[filter_groups][0][filters][1][field]=category_id&searchCriteria[filter_groups][0][filters][1][value]=261

I would like to get something like this (items= 1):

{
    "items": [
        {
            "id": 1452,
            "sku": "38000184932",
            "name": "Pringles Original 124gr",
            "attribute_set_id": 10,
            "price": 23.8,
            "status": 1,
            "visibility": 4,
            "type_id": "simple",
            "created_at": "2020-10-23 12:48:35",
            "updated_at": "2022-04-22 15:31:41",
            "weight": 0.1,
            "extension_attributes": {
                "website_ids": [
                    1
                ],
                "category_links": [
                    {
                        "position": 0,
                        "category_id": "17"
                    },
                    {
                        "position": 0,
                        "category_id": "21"
                    },
                    {
                        "position": 14,
                        "category_id": "261"
                    }
                ]
            },
            "product_links": [
                {
                    "sku": "38000184932",
                    "link_type": "related",
                    "linked_product_sku": "38000184956",
                    "linked_product_type": "simple",
                    "position": 1
                },
                {
                    "sku": "38000184932",
                    "link_type": "related",
                    "linked_product_sku": "38000184949",
                    "linked_product_type": "simple",
                    "position": 2
                }
            ],
            "options": [],
            "media_gallery_entries": [
                {
                    "id": 26574,
                    "media_type": "image",
                    "label": null,
                    "position": 5,
                    "disabled": false,
                    "types": [
                        "image",
                        "small_image",
                        "thumbnail",
                        "swatch_image"
                    ],
                    "file": "/p/r/pringles_logo.png"
                }
            ],
            "tier_prices": [],
            "custom_attributes": [
                {
                    "attribute_code": "image",
                    "value": "/p/r/pringles_logo.png"
                },
                {
                    "attribute_code": "url_key",
                    "value": "pringles-original-bolivia"
                },
                {
                    "attribute_code": "page_layout",
                    "value": "product-full-width"
                },
                {
                    "attribute_code": "gift_message_available",
                    "value": "0"
                },
                {
                    "attribute_code": "short_description",
                    "value": "<h3><strong>Pringles Original </strong></h3>\r\n<p>Cuando eres original, tu estableces el estándar de cómo se hace. Con el atractivo sabor de esta papa, llevarás este estándar de oro hasta el banco de sabores. Es el único bocadillo salado que siempre da en el clavo.</p>"
                },
                {
                    "attribute_code": "small_image",
                    "value": "/p/r/pringles_logo.png"
                },
                {
                    "attribute_code": "meta_title",
                    "value": "Pringles Original 124gr"
                },
                {
                    "attribute_code": "options_container",
                    "value": "container2"
                },
                {
                    "attribute_code": "gift_wrapping_available",
                    "value": "0"
                },
                {
                    "attribute_code": "simec_name",
                    "value": "Pringles Original 124gr"
                },
                {
                    "attribute_code": "thumbnail",
                    "value": "/p/r/pringles_logo.png"
                },
                {
                    "attribute_code": "meta_keyword",
                    "value": "Pringles Original 124gr, papas fritas, bolivia"
                },
                {
                    "attribute_code": "swatch_image",
                    "value": "/p/r/pringles_logo.png"
                },
                {
                    "attribute_code": "meta_description",
                    "value": "Pringles: Original 124gr en Bolivia"
                },
                {
                    "attribute_code": "simec_origin",
                    "value": "Pringles Original 124gr"
                },
                {
                    "attribute_code": "simec_unit",
                    "value": "UND"
                },
                {
                    "attribute_code": "simec_provider",
                    "value": "6247"
                },
                {
                    "attribute_code": "msrp_display_actual_price_type",
                    "value": "0"
                },
                {
                    "attribute_code": "required_options",
                    "value": "0"
                },
                {
                    "attribute_code": "has_options",
                    "value": "0"
                },
                {
                    "attribute_code": "image_label",
                    "value": "Pringles Original 124gr"
                },
                {
                    "attribute_code": "small_image_label",
                    "value": "Pringles Original 124gr"
                },
                {
                    "attribute_code": "thumbnail_label",
                    "value": "Pringles Original 124gr"
                },
                {
                    "attribute_code": "tax_class_id",
                    "value": "2"
                },
                {
                    "attribute_code": "category_ids",
                    "value": [
                        "17",
                        "21",
                        "261"
                    ]
                },
                {
                    "attribute_code": "is_returnable",
                    "value": "2"
                },
                {
                    "attribute_code": "brand",
                    "value": "5856"
                }
            ]
        }
],
    "search_criteria": {
        "filter_groups": [
            {
                "filters": [
                    {
                        "field": "brand",
                        "value": "5856",
                        "condition_type": "eq"
                    }
                ]
            }
        ]
    },
    "total_count": 5
}

but I got all products that category have on it (items = 31)