How to get product ids of specific category and not in other categories in Magento? Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?Script to hide empty categories works but not with products without stockArray of product ids for a given category (ignoring is_anchor)How to get all products that aren't in a specific category in Magento?How to get all products from an array of specific categories and grouped by the categoriesHow to get category ids of specific store in Magento 2?Add category IDs to product collectionGet ids and names of parent categoriesHow to get category ids from product collectionMagento 2. How to get All Parent Categories Ids from current category IDHow to get all the Children Categories IDs of the Specific Category in Magento2

What computer would be fastest for Mathematica Home Edition?

How can you insert a "times/divide" symbol similar to the "plus/minus" (±) one?

What's the point in a preamp?

Slither Like a Snake

Strange behaviour of Check

Why don't the Weasley twins use magic outside of school if the Trace can only find the location of spells cast?

90's book, teen horror

Autumning in love

What loss function to use when labels are probabilities?

Cauchy Sequence Characterized only By Directly Neighbouring Sequence Members

Was credit for the black hole image misattributed?

What do you call the holes in a flute?

Unexpected result with right shift after bitwise negation

What is the electric potential inside a point charge?

What did Darwin mean by 'squib' here?

How to say that you spent the night with someone, you were only sleeping and nothing else?

Do working physicists consider Newtonian mechanics to be "falsified"?

Biased dice probability question

What do you call a plan that's an alternative plan in case your initial plan fails?

What to do with post with dry rot?

Using "nakedly" instead of "with nothing on"

Stop battery usage [Ubuntu 18]

Unable to start mainnet node docker container

Can a non-EU citizen traveling with me come with me through the EU passport line?



How to get product ids of specific category and not in other categories in Magento?



Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
Announcing the arrival of Valued Associate #679: Cesar Manara
Unicorn Meta Zoo #1: Why another podcast?Script to hide empty categories works but not with products without stockArray of product ids for a given category (ignoring is_anchor)How to get all products that aren't in a specific category in Magento?How to get all products from an array of specific categories and grouped by the categoriesHow to get category ids of specific store in Magento 2?Add category IDs to product collectionGet ids and names of parent categoriesHow to get category ids from product collectionMagento 2. How to get All Parent Categories Ids from current category IDHow to get all the Children Categories IDs of the Specific Category in Magento2



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








2















I want to get product ids of a specific category and product ids not in other categories only in a specific category.



For example,



category ids = 3, 4, 10 and product ids = 10, 12, 14 and category id 3 belong to product id 10 and category id 4 belong to product ids 10, 12, 14 and category id 10 belong to product id 14.



When I filter on category id = 4, it returns product ids 10, 12 and 14, but I want to return only product id 12 because I only want the product id which is not in other categories. In my filter category id 4 returns product ids 10,12 and 14 but I only want to product id 4 because 10 and 14 belong to other categories which I don't want.
I only want to product id 12 in filter. Which filter I used ?



$catIds = array(4);
$notCatIds = array(3, 10);
$productCollection = Mage::getResourceModel('catalog/product_collection')
->setStoreId(0)
->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id=entity_id', null, 'left')
->addAttributeToFilter('category_id', array('in' => $notCatIds))
->addAttributeToFilter('category_id', array('in' => $catIds))
->addAttributeToFilter('category_id', array('nin' => $notCatIds))
->addAttributeToFilter('category_id', array('nin' => array(2)))// 2 is default category id
->addAttributeToSelect('*');
$productCollection->getSelect()->group('product_id')->distinct(true);

echo '<pre>';
print_r($productCollection->getData());









share|improve this question
















bumped to the homepage by Community 1 min ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.















  • Did you solve??

    – Gem
    Apr 23 '18 at 4:20


















2















I want to get product ids of a specific category and product ids not in other categories only in a specific category.



For example,



category ids = 3, 4, 10 and product ids = 10, 12, 14 and category id 3 belong to product id 10 and category id 4 belong to product ids 10, 12, 14 and category id 10 belong to product id 14.



When I filter on category id = 4, it returns product ids 10, 12 and 14, but I want to return only product id 12 because I only want the product id which is not in other categories. In my filter category id 4 returns product ids 10,12 and 14 but I only want to product id 4 because 10 and 14 belong to other categories which I don't want.
I only want to product id 12 in filter. Which filter I used ?



$catIds = array(4);
$notCatIds = array(3, 10);
$productCollection = Mage::getResourceModel('catalog/product_collection')
->setStoreId(0)
->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id=entity_id', null, 'left')
->addAttributeToFilter('category_id', array('in' => $notCatIds))
->addAttributeToFilter('category_id', array('in' => $catIds))
->addAttributeToFilter('category_id', array('nin' => $notCatIds))
->addAttributeToFilter('category_id', array('nin' => array(2)))// 2 is default category id
->addAttributeToSelect('*');
$productCollection->getSelect()->group('product_id')->distinct(true);

echo '<pre>';
print_r($productCollection->getData());









share|improve this question
















bumped to the homepage by Community 1 min ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.















  • Did you solve??

    – Gem
    Apr 23 '18 at 4:20














2












2








2








I want to get product ids of a specific category and product ids not in other categories only in a specific category.



For example,



category ids = 3, 4, 10 and product ids = 10, 12, 14 and category id 3 belong to product id 10 and category id 4 belong to product ids 10, 12, 14 and category id 10 belong to product id 14.



When I filter on category id = 4, it returns product ids 10, 12 and 14, but I want to return only product id 12 because I only want the product id which is not in other categories. In my filter category id 4 returns product ids 10,12 and 14 but I only want to product id 4 because 10 and 14 belong to other categories which I don't want.
I only want to product id 12 in filter. Which filter I used ?



$catIds = array(4);
$notCatIds = array(3, 10);
$productCollection = Mage::getResourceModel('catalog/product_collection')
->setStoreId(0)
->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id=entity_id', null, 'left')
->addAttributeToFilter('category_id', array('in' => $notCatIds))
->addAttributeToFilter('category_id', array('in' => $catIds))
->addAttributeToFilter('category_id', array('nin' => $notCatIds))
->addAttributeToFilter('category_id', array('nin' => array(2)))// 2 is default category id
->addAttributeToSelect('*');
$productCollection->getSelect()->group('product_id')->distinct(true);

echo '<pre>';
print_r($productCollection->getData());









share|improve this question
















I want to get product ids of a specific category and product ids not in other categories only in a specific category.



For example,



category ids = 3, 4, 10 and product ids = 10, 12, 14 and category id 3 belong to product id 10 and category id 4 belong to product ids 10, 12, 14 and category id 10 belong to product id 14.



When I filter on category id = 4, it returns product ids 10, 12 and 14, but I want to return only product id 12 because I only want the product id which is not in other categories. In my filter category id 4 returns product ids 10,12 and 14 but I only want to product id 4 because 10 and 14 belong to other categories which I don't want.
I only want to product id 12 in filter. Which filter I used ?



$catIds = array(4);
$notCatIds = array(3, 10);
$productCollection = Mage::getResourceModel('catalog/product_collection')
->setStoreId(0)
->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id=entity_id', null, 'left')
->addAttributeToFilter('category_id', array('in' => $notCatIds))
->addAttributeToFilter('category_id', array('in' => $catIds))
->addAttributeToFilter('category_id', array('nin' => $notCatIds))
->addAttributeToFilter('category_id', array('nin' => array(2)))// 2 is default category id
->addAttributeToSelect('*');
$productCollection->getSelect()->group('product_id')->distinct(true);

echo '<pre>';
print_r($productCollection->getData());






magento-1.8 product category






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 15 '18 at 16:11









MGento

1,224319




1,224319










asked Feb 18 '15 at 17:15









johnjohn

114




114





bumped to the homepage by Community 1 min ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







bumped to the homepage by Community 1 min ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.














  • Did you solve??

    – Gem
    Apr 23 '18 at 4:20


















  • Did you solve??

    – Gem
    Apr 23 '18 at 4:20

















Did you solve??

– Gem
Apr 23 '18 at 4:20






Did you solve??

– Gem
Apr 23 '18 at 4:20











1 Answer
1






active

oldest

votes


















0














Step1: all categories ids form Category and then



$categiesIDs= Mage::getResourceModel('catalog/category_collection')->getAllIds();


Step2: exclude your category[12] from $categiesIDs uset



Step3: Then Product collection filter by Categories ids.



$productCollection->getSelect()
->join(
array('at_category_id' => $productCollection->getTable('catalog/category_product')),
'at_category_id.product_id=e.entity_id',
array(
'at_category_id.category_id',
'cattotal'=> new Zend_Db_Expr('COUNT(*)')
)
->group('e.entity_id');





share|improve this answer

























  • 12 is product id not category id. what you say i dont understand ? please eleborate

    – john
    Feb 18 '15 at 18:23











  • 10,12 and 14 are product ids which belongs to category id (4) and category id (3) belongs to product id(10) and category id 10 belongs to product id(14).Now My issue is when i filter using category id(4), it returns 10,12,14 product ids but i only want to product id 12 because product id(12) is not belongs to other categories

    – john
    Feb 18 '15 at 18:29











  • just wait .. you want to this type of work.get product collection filter which have only category

    – Amit Bera
    Feb 18 '15 at 18:39











  • yes something like this. In sort not common product ids not in filter get back only. Example men and women are categories, product ids (10,12,14).men contains 10 and 14 product ids and women category contain 10,12,14 product ids. when i filter women category,i only want product id(12) because product id(12) not contain in men category.

    – john
    Feb 18 '15 at 18:45











  • i don't want to 10 and 14 product ids because it belongs to other(men) category in filter.

    – john
    Feb 18 '15 at 18:47











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
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f57717%2fhow-to-get-product-ids-of-specific-category-and-not-in-other-categories-in-magen%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









0














Step1: all categories ids form Category and then



$categiesIDs= Mage::getResourceModel('catalog/category_collection')->getAllIds();


Step2: exclude your category[12] from $categiesIDs uset



Step3: Then Product collection filter by Categories ids.



$productCollection->getSelect()
->join(
array('at_category_id' => $productCollection->getTable('catalog/category_product')),
'at_category_id.product_id=e.entity_id',
array(
'at_category_id.category_id',
'cattotal'=> new Zend_Db_Expr('COUNT(*)')
)
->group('e.entity_id');





share|improve this answer

























  • 12 is product id not category id. what you say i dont understand ? please eleborate

    – john
    Feb 18 '15 at 18:23











  • 10,12 and 14 are product ids which belongs to category id (4) and category id (3) belongs to product id(10) and category id 10 belongs to product id(14).Now My issue is when i filter using category id(4), it returns 10,12,14 product ids but i only want to product id 12 because product id(12) is not belongs to other categories

    – john
    Feb 18 '15 at 18:29











  • just wait .. you want to this type of work.get product collection filter which have only category

    – Amit Bera
    Feb 18 '15 at 18:39











  • yes something like this. In sort not common product ids not in filter get back only. Example men and women are categories, product ids (10,12,14).men contains 10 and 14 product ids and women category contain 10,12,14 product ids. when i filter women category,i only want product id(12) because product id(12) not contain in men category.

    – john
    Feb 18 '15 at 18:45











  • i don't want to 10 and 14 product ids because it belongs to other(men) category in filter.

    – john
    Feb 18 '15 at 18:47















0














Step1: all categories ids form Category and then



$categiesIDs= Mage::getResourceModel('catalog/category_collection')->getAllIds();


Step2: exclude your category[12] from $categiesIDs uset



Step3: Then Product collection filter by Categories ids.



$productCollection->getSelect()
->join(
array('at_category_id' => $productCollection->getTable('catalog/category_product')),
'at_category_id.product_id=e.entity_id',
array(
'at_category_id.category_id',
'cattotal'=> new Zend_Db_Expr('COUNT(*)')
)
->group('e.entity_id');





share|improve this answer

























  • 12 is product id not category id. what you say i dont understand ? please eleborate

    – john
    Feb 18 '15 at 18:23











  • 10,12 and 14 are product ids which belongs to category id (4) and category id (3) belongs to product id(10) and category id 10 belongs to product id(14).Now My issue is when i filter using category id(4), it returns 10,12,14 product ids but i only want to product id 12 because product id(12) is not belongs to other categories

    – john
    Feb 18 '15 at 18:29











  • just wait .. you want to this type of work.get product collection filter which have only category

    – Amit Bera
    Feb 18 '15 at 18:39











  • yes something like this. In sort not common product ids not in filter get back only. Example men and women are categories, product ids (10,12,14).men contains 10 and 14 product ids and women category contain 10,12,14 product ids. when i filter women category,i only want product id(12) because product id(12) not contain in men category.

    – john
    Feb 18 '15 at 18:45











  • i don't want to 10 and 14 product ids because it belongs to other(men) category in filter.

    – john
    Feb 18 '15 at 18:47













0












0








0







Step1: all categories ids form Category and then



$categiesIDs= Mage::getResourceModel('catalog/category_collection')->getAllIds();


Step2: exclude your category[12] from $categiesIDs uset



Step3: Then Product collection filter by Categories ids.



$productCollection->getSelect()
->join(
array('at_category_id' => $productCollection->getTable('catalog/category_product')),
'at_category_id.product_id=e.entity_id',
array(
'at_category_id.category_id',
'cattotal'=> new Zend_Db_Expr('COUNT(*)')
)
->group('e.entity_id');





share|improve this answer















Step1: all categories ids form Category and then



$categiesIDs= Mage::getResourceModel('catalog/category_collection')->getAllIds();


Step2: exclude your category[12] from $categiesIDs uset



Step3: Then Product collection filter by Categories ids.



$productCollection->getSelect()
->join(
array('at_category_id' => $productCollection->getTable('catalog/category_product')),
'at_category_id.product_id=e.entity_id',
array(
'at_category_id.category_id',
'cattotal'=> new Zend_Db_Expr('COUNT(*)')
)
->group('e.entity_id');






share|improve this answer














share|improve this answer



share|improve this answer








edited Jul 20 '17 at 9:22









sv3n

9,96662557




9,96662557










answered Feb 18 '15 at 18:03









Amit BeraAmit Bera

60k1677178




60k1677178












  • 12 is product id not category id. what you say i dont understand ? please eleborate

    – john
    Feb 18 '15 at 18:23











  • 10,12 and 14 are product ids which belongs to category id (4) and category id (3) belongs to product id(10) and category id 10 belongs to product id(14).Now My issue is when i filter using category id(4), it returns 10,12,14 product ids but i only want to product id 12 because product id(12) is not belongs to other categories

    – john
    Feb 18 '15 at 18:29











  • just wait .. you want to this type of work.get product collection filter which have only category

    – Amit Bera
    Feb 18 '15 at 18:39











  • yes something like this. In sort not common product ids not in filter get back only. Example men and women are categories, product ids (10,12,14).men contains 10 and 14 product ids and women category contain 10,12,14 product ids. when i filter women category,i only want product id(12) because product id(12) not contain in men category.

    – john
    Feb 18 '15 at 18:45











  • i don't want to 10 and 14 product ids because it belongs to other(men) category in filter.

    – john
    Feb 18 '15 at 18:47

















  • 12 is product id not category id. what you say i dont understand ? please eleborate

    – john
    Feb 18 '15 at 18:23











  • 10,12 and 14 are product ids which belongs to category id (4) and category id (3) belongs to product id(10) and category id 10 belongs to product id(14).Now My issue is when i filter using category id(4), it returns 10,12,14 product ids but i only want to product id 12 because product id(12) is not belongs to other categories

    – john
    Feb 18 '15 at 18:29











  • just wait .. you want to this type of work.get product collection filter which have only category

    – Amit Bera
    Feb 18 '15 at 18:39











  • yes something like this. In sort not common product ids not in filter get back only. Example men and women are categories, product ids (10,12,14).men contains 10 and 14 product ids and women category contain 10,12,14 product ids. when i filter women category,i only want product id(12) because product id(12) not contain in men category.

    – john
    Feb 18 '15 at 18:45











  • i don't want to 10 and 14 product ids because it belongs to other(men) category in filter.

    – john
    Feb 18 '15 at 18:47
















12 is product id not category id. what you say i dont understand ? please eleborate

– john
Feb 18 '15 at 18:23





12 is product id not category id. what you say i dont understand ? please eleborate

– john
Feb 18 '15 at 18:23













10,12 and 14 are product ids which belongs to category id (4) and category id (3) belongs to product id(10) and category id 10 belongs to product id(14).Now My issue is when i filter using category id(4), it returns 10,12,14 product ids but i only want to product id 12 because product id(12) is not belongs to other categories

– john
Feb 18 '15 at 18:29





10,12 and 14 are product ids which belongs to category id (4) and category id (3) belongs to product id(10) and category id 10 belongs to product id(14).Now My issue is when i filter using category id(4), it returns 10,12,14 product ids but i only want to product id 12 because product id(12) is not belongs to other categories

– john
Feb 18 '15 at 18:29













just wait .. you want to this type of work.get product collection filter which have only category

– Amit Bera
Feb 18 '15 at 18:39





just wait .. you want to this type of work.get product collection filter which have only category

– Amit Bera
Feb 18 '15 at 18:39













yes something like this. In sort not common product ids not in filter get back only. Example men and women are categories, product ids (10,12,14).men contains 10 and 14 product ids and women category contain 10,12,14 product ids. when i filter women category,i only want product id(12) because product id(12) not contain in men category.

– john
Feb 18 '15 at 18:45





yes something like this. In sort not common product ids not in filter get back only. Example men and women are categories, product ids (10,12,14).men contains 10 and 14 product ids and women category contain 10,12,14 product ids. when i filter women category,i only want product id(12) because product id(12) not contain in men category.

– john
Feb 18 '15 at 18:45













i don't want to 10 and 14 product ids because it belongs to other(men) category in filter.

– john
Feb 18 '15 at 18:47





i don't want to 10 and 14 product ids because it belongs to other(men) category in filter.

– john
Feb 18 '15 at 18:47

















draft saved

draft discarded
















































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.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f57717%2fhow-to-get-product-ids-of-specific-category-and-not-in-other-categories-in-magen%23new-answer', 'question_page');

);

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







Popular posts from this blog

Can not update quote_id field of “quote_item” table magento 2Magento 2.1 - We can't remove the item. (Shopping Cart doesnt allow us to remove items before becomes empty)Add value for custom quote item attribute using REST apiREST API endpoint v1/carts/cartId/items always returns error messageCorrect way to save entries to databaseHow to remove all associated quote objects of a customer completelyMagento 2 - Save value from custom input field to quote_itemGet quote_item data using quote id and product id filter in Magento 2How to set additional data to quote_item table from controller in Magento 2?What is the purpose of additional_data column in quote_item table in magento2Set Custom Price to Quote item magento2 from controller

How to solve knockout JS error in Magento 2 Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?(Magento2) knockout.js:3012 Uncaught ReferenceError: Unable to process bindingUnable to process binding Knockout.js magento 2Cannot read property `scopeLabel` of undefined on Product Detail PageCan't get Customer Data on frontend in Magento 2Magento2 Order Summary - unable to process bindingKO templates are not loading in Magento 2.1 applicationgetting knockout js error magento 2Product grid not load -— Unable to process binding Knockout.js magento 2Product form not loaded in magento2Uncaught ReferenceError: Unable to process binding “if: function()return (isShowLegend()) ” magento 2

Nissan Patrol Зміст Перше покоління — 4W60 (1951-1960) | Друге покоління — 60 series (1960-1980) | Третє покоління (1980–2002) | Четверте покоління — Y60 (1987–1998) | П'яте покоління — Y61 (1997–2013) | Шосте покоління — Y62 (2010- ) | Посилання | Зноски | Навігаційне менюОфіційний український сайтТест-драйв Nissan Patrol 2010 7-го поколінняNissan PatrolКак мы тестировали Nissan Patrol 2016рвиправивши або дописавши її