Magento 2: How to add multiple AND conditions to one single attribute that could be used to join other condition groups?How to use FIND_IN_SET on a multiselect attribute filter with an AND condition?Adding attribute using JOIN to CollectionMagento 2: Product Repositories, Filter Groups, and `AND`Assign Multiple Filter to Single FilterGroup in magento 2Magento 2: addAttributeToFilter not returning any resultsMagento : Filter Collection by Attribute that Doesn't Exist or Null or another conditionMagento2: How to add multiple AND and OR conditions to filter/filterGroups?Magento 2 : how to addCategoriesFilter with AND condtion?Magento 1.9 collection multi conditionsMagento 2.3 custom conditions for attribute filter using addAttributeToFilter
Why can't I use =default for default ctors with a member initializer list
What speaks against investing in precious metals?
Wooden cooking layout
Is it possible to have a wealthy country without a middle class?
Has there been a multiethnic Star Trek character?
A IP can traceroute to it, but can not ping
Is this use of the expression "long past" correct?
SQL counting distinct over partition
Which languages would be most useful in Europe at the end of the 19th century?
Arriving at the same result with the opposite hypotheses
Is it legal for a bar bouncer to confiscate a fake ID
How is John Wick 3 a 15 certificate?
How can I get an unreasonable manager to approve time off?
How to communicate to my GM that not being allowed to use stealth isn't fun for me?
How can I make some of my chapters "come to life"?
Is White controlling this game?
Someone whose aspirations exceed abilities or means
Generate basis elements of the Steenrod algebra
What is the maximum number of net attacks that one can make in a round?
Certain search in list
Extreme flexible working hours: how to control people and activities?
Fixing obscure 8080 emulator bug?
How to use memset in c++?
Soft question: Examples where lack of mathematical rigour cause security breaches?
Magento 2: How to add multiple AND conditions to one single attribute that could be used to join other condition groups?
How to use FIND_IN_SET on a multiselect attribute filter with an AND condition?Adding attribute using JOIN to CollectionMagento 2: Product Repositories, Filter Groups, and `AND`Assign Multiple Filter to Single FilterGroup in magento 2Magento 2: addAttributeToFilter not returning any resultsMagento : Filter Collection by Attribute that Doesn't Exist or Null or another conditionMagento2: How to add multiple AND and OR conditions to filter/filterGroups?Magento 2 : how to addCategoriesFilter with AND condtion?Magento 1.9 collection multi conditionsMagento 2.3 custom conditions for attribute filter using addAttributeToFilter
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I could filter a product collection by (attribute A: condition A OR condition B) AND (attribute B: condition C OR condition D) with the following codes:
$collection->addAttributeToFilter('attribute A', [
[condition here...], //e.g. ['neq' => 'x']
[condition here...] //e.g. ['gt' => 'y']
]);
$collection->addAttributeToFilter('attribute B', [
[condition here...],
[condition here...]
]);
But I have no idea how to achieve this:
(attribute A: condition A AND condition B) OR (attribute B: condition C and condition D)
I have also tried to use search criteria builder, but still no luck so far.
magento2 product-collection eav-attributes
|
show 1 more comment
I could filter a product collection by (attribute A: condition A OR condition B) AND (attribute B: condition C OR condition D) with the following codes:
$collection->addAttributeToFilter('attribute A', [
[condition here...], //e.g. ['neq' => 'x']
[condition here...] //e.g. ['gt' => 'y']
]);
$collection->addAttributeToFilter('attribute B', [
[condition here...],
[condition here...]
]);
But I have no idea how to achieve this:
(attribute A: condition A AND condition B) OR (attribute B: condition C and condition D)
I have also tried to use search criteria builder, but still no luck so far.
magento2 product-collection eav-attributes
Try like:$collection->addAttributeToFilter('attribute A', [ [condition here... , condition here...], ]);
– fmsthird
May 31 at 7:50
@magefms The conditions A and B I want would be something like ['gt' => 'xxx'] and ['neq' => 'yyy']. The syntax you provided seems not working.
– d.yuk
May 31 at 8:45
why not try like$collection->addAttributeToFilter('attribute A', [ [condition here...] ]); $collection->addAttributeToFilter('attribute A', [ [condition here number 2...] ]);
– fmsthird
May 31 at 8:49
creating two filter for the same attribute that might work
– fmsthird
May 31 at 8:49
can you try like$collection->addAttributeToFilter( array( array(array('attribute' => 'attribute A', 'neq' => 'x'), array('attribute' => 'attribute A', 'gt' => 'y')), array(array('attribute' => 'attribute B', 'neq' => 'x'), array('attribute' => 'attribute B', 'neq' => 'x')) ) );
– fmsthird
May 31 at 9:12
|
show 1 more comment
I could filter a product collection by (attribute A: condition A OR condition B) AND (attribute B: condition C OR condition D) with the following codes:
$collection->addAttributeToFilter('attribute A', [
[condition here...], //e.g. ['neq' => 'x']
[condition here...] //e.g. ['gt' => 'y']
]);
$collection->addAttributeToFilter('attribute B', [
[condition here...],
[condition here...]
]);
But I have no idea how to achieve this:
(attribute A: condition A AND condition B) OR (attribute B: condition C and condition D)
I have also tried to use search criteria builder, but still no luck so far.
magento2 product-collection eav-attributes
I could filter a product collection by (attribute A: condition A OR condition B) AND (attribute B: condition C OR condition D) with the following codes:
$collection->addAttributeToFilter('attribute A', [
[condition here...], //e.g. ['neq' => 'x']
[condition here...] //e.g. ['gt' => 'y']
]);
$collection->addAttributeToFilter('attribute B', [
[condition here...],
[condition here...]
]);
But I have no idea how to achieve this:
(attribute A: condition A AND condition B) OR (attribute B: condition C and condition D)
I have also tried to use search criteria builder, but still no luck so far.
magento2 product-collection eav-attributes
magento2 product-collection eav-attributes
edited May 31 at 8:46
d.yuk
asked May 31 at 7:28
d.yukd.yuk
247212
247212
Try like:$collection->addAttributeToFilter('attribute A', [ [condition here... , condition here...], ]);
– fmsthird
May 31 at 7:50
@magefms The conditions A and B I want would be something like ['gt' => 'xxx'] and ['neq' => 'yyy']. The syntax you provided seems not working.
– d.yuk
May 31 at 8:45
why not try like$collection->addAttributeToFilter('attribute A', [ [condition here...] ]); $collection->addAttributeToFilter('attribute A', [ [condition here number 2...] ]);
– fmsthird
May 31 at 8:49
creating two filter for the same attribute that might work
– fmsthird
May 31 at 8:49
can you try like$collection->addAttributeToFilter( array( array(array('attribute' => 'attribute A', 'neq' => 'x'), array('attribute' => 'attribute A', 'gt' => 'y')), array(array('attribute' => 'attribute B', 'neq' => 'x'), array('attribute' => 'attribute B', 'neq' => 'x')) ) );
– fmsthird
May 31 at 9:12
|
show 1 more comment
Try like:$collection->addAttributeToFilter('attribute A', [ [condition here... , condition here...], ]);
– fmsthird
May 31 at 7:50
@magefms The conditions A and B I want would be something like ['gt' => 'xxx'] and ['neq' => 'yyy']. The syntax you provided seems not working.
– d.yuk
May 31 at 8:45
why not try like$collection->addAttributeToFilter('attribute A', [ [condition here...] ]); $collection->addAttributeToFilter('attribute A', [ [condition here number 2...] ]);
– fmsthird
May 31 at 8:49
creating two filter for the same attribute that might work
– fmsthird
May 31 at 8:49
can you try like$collection->addAttributeToFilter( array( array(array('attribute' => 'attribute A', 'neq' => 'x'), array('attribute' => 'attribute A', 'gt' => 'y')), array(array('attribute' => 'attribute B', 'neq' => 'x'), array('attribute' => 'attribute B', 'neq' => 'x')) ) );
– fmsthird
May 31 at 9:12
Try like:
$collection->addAttributeToFilter('attribute A', [ [condition here... , condition here...], ]);
– fmsthird
May 31 at 7:50
Try like:
$collection->addAttributeToFilter('attribute A', [ [condition here... , condition here...], ]);
– fmsthird
May 31 at 7:50
@magefms The conditions A and B I want would be something like ['gt' => 'xxx'] and ['neq' => 'yyy']. The syntax you provided seems not working.
– d.yuk
May 31 at 8:45
@magefms The conditions A and B I want would be something like ['gt' => 'xxx'] and ['neq' => 'yyy']. The syntax you provided seems not working.
– d.yuk
May 31 at 8:45
why not try like
$collection->addAttributeToFilter('attribute A', [ [condition here...] ]); $collection->addAttributeToFilter('attribute A', [ [condition here number 2...] ]);
– fmsthird
May 31 at 8:49
why not try like
$collection->addAttributeToFilter('attribute A', [ [condition here...] ]); $collection->addAttributeToFilter('attribute A', [ [condition here number 2...] ]);
– fmsthird
May 31 at 8:49
creating two filter for the same attribute that might work
– fmsthird
May 31 at 8:49
creating two filter for the same attribute that might work
– fmsthird
May 31 at 8:49
can you try like
$collection->addAttributeToFilter( array( array(array('attribute' => 'attribute A', 'neq' => 'x'), array('attribute' => 'attribute A', 'gt' => 'y')), array(array('attribute' => 'attribute B', 'neq' => 'x'), array('attribute' => 'attribute B', 'neq' => 'x')) ) );
– fmsthird
May 31 at 9:12
can you try like
$collection->addAttributeToFilter( array( array(array('attribute' => 'attribute A', 'neq' => 'x'), array('attribute' => 'attribute A', 'gt' => 'y')), array(array('attribute' => 'attribute B', 'neq' => 'x'), array('attribute' => 'attribute B', 'neq' => 'x')) ) );
– fmsthird
May 31 at 9:12
|
show 1 more comment
0
active
oldest
votes
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f276825%2fmagento-2-how-to-add-multiple-and-conditions-to-one-single-attribute-that-could%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f276825%2fmagento-2-how-to-add-multiple-and-conditions-to-one-single-attribute-that-could%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Try like:
$collection->addAttributeToFilter('attribute A', [ [condition here... , condition here...], ]);
– fmsthird
May 31 at 7:50
@magefms The conditions A and B I want would be something like ['gt' => 'xxx'] and ['neq' => 'yyy']. The syntax you provided seems not working.
– d.yuk
May 31 at 8:45
why not try like
$collection->addAttributeToFilter('attribute A', [ [condition here...] ]); $collection->addAttributeToFilter('attribute A', [ [condition here number 2...] ]);
– fmsthird
May 31 at 8:49
creating two filter for the same attribute that might work
– fmsthird
May 31 at 8:49
can you try like
$collection->addAttributeToFilter( array( array(array('attribute' => 'attribute A', 'neq' => 'x'), array('attribute' => 'attribute A', 'gt' => 'y')), array(array('attribute' => 'attribute B', 'neq' => 'x'), array('attribute' => 'attribute B', 'neq' => 'x')) ) );
– fmsthird
May 31 at 9:12