我在顯示自定義產品集合時遇到了分頁問題。由於我對Magento感到陌生,請根據我的理解耐心等待。Magento:自定義集合中缺少分頁
目標:我想在產品視圖頁面上展示來自同一類別的其他產品,並利用我正在使用的無限滾動擴展。因此,用戶將在產品頁面上顯示(說)5種產品,但隨着用戶向下滾動,將會加載並顯示5種產品的下一頁。此擴展在我的類別列表頁面上運行良好。
問題:我能夠通過下面的代碼,以顯示產品頁面上的產品,無限滾動看起來也活躍,但分頁不工作。所有來自集合的產品都會一次加載,以便第2頁上的無限滾動顯示用戶向下滾動時第一頁產品的重複列表。
如果有人能幫助我解決這個問題,我將非常感激。
下面是我寫的: /app/code/local/Mage/Catalog/Block/Product/OtherProducts.php
<?php
class Mage_Catalog_Block_Product_OtherProducts extends Mage_Catalog_Block_Product_List
{
protected function _getProductCollection()
{
$aCategoryId = $this->getProduct()->getCategoryIds();
if (!$aCategoryId) {
echo "This product is not assigned to any categories.";
}
$iCategoryId = $aCategoryId[0];
$oCategory = Mage::getModel('catalog/category')->load($iCategoryId);
$oProductCollection = $oCategory
->getProductCollection()
->addCategoryFilter($oCategory)
->addAttributeToSelect('*')
->addFieldToFilter('entity_id', array('neq' => $this->getProduct()->getId()));
return $oProductCollection;
}
}
?>
/應用程序/設計/前端/默認//佈局/catalog.xml,位於「產品視圖」頁面的xml之後。
<reference name="content">
<block type="catalog/product_OtherProducts" name="product_OtherProducts" template="catalog/product/otherslist.phtml">
<action method="setColumnCount"><columns>5</columns></action>
<action method="setProductsCount"><count>5</count></action>
<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" />
<action method="setDefaultGridPerPage"><limit>10</limit></action>
<action method="addPagerLimit"><mode>grid</mode><limit>12</limit></action>
<action method="addPagerLimit"><mode>grid</mode><limit>24</limit></action>
<action method="addPagerLimit"><mode>grid</mode><limit>36</limit></action>
<action method="addPagerLimit"><mode>grid</mode><limit>48</limit></action>
<action method="addPagerLimit" translate="label"><mode>grid</mode><limit>all</limit><label>All</label></action>
</block>
<action method="addColumnCountLayoutDepend"><layout>one_column</layout><count>6</count></action>
<action method="setToolbarBlockName"><name>product_list_toolbar</name></action>
</block>
</reference>
/app/design/frontend/default/roadgods/template/catalog/product/otherslist.phtml
<?php
$_productCollection=$this->getLoadedProductCollection();
$_helper = $this->helper('catalog/output');
?>
<?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 if($this->getMode()!='grid'): ?>
<?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(160,200); ?>" width="160" height="200" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" /></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 Mage::helper('commonfun')->getProductShortName($_helper->productAttribute($_product, $_product->getName() , 'name'),0,60); ?></a></h2>
<?php /*?> <?php if($_product->getRatingSummary()): ?>
<?php echo $this->getReviewsSummaryHtml($_product) ?>
<?php endif; ?><?php */?>
<?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->__('Sold Out') ?></span></p>-->
<?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>
<?php /*?><ul class="add-to-links">
<?php if ($this->helper('wishlist')->isAllow()) : ?>
<li><a href="<?php echo $this->helper('wishlist')->getAddUrl($_product) ?>" class="link-wishlist"><?php echo $this->__('Add to Wishlist') ?></a></li>
<?php endif; ?>
<?php if($_compareUrl=$this->getAddToCompareUrl($_product)): ?>
<li><span class="separator">|</span> <a href="<?php echo $_compareUrl ?>" class="link-compare"><?php echo $this->__('Add to Compare') ?></a></li>
<?php endif; ?>
</ul><?php */?>
</div>
</div>
</li>
<?php endforeach; ?>
</ol>
<script type="text/javascript">decorateList('products-list', 'none-recursive')</script>
<?php else: ?>
<?php // Grid Mode ?>
<?php $_collectionSize = $_productCollection->count() ?>
<?php $_columnCount = $this->getColumnCount(); ?>
<?php $i=0; foreach ($_productCollection as $_product): ?>
<?php if ($i++%$_columnCount==0): ?>
<div class="productslist_view">
<div class="pro_cat">
<ul class="products-grid productslist_v-grid">
<?php endif ?>
<li class="item<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>">
<div class="pro2">
<?php
$price = $_product->getPrice();
$specialprice = $_product->getFinalPrice();
if($specialprice==$price){ }
else {
echo '<p class="yellow_price">';
$totalPercent = (($price - $specialprice) *100)/ $price;
echo round($totalPercent)."%";
echo '<br /> Off</p>';
}
?>
<div class="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')->keepAspectRatio(TRUE)->keepFrame(TRUE)->resize(160,200); ?>" width="160" height="200" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" /></a>
</div>
<?php
$sku_gift = $_product->getData('sku_of_product_gift');
if(!$sku_gift==''):
$prod_gift = Mage::getModel('catalog/product')->loadByAttribute('sku', $sku_gift);
$gift_name = $prod_gift->getName();
$gift_image = Mage::helper('catalog/image')->init($prod_gift, 'small_image')->resize(30);
?>
<div class="productgiftlist">
<a href="<?php echo $_product->getProductUrl() ?>" title= "<?php echo $gift_name?>" style="color:white">
<img src="<?php echo $gift_image ?>" style="float:left;margin:3px;"><?php echo " + Free ".$gift_name ?>
</a>
</div>
<?php endif; ?>
<p class="new_name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>"><?php echo Mage::helper('commonfun')->getProductShortName($_helper->productAttribute($_product, $_product->getName(), 'name'),0,60) ?></a></p>
<?php /*?> <?php if($_product->getRatingSummary()): ?>
<?php echo $this->getReviewsSummaryHtml($_product, 'short') ?>
<?php endif; ?><?php */?>
<p style="margin:auto; width:100%; float:left; height:auto; "><?php echo $this->getPriceHtml($_product, true) ?> </p>
<p style="margin:auto; width:100%; float:left; height:auto; ">
<?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>--></p>
<?php else: ?>
<p style="margin:auto; width:100%; float:left; height:auto; "> <span><?php echo $this->__('Sold Out') ?></span></p>
<?php endif; ?>
<p style="margin:auto; width:100%; float:left; height:auto; "> <ul class="add-to-links">
<?php if ($this->helper('wishlist')->isAllow()) : ?>
<li><a href="<?php echo $this->helper('wishlist')->getAddUrl($_product) ?>" class="link-wishlist"><?php echo $this->__('Add to Wishlist') ?></a></li>
<?php endif; ?>
<?php if($_compareUrl=$this->getAddToCompareUrl($_product)): ?>
<!-- <li><span class="separator">|</span> <a href="<?php echo $_compareUrl ?>" class="link-compare"><?php echo $this->__('Add to Compare') ?></a></li>-->
<?php endif; ?>
</ul>
</p>
</div>
</li>
<?php if ($i%$_columnCount==0 || $i==$_collectionSize): ?>
</ul>
</div>
</div>
<?php endif ?>
<?php endforeach ?>
<script type="text/javascript">decorateGeneric($$('ul.products-grid'), ['odd','even','first','last'])</script>
<?php endif; ?>
<!--<div class="toolbar-bottom">
<?php /*echo $this->getToolbarHtml()*/ ?>
</div>-->
</div>
<?php endif; ?>
任何人都可以,請幫助我這個請,將是非常感激。
您好,非常感謝您的回答! 我試過這個,但是這並不能解決問題。分頁仍然不起作用,所有的產品都被加載到第一頁上。 您是否有其他嫌疑人? 順便說一句,如前所述,我在產品瀏覽頁面上這樣做,這是爲什麼它不起作用? – 2014-09-30 17:48:32