0

This snippet works fine except that it returns a different set of product collection, mainly due to is anchor attribute:

$category = Mage::getModel('catalog/category')->load(1371);
$collection = Mage::getModel('catalog/product')
    ->getCollection()
    ->addCategoryFilter($category);

The snippet above returns the complete products including the child category products. However, when running through cron, it returns only a small amount of items. I could simulate what the cron is getting by defining:

Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);

I want to get the collection that includes the sub category products. How can I achieve this?

1

Try This code

<?php
error_reporting(E_ALL | E_STRICT);
$mageFilename = 'app/Mage.php';
require_once $mageFilename;
Mage::setIsDeveloperMode(true);
ini_set('display_errors', 1);
ini_set('memory_limit', '600M');
ini_set('max_execution_time', 1800);
umask(0);
Mage::app('admin'); 
    $_productCollection = Mage::getModel('catalog/category')->load(48)
    ->getProductCollection()
    ->addAttributeToSelect('*')
     ->addAttributeToFilter('visibility', 4);
     foreach($_productCollection as $product){
         var_dump($product->getName());

     }

?>

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.