2012-07-30 180 views
0

我没怎么表现出特殊的定价(上销售)的产品在Magento主页。我尝试了很多,但它不能...如何在首页上显示特价(销售产品)在magento产品?

{{block type="catalog/product_list" name="home.catalog.product.list" alias="products_homepage" template="catalog/product/list.phtml"}} 

这也是行不通的。

+0

https://github.com/rvpatel/Magento- Special-Product-Module – 2015-04-15 05:32:20

回答

0

这取决于你想如何服务产品。如果您的所有销售的产品已经在销售类,你可以做到以下几点,你的类的Layout Update XML领域内(见Design标签):

<reference name="content"> 
    <block type="catalog/product_list" template="catalog/product/list.phtml"> 
     <action method="setCategoryId"><category_id>[your_category_id]</category_id></action> 
    </block> 
</reference> 

但如果你想要从所有所有销售产品类别,您需要创建一个新的块类型。一个很好的例子是Mage_Catalog_Block_Product_New块类型。该块用于从商店中检索所有新产品。您将几乎需要该块的精确副本,只有产品集合在_beforeToHtml()中加载的方式不同。

要在_beforeToHtml()与加载的收集则是:

$collection = Mage::getResourceModel('catalog/product_collection'); 

    $dateToday = date('m/d/y'); 
    $tomorrow = mktime(0, 0, 0, date('m'), date('d')+1, date('y')); 
    $dateTomorrow = date('m/d/y', $tomorrow); 

    $collection 
     ->addAttributeToFilter('special_price', array('gt' => 0)) 
    ->addAttributeToFilter('special_from_date', array('date' => true, 'to' => $dateToday)) 
    ->addAttributeToFilter('special_to_date', array('or'=> array(
      0 => array('date' => true, 'from' => $dateTomorrow), 
      1 => array('is' => new Zend_Db_Expr('null'))) 
    ), 'left'); 

这检索所有产品,优惠的价格大于零和特殊日期/从匹配当前日期。

1

你也应该检索设定了 'special_price' atrribute,很容易,只需添加以下代码:

->addAttributeToSelect(array('name', 'price', 'small_image', 'status','special_price'), 'inner') 
2

写:
app/code/local/Mage/Catalog/Block/Product/Special.php

<?php 
    class Mage_Catalog_Block_Product_Special extends Mage_Catalog_Block_Product_List 
    { 
     function get_prod_count() 
     { 
      //unset any saved limits 
      Mage::getSingleton('catalog/session')->unsLimitPage(); 
      return (isset($_REQUEST['limit'])) ? intval($_REQUEST['limit']) : 9; 
     }// get_prod_count 
     function get_cur_page() 
     { 
      return (isset($_REQUEST['p'])) ? intval($_REQUEST['p']) : 1; 
     }// get_cur_page 
     /** 
     * Retrieve loaded category collection 
     * 
     * @return Mage_Eav_Model_Entity_Collection_Abstract 
     **/ 
     protected function _getProductCollection() 
     { 
      $todayDate = Mage::app()->getLocale()->date()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT); 
      $tomorrow = mktime(0, 0, 0, date('m'), date('d')+1, date('y')); 
      $dateTomorrow = date('m/d/y', $tomorrow); 
      $collection = Mage::getResourceModel('catalog/product_collection'); 
      $collection->setVisibility(Mage::getSingleton('catalog/product_visibility')->getVisibleInCatalogIds()); 
      $collection = $this->_addProductAttributesAndPrices($collection) 
      ->addStoreFilter() 
      ->addAttributeToSort('entity_id', 'desc') //<b>THIS WILL SHOW THE LATEST PRODUCTS FIRST</b> 
      ->addAttributeToFilter('special_from_date', array('date' => true, 'to' => $todayDate)) 
      ->addAttributeToFilter('special_to_date', array('or'=> array(0 => array('date' => true, 'from' => $dateTomorrow), 1 => array('is' => new Zend_Db_Expr('null')))), 'left') 
      ->setPageSize($this->get_prod_count()) 
      ->setCurPage($this->get_cur_page()); 
      $this->setProductCollection($collection); 
      return $collection; 
     }// _getProductCollection 
    }// Mage_Catalog_Block_Product_New 
    ?> 

在CMS页---->主页(管理面板),点击设计选项卡,然后在页面布局 - >布局更新xml把这个代码..

<reference name="content"> 
    <block type="catalog/product_special" name="product_special" template="catalog/product/list.phtml"> 
     <block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml"> 
       <action method="setDefaultDirection"><dir>desc</dir></action> 
       <action method="setDefaultOrder"><field>entity_id</field></action> 
       <block type="page/html_pager" name="product_list_toolbar_pager" /> 
     </block> 
     <action method="addColumnCountLayoutDepend"><layout>three_columns</layout><count>3</count></action> 
     <action method="setToolbarBlockName"><name>product_list_toolbar</name></action> 
    </block> 
</reference> 

希望这有助于ü:P

+0

Magento 1.8.1 – vanduc1102 2015-03-26 15:52:55

+0

如果我想将产品网格显示列从三个更改为四个,该怎么办? – 2015-11-18 13:01:37

0

您可以使用扩展其免费的 网址:http://www.magentocommerce.com/magento-connect/top-seller-new-feature-most-viewed-catalog-sale-recently-ordered-all-products-7-in-one-catalog-by-etatvasoft.html。 转到系统>>配置>> Tatvasoft >>目录扩展配置>>您想要的功能>>启用>>是 它将显示特色产品中的销售产品和促销类别中的销售。也不要忘记在CMS添加这些行>页>主页

To see Bestsellers products 
{{block type="catalogextensions/bestsellers_home_list" name="bestsellers_list" template="catalogextensions/home_bestsellers.phtml"}} 
To see Featured products 
{{block type="catalogextensions/featured_home_list" name="featured_list" template="catalogextensions/home_featured.phtml"}} 
In Default attribute set >> 'Is Featured' attributes is added. You need to select “yes” value to show product as feature product 
To see Mostviewed products 
{{block type="catalogextensions/mostviewed_home_list" name="mostviewed_list" template="catalogextensions/home_mostviewed.phtml"}} 
To see Newproduct products 
{{block type="catalogextensions/newproduct_home_list" name="newproduct_list" template="catalogextensions/home_newproduct.phtml"}} 
To see catalog Sale products 
{{block type="catalogextensions/promotional_home_list" name="promotional_list" template="catalogextensions/home_promotional.phtml"}} 
For showing the products in promotional rule, One catalog rule needs to be setup. 
To see RecentlyOrdered products 
{{block type="catalogextensions/lastordered_home_list" name="lastordered_home_list" template="catalogextensions/home_lastordered.phtml"}} 
To see All products without any category filter 
href=" echo $this->getUrl('catalogextensions/index/allproduct');" for All Products link 

也不要忘记提及特价产品,并启用的特点是>是