2012-08-02 70 views

回答

2

如果你仅仅需要包含类别ID和SKU的数组的数组...

$skuArray = array(); 
$categoryCollection = Mage::getModel('catalog/category')->getCollection(); 
foreach ($categoryCollection as $category) { 
    $skuArray[$category->getId()] = $category->getProductCollection()->getColumnValues('sku'); 
} 

另外,一个新的字段添加到每个对象集合到包含的SKU ...

$categoryCollection = Mage::getModel('catalog/category')->getCollection(); 
foreach ($categoryCollection as $category) { 
    $skus = $category->getProductCollection()->getColumnValues('sku'); 
    $category->setData('skus', $skus); 
} 

如果您稍后在代码中进一步处理集合,并且仍然需要访问产品sku数组,那么这将是一个选项。

foreach($categoryCollection as $category) { 
    $categorySkus = $category->getData('skus'); 
} 
2

您可以使用:

$categories = Mage::getResourceModel('catalog/category_collection'); 
foreach ($categories as $category) { 
    $products = $category->getProductCollection(); 
    foreach ($products as $product) { 
     $sku[$product->getId()] = $product->getSku(); 
    } 
} 

我存储所有的SKU在$sku作为数组。你的可能会有所不同。