drwghu6386 2014-04-11 10:05
浏览 96
已采纳

Magento的。 分层导航未显示

I have CMS page which outputs list of all products. It uses block created by custom extension.

The problem is that it does not output Layered Navigation filters.

Here is CMS page Layout update:

<reference name="content">
  <block type="wtc_allproducts/list" name="allproducts" template="wtc/allproducts/list.phtml">

    <!-- Layered Navigation Block; setCategoryId sets id of Root category -->
    <block type="catalog/layer_view" name="catalog.leftnav" template="catalog/layer/view.phtml" >
      <action method="setCategoryId"><category_id>2</category_id></action>
    </block>

    <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="setToolbarBlockName"><name>product_list_toolbar</name></action>
  </block>
</reference>

wtc/allproducts/list.phtml code:

<div class="row">
  <div class="col-xs-12">
    <div class="infoblock">
      <?php echo $this->getChildHtml('catalog.leftnav'); ?>
    </div>
  </div>
</div>


<?php if (($_products = $this->getProductCollection()) && $_collectionSize = $_products->getSize()): ?>
<div class="row">
  <div class="col-xs-12">
    <div class="category-products">
      <div class="row">
        <?php echo $this->getToolbarHtml() ?>

        <?php foreach ($_products->getItems() as $_product): ?>

          <div class="col-xs-3">
            <div class="brand product-item">
               <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(180); ?>" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" /></a>
              <p><?php echo $this->htmlEscape($_product->getName()) ?></p>

              <div class="price"><?php echo $this->getPriceHtml($_product, true) ?></div>

              <?php if($_product->isSaleable()): ?>
                <input type="image" class="button btn-cart" src="<?php echo $this->getSkinUrl('images/assets/addtocart.png'); ?>" style="height: 34px;" alt="<?php echo $this->__('Add to Cart') ?>" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')">
              <?php else: ?>
                <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
              <?php endif; ?>

            </div><!-- /.brand.product-item -->
          </div><!-- /.col-xs-3 -->
        <?php endforeach ?>
      </div><!-- /.row -->

      <div class="toolbar-bottom">
        <?php echo $this->getToolbarHtml() ?>
      </div><!-- /.toolbar-bottom -->

    </div><!-- /.category-products -->
  </div></div>
<?php endif; ?>

WTC/AllProducts/Block/List.php code:

<?php

class WTC_AllProducts_Block_List extends Mage_Catalog_Block_Product_Abstract
{
  protected $_defaultToolbarBlock = 'catalog/product_list_toolbar';

  protected $_allProductsCollection;

  protected function _getAllProductsCollection()
  {
    if (is_null($this->_allProductsCollection)) {
      $layer = Mage::getSingleton('catalog/layer');

      $this->_allProductsCollection = $layer->getProductCollection();

      $this->getToolbarBlock()->removeOrderFromAvailableOrders('position');
      $this->getToolbarBlock()->removeOrderFromAvailableOrders('aitmanufacturers_sort');

      $this->_allProductsCollection->setPage(
        $this->getToolbarBlock()->getCurrentPage(),
        $this->getToolbarBlock()->getLimit()
      );
    }

    return $this->_allProductsCollection;
  }

  public function getAllProductsCollection()
  {
    return $this->_getAllProductsCollection();
  }


  public function getMode()
  {
    return $this->getChild('toolbar')->getCurrentMode();
  }

  protected function _beforeToHtml()
  {
    $toolbar = $this->getToolbarBlock();

    // called prepare sortable parameters
    $collection = $this->_getAllProductsCollection();

    // use sortable parameters
    if ($orders = $this->getAvailableOrders()) {
      $toolbar->setAvailableOrders($orders);
    }
    if ($sort = $this->getSortBy()) {
      $toolbar->setDefaultOrder($sort);
    }
    if ($dir = $this->getDefaultDirection()) {
      $toolbar->setDefaultDirection($dir);
    }
    if ($modes = $this->getModes()) {
      $toolbar->setModes($modes);
    }

    // set collection to toolbar and apply sort
    $toolbar->setCollection($collection);

    $this->setChild('toolbar', $toolbar);
    Mage::dispatchEvent('catalog_block_product_list_collection', array(
      'collection' => $this->_getAllProductsCollection()
    ));

    $this->setProductCollection($collection);

    return parent::_beforeToHtml();
  }

  public function getToolbarBlock()
  {
    if ($blockName = $this->getToolbarBlockName()) {
      if ($block = $this->getLayout()->getBlock($blockName)) {
        return $block;
      }
    }
    $block = $this->getLayout()->createBlock($this->_defaultToolbarBlock, microtime());
    return $block;
  }

  public function getToolbarHtml()
  {
    return $this->getChildHtml('toolbar');
  }

  public function setCollection($collection)
  {
    $this->_allProductsCollection = $collection;
    return $this;
  }
}

I don't see where is my mistake.

  • 写回答

3条回答 默认 最新

  • duanmeng7865 2014-04-13 17:55
    关注

    I found if statement in catalog/layer/view.phtml left by previous programmer, which disallowed to show layered navigation filters if page has an URL. :/ Sorry

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?