Magento促销分类列出售价

时间:2015-04-30 14:42:27

标签: magento layered-navigation

我需要在一个类别页面上显示所有待售产品..而不是通过整个目录和手动添加产品我想要一个功能,将选择"特价"产品

我在网上发现了这篇文章 http://www.creativemgroup.com/creative-media-web-services/magento-blog/68-create-a-magento-on-sale-category-the-right-way

&安培; got is working here

问题是它没有对产品进行排序"排序依据"更改排序选项没有区别..我如何使用此代码但仍能使用排序工具栏?..

非常感谢您的帮助......

////////////////////////////// 这是我的Catogory中的代码 - 自定义设计 //////////////////////////////

<reference name="content">
<remove name="product_list"/>
<block type="catalog/product_sale" name="product_sale" alias="sale" template="catalog/product/list.phtml">
<block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">
<block type="page/html_pager" name="product_list_toolbar_pager"/>
</block>
<action method="setLimit"><limit>32</limit></action>
<action method="setColumnCount"><columns>3</columns></action>
<action method="setToolbarBlockName"><name>product_list_toolbar</name></action>
<action method="addPriceBlockType">
<type>bundle</type>
<block>bundle/catalog_product_price</block>
<template>bundle/catalog/product/price.phtml</template>
</action>
</block>
</reference>
<reference name="product_list_toolbar">
<action method="setDefaultGridPerPage">
<limit>32</limit>
</action>
</reference>

////////////////////////////////////////// 这是PHP的主要功能 /////////////////////////////////////////

类Mage_Catalog_Block_Product_Sale扩展Mage_Catalog_Block_Product_List {

//public $_collection;  

public function getProductsLimit() 
{ 
    if ($this->getData('limit')) {
        return intval($this->getData('limit'));
    } else {
        return 32;
    }
}

public function __construct()
{
    parent::__construct();
    $collection = $this->_getProductCollection();
    $this->setCollection($collection);
}






 protected function _getProductCollection()  
 {  
            $page = Mage::getBlockSingleton('page/html_pager')->getCurrentPage();
            date_default_timezone_set(Mage::getStoreConfig('general/locale/timezone'));
            $todayDate = strftime("%Y-%m-%d",Mage::app()->getLocale()->storeTimeStamp(Mage::app()->getStore()->getId()));
            $storeId    = Mage::app()->getStore()->getId();  
            $product    = Mage::getModel('catalog/product');  

            $this->_productCollection = $product->setStoreId($storeId)  
                ->getCollection()  
                ->addAttributeToSelect(array('name','status', 'price', 'special_price', 'small_image','required_options','special_from_date', 'special_to_date'), 'inner')
                ->joinField('stock_status','cataloginventory/stock_status','stock_status',
                    'product_id=entity_id', array(
                      'stock_status' => Mage_CatalogInventory_Model_Stock_Status::STATUS_IN_STOCK,
                      'website_id' => Mage::app()->getWebsite()->getWebsiteId(),
                    ))
                ->addAttributeToFilter('special_price', array('gt' => 0), 'left')
                ->addAttributeToFilter('special_from_date', array('date' => true, 'to' => $todayDate))
                ->addAttributeToFilter('special_to_date', array('or'=> array(
                    0 => array('date' => true, 'from' => $todayDate),
                    1 => array('is' => new Zend_Db_Expr('null')))
                ), 'left')
                //->setOrder('created_at', 'desc')
                ->addAttributeToSort('created_at', 'desc')
                ->addFinalPrice()
                ->addStoreFilter()
                ->setPageSize($this->getProductsLimit())
                ->setCurPage($page)
                ->addAttributeToFilter('status', 1)
                ->addUrlRewrite();

        Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($this->_productCollection);  
        Mage::getSingleton('catalog/product_visibility')->addVisibleInSearchFilterToCollection($this->_productCollection);


            $checkedProducts = new Varien_Data_Collection();
                foreach ($this->_productCollection as $k => $p) {
                    $p = $p->loadParentProductIds();
                    $parentIds = $p->getData('parent_product_ids');

                    if (is_array($parentIds) && !empty($parentIds)) {
                        if (!$checkedProducts->getItemById($parentIds[0])) {
                            $parentProduct = Mage::getModel('catalog/product')->setStoreId($storeId)->load($parentIds[0]);
                            if ($parentProduct->isVisibleInCatalog()) {
                                $checkedProducts->addItem($parentProduct);
                            }
                        }
                    } else {
                        if (!$checkedProducts->getItemById($k)) {
                            $checkedProducts->addItem($p);
                        }
                    }
                    if (count($checkedProducts) >= $this->getProductsLimit()) {
                        break;
                    }
                }

返回$ this-&gt; _productCollection;

 }  

}

//////////////////////////////

2 个答案:

答案 0 :(得分:1)

我的猜测是你的问题与你的逻辑中不包括分层导航有关。您已覆盖@Override public void start(Stage primaryStage) throws IOException { FrustumMesh cone = new FrustumMesh(1,0.2,4,2); MeshUtils.mesh2STL("frustum.stl", cone.getMesh()); } 方法并直接实例化您的收藏集,而不是来自_getProductCollection()的{​​{3}}。您将不得不将该功能重新纳入您的新方法。

答案 1 :(得分:0)

      $params = $this->getRequest()->getParams();
      $dir = (!empty($params['dir'])) ? $params['dir'] : 'desc';   
      $order = (!empty($params['order']) && $params['order'] != 'position') ? $params['order'] : 'created_at';

      //modify collection method:
      ->addAttributeToSort($order, $dir)