正如您可能猜到的那样,当我们启用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();
那么,您是否有任何想法获得上述收藏?
答案 0 :(得分:5)
使用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";
}
但似乎无法按属性进行过滤。加入& amp; addViewsCount()调用。它将属性添加到选择查询,但也选择*。