2
我一直在努力解決這個問題很長一段時間,看起來很容易解決,我不能自己做。僅在產品視圖中顯示當前類別的產品
本品與2個不同的類別相關的,我想只顯示這個電流類別的產品列表(在這種情況下,ID 188),不來自產品列出的所有貓。它就像通過「current_cat_Id」或其他東西來過濾這個列表。
當前的代碼是這樣的:
<div class="box base-mini mini-related-items">
<?php
$test = Mage::getModel('catalog/layer')->getCurrentCategory()->getId();
echo 'Current Main Category of this product this list should show:'.$test;
?>
<?php
if ($_product) {
// get collection of categories this product is associated with
$categories =$_product->getCategoryCollection()
//->setPage(1, 1) //selects only one category
->addFieldToFilter('level','4') //selects only 3rd level categories
//->addFieldToFilter('parent_id','188') //select only child categories of no 3
// ->setOrder("level") //combined by setPage, returns the lowest level category
->load();
// if the product is associated with any category
if ($categories->count())
foreach ($categories as $_category)
{
$cur_category = Mage::getModel('catalog/category')->load($_category->getId());
?>
<div class="head"><h4>Todos os produtos da coleção <strong><?=$cur_category->getName()?> (Id: <?=$cur_category->getId()?>)</strong></h4></div>
<div class="content">
<ol>
<? $products = Mage::getResourceModel('catalog/product_collection')
->addCategoryFilter($_category)
->addAttributeToSelect('small_image');
foreach ($products as $productModel)
{
$_product = Mage::getModel('catalog/product')->load($productModel->getId());
$width=50; $height=50;
$_imageUrl = $this->helper('catalog/image')->init($productModel, 'small_image')->resize($width, $height);
?>
<li<?php if($_product->isComposite() || !$_product->isSaleable()): ?> class="super-products"<?php endif; ?> class="product-box">
<div class="product-images">
<a href="<?php echo $_product->getProductUrl() ?>"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'thumbnail')->resize(50) ?>" alt="<?php echo $this->htmlEscape($_product->getName()) ?>" width="50" height="50" /></a>
</div>
<div class="product-details">
<a href="<?php echo $_product->getProductUrl() ?>"><?php echo $this->htmlEscape($_product->getName()) ?></a>
<!-- Price -->
<?php echo $this->getPriceHtml($_product, true) ?>
</div>
</li>
<? }
echo "</ol><div class=\"clear\"></div></div>";
}
}
?>
</div>
可能有人請幫我解決了? 預先感謝您的幫助!
乾杯, JW
那麼你現在有什麼問題?你能夠成功檢索當前類別嗎?你會得到什麼輸出? – 2010-09-30 19:24:54