Skip to main content

Posts

Showing posts with the label filters

Magento 2 product collection Filtering multi-select attribute values

  If you have multi-select attribute of product like below If you want filter value for this option Use below syntax to get product data: ->addAttributeToFilter('store_model', array('finset' => $params['store_model'])) finset key is used for multiselect attribute filter. $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $products = $objectManager->get('Magento\Catalog\Model\Product')         ->getCollection()         ->addAttributeToSelect('*')         ->addAttributeToSelect('store_brand')         ->addAttributeToSelect('store_model')         ->addAttributeToSelect('store_year')         ->addAttributeToFilter('store_brand', array('finset' => $params['store_brand']))         ->addAttributeToFilter('store_model', array('finset' => $params['store_model']))         ->addAttributeToFilter('store_year', array('

Magetno 2 get the products collection filter by attributes with or condition

how to get product collection with filters? I'm use magento 2 . So i'm trying to get in product collection with filter multiple attributes with or condition for custom search use below product collection object if your wring any blocks if not use object manager and create product collection object use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory as ProductCollection; $productcollection = $objectManager->create('Magento\Catalog\Model\ResourceModel\Product\Collection'); $collection = $this->_productCollection                                     ->create()                                     ->addFieldToSelect('*')                                     ->addAttributeToFilter(                                     array(                                             array('attribute' => 'name', array('like' => '%'.$queryString.'%')),                                             array('attribu