4

请查看我的问题步骤。

我创建了一个名为 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, 'small_image'), null, 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(), null, 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 工作正常,但分页不起作用。任何机构都可以帮助我如何实现它?

4

1 回答 1

1

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

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

也许这对你有帮助。$_productCollection - 模板中的产品集合。

于 2013-06-16T17:04:34.190 回答