2012-08-02 78 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作爲數組。你的可能會有所不同。