如果我要创建一个将使用给定collection
检索所有products
属于的,如下所示:category
ID
$storeId = Mage::app()->getStore()->getId();
$product = Mage::getModel('catalog/product');
$category = Mage::getModel('catalog/category')->load(39);
$catName = $category->getName();
$visibility = array(
Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH,
Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG
);
$products = $product->setStoreId($storeId)
->getCollection()
->addAttributeToFilter('visibility', $visibility)
->addCategoryFilter($category)
->addAttributeToSelect(array('name'), 'inner')
->setOrder('name', 'asc')
;
$collection = $products;
然后我将如何遍历集合并访问每个项目的数据,在这种情况下,项目是一个产品。
我本来希望像下面这样的东西给我每个项目可用的数据,但似乎不起作用:
foreach ($collection as $key => $value) {
var_dump($value->getData());
}