从品类中拉出产品及其在magento中的属性

问题描述:

我将使用哪种类型的块以及将调用哪种方法。从品类中拉出产品及其在magento中的属性

此外,它会返回什么类型的数组,哪里可以找到属性,价格和所有好东西。

感谢

声明自己的块的模块中,并使用下面的代码来获得你所需要的产品:

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