简体   繁体   English

Magento新产品过滤器属性

[英]Magento New Products Filter Attribute

I have followed this guide, and have had new products display for some time now, but the filter on the left hand side never displayed: http://www.dnawebagency.com/displaying-new-products-in-magento-with-pagination/ 我已按照本指南进行了一段时间的新产品显示,但左侧的过滤器从未显示: http//www.dnawebagency.com/displaying-new-products-in-magento-with-分页/

This code is as follows under /app/code/local/Mage/Catalog/Block/Product/New.php 此代码如下/app/code/local/Mage/Catalog/Block/Product/New.php

<?php

class Mage_Catalog_Block_Product_New 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']) : 12;
   }// 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);

      //$collection = Mage::getResourceModel('catalog/product_collection');
    $collection = Mage::getModel('catalog/product')->getCollection();
      $collection->setVisibility(Mage::getSingleton('catalog/product_visibility')->getVisibleInCatalogIds());

      $collection = $this->_addProductAttributesAndPrices($collection)
         ->addStoreFilter()
         ->addAttributeToFilter('news_from_date', array('date' => true, 'to' => $todayDate))
         ->addAttributeToFilter('news_to_date', array('or'=> array(
            0 => array('date' => true, 'from' => $todayDate),
            1 => array('is' => new Zend_Db_Expr('null')))
         ), 'left')
         ->addAttributeToSort('news_from_date', 'desc')
         ->setPageSize($this->get_prod_count())
         ->setCurPage($this->get_cur_page());

      $this->setProductCollection($collection);

      return $collection;
   }// _getProductCollection
}// Mage_Catalog_Block_Product_New
?>

Now I got the filter on the page using the following XML on the page template 现在,我在页面模板上使用以下XML获取了页面上的过滤器

<!-- add layered navigation to left column -->
<reference name="left">
  <block type="catalog/layer_view" name="catalog.leftnav" before="-"  template="catalog/layer/view.phtml" />
</reference>

Now the filter on the left hand side displays, but it shows all category counts, and when clicking any of the filters, it does not narrow the search down on the current new stock. 现在左侧的过滤器显示,但它显示所有类别计数,并且当单击任何过滤器时,它不会缩小当前新库存的搜索范围。

I have been scratching my head and searching all over the net to try and get this to work. 我一直在挠头,在网上搜索,试着让它发挥作用。

Anyone have any ideas? 有人有想法么?

The full xml on the page is as follows 页面上的完整xml如下所示

<action method="addFilter">
</action>
<reference name="content">
    <block type="catalog/product_new" name="product_list" after="product_filter"  template="catalog/product/list.phtml">
      <action method="setCategoryId"><category_id>3</category_id></action>
      <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="addColumnCountLayoutDepend"><layout>empty</layout>
          <count>6</count>
      </action>
      <action method="addColumnCountLayoutDepend">
          <layout>one_column</layout>
          <count>5</count>
      </action>
      <action method="addColumnCountLayoutDepend">
          <layout>two_columns_left</layout>
          <count>3</count>
      </action>
      <action method="addColumnCountLayoutDepend">
          <layout>two_columns_right</layout>
          <count>4</count>
      </action>
      <action method="addColumnCountLayoutDepend">
          <layout>three_columns</layout>
          <count>3</count>
      </action>
      <action method="setToolbarBlockName">
          <name>product_list_toolbar</name>
      </action>
    </block>
</reference>

<!-- add layered navigation to left column -->
<reference name="left">
  <block type="catalog/layer_view" name="catalog.leftnav" before="-"  template="catalog/layer/view.phtml" />
</reference>

Please specify the category id for layer 请指定图层的类别ID

 <reference name="left">
        <!-- Layered Navigation Block -->
        <block type="catalog/layer_view" name="catalog.leftnav" template="catalog/layer/view.phtml" >
                <action method="setCategoryId"><category_id>3</category_id></action>
        </block>
</reference>

More details please check.... 更多细节请检查....

CMS page with layered navigation not working 具有分层导航功能的CMS页面无效

Call a block on home page through static block with content value as 通过静态块调用主页上的块,内容值为

{{block type="catalog/product_list" name="product_listing" template="catalog/product/new.phtml"}}

or you can directly call this block on cms home , paste this 或者你可以直接在cms home上调用这个块,粘贴它

{{block type="catalog/product_list" name="product_listing" template="catalog/product/new.phtml" }}

in your CMS home page content. 在您的CMS主页内容中。

create a file in folder frontend/theme_folder/default/template/catalog/product as new.phtml. 在文件夹frontend / theme_folder / default / template / catalog / product中创建一个文件new.phtml。

Paste the below code in it as : 将以下代码粘贴到其中:

New Products 新产品

<?php
$_productCollection = Mage::getResourceModel('reports/product_collection')
                    ->addAttributeToSelect('*')
                    ->setVisibility(array(2,3,4))                   
                    ->setOrder('created_at', 'desc')
                    ->setPage(1, 4);
?>
 <?php $_iterator = 0; ?>
     <ul class="products-grid">
            <?php  foreach($_productCollection as $_product) : ?>
            <li class="item<?php if( ++$_iterator == sizeof($_productCollection) ): ?> last<?php endif; ?>">
                <?php // Product Image ?>
                       <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(135); ?>" width="135" height="135" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" /></a>

                      <div class="product-shop">
                            <div class="f-fix">
                                <h2 class="product-name"><a href="<?php echo $_product->getProductUrl(); ?>"><?php echo $_product->getName(); ?></h2>

                                 <?php echo $this->getPriceHtml($_product, true) ?>
                                <?php if($_product->isSaleable()): ?>
                                    <p><button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button></p>
                                <?php else: ?>
                                    <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
                                <?php endif; ?>
                            </div>
                    </div>
              </li>
        <?php endforeach;  ?>
    </ul>

Thats it you will be able to see the newest 4 product on home page. 多数民众赞成你将能够在主页上看到最新的4产品。 you can increase the number of product by increasing the ->setPage(1, 4); 你可以通过增加 - > setPage(1,4)来增加产品数量; to your required number of product on home page. 在主页上显示您所需的产品数量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM