Created
January 24, 2018 09:27
-
-
Save 6ui11em/fed5b543d7a168d28a40760ae2be1190 to your computer and use it in GitHub Desktop.
Magento 2 save product attribute in specific store #magento2 #php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Save Magento 2 products based on the current store.
It worked exactly how I want. It really helps.