Magento add most popular products
2012-10-16 09:44
302 查看
在magento\app\code\local\Mage\Catalog\Block\Product 创建一个文件名为 MostPopular.php 的文件
在magento\app\design\frontend\bagstore\default\template\catalog\product 创建一个文件名为MostPopular.phtml的文件
在同一个文件夹内查找new.phtml 并复制代码到 MostPopular.phtml 内。
在任何phtml位置用
输出
或在xhtml中用
输出到想要的位置。
<?php class Mage_Catalog_Block_Product_MostPopular extends Mage_Catalog_Block_Product_Abstract { public function __construct() { parent::__construct(); $storeId = Mage::app()->getStore()->getId(); $products = Mage::getResourceModel('reports/product_collection') //->addAttributeToSelect('*') ->addAttributeToSelect(array('name', 'price', 'small_image', 'short_description', 'description')) ->setStoreId($storeId) ->addStoreFilter($storeId) ->addViewsCount(); Mage::getSingleton(‘catalog/product_status’)->addVisibleFilterToCollection($products); Mage::getSingleton(‘catalog/product_visibility’)->addVisibleInCatalogFilterToCollection($products); //$products->setPageSize(6)->setCurPage(1); $this->setProductCollection($products); } }
在magento\app\design\frontend\bagstore\default\template\catalog\product 创建一个文件名为MostPopular.phtml的文件
在同一个文件夹内查找new.phtml 并复制代码到 MostPopular.phtml 内。
在任何phtml位置用
<?php echo $this->getLayout()->createBlock(‘catalog/product_MostPopular’)->setTemplate(‘catalog/product/MostPopular.phtml’)->toHtml();?>
输出
或在xhtml中用
<block type=”catalog/product_MostPopular” template=”catalog/product/MostPopular.phtml” />
输出到想要的位置。
相关文章推荐
- [Magento] Add downloadable products
- magento添加多个产品到购物车(Add multiple products to cart )
- addAttributeToFilter Conditionals In Magento
- magento-如何添加-删除add to wishlist 和add to compare
- Display sub-category products in root category in Magento
- [zz]100 most popular Machine Learning talks at Videolectures
- magento产品成功添加到购物车后跳转到不同页面 添加 add to cart 按钮
- Magento模型集合addFieldToFilter常用过滤条件
- How to add some custom registration fields while creating your magento account?(compatible also for 1.4.2.0 version)
- Add Custom Info on Invoice Pdf for Magento
- Overload resolution failed because no Public 'Add' is most specific for these arguments
- addAttributeToFilter Conditionals In Magento
- How to show related products in product view page with magento?
- The Most Popular Java API Classes 地址
- Air Jordans Will be The Most Popular Shoes
- Magento -- 让Magento系统目录只显示有库存的产品(Instock Products Only)
- Magento 条件筛选 addAttributeToFilter
- magento导入导出Custom Options, Tier Prices and Grouped Products
- Add custom Field in Order Total for Magento
- 如何解决Site Collection中Most Popular items not working?