Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kmddevdani/4d223a76b28da0a2fd2e492e8ef85f5a to your computer and use it in GitHub Desktop.
Save kmddevdani/4d223a76b28da0a2fd2e492e8ef85f5a to your computer and use it in GitHub Desktop.
magento2 update product attributes, store-specific
<?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