Magento 2 - Multiple categories filter on product collectionFilter product collection by multiple categories?Filter Product Collection by BOTH multiple catgeoriesMagento2: Filter product collection by product attributeExcluding products from multiple categories in collectionMagento 2: Filter Product Collection by Multiple Categories (Magento 2.1)Magento 2 get out of stock products in collectionFilter Product Collection by Child product attributemagento 2 get product collection with custom filter on product listing pageFilter product collection by sku or namehow to use filters for new collection
A curve pass via points at TiKz
Why was Endgame Thanos so different than Infinity War Thanos?
How are one-time password generators like Google Authenticator different from having two passwords?
Why was Thor doubtful about his worthiness to Mjolnir?
SSD - Disk is OK, one bad sector
Page contents aligning weirdly in LaTeX/Overleaf
How are Core iX names like Core i5, i7 related to Haswell, Ivy Bridge?
Size of a folder with du
How to Access data returned from Apex class in JS controller using Lightning web component
How to slow yourself down (for playing nice with others)
What's the word for the soldier salute?
Why not just directly invest in the holdings of an ETF?
Reaction of borax with NaOH
How to minimise the cost of guessing a number in a high/low guess game?
Why is “Ich wusste, dass aus dir mal was wird” grammitally correct?
How could a Lich maintain the appearance of being alive without magic?
Was there ever any real use for a 6800-based Apple I?
How to compact two the parabol commands in the following example?
Surely they can fit?
Ex-manager wants to stay in touch, I don't want to
Light Switch Terminals
Two researchers want to work on the same extension to my paper. Who to help?
How does noise-cancellation work in Mac laptops?
Proof that the inverse image of a single element is a discrete space
Magento 2 - Multiple categories filter on product collection
Filter product collection by multiple categories?Filter Product Collection by BOTH multiple catgeoriesMagento2: Filter product collection by product attributeExcluding products from multiple categories in collectionMagento 2: Filter Product Collection by Multiple Categories (Magento 2.1)Magento 2 get out of stock products in collectionFilter Product Collection by Child product attributemagento 2 get product collection with custom filter on product listing pageFilter product collection by sku or namehow to use filters for new collection
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have a product collection $collection
which is created by MagentoCatalogModelResourceModelProductCollection
code is:
$collection = $objectManager->create('MagentoCatalogModelResourceModelProductCollection');
$collection->addAttributeToSelect('*');
$collection->addAttributeToFilter('status', array('eq' => MagentoCatalogModelProductAttributeSourceStatus::STATUS_ENABLED));
How can I add multiple category filter in it?
magento2 collection
New contributor
add a comment |
I have a product collection $collection
which is created by MagentoCatalogModelResourceModelProductCollection
code is:
$collection = $objectManager->create('MagentoCatalogModelResourceModelProductCollection');
$collection->addAttributeToSelect('*');
$collection->addAttributeToFilter('status', array('eq' => MagentoCatalogModelProductAttributeSourceStatus::STATUS_ENABLED));
How can I add multiple category filter in it?
magento2 collection
New contributor
add a comment |
I have a product collection $collection
which is created by MagentoCatalogModelResourceModelProductCollection
code is:
$collection = $objectManager->create('MagentoCatalogModelResourceModelProductCollection');
$collection->addAttributeToSelect('*');
$collection->addAttributeToFilter('status', array('eq' => MagentoCatalogModelProductAttributeSourceStatus::STATUS_ENABLED));
How can I add multiple category filter in it?
magento2 collection
New contributor
I have a product collection $collection
which is created by MagentoCatalogModelResourceModelProductCollection
code is:
$collection = $objectManager->create('MagentoCatalogModelResourceModelProductCollection');
$collection->addAttributeToSelect('*');
$collection->addAttributeToFilter('status', array('eq' => MagentoCatalogModelProductAttributeSourceStatus::STATUS_ENABLED));
How can I add multiple category filter in it?
magento2 collection
magento2 collection
New contributor
New contributor
New contributor
asked May 8 at 9:15
Shan AtifShan Atif
468
468
New contributor
New contributor
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
First of all, do not use object manager, create your object from constructor
$protected $collection;
public function __construct(
...
MagentoCatalogModelResourceModelProductCollection $collection
...
)
...
$this->collection = $collection;
...
For your category filter use this:
$categories = "12,13,14"; //Comma separated category IDs
$collection->addCategoriesFilter(array('in' => $categories));
Collection will join category table and will add your filter
add a comment |
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
);
);
Shan Atif is a new contributor. Be nice, and check out our Code of Conduct.
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%2f273806%2fmagento-2-multiple-categories-filter-on-product-collection%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
First of all, do not use object manager, create your object from constructor
$protected $collection;
public function __construct(
...
MagentoCatalogModelResourceModelProductCollection $collection
...
)
...
$this->collection = $collection;
...
For your category filter use this:
$categories = "12,13,14"; //Comma separated category IDs
$collection->addCategoriesFilter(array('in' => $categories));
Collection will join category table and will add your filter
add a comment |
First of all, do not use object manager, create your object from constructor
$protected $collection;
public function __construct(
...
MagentoCatalogModelResourceModelProductCollection $collection
...
)
...
$this->collection = $collection;
...
For your category filter use this:
$categories = "12,13,14"; //Comma separated category IDs
$collection->addCategoriesFilter(array('in' => $categories));
Collection will join category table and will add your filter
add a comment |
First of all, do not use object manager, create your object from constructor
$protected $collection;
public function __construct(
...
MagentoCatalogModelResourceModelProductCollection $collection
...
)
...
$this->collection = $collection;
...
For your category filter use this:
$categories = "12,13,14"; //Comma separated category IDs
$collection->addCategoriesFilter(array('in' => $categories));
Collection will join category table and will add your filter
First of all, do not use object manager, create your object from constructor
$protected $collection;
public function __construct(
...
MagentoCatalogModelResourceModelProductCollection $collection
...
)
...
$this->collection = $collection;
...
For your category filter use this:
$categories = "12,13,14"; //Comma separated category IDs
$collection->addCategoriesFilter(array('in' => $categories));
Collection will join category table and will add your filter
answered May 8 at 9:19
Shoaib MunirShoaib Munir
2,98431141
2,98431141
add a comment |
add a comment |
Shan Atif is a new contributor. Be nice, and check out our Code of Conduct.
Shan Atif is a new contributor. Be nice, and check out our Code of Conduct.
Shan Atif is a new contributor. Be nice, and check out our Code of Conduct.
Shan Atif is a new contributor. Be nice, and check out our Code of Conduct.
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%2f273806%2fmagento-2-multiple-categories-filter-on-product-collection%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