3

I have a Magento website which uses the value of an dropdown (Yes/No) attribute in a if statement condition. The problem I'm having is based on one store view I'm getting '1' and the other is '0' (where '1' is the correct value in this instance).

For example I have this code:

if($_product->getData("lookinsideactive") == 1):
      if(Mage::app()->getStore()->getId() == 1):
                    echo "Store message 1";
                elseif(Mage::app()->getStore()->getId() == 12):
                    echo "Store message 2";
      endif;
endif;

When I go to store ID 1 the message doesn't appear, but in the store id 12 the message 'Store message 2' appears so the first if statement condition is true.

If I print these:

echo $_product->getData("lookinsideactive");

I get '0' in store ID 1 and '1' in store ID 12.

I've tried:

echo $_product->getAttributeText('lookinsideactive');

Where store ID 1 shows 'No' and store ID 12 shows 'Yes'.

Another thing is these conditions work perfectly fine on other products on both store views its just this one product that this result is showing.

So overall the result should be either '1' on both store views for that product or '0' on both store views.

I have checked the attribute set with this problem product and another working product and they both are using the same attribute set, with the same attribute value 'lookinsideactive'.

I am unsure if I've missed something simple but need some advice on a possible cause or some advice to debug this.

Any help is much appreciated, thank you.

3

You can have different scopes for different attributes. Your attribute has obviosuly the scope "store view". Alterantives are: "store", "website" and "global".

You can change the scope with a script, but after that change, I think you have to clean up the database because magento ignores the scope while fetching the data. It only is important when writing them.

You can check this in the backend, when you view a product you can change the scope in the upper left side and beside the selectbox is the information [store view] what the scope of the attribute is.

  • Thank you so much! You saved me a big headache when I had tunnel vision. I feel a bit silly I didn't check this. I changed the scope and it works as expected. Sorry I don't have enough reputation to up vote, but can only accept the answer. – thairish Sep 4 '13 at 21:49

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.