如何在主页上显示特价(产品销售)产品在magento?

时间:2012-07-30 10:58:55

标签: php xml magento product

我不知道如何在magento主页上显示特价(销售)产品。我试了很多但是它不能......

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

这也行不通。

4 个答案:

答案 0 :(得分: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页面----&gt;主页(管理面板),单击设计选项卡,然后在页面布局 - &gt;布局更新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

答案 1 :(得分:1)

您还应该从集合中检索“特价”属性,这很容易,只需添加以下代码:

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

答案 2 :(得分: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');

这将检索特殊价格大于零的所有产品以及与当前日期匹配的特殊日期。

答案 3 :(得分: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。 转到系统&gt;&gt;配置&gt;&gt; Tatvasoft&gt;&gt;目录扩展配置&gt;&gt;您想要的功能&gt;&gt;启用&gt;&gt;是 它将在促销中展示特色产品的销售产品和销售类别。另外不要忘记在cms&gt; pages&gt; home

中添加这些行
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

也不要忘记注意产品中的特价和启用功能&gt;是