2015-04-07 193 views

回答

0

使用以下代碼向Magento根添加一個php頁面(categoru-name.php)。你需要做一些修改才能使其工作。

/** START Include Magento **/ 
define('MAGENTO_ROOT', getcwd()); 

$compilerConfig = MAGENTO_ROOT . '/includes/config.php'; 
if (file_exists($compilerConfig)) { 
    include $compilerConfig; 
}else{exit;} 

$mageFilename = MAGENTO_ROOT . '/app/Mage.php'; 

if (file_exists($mageFilename)) { 
    require_once $mageFilename; 
}else{exit;} 

Mage::app(); 
/** END Include Magento **/ 

// This is not a complete code. You need to fill in. 

// Add from query paramter 
$categoryIds = array("Insert IDs from URL"); 
$categoryIdList = array(); 
array_push($categoryIdList,$categoryIds); //Collect child category IDs 

foreach($categoryIds as $Catid){ 
    $cat = Mage::getModel('catalog/category')->load($Catid); 
    $subCats = $cat->getChildren(); 
    $arrSubCats = explode(',',$subCats); 
    array_push($categoryIdList,$arrSubCats); //Collect child category IDs 

    // Go another level down 
     foreach($arrSubCats as $Catid){ 
     $cat = Mage::getModel('catalog/category')->load($Catid); 
     $subSubCats = $cat->getChildren(); 
     $arrSubSubCats = explode(',',$subSubCats); 
     array_push($categoryIdList,$arrSubSubCats); //Collect child category IDs 

     // Go another level down 
     // Another foreach loop for $arrSubSubCats 
    } 
} 

// Now we have all categoryIds in the tree. 
// Get all products. 
$collection = Mage::getModel('catalog/product') 
          ->getCollection() 
          ->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id = entity_id', null, 'left') 
          ->addAttributeToSelect('*') 
          ->addAttributeToFilter('category_id', array('in' => $categoryIdList))