加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – 根据magento中的过滤器设置分页

发布时间:2020-12-13 22:48:44 所属栏目:PHP教程 来源:网络整理
导读:请查看我的步骤以获取问题. 我创建了一个名为Category的magento产品类别,适用于所有产品类别. 为了显示产品列表,我在目录文件夹中创建了一个custom_list.phtml,我已经在magento后端更新了布局文件. custom_list.phtml的代码 ?php/** * Magento * * NOTICE OF
请查看我的步骤以获取问题.

我创建了一个名为Category的magento产品类别,适用于所有产品类别.

为了显示产品列表,我在目录文件夹中创建了一个custom_list.phtml,我已经在magento后端更新了布局文件.

custom_list.phtml的代码

<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web,please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category    design
 * @package     base_default
 * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
?>
<?php
/**
 * Product list template
 *
 * @see Mage_Catalog_Block_Product_List
 */
?>
<?php

    $_productCollection=$this->getLoadedProductCollection();
    $_helper = $this->helper('catalog/output');
    $startWith = $_REQUEST['startWith'];
    $byCountry = $_REQUEST['byCountry'];
    $currentCategory = $this->getCurrentCategory();    
    var_dump(get_class_methods(get_class($this)));
?>
<div>
    <?php if(isset($startWith)): ?>
    <?php
        $_productCollection->clear()
                            ->addAttributeToFilter('name',array( array('like' => $startWith.'%')))
                            ->load();
     ?>
    <span><?php echo $this->__('WINES WITH THE LETTER ').'"'.$startWith.'"'; ?></span>
    <?php elseif(isset($byCountry)): ?>
    <?php
        $_productCollection->clear()
                            ->addAttributeToFilter('country_of_manufacture',array( array('like' => $byCountry)))
                            ->load();
        /*$attributeInfo = Mage::getResourceModel('eav/entity_attribute_collection')
                ->setCodeFilter('country_of_manufacture')
                ->getFirstItem();*/
        $attribute_code = "country_of_manufacture";
        $attribute_details = Mage::getSingleton("eav/config")->getAttribute("catalog_product",$attribute_code);
        $options = $attribute_details->getSource()->getAllOptions(false);
        $countryLabel="";
        foreach($options as $option){
            // print_r($option) and find all the elements
            //echo $option["value"];
            //echo $option["label"];
            if($option["value"]==$byCountry){
                $countryLabel = $option["label"];
            }
        }
     ?>
    <span><?php echo $this->__('WINES FROM ').'&#8220;&nbsp;'.$countryLabel.'&nbsp;&#8221;'; ?></span>
    <?php endif; ?>
    <span><a href="<?php echo Mage::getModel('catalog/layer')->getCurrentCategory()->getUrl(); ?>"><?php echo $this->__('GO BACK TO MAP'); ?></a></span>
</div>
<?php if(!$_productCollection->count()): ?>
<p class="note-msg"><?php echo $this->__('There are no products matching the selection.') ?></p>
<?php else: ?>
<div class="category-products">
    <?php //echo $this->getToolbarHtml() ?>
    <?php // List mode ?>
    <?php $_iterator = 0; ?>
    <ol class="products-list" id="products-list">
    <?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(65,210); ?>" width="65" height="210" alt="<?php echo $this->stripTags($this->getImageLabel($_product,true) ?>" />
                <?php /**********************************************************/ ?>
                <?php
                    // Get the Special Price
                    $specialprice = Mage::getModel('catalog/product')->load($_product->getId())->getSpecialPrice();
                    // Get the Special Price FROM date
                    $specialPriceFromDate = Mage::getModel('catalog/product')->load($_product->getId())->getSpecialFromDate();
                    // Get the Special Price TO date
                    $specialPriceToDate = Mage::getModel('catalog/product')->load($_product->getId())->getSpecialToDate();
                    // Get Current date
                    $today =  time();

                    if ($specialprice):
                        if($today >= strtotime( $specialPriceFromDate) && $today <= strtotime($specialPriceToDate) || $today >= strtotime( $specialPriceFromDate) && is_null($specialPriceToDate)):
                ?>
                        <img width="30" height="30" class="onsaleicon"  />
                <?php
                        endif;
                    endif;
                ?>
                <?php /**********************************************************/ ?>
            </a>
            <?php // Product description ?>
            <div class="product-shop">
                <div class="f-fix">
                    <?php $_productNameStripped = $this->stripTags($_product->getName(),true); ?>
                    <h2 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $_productNameStripped; ?>"><?php echo $_helper->productAttribute($_product,$_product->getName(),'name'); ?></a></h2>
                    <?php if($_product->getRatingSummary()): ?>
                    <?php echo $this->getReviewsSummaryHtml($_product) ?>
                    <?php endif; ?>
                    <div class="desc std">
                        <?php echo $_helper->productAttribute($_product,$_product->getShortDescription(),'short_description') ?>
                        <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $_productNameStripped ?>" class="link-learn"><?php echo $this->__('Learn More') ?></a>
                    </div>
                    <div class="custProdList">
                        <?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>
            </div>
        </li>
    <?php endforeach; ?>
    </ol>
    <script type="text/javascript">decorateList('products-list','none-recursive')</script>
    <div class="toolbar-bottom">
        <?php echo $this->getToolbarHtml() ?>
    </div>
</div>
<?php endif; ?>

fiter工作正常,但分页不起作用.任何身体请帮助我如何实现它?

解决方法

您可以在模板中添加此代码.

<?php
            $pager=new Mage_Page_Block_Html_Pager();
            $pager->setAvailableLimit(8);
            $pager->setCollection($_productCollection);
            $pager->setShowPerPage(6);
?>

也许这有助于你. $_productCollection – 模板中的产品集合.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读