正如您可能猜到的,当我们启用Flat Catalog Product选项时,我们无法从产品报告集合中获取"名称,价格等"的产品属性.启用此选项后,所有属性都保留在catalog_product_flat.所以,我想做一个扩展,以显示大多数已浏览的产品,但由于上述问题没有成功.
我尝试了很多方法,但没有发生如下:
$collection = Mage::getResourceModel('reports/product_collection')
->addAttributeToSelect(*)
->setStoreId($store)
->addStoreFilter($store)
->addViewsCount();
$collection = Mage::getResourceModel('reports/product_collection')
->addAttributeToSelect(*)
->addAttributeToSelect(array('name', 'price')) // this will not work is because of the collection
->setStoreId($store)
->addStoreFilter($store)
->addViewsCount();
Run Code Online (Sandbox Code Playgroud)
那么,你有什么想法获得上述收藏品吗?
使用catalog_product_flat_ $ storeId进行内部联接应该可以解决问题:
$storeId = Mage::app()->getStore()->getId();
$collection = Mage::getResourceModel('reports/product_collection')
->addViewsCount();
$collection->getSelect()->joinInner(array('e2' => 'catalog_product_flat_'.$storeId), 'e2.entity_id = e.entity_id');
foreach ($collection as $prod) {
echo "Name: ".$prod->getName()."\n";
echo "Price: ".$prod->getPrice()."\n";
echo "Views: ".$prod->getViews()."\n";
echo "\n";
}
Run Code Online (Sandbox Code Playgroud)
但是,似乎无法按属性进行过滤.这与join&addViewsCount()调用混淆了.它将属性添加到选择查询,但也选择*.
| 归档时间: |
|
| 查看次数: |
1591 次 |
| 最近记录: |