Skip to content

Instantly share code, notes, and snippets.

@6ui11em
Created January 24, 2018 09:27
Show Gist options
  • Save 6ui11em/fed5b543d7a168d28a40760ae2be1190 to your computer and use it in GitHub Desktop.
Save 6ui11em/fed5b543d7a168d28a40760ae2be1190 to your computer and use it in GitHub Desktop.
Magento 2 save product attribute in specific store #magento2 #php
// get current store and product store to restore values after save
$currentStore = $this->storeManager->getStore();
$productStore = $product->getStoreId();
// save to desired storeId
$this->storeManager->setCurrentStore($storeId);
$product->setStoreId($storeId);
// you can use also $product->setName ...
$product->setData($attributeCode, $value);
$this->productResource->saveAttribute($product, $attributeCode);
// restore product and current store values
$product->setStoreId($productStore);
$this->storeManager->setCurrentStore($currentStore);
@vpiyappan
Copy link

Save Magento 2 products based on the current store.
It worked exactly how I want. It really helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment