我有以下代码:
$_productCollection = $this->getLoadedProductCollection();
foreach ($_productCollection as $_product)
{
if ($_product->_data['type_id'] == 'configurable')
{
...
}
}
虽然它完成了它应该做的事情,但它大大减慢了页面加载时间。是否可以仅加载可配置产品并删除“可配置”检查?商店有12000种产品,大约700种是可配置的,其余的是儿童简单产品。
我发现以下代码返回所有可配置产品。我只需要当前类别中的产品:
$collectionConfigurable = Mage::getResourceModel('catalog/product_collection')
->addAttributeToFilter('type_id', array('eq' => 'configurable'));
问题在于getLoadedProductCollection()
是否已加载 - 产品数据已从数据库中检索。仅使用当前类别的产品集合也不够好,这会忽略“层”(属性过滤器)。诀窍是首先从列表中删除加载的产品。
// First make a copy, otherwise the rest of the page might be affected!
$_productCollection = clone $this->getLoadedProductCollection();
// Unset the current products and filter before loading the next.
$_productCollection->clear()
->addAttributeToFilter('type_id', 'configurable')
->load();
print_r($_productCollection)
也有它的问题,您不仅输出产品,还输出数据库连接、缓存值以及产品的单独资源等资源的所有详细信息...
在这种情况下,我认为您会更满意:
print_r($_productCollection->toArray())
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)