Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
magento类别循环未显示重要的产品信息_Magento_Magento 1.7 - Fatal编程技术网

magento类别循环未显示重要的产品信息

magento类别循环未显示重要的产品信息,magento,magento-1.7,Magento,Magento 1.7,我试图通过将产品划分为子类别来组织分类页面。当我使用代码循环子类别(在catalog\product\list.phtml上)时: $child\u cat=Mage::getModel('catalog/category')->load($child\u id); $\u productCollection=Mage::getResourceModel('catalog/product\u collection')->addCategoryFilter($child\u cat) 然后继续循环

我试图通过将产品划分为子类别来组织分类页面。当我使用代码循环子类别(在catalog\product\list.phtml上)时:

$child\u cat=Mage::getModel('catalog/category')->load($child\u id); $\u productCollection=Mage::getResourceModel('catalog/product\u collection')->addCategoryFilter($child\u cat)

然后继续循环浏览产品

foreach($\u productCollection作为$\u product):

它似乎没有区分设置为可见的产品和不可见的产品(两者都显示)。它也不显示图像、价格或任何其他信息。我得到的唯一正确信息是产品URL


为什么会发生这种情况?我如何修复它?

默认情况下,当您加载产品集合时,您将获得有关产品的大量信息。例:

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 = Mage::getModel( 'catalog/product' )->load( $_product->getId() );
$images = $product->getMediaGalleryImages();
现在您将看到类似的内容(使用
$\u product->debug()
转储一些信息):

媒体库信息(标签等)是另一个beast,必须通过
Mage\u Catalog\u Model\u产品
对象的
getMediaGalleryImages()
方法专门请求

但是如果在产品集合中循环调用,此方法将返回
NULL
。奇怪的是,如果不显式地加载产品模型,您就无法访问这些数据(因为我在本文的回答中将不详细介绍这些原因)。因此,我们需要尝试以下方法:

$_productCollection = Mage::getResourceModel( 'catalog/product_collection' );
// Filter by enabled products
$_productCollection->addAttributeToFilter( 'status', 1 );
// Load all product information
$_productCollection->addAttributeToSelect( '*' );
$_productCollection->addCategoryFilter( $category );
$product = Mage::getModel( 'catalog/product' )->load( $_product->getId() );
$images = $product->getMediaGalleryImages();
不过,在你的收集循环中有这样做的,所以要小心


编辑:

Mage\u目录\u块\u产品->getLoadedProductCollection()

Long,Long,Long故事短片(这种方法深入人心)。。。据我所知,
getLoadedProductCollection()
将只显示产品列表中使用的
属性
设置为
Yes

原因在Mage\u目录\u模型\u资源\u配置中

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);
}

默认情况下,当您加载产品集合时,您将获得关于产品的少量信息。例:

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 = Mage::getModel( 'catalog/product' )->load( $_product->getId() );
$images = $product->getMediaGalleryImages();
现在您将看到类似的内容(使用
$\u product->debug()
转储一些信息):

媒体库信息(标签等)是另一个beast,必须通过
Mage\u Catalog\u Model\u产品
对象的
getMediaGalleryImages()
方法专门请求

但是如果在产品集合中循环调用,此方法将返回
NULL
。奇怪的是,如果不显式地加载产品模型,您就无法访问这些数据(因为我在本文的回答中将不详细介绍这些原因)。因此,我们需要尝试以下方法:

$_productCollection = Mage::getResourceModel( 'catalog/product_collection' );
// Filter by enabled products
$_productCollection->addAttributeToFilter( 'status', 1 );
// Load all product information
$_productCollection->addAttributeToSelect( '*' );
$_productCollection->addCategoryFilter( $category );
$product = Mage::getModel( 'catalog/product' )->load( $_product->getId() );
$images = $product->getMediaGalleryImages();
不过,在你的收集循环中有这样做的,所以要小心


编辑:

Mage\u目录\u块\u产品->getLoadedProductCollection()

Long,Long,Long故事短片(这种方法深入人心)。。。据我所知,
getLoadedProductCollection()
将只显示产品列表中使用的
属性
设置为
Yes

原因在Mage\u目录\u模型\u资源\u配置中

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);
}

哇-谢谢你的详细回复。你警告过会有性能问题-我对此非常担心。所有产品信息都通过$\u productCollection=$this->getLoadedProductCollection()在页面开头加载;目前,我正在抓取子类别,并试图获得另一个完整的产品信息负载(你在这里回答的问题)。这似乎是重复的-有没有办法避免这种情况?性能的影响来自(技术上)在foreach循环中重新加载/查询每个产品模型。不理想。简单的回答是:这取决于您的设置。使用产品模型的
->debug()。查看其中的可用内容,然后通过
addAttributeToSelect
慢慢添加所需字段。当您指定
addAttributeToSelect('images')
时,似乎包含了图像库的基本信息,所以您可能很乐意去。我会调查一下-非常感谢您的时间和knwoledge-您对我帮助很大!啊,我刚刚注意到
$this->getLoadedProductCollection()
。。。是的,那很有趣。除了在一些自定义代码中凌驾于方法之上之外,您无法对其进行修改,但是,IIRC,这会有点麻烦。我将在下面讨论。哇-谢谢你的详细回复。你警告过会有性能问题-我对此非常担心。所有产品信息都通过$\u productCollection=$this->getLoadedProductCollection()在页面开头加载;目前,我正在抓取子类别,并试图获得另一个完整的产品信息负载(你在这里回答的问题)。这似乎是重复的-有没有办法避免这种情况?性能的影响来自(技术上)在foreach循环中重新加载/查询每个产品模型。不理想。简单的回答是:这取决于您的设置。使用产品模型的
->debug()。查看其中的可用内容,然后通过
addAttributeToSelect
慢慢添加所需字段。当您指定
addAttributeToSelect('images')
时,似乎包含了图像库的基本信息,所以您可能很乐意去。我会调查一下-非常感谢您的时间和knwoledge-您对我帮助很大!啊,我知道