0

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 :-)
| improve this question | | | | |
  • First of all, you should use 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 the catalog_product_entity_* tables to compare values before and after your admin save. Usual suspect here is visibility. 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()). – Mark van der Sanden Nov 8 '13 at 10:16
  • @MarkvanderSanden thanks for your hints. It's not that the product doesn't show, just the attribute values with website scope. I already used $product->setWebsiteIds(). I now made some tests, looked at the catalog_product_entity_* tables and tried to clarify it all. – johjoh Nov 8 '13 at 16:23
  • I'm sure it has something to do with where in the chain you call 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. – Mark van der Sanden Nov 11 '13 at 8:59
  • Yes you were right: did have to do with the order of calls – but in another spot. See my answer below. Thanks for the hint. Bit confusing this topic. – johjoh Nov 11 '13 at 18:07
1

The problem was caused from another part of the script which loaded the product again to set the store view specific values. And the problem was to set the store id before loading the product.

My old code:

$product_de = Mage::getModel('catalog/product');
$product_de
    ->setStoreId('1')
    ->load($id)
    ... // set some store view specific data
    ->save();

The fixed code:

$product_de = Mage::getModel('catalog/product');
$product_de
    ->load($id)
    ->setStoreId('1')
    ... // set some store view specific data
    ->save();

Now only one entry get's inserted in the catalog_product_entity_* table – with store_id = 0.

Strange because I've seen it in the other order e.g. here: http://www.webguys.de/magento/produkte-mehrsprachig-importieren/ (german website)

Don't know if this is a bug, or there is a reasonable explanation for this behaviour.

| improve this answer | | | | |

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.