Skip to content

I want to filter product collection by category id,custom attribute as we did in Magento1.9 or earlier #2255

@gg24

Description

@gg24

$collection = Mage::getResourceModel('catalog/product_collection');
$collection->addAttributeToSelect('name','your-attribute');
$collection->addAttributeToFilter('your-attribute', array('eq' => 'attr-value'));

or

$category = Mage::getModel('catalog/category')->load($categoryId);
$collection = Mage::getModel('catalog/product')->getCollection()
->addCategoryFilter($category);

How can I achieve in Magento2.0

I want to filter the product collection by category id, custom category attribute(store id, customer group id).
I have create two custom attribute for category in Magento admin for Store and customer segmentation, I provide the options as Multiselect in the following way,
for store selection(in the dropdown, all store created come dynamically ).
for segmentation selection(in the dropdown, all customer group created come dynamically )

Now i want to filter product collection on the basis of attribute filter(store id, customer group id)
store
segmentation

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions