1

Assuming that each product can only be assigned to no more than 1 category, how would I retrieve the category's ID by using the known Product's ID? I would also like to list all IDs within a Category from the known Category ID.

Case 1:

Category_? -> Product_with_ID_34

Category_? -> Product_with_ID_12

Category_? -> Product_with_ID_08 Get immediate containing category of the known product ID

Case 2:

Category_with_ID_1 ->

           Show ID of all products listed in this category

Category_with_ID_2 ->

           Show ID of all products listed in this category

Category_with_ID_3 ->

           Show ID of all products listed in this category

EDIT: Of course a category can contain more than 1 product

  • Its worth noting that what I'm trying to achieve is to create a json file that contains: Category_ID -> Product_ID – borislemke Jul 15 '15 at 9:04
2

Not sure if I've understood your question, but both methods are provided by Magento objects. I asume you know how to load catalog objects by ID in Magento

Get CategoryIds of a product

$categoryIds = $product->getCategoryIds();

Get ProductIds of a category

$productIds = $category->getProductCollection()->getAllIds();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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