2012-07-30 149 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 

也不要忘記提及特價產品,並啓用的特點是>是

相關問題