【问题标题】:Magento New Products Filter AttributeMagento 新产品过滤器属性
【发布时间】:2014-02-06 11:44:50
【问题描述】:

我已按照此指南进行操作,并且已经展示了一段时间的新产品,但左侧的过滤器从未显示: http://www.dnawebagency.com/displaying-new-products-in-magento-with-pagination/

这段代码在/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
?>

现在我在页面模板上使用以下 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>

现在左侧的过滤器显示,但它显示所有类别计数,并且当单击任何过滤器时,它不会缩小对当前新股票的搜索范围。

我一直在摸索并在网上搜索以尝试使其正常工作。

有人有什么想法吗?

页面上的完整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>

【问题讨论】:

  • 您找到解决方案了吗?如果是这样,欢迎您回答自己的问题。我也在找这个,没有成功。

标签: php magento


【解决方案1】:

请指定图层的类别 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>

更多详情请查看....

CMS page with layered navigation not working

【讨论】:

  • 嗨,阿米特,它实际上没有类别,因为它只是提取了 news_from 和 news_to 日期之间的所有库存
【解决方案2】:

通过静态块调用主页上的块,内容值为

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

或者你可以直接在cms home上调用这个块,粘贴这个

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

在您的 CMS 主页内容中。

在文件夹中创建一个文件 前端/主题文件夹/默认/模板/目录/产品为 new.phtml。

将以下代码粘贴为:

新产品

<?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>

就是这样,您将能够在主页上看到最新的 4 产品。您可以通过增加 ->setPage(1, 4); 来增加产品的数量;到您在主页上所需的产品数量。

【讨论】:

  • 嗨 Jagi,基本上我们在主页上有特色产品(不是新产品),然后我们需要一个页面,其中包含设置了 news_from 和 news_to 日期范围的所有新产品。我希望使用左侧的过滤器对此进行分页以过滤产品。我们将其作为 domain.com/new-products/ url
  • 这个选项也不给我左边的栏来过滤产品。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-06-22
  • 2016-10-14
  • 1970-01-01
相关资源
最近更新 更多