0

Hi we're trying to check the value of multiple custom attributes before showing some text... I have made sure that each attribute is set with the option "Visible on Product View Page on Front-end" set to YES.

I also made sure my test product has all the following attributes with the following values set

damage_front = FRONT: No damage
damage_right = RIGHT SIDE: No damage
damage_left = LEFT SIDE: No damage
damage_back = BACK: No damage
damage_handles = HANDLES: No damage

I then added the below code to my product view page...

<?php if ($_product->getAttributeText('damage_front') == "FRONT: No damage" && $_product->getAttributeText('damage_back') == "Back: No damage" && $_product->getAttributeText('damage_right') == "RIGHT SIDE: No damage" && $_product->getAttributeText('damage_left') == "LEFT SIDE: No damage" && $_product->getAttributeText('damage_top') == "TOP: No damage" && $_product->getAttributeText('damage_handles') == "HANDLES: No damage"): ?>
{
echo "<div style ='color:#ffffff'><b>This Product is Box Damaged Only</b></div>";
}
<?php endif; ?>

Unfortunatly this does not show any text output, so just to test further i reduced the statement to just check one attribute...

<?php if ($_product->getAttributeText('damage_front') == "FRONT: No damage") : ?>
{
<?php echo "<div style ='color:#ffffff'><b>This Product is Box Damaged Only</b></div>"; ?>
}

<?php endif; ?>

This still doesnt show the required Box Damaged only text.

Finally just to test, i removed the whole IF statment and added

<?php echo "<div style ='color:#ffffff'><b>This Product is Box Damaged Only</b></div>"; ?>

As expected this does show the text in the correct position on the product view page, can anyone please show me where i'm going wrong to check all the attribute values and show text if they match?

edit: since checking another similar post i have also tried the following...

<?php if ($_product->getData('damage_front') == "FRONT: No damage" && $_product->getData('damage_back') == "Back: No damage" && $_product->getData('damage_right') == "RIGHT SIDE: No damage" && $_product->getData('damage_left') == "LEFT SIDE: No damage" && $_product->getData('damage_top') == "TOP: No damage" && $_product->getData('damage_handles') == "HANDLES: No damage"): ?>

The suggested answers on the other post do not rectify this issue and therefore i think it's a different problem altogether.

EDIT: Ok I've managed to fix my own problem and here's how i did it...

    <?php
if ($_product->getData('damage_front') == "FRONT: No damage" && ($_product->getData('damage_back') == "BACK: No damage" && ($_product->getData('damage_right') == "RIGHT SIDE: No damage" && ($_product->getData('damage_left') == "LEFT SIDE: No damage" && ($_product->getData('damage_top') == "TOP: No damage" && ($_product->getData('damage_handles') == "HANDLES: No damage")))))):
 ?>
                              <h3>Box Damaged Only.</h3>
                          <p>
                              This item is in perfect condition and only has box damage.
                          </p>
                      </div>
                  </div>
<?php endif;?>
  • Ok using suggestions on that page i tried adding this code... <?php if ($_product->getData('damage_front') == "FRONT: No damage") : ?> { <?php echo "<div style ='color:#ffffff'><b>This Product is Box Damaged Only</b></div>"; ?> } <?php endif; ?> , this works fine but when adding multiple attributes to check it fails so im still struggling to check the 5 attributes and output the text if they all indicate no damage – TonyG Apr 5 '18 at 13:17
  • Can yo please add you modified code to the question? – sv3n Apr 5 '18 at 13:24
  • Why has this been marked as a duplicate question when the other question is all about checking stock status and not about custom attributes? – TonyG Apr 5 '18 at 14:12
  • Flagged as duplicate, because it doesn't make a difference which attribute is checked. Thought you find a solution there. Seems not ... so voted to reopen. – sv3n Apr 5 '18 at 14:25
  • Thanks SV3N hopefully we can get a solution to this issue – TonyG Apr 5 '18 at 14:34
0

=> There are some points which is help to solve your problem :

  • First of all, check in which file you are modifying this code in product view page?
  • Have you check in product's collection attribute is listing or not?
  • If product's collection attribute is listing or not then try with the $_product->addAttributeToSelect('attribue_code');
  • Do Reindex.

Hope you'll find solution using this answer.

| improve this answer | |
  • Hi and thanks for your responce, we are modifying app/design/frontend/rwd/ourtheme/template/catalog/product/view.phtml and we have checked to make sure the atttributes are listing and we can see them in the additional information tab. – TonyG Apr 5 '18 at 11:58
  • Also just added $_product->addAttributeToSelect('damage_front'); which stops the product page from loading – TonyG Apr 5 '18 at 12:13

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