Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top