2

I'm trying to display a different static block for certain types of products. I am able to get this to work with my code bellow, however when switching store views the static block disappears even though it is set for all.

<?php if (isset($p['secCol_2'])) echo $p['secCol_2']; ?>

<?php if ($_product->getAttributeText('colocation') == "No"): ?>                    
    <?php echo $this->getChildHtml('container_product_secondary_2'); ?>
<?php endif; ?>
<?php if ($_product->getAttributeText('colocation') == "Yes"): ?>
    <?php echo $this->getChildHtml('container_product_secondary_colocation'); ?>
<?php endif; ?>

For reference, the original code that works on all store views with 1 static block:

<?php if (isset($p['secCol_2'])) echo $p['secCol_2']; ?>
<?php echo $this->getChildHtml('container_product_secondary_2'); ?>

What can I do to the above code so that it works on all store views?

EDIT: With the assistance from the comments I have now figured out that the issue is that the store view is translated. Yes/No is becoming Oui/Non and that is why the blocks are not being displayed.

How do I over come this?

3
  • have assigned "colocation" attribute to all the stores and its products? Commented Jan 18, 2018 at 19:38
  • yes - it is and both containers only work on a single store view.
    – SR_Magento
    Commented Jan 18, 2018 at 22:25
  • 1
    Is your attribute return boolean? Or “Yes/No” ??? Commented Jan 18, 2018 at 22:31

2 Answers 2

2

With the assistance from the comments I have now figured out that the issue is that the store view is translated. Yes/No is becoming Oui/Non and that is why the blocks are not being displayed.

How do I over come this?

To make it work with different languages, try this:

Change

if ($_product->getAttributeText('colocation') == "No")

To

if ($_product->getAttributeText('colocation') == $this->__("No"))
1
  • Worked like a charm - thanks for solving this mystery for me!
    – SR_Magento
    Commented Jan 19, 2018 at 15:02
4

(put this in an answer because in a comment I've not enough space)

I would do this test to check if the problem is in the blocks by removing the if ($_product->getAttributeText('colocation') == and check if both blocks are shown in the page, if not this means that the problem is in the blocks definitions.

first of all I'll check if the blocks are allowed in system configuration

and then I'll check also the layout (xml) of the to store view in order to verify if they have different templates and they both have the blocks definitions.

if the blocks are properly shown the problem may be in the attributes:

$_product->getAttributeText('colocation')

return the translated frontend label and may change on different store view, you can use this instruction:

$_product->getData('colocation')

That will return the "numeric" value of the option that does not change.

4
  • The original code works, so yes if I remove the additional if statement for the colocation attribute it appears on both views.
    – SR_Magento
    Commented Jan 19, 2018 at 11:34
  • 1
    this means that the blocks are well defined, and therefore the problem is in the attributes coded "colocation". did you tried to echos the attribute values ? Yes/No will be translated in the store view language (if you use different language)
    – Giuseppe
    Commented Jan 19, 2018 at 11:41
  • Okay you're on to something, the language is translated so the Yes/No becomes Oui/Non --- when I put the code to Oui/Non the opposite store view works.
    – SR_Magento
    Commented Jan 19, 2018 at 13:25
  • I've integrated the answer including the attribute section.
    – Giuseppe
    Commented Jan 19, 2018 at 16:47

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.