Note that there are some explanatory texts on larger screens.

plurals
  1. POShow only current category’s products in Product View
    text
    copied!<p>I’ve been struggling with this question for a long time and it seems very easy to solve, I just can’t do it by myself.</p> <p>Take a look at this page: <a href="http://adegean.dominiotemporario.com/porcelanas-brancas/artigos-de-mesa/linha-americana/saladeira-pequena-americana.html" rel="nofollow">http://adegean.dominiotemporario.com/porcelanas-brancas/artigos-de-mesa/linha-americana/saladeira-pequena-americana.html</a></p> <p>This product is associated with 2 different categories, and I would like to show only a list of products of this current category (in this case, ID 188), not from all the cats the product is listed in. It’s just something like filtering this list by “current_cat_Id” or something.</p> <p>The current code is this: </p> <pre><code> &lt;div class="box base-mini mini-related-items"&gt; &lt;?php $test = Mage::getModel('catalog/layer')-&gt;getCurrentCategory()-&gt;getId(); echo 'Current Main Category of this product this list should show:'.$test; ?&gt; &lt;?php if ($_product) { // get collection of categories this product is associated with $categories =$_product-&gt;getCategoryCollection() //-&gt;setPage(1, 1) //selects only one category -&gt;addFieldToFilter('level','4') //selects only 3rd level categories //-&gt;addFieldToFilter('parent_id','188' ) //select only child categories of no 3 // -&gt;setOrder("level") //combined by setPage, returns the lowest level category -&gt;load(); // if the product is associated with any category if ($categories-&gt;count()) foreach ($categories as $_category) { $cur_category = Mage::getModel('catalog/category')-&gt;load($_category-&gt;getId()); ?&gt; &lt;div class="head"&gt;&lt;h4&gt;Todos os produtos da coleção &lt;strong&gt;&lt;?=$cur_category-&gt;getName()?&gt; (Id: &lt;?=$cur_category-&gt;getId()?&gt;)&lt;/strong&gt;&lt;/h4&gt;&lt;/div&gt; &lt;div class="content"&gt; &lt;ol&gt; &lt;? $products = Mage::getResourceModel('catalog/product_collection') -&gt;addCategoryFilter($_category) -&gt;addAttributeToSelect('small_image'); foreach ( $products as $productModel ) { $_product = Mage::getModel('catalog/product')-&gt;load($productModel-&gt;getId()); $width=50; $height=50; $_imageUrl = $this-&gt;helper('catalog/image')-&gt;init($productModel, 'small_image')-&gt;resize($width, $height); ?&gt; &lt;li&lt;?php if($_product-&gt;isComposite() || !$_product-&gt;isSaleable()): ?&gt; class="super-products"&lt;?php endif; ?&gt; class="product-box"&gt; &lt;div class="product-images"&gt; &lt;a href="&lt;?php echo $_product-&gt;getProductUrl() ?&gt;"&gt;&lt;img src="&lt;?php echo $this-&gt;helper('catalog/image')-&gt;init($_product, 'thumbnail')-&gt;resize(50) ?&gt;" alt="&lt;?php echo $this-&gt;htmlEscape($_product-&gt;getName()) ?&gt;" width="50" height="50" /&gt;&lt;/a&gt; &lt;/div&gt; &lt;div class="product-details"&gt; &lt;a href="&lt;?php echo $_product-&gt;getProductUrl() ?&gt;"&gt;&lt;?php echo $this-&gt;htmlEscape($_product-&gt;getName()) ?&gt;&lt;/a&gt; &lt;!-- Price --&gt; &lt;?php echo $this-&gt;getPriceHtml($_product, true) ?&gt; &lt;/div&gt; &lt;/li&gt; &lt;? } echo "&lt;/ol&gt;&lt;div class=\"clear\"&gt;&lt;/div&gt;&lt;/div&gt;"; } } ?&gt; &lt;/div&gt; </code></pre> <p>Could someone please help me solving that?? Thank you in advance for your help!</p> <p>Cheers, jw </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload