我在将产品列表工具栏从内容块移动到左侧块时遇到问题。
我想只显示排序选项,这可以通过设置自定义工具栏模板文件toolbar_custom.html轻松完成。但我输出错误。
到目前为止,我在layout/catalog.xml
中添加了这些行:
<catalog_category_default translate="label">
<label>Catalog Category (Non-Anchor)</label>
<reference name="left">
<block type="catalog/navigation" name="catalog.leftnav" after="currency" template="catalog/navigation/left.phtml">
<block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar_custom.phtml"/>
<action method="setToolbarBlockName"><name>product_list_toolbar</name></action>
</block>
</reference>
<reference name="content">
<block type="catalog/category_view" name="category.products" template="catalog/category/view.phtml">
<block type="catalog/product_list" name="product_list" template="catalog/product/list.phtml"/>
</block>
</reference>
</catalog_category_default>
,这在navigation/left.phtml
:
<?php $magento_block = Mage::getSingleton('core/layout'); ?>
<?php $toolbarHtml = $magento_block->createBlock('catalog/product_list'); ?>
<?php $toolbarHtml->setTemplate('catalog/product/list/toolbar_custom.phtml'); ?>
<?php echo $toolbarHtml ->toHTML(); ?>
这是我的自定义工具栏模板 - toolbar_custom.phtml
:
<?php if($this->getCollection()->getSize()): ?>
<div class="toolbar">
<?php if( $this->isExpanded() ): ?>
<div class="sort-by">
<label><?php echo $this->__('Sort By') ?></label>
<select onchange="setLocation(this.value)">
<?php var_dump($this->getName()); ?>
<?php foreach($this->getAvailableOrders() as $_key=>$_order): ?>
<option value="<?php echo $this->getOrderUrl($_key, 'asc') ?>"<?php if($this->isOrderCurrent($_key)): ?> selected="selected"<?php endif; ?>>
<?php echo $this->__($_order) ?>
</option>
<?php endforeach; ?>
</select>
</div>
<?php endif; ?>
</div>
<?php endif ?>
当我在浏览器中打开产品列表页面时,我收到以下错误消息:
致命错误:在非对象中调用成员函数getSize() Magento的/应用程序/设计/前端/ my_theme /默认/模板/目录/产品/列表/ toolbar_custom.phtml 第37行
我正在使用Magento Community 1.6 ..
答案 0 :(得分:1)
在layout / catalog.xml文件下,执行Default部分中的更改..
<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>
在此参考部分
中包含上述代码<reference name="left">
<block type="catalog/navigation" name="catalog.categorymenu" before="cart_sidebar" template="catalog/navigation/left_catalog.phtml"/>
</reference>
你可以在块中使用你自己的toolbar.phtml文件
答案 1 :(得分:1)
我遇到了同样的问题。这对我有用:
在<reference name="left">
块的layout / catalog.xml中,插入:
<block type="catalog/product_list" name="catalog_product_list" template="catalog/product/list.phtml"></block>
然后,在您想要工具栏的left.phtml中:
<?php
$toolbar = $this->getChild('catalog_product_list')->getToolbarBlock();
$toolbar->setCollection($this->getChild('catalog_product_list')->getLoadedProductCollection());
echo $toolbar->toHtml();
?>
答案 2 :(得分:0)
将此添加到您的布局:
<catalog_category_layered translate="label">
<reference name="left">
<!-- Adds the toolbar to the left column -->
<block type="catalog/category_view" name="category.page.toolbar" template="catalog/category/sidetoolbar.phtml">
<block type="catalog/product_list" name="product_list" template="catalog/product/list.phtml">
<block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml" />
<action method="setToolbarBlockName"><name>product_list_toolbar</name></action>
</block>
</block>
<!-- We use the original toolbar - you could also write your own -->
<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>
</reference>
</catalog_category_layered>
在catalog / category / sidetoolbar.phtml上创建一个新模板:
<?php
// lets get the toolbar block
$toolbar = $this->getChild('product_list')->getToolbarBlock();
// add the product collection
$toolbar->setCollection($this->getChild('product_list')->getLoadedProductCollection());
?>
答案 3 :(得分:-1)
只需重命名这些块:
<block type="catalog/product_list_toolbar" name="product_list_toolbar_custom" template="catalog/product/list/toolbar_custom.phtml"/>
<action method="setToolbarBlockName"><name>product_list_toolbar_custom</name></action>