Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

how do I say “if category is… then”? 
 
Vicky P
Sr. Member
 
Total Posts:  93
Joined:  2008-02-27
Devon, UK
 

I’m building a site which will be selling yarn.  Each type of yarn is a grouped product, which is made up of simple products in each colour and shade.  I wanted to show a colour swatch next to each associated product and so using a very helpful post I found on the forum, I modified the template/catalog/product/view/type/grouped page with this line

<td><?php echo '<a href="'.$this->helper('catalog/image')->init($_item'image').'" ><img src="'.$this->helper('catalog/image')->init($_item'thumbnail')->resize(5050).'" width="50"><a>'?></td>

It works great.

However the site will also be selling knitting needles.  Again these will be grouped products with each size as an associated product.  But I don’t need to have a swatch next to the item.  They all look the same so the main photo is fine on its own.

I would like to put a conditional statement above my modified to code so that it only shows the swatch that if the product is in “yarn” category.

I can’t work how to say “if the category is yarn then...”.  Can anyone help me please?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Vicky P
Sr. Member
 
Total Posts:  93
Joined:  2008-02-27
Devon, UK
 

Is there no-one that can explain how to this please?  I would have thought it was fairly straightforward, but I just don’t know/understand the syntax to use.

 
Magento Community Magento Community
Magento Community
Magento Community
 
MA_19
Member
 
Total Posts:  41
Joined:  2009-01-21
 

Something like this should do it:

<?php if('yarn' == $this->getCurrentCategory()->getName()) : ?>

<td><?php echo '<a href="'.$this->helper('catalog/image')->init($_item'image').'" ><img src="'.$this->helper('catalog/image')->init($_item'thumbnail')->resize(5050).'" width="50"><a>'?></td>

<?php endif; ?>
 
Magento Community Magento Community
Magento Community
Magento Community
 
Vicky P
Sr. Member
 
Total Posts:  93
Joined:  2008-02-27
Devon, UK
 

Hi, Thanks for replying so quickly.

It didn’t work, but it led me to being able to do what I needed to.

<?php 
    $_cat 
$this->getProduct()->getCategory();
    
$_parent_cat $_cat->getParentCategory()->getName();
?>

then…

<?php if ($_parent_cat == 'Yarn'): ?>
        
<td><?php echo '<a href="'.$this->helper('catalog/image')->init($_item'image').'" ><img src="'.$this->helper('catalog/image')->init($_item'thumbnail')->resize(5050).'" width="50" alt="" /></a>'?></td>
        
<?php endif; ?>
 
Magento Community Magento Community
Magento Community
Magento Community
 
MA_19
Member
 
Total Posts:  41
Joined:  2009-01-21
 

well it was a guess, and I hadn’t tested it but I’m glad it led you in the right direction wink

Matt

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top