如何在 Magento 特价页面中包含分页?

发布于 2024-10-07 01:02:05 字数 4011 浏览 0 评论 0原文

我想使用Magento的特价功能并在CMS页面中显示所有特价产品。它有效,但即使我为 10 种产品指定了特价,也只会显示 9 种产品。然后我想到了分页。现在我尝试了谷歌搜索找到的那些建议方法,但它们不起作用(也许我错过了一些东西)。这就是为什么我想询问从哪里开始的方向。这是我用于特价的代码。

<?php if (($_products = $this->getProductCollection()) && $_products->getSize()): ?>
  <div class="widget widget-new-products">
<div class="widget-title">
    <h2><?php echo $this->__('Special Product') ?></h2>
</div>
<div class="widget-products">

<?php $_columnCount = $this->getColumnCount(); ?>
    <?php $i=0; foreach ($_products->getItems() as $_product): ?>
    <?php if ($i++%$_columnCount==0): ?>
    <ul class="products-grid">
    <?php endif ?>
        <li class="item<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>">
                <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>" class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image') ?>" width="195px" height="195px" alt="<?php echo $this->htmlEscape($_product->getName()) ?>" /></a>
                <h3 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>)"><?php echo $this->htmlEscape($_product->getName()) ?></a></h3>

                <!-- ###### BRANDS EG. BY CHIC ON A MISSION ###### -->
                <div class="product-brand"><?php echo $this->htmlEscape($_product->getextraline()) ?></div>
                <?php echo $this->getReviewsSummaryHtml($_product, 'short') ?> 
                <?php echo $this->getPriceHtml($_product, true, '-widget-new-grid') ?>

            <div class="actions">
                <?php if($_product->isSaleable()): ?>
                    <!-- <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>-->
                <?php else: ?>
                    <!--<p class="availability out-of-stock"><span><?php // echo $this->__('Out of stock') ?></span></p>-->
                    <div class="out-of-stock-special"><img src="<?php echo $this->getSkinUrl('images/donna/soldout-overon.png') ?>" alt="uitverkocht" width="50px" /></div>
                <?php endif; ?>

            </div>
            </li>
    <?php if ($i%$_columnCount==0 || $i==count($_products)): ?>
    </ul>
    <?php endif ?>
    <?php endforeach; ?>

</div>

然后我把这段代码放在CMS内容中。

{{block type="catalog/product_special" template="catalog/product/special.phtml"}}

我尝试使用这段代码。 getToolbarHtml() ?>,但它不起作用。我也尝试过这个。 getToolbarBlock()->setTemplate('catalog/product/list/ctoolbar.phtml')->toHtml(); ?>

我还尝试了 CMS 设计中的布局更新。

<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>three_columns</layout><count>3</count></action>
<action method="setToolbarBlockName"><name>product_list_toolbar</name></action>
</block>
<update handle="page_three_column" />

它也不起作用。希望有人能在这方面指导我。 :)

I want to use the special price feature of Magento and display all products with special price in a CMS page. It's working, but only 9 products will display even if I assigned a special price to 10 products. Then I thought about pagination. Now I tried those suggested methods I found Googling but they didn't work (maybe I missed something). That's why I want to ask for direction on where to begin. This is the code I used for the special price.

<?php if (($_products = $this->getProductCollection()) && $_products->getSize()): ?>
  <div class="widget widget-new-products">
<div class="widget-title">
    <h2><?php echo $this->__('Special Product') ?></h2>
</div>
<div class="widget-products">

<?php $_columnCount = $this->getColumnCount(); ?>
    <?php $i=0; foreach ($_products->getItems() as $_product): ?>
    <?php if ($i++%$_columnCount==0): ?>
    <ul class="products-grid">
    <?php endif ?>
        <li class="item<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>">
                <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>" class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image') ?>" width="195px" height="195px" alt="<?php echo $this->htmlEscape($_product->getName()) ?>" /></a>
                <h3 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>)"><?php echo $this->htmlEscape($_product->getName()) ?></a></h3>

                <!-- ###### BRANDS EG. BY CHIC ON A MISSION ###### -->
                <div class="product-brand"><?php echo $this->htmlEscape($_product->getextraline()) ?></div>
                <?php echo $this->getReviewsSummaryHtml($_product, 'short') ?> 
                <?php echo $this->getPriceHtml($_product, true, '-widget-new-grid') ?>

            <div class="actions">
                <?php if($_product->isSaleable()): ?>
                    <!-- <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>-->
                <?php else: ?>
                    <!--<p class="availability out-of-stock"><span><?php // echo $this->__('Out of stock') ?></span></p>-->
                    <div class="out-of-stock-special"><img src="<?php echo $this->getSkinUrl('images/donna/soldout-overon.png') ?>" alt="uitverkocht" width="50px" /></div>
                <?php endif; ?>

            </div>
            </li>
    <?php if ($i%$_columnCount==0 || $i==count($_products)): ?>
    </ul>
    <?php endif ?>
    <?php endforeach; ?>

</div>

Then I placed this code in the CMS content.

{{block type="catalog/product_special" template="catalog/product/special.phtml"}}

I tried using this code. <?php echo $this->getToolbarHtml() ?>, but it wont work. I also tried this one. <?php echo $this->getToolbarBlock()->setTemplate('catalog/product/list/ctoolbar.phtml')->toHtml(); ?>.

I also tried the layout updates in the CMS design.

<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>three_columns</layout><count>3</count></action>
<action method="setToolbarBlockName"><name>product_list_toolbar</name></action>
</block>
<update handle="page_three_column" />

It didn't work either. Hopefully someone will guide me in this. :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

隔纱相望 2024-10-14 01:02:05

您可以尝试这个解决方案...

1)创建块以这种方式显示特殊产品:

class Yournamespace_Mycatalog_Product_List_Specials extends Mage_Catalog_Block_Product_List{

  protected function _getProductCollection(){
    // your code here to retrieve special priced products
  }
}

2)然后使用模板文件catalog/product/list.phtml的更新版本。它应该包括工具栏(假设 mycatalog/product/list/specials.phtml)

3) 更新您的 cms 块定义:

{{block type="mycatalog/product_list_specials" template="mycatalog/product/list/specials.phtml" }}

You can try this solution...

1) create your block to display the special products this way:

class Yournamespace_Mycatalog_Product_List_Specials extends Mage_Catalog_Block_Product_List{

  protected function _getProductCollection(){
    // your code here to retrieve special priced products
  }
}

2) then use an updated version of template file catalog/product/list.phtml. It should include the toolbar (let's say mycatalog/product/list/specials.phtml)

3) Update your cms block definition:

{{block type="mycatalog/product_list_specials" template="mycatalog/product/list/specials.phtml" }}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文