简体   繁体   中英

Magento2 OR query on collection

We have been trying to make a query when a user apply some filters on front end. We are trying to make OR query in products collection: tried the following but none of them work

$collection->addAttributeToFilter(['web_mobile_filter','offer_group_name_value'],
            [
                ['in' => '1122'],
                ['in' => '72']
            ]);

and

  $collection->addAttributeToFilter(
        [
            [
                'attribute' => 'web_mobile_filter',
                'in' => '1122'
            ],
            [
                'attribute' => 'offer_group_name_value',
                'in' => '72,73'
            ],
        ]
    );

Can someone help me, find me what i am doing wrong here please?

You can write like this :-

$collection->addAttributeToFilter( 'web_mobile_filter',
            [         
                'in' => '1122'
            ]);

\n
\n
\n
$collection->addAttributeToFilter(array( array('attribute' => 'special_price','null' => true), array('attribute' => 'product_in_stock','eq' => 1)), '', 'left' );
\n
\n
\n

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM