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