0

I am having a main category which has about 10 subcategories that include about 1000 products. Please note that this category is an anchor and its products are inherited from its subcategories. I am using the following code to fetch all the products inside that category, but I only get about 300 (which are assigned to the specific category, leftovers from before the category changed to anchor).

How can I make my API call to fetch all the SKUs of the products in the subcategories as well?

$productList = $mclient->call($session, 'catalog_category.assignedProducts', 279);
foreach($productList as $product){
    $catProducts[] = array('catalog_product.info', $product['product_id']);
}
$result = $mclient->multiCall($session, $catProducts);

1 Answer 1

0

I have managed to achieve what I want by looping through every subcategory and fetching its products. Here is the code if anyone might need it in the future:

$category_tree = $mclient->call($session, 'catalog_category.tree', 279);
foreach($category_tree['children'] as $category){
    foreach($category['children'] as $child_cat){
        $productList = array_merge($mclient->call($session, 'catalog_category.assignedProducts', $child_cat['category_id']), $productList);
    }
}
foreach($productList as $product){
    $catProducts[] = array('catalog_product.info', $product['product_id']);
}
$result = $mclient->multiCall($session, $catProducts);

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.