Flat product release

as you might have guessed, when we turn on the Flat Catalog Product option, we cannot get product attributes such as "name, price, etc." from the collection of product reports. When this option is enabled, all attributes are stored in catalog_product_flat . So, I want to make an extension to show the most viewed products, but success is not due to the above problem.

I tried many ways, but nothing happened as follows:

 $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(); 

So, do you have any idea to purchase the mentioned collection?

+4
source share
1 answer

Inner Join with catalog_product_flat_ $ storeId should do the trick:

  $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"; } 

Doesn't look like a filter by attribute. This got confused with calling join and addViewsCount (). It adds attributes to the select query, but also selects *.

+5
source

Source: https://habr.com/ru/post/1391853/


All Articles