0

I recently tried to update some product-information on the default storeView (id 0). Instead of applying the changes to the default store, it instead applied them to the product in the next higher increment of storeIds. I then tried to get all available storeIds for the product and the default store was not listed. Is it not possible to make changes to the default storeView programmatically?

2 Answers 2

0

yes, it is possible to add values directly to the default store view for any product. By default, all products belong to the default store view, there is no need to somehow assign them there.

this can be seen in action when you save a value in admin in the 'all store views' scope (which is the default store with id 0) as opposed to having a value on say 'default store view' (with id 1).

just play a little in your admin and you will see the difference.

the default store view is not counted as a storeview per se and that's why you don't see it returned in the query for the retrieval of the product storeviews.

1
  • Thank you for your answer, it was very insightful and sparks hope. While I was able to change the product-data of the default store-view through the admin-frontend manually, I have yet to achieve this programmatically. Whenever I try to edit product data using the ProductRepository (handing over no store-id or a storeId value of 0), the product data of another store is instead updated (the store with storeId 1).
    – Hurrpadurr
    Feb 4, 2021 at 10:08
0

The problem I was encountering was only present when using the ProductRepository-class to try and update the product in question.

I got it to work by using the following code:

$storeId = 0;
$productCollectionFactory = $objectManager->get(CollectionFactory::class);
$action = $objectManager->create(Action::class);
$updateAttributes['name'] = "test";

$action->updateAttributes([$product->getId()], $updateAttributes, $storeId);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.