15/08/2022
We use cookies to make your experience better. To comply with the new e-Privacy directive, we need to ask for your consent to set the cookies. Learn more.
We use cookies to make your experience better. To comply with the new e-Privacy directive, we need to ask for your consent to set the cookies. Learn more.
You can use OR & AND condition to collection in magento 2
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
protected $productCollectionFactory;
public function __construct(CollectionFactory $productCollectionFactory)
{
$this->productCollectionFactory = $productCollectionFactory;
}
$collection = $this->productCollectionFactory->create();
$collection->addAttributeToSelect('*');
$collection->addAttributeToFilter([['attribute'=>'sku','like'=>'%ch%'],['attribute'=>'status', 'eq'=>'1']]);
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
protected $productCollectionFactory;
public function __construct(CollectionFactory $productCollectionFactory)
{
$this->productCollectionFactory = $productCollectionFactory;
}
$collection = $this->productCollectionFactory->create();
$collection->addAttributeToSelect('*');
$collection->addAttributeToFilter([['attribute'=>'sku','like'=> '%ch%'],
['attribute'=>'status','eq' => '1']]);
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
protected $productCollectionFactory;
public function __construct(CollectionFactory $productCollectionFactory)
{
$this->productCollectionFactory = $productCollectionFactory;
}
$collection = $this->productCollectionFactory->create();
$collection->addAttributeToSelect('*');
$collection->addFieldToFilter(['attribute_set_id','type_id'],[['eq'=>4],['eq'=>'simple']]
);