1

I am trying to display an if statement for products to show Item details if they exist. Otherwise display an attribute.

<?php echo $_product->getAttributeText('filter_metal'); ?>

and it displays the attribute no problem as it exists.

But however I want to check for an item detail first (not an attribute) and then if that exists to display this instead.

On the product page I can get this product detail by;

<?php echo $_product->getData('metal_type'); ?>

but on the category list page it does not.. I am sure I am missing something. Any assistance is great.

Here is what I was trying also to get if else;

<?php if ($_product->getData('metal_type')): ?> <?php echo $_product->getData('metal_type')?> <?php else:?> <?php echo $_product->getAttributeText('filter_metal'); ?> <?php endif;?>

Any help is much appreciated.

1 Answer 1

1

A custom product attribute is always available on product detail page. In a category or other product list there are only the attributes available which have the flag Use in product listing set to Yes. Please check the settings of your attributes filter_metal and metal_type and correct the Use in product listing Flag.

After configuring the attributes correctly, please rebuild the product flat index and after that you should be able to use both attributes in product lists as you want.

I hope that helps.

1
  • 100%, thanks.. not sure how i missed this. Commented Feb 27, 2019 at 0:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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