我没有如何在magento主页上显示特价(销售)产品。我尝试了很多,但它不能......
{{block type="catalog/product_list" name="home.catalog.product.list" alias="products_homepage" template="catalog/product/list.phtml"}}
这也行不通。
写 :
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
您还应该从集合中检索“special_price”属性,这很容易,只需添加以下代码:
->addAttributeToSelect(array('name', 'price', 'small_image', 'status','special_price'), 'inner')
您可以使用免费的扩展 URL: 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>pages>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
也不要忘记提及产品和启用的特价>是的
这取决于您希望如何为产品提供服务。如果您的所有销售产品都已在销售类别中,您可以在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');
这将检索所有特价大于零的产品,并且该特殊日期与当前日期匹配。