0

I know there are many ways to do things in Magento, could someone explain to be the best approach to show an asset within a product page if the attribute set ID matches?

I have used this before for a product attribute, but do not understand how to fetch and match an attribute set ID?

<?php if ($_product->getAttributeText ('bogof') == "Yes"): ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('')->toHtml() ?>
<?php endif; ?>

Thank you

2

You can retrieve the attribute set ID with below code.

$_product->getAttributeSetId()

On a side note, retrieving a static block like that is not really best practice. Try using the layout XML

<catalog_product_view>
   [...]
   <reference name="product.info">
      <block type="cms/block" name="bogof_block">
         <action method="setBlockId"><block_id>bogof_block</block_id></action>
      </block>
   </reference>
   [...]
</catalog_product_view>

and in the view.phtml for the product

if ($_product->getAttributeSetId() == 4) {
   $this->getChildHtml('bogof_block');
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.