11

I opened a product in the backend, but when I switch to the categories tab, the category tree is fully collapsed. I would have to expand all categories to see in which ones the product is in.

How can I quickly see (in the backend) to which categories the product belongs?

2
  • It's the only default way to do so via the backend ;) Do you have database access?
    – Kenny
    Jan 23, 2013 at 8:44
  • 1
    My first idea was to run tree.expandAll() in a browser console but unfortunately it will work only for Manage Categories page. Jan 23, 2013 at 12:51

3 Answers 3

11

There is no core functionality to archive this in the backend.

If you have database read access to run raw queries you can use the following queries to get an overview of all the categories that are linked to a certain product:

Option 1 => Get all categories of a product by entering the product's entity ID:

SELECT c3.sku, c2.value
FROM catalog_category_product c1
INNER JOIN catalog_category_entity_varchar c2 ON (c1.category_id = c2.entity_id)
INNER JOIN catalog_product_entity c3 ON (c1.product_id = c3.entity_id)
WHERE c2.attribute_id = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'name' AND entity_type_id = 3)
AND c3.entity_id = FILL_IN_PRODUCT_ID_HERE

Option 2 => Get all categories of a product by entering the product's SKU:

SELECT c3.sku, c2.value
FROM catalog_category_product c1
INNER JOIN catalog_category_entity_varchar c2 ON (c1.category_id = c2.entity_id)
INNER JOIN catalog_product_entity c3 ON (c1.product_id = c3.entity_id)
WHERE c2.attribute_id = (SELECT attribute_id FROM eav_attribute WHERE attribute_code = 'name' AND entity_type_id = 3)
AND c3.sku = FILL_IN_PRODUCT_SKU_HERE
6

You can load the product by it's ID and then get the category ids.

require('app/Mage.php');
umask(0);
Mage::app('admin');
$id = 1; //Your product ID here
$product = Mage::getModel('catalog/product')->load($id);
$categoryIds = $product->getCategoryIds();
echo '<h1>' . $product->getName() . '</h1>';
foreach ($categoryIds as $cid) {
    $category = Mage::getModel('catalog/category')->load($cid);
    echo $category->getName() . '<br />';
}

Tested and working.

You can put this in a seperate file and just run that file to get the product's categories.

EDIT

There is no core functionality to view this in the backend. I believe it would take a slight backend modification to have the enabled categories expanded (perhaps with some JS)

3
  • 1
    I was more looking for a backend solution :-)
    – Alex
    Jan 23, 2013 at 11:02
  • @Alex I figured after re-reading your question :P I believe it would take a slight backend modification to have the enabled categories expanded (perhaps with some JS). AFAIK there is no core functionality that does what you want. Jan 23, 2013 at 11:08
  • ®Rick: Not your fault - I edited my question to contain that info g
    – Alex
    Jan 23, 2013 at 11:34
2

Filterable and searchable category column in admin: https://github.com/vuleticd/admin_grid_category_filter

Cheers!

1
  • 2
    Could you add some comments to your answer? Posting a link only answer can be helpful but the link can be broken in the future, so posting some code that remains visible would be more useful for future visitor to the post
    – Yaroslav
    Jan 24, 2013 at 7:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.