Created
May 27, 2018 21:33
-
-
Save kmddevdani/4d223a76b28da0a2fd2e492e8ef85f5a to your computer and use it in GitHub Desktop.
magento2 update product attributes, store-specific
This file contains hidden or 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
<?php | |
/** | |
* Sets different values for an attribute, depending on the store. | |
* | |
* This example sets the hs code attribute of product 123 to 111111 for the UK and 222222 for AU. | |
*/ | |
$storeIdUK = 1; | |
$storeIdAU = 2; | |
$product_id = 123; | |
$hs_code_uk = '111111'; | |
$hs_code_au = '222222'; | |
$attrDataUK = [ | |
'hs_code' => $hs_code_uk | |
]; | |
$attrDataAU = [ | |
'hs_code' => $hs_code_au | |
]; | |
$productAction = $this->_objectManager->get(\Magento\Catalog\Model\ResourceModel\Product\Action::class); | |
/** OR: | |
$productAction = $productAction = $this->container->get( | |
\Magento\Catalog\Model\ResourceModel\Product\Action::class | |
); | |
*/ | |
$productAction->updateAttributes([$product_id], $attrDataUK, $storeIdUK); | |
$productAction->updateAttributes([$product_id], $attrDataAU, $storeIdAU); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment