0

I need to get a product collection to filter multiple attributes.

Forexample:

First: color multi select filter(attribute) values: 23, 25, 26.

Second: system multi-select filter(attribute) values: 27, 28.

I am getting filter values in one array and need to filter in the collection.

There are comma separated $list = 23, 25, 26,27, 28 In the controller file:

$list =  $this->getRequest()->getParam('list', false);
$filter_ids = explode(",",$list);

$productcollection = $objectManager->create('Magento\Catalog\Model\ResourceModel\Product\CollectionFactory');
$categoryProducts = $productcollection->create()->addAttributeToSelect('*')->addAttributeToFilter('color', array('in',$filter_ids))->addAttributeToFilter('system', array('in',$filter_ids))->load();

I am not getting a result in this way. where I am wrong. Please suggest to me.

Thanks

2
  • Did you get the result for only one product ? or is there any error?
    – aravind
    Feb 28 '20 at 9:39
  • I am getting zero result
    – Shomita
    Feb 28 '20 at 9:43
2

Check with my code,

$list =  $this->getRequest()->getParam('list', false);
$filter_ids = explode(",",$list);
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$productcollection = $objectManager->create('Magento\Catalog\Model\ResourceModel\Product\CollectionFactory');
$categoryProducts =  $productcollection->create()->addAttributeToSelect('*')->addAttributeToFilter(
        array(
            array('attribute'=> 'color','in' => $filter_ids),
            array('attribute'=> 'system','in' => $filter_ids),
        )
    );
11
  • okay.. Am checking
    – Shomita
    Feb 28 '20 at 9:59
  • Getting error Exception #0 (Exception): Warning: Illegal string offset 'attribute' in /vendor/magento/module-eav/Model/Entity/Collection/AbstractCollection.php on line 370
    – Shomita
    Feb 28 '20 at 10:01
  • I have update the code, Need to use addAttributeToFilter instead of addFieldToFilter
    – aravind
    Feb 28 '20 at 10:02
  • Getting same error
    – Shomita
    Feb 28 '20 at 10:06
  • @aravid are you checking?
    – Shomita
    Feb 28 '20 at 10:21

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.