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?

  • have assigned "colocation" attribute to all the stores and its products? – Abhishek Panchal Jan 18 '18 at 19:38
  • yes - it is and both containers only work on a single store view. – SR_Magento Jan 18 '18 at 22:25
  • 1
    Is your attribute return boolean? Or “Yes/No” ??? – Abhishek Panchal Jan 18 '18 at 22:31
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"))
| improve this answer | |
  • Worked like a charm - thanks for solving this mystery for me! – SR_Magento Jan 19 '18 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.

| improve this answer | |
  • The original code works, so yes if I remove the additional if statement for the colocation attribute it appears on both views. – SR_Magento Jan 19 '18 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 Jan 19 '18 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 Jan 19 '18 at 13:25
  • I've integrated the answer including the attribute section. – Giuseppe Jan 19 '18 at 16:47

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.