开发者

Magento backend, can't get store view attribute value

开发者 https://www.devze.com 2023-04-01 20:43 出处:网络
Everything below happens in the backend of magento, not frontend. I have added programmatically attributes to all products.

Everything below happens in the backend of magento, not frontend.

I have added programmatically attributes to all products. These attributes are scoped on store_view. I have programmatically updated these attributes for each store view. Everything has worked fine until now.

Now, I'm trying to get statistics on these attributes. Basically, get a product collection, set store id filter, get my attribute.

Problem >> he always return the default value (admin store view) and never the store_view value.

        $products = Mage::getModel('catalog/product')
                        ->getCollection()
                        ->addAttributeToSelect('name')
                        ->addAttributeToSelect('myattribute')
                        ->addStoreFilter(5);

        foreach($products as $product){
            echo $product->getData('name').' -> '.$product->getData('myattribute').'<br />';
        }

This echoes the store view name of the product but not the myattribute store view value. The only difference between these two attributes is that the "Use default value" is not checked for the name attribute in the backend, which then return the store view value of it.

I checked in database, the value is there for the store view for myattribute.

Any idea to get this store view value in backend 开发者_运维百科? Or any idea to programmatically disable this checkbox "Use default value" when i update/create myattribute ?


I finally found the solution.

For use default value to be unchecked there has to be a value for store_id 0 (admin).

I simply saved a value for the store_id i want and store_id 0 and then everything worked properly. Hoping this will be useful to someone else.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号