All product attributes with website scope are not showing any values in frontend after import. In the backend they do. I have one website, one store group and two store views (languages). In the backend the correct values are shown in both store views with a "[WEBSITE]" behind the textbox. The default values are empty.
To open the product in the backend on global scope and save it again fixes the problem.
The problem occured after some updates and reimporting all products. I'm importing by doing something like this:
$product = Mage::getModel('catalog/product');
$product
->setWebsiteIds(array('1'))
->setStoreId('1')
->setStatus(1)
->setSku('123')
...
->setAttribute('...')
->save();
Reindexing doesn't help.
Why are the attribute values not shown before saving via the admin?
UPDATE
I took a look to the DB. Before saving via Admin, I have two (identical) values, one for each store view. After there is a third with store_id = 0 and value = NULL.
I also tried without ->setStoreId('1')
... then the insert of a new product works, but the update doesn't work any longer. I looked to the DB again and only the value for store_id = 0 got updated.
Reformulated Question: Is it correct, that I have to handel insert and update differently, or am I missing something ... and if yes – why?
(I'm still very much confused with the scopes and in this case trying to brake it down to an explicit szenario.)
Summary
1st TRY: only ->setWebsiteIds(array('1'))
, here insert works, update doesn't.
Values after insert via script:
store_id values
0 initial_value
1 initial_value
2 initial_value
... right value on the frontend :-)
Values after update via script:
store_id values
0 updated_value
1 initial_value
2 initial_value
... old value on the frontend :-(
2nd TRY: ->setWebsiteIds(array('1'))
and ->setStoreId('1')
, here other way round: update works, insert doesn't (without open and save in the backend)
Values after insert via script:
store_id values
1 initial_value
2 initial_value
... no value on the frontend :-(
Values after open/save via backend:
store_id values
0 NULL
1 initial_value
2 initial_value
... right value on the frontend :-)
Values after update via script:
store_id values
0 NULL
1 updated_value
2 updated_value
... right value on the frontend :-)
Mage::getModel('catalog/product')
to instantiate a new product model. But that doesn't solve your problem. I think you missed some attributes in your import. Please have a look at thecatalog_product_entity_*
tables to compare values before and after your admin save. Usual suspect here isvisibility
. If you didn't find the solution there, you could check if a stock item exists and if the product has been assigned to the website (using$product->setWebsiteIds()
).$product->setWebsiteIds()
. I now made some tests, looked at thecatalog_product_entity_*
tables and tried to clarify it all.setStoreId()
. I once noticed in a project that if there's no default value (store id 0) in the database for an attribute, that the store specific value will not show up.