默认情况下,当您加载产品集合时,您将获得有关产品的少量信息。例如:
Array
(
[entity_id] => 9
[entity_type_id] => 4
[attribute_set_id] => 4
[type_id] => simple
[sku] => DLKJFER343
[has_options] => 0
[required_options] => 0
[created_at] => 2012-12-07 16:04:58
[updated_at] => 2012-12-11 16:21:37
[cat_index_position] => 0
[stock_item (Varien_Object)] => Array
(
)
)
您需要明确告诉 Magento 加载额外信息或按如下值过滤:
$_productCollection = Mage::getResourceModel( 'catalog/product_collection' );
// Filter by enabled products
$_productCollection->addAttributeToFilter( 'status', 1 );
// Load all product information
$_productCollection->addAttributeToSelect( '*' );
$_productCollection->addCategoryFilter( $category );
现在您会看到类似这样的内容(使用$_product->debug() 转储一些信息):
Array
(
[entity_id] => 3
[entity_type_id] => 4
[attribute_set_id] => 4
[type_id] => simple
[sku] => DLKJFER343
[has_options] => 0
[required_options] => 0
[created_at] => 2012-12-05 18:47:39
[updated_at] => 2012-12-11 16:20:25
[cat_index_position] => 0
[status] => 1
[visibility] => 4
[enable_googlecheckout] => 1
[tax_class_id] => 2
[is_recurring] => 0
[weight] => 3.0000
[price] => 534.2500
[name] => Sample Product
[url_key] => some-product
[is_returnable] => 2
[msrp_enabled] => 2
[msrp_display_actual_price_type] => 4
[image] => /w/r/something.png
[small_image] => /w/r/something_sm.png
[thumbnail] => /w/r/something_th.png
[options_container] => container2
[url_path] => some-product.html
[image_label] => One image label
[small_image_label] => Another image label
[thumbnail_label] => An image label
[description] => Long winded blah, blah, blah.
[short_description] => Blah, blah, blah.
[stock_item (Varien_Object)] => Array
(
)
)
媒体库信息(标签等)是另一回事,必须通过Mage_Catalog_Model_Product 对象的getMediaGalleryImages() 方法专门请求。
但是如果在循环通过产品集合时调用此方法,将返回 NULL。奇怪的是,如果不显式加载产品模型,您将无法访问这些数据(原因我不会在此回复中详细说明)。所以,我们需要尝试这样的事情:
$product = Mage::getModel( 'catalog/product' )->load( $_product->getId() );
$images = $product->getMediaGalleryImages();
不过,a performance hit 在您的收集循环中执行此操作,所以要小心。
编辑:
Mage_Catalog_Block_Product->getLoadedProductCollection()
长,长,长简而言之(此方法深入研究)...据我所知,getLoadedProductCollection() 只会显示将Used In Product Listing 设置为Yes 的属性。
原因在于 Mage_Catalog_Model_Resource_Config...
public function getAttributesUsedInListing()
{
// ... some code above omitted...
->where('main_table.entity_type_id = ?', (int)$this->getEntityTypeId())
// THIS RIGHT HERE IS WHY
->where('additional_table.used_in_product_listing = ?', 1);
return $adapter->fetchAll($select);
}