2010-08-17 116 views

回答

2

聲明自己的塊的模塊中,並使用下面的代碼來獲得你所需要的產品:

function getProducts() { 
    $id = $this->getCategoryId(); // you will have to call setCategoryId somewhere else 
    $category = Mage::getModel("catalog/category")->load($id); 

    $products = $category->getProductCollection(); 
    $products->addAttributeToSelect("*"); // adds all attributes 
    //$products->addAttributeToSelect(array("name", "color")); // more precise way to add attributes 

    return $products; 
} 

然後,在你的看法:

$products = $this->getProducts(); // this is a collection object, not an array, but we can iterate over it anyway. 
foreach($products as $productObject) { 
    $color = $productObject->getColor(); 
    $name = $productObject->getName(); 
    $sku = $productObject->getSku(); // some things are retrieved even if you don't ask for them. 
} 

應讓你開始。有關如何檢索屬性的更多信息,請參見app/code/core/Mage/Catalog/Model/Product.php。如果您仍然遇到問題,請發佈一些您嘗試過的代碼,然後繼續。

希望有幫助!

謝謝, Joe

相關問題