Magento 2 Programatically update price attribututes per store but code is updating for all stores
I want to update price for particular store(us) by programmatically.I used below script and its working but problem is it updates for all stores not for particular
function updateconfigProductPrice($productsku_update,$price_to_update,$storeCode)
{
$proObj = getObjectInstance()->get('MagentoCatalogModelProduct');
if ($proObj->getIdBySku($productsku_update))
{
$productId = $proObj->getIdBySku($productsku_update);
}
else
{
return FALSE;
}
if($storeCode=='us')
{
$storeId = '9';
}
//echo 'store_code'.$storeId;
if ($productId!= '') {
$configProduct = getObjectInstance()->create('MagentoCatalogModelProduct')->load($productId);
//var_dump($configProduct->getWebsiteIds());
//die;
$_children = $configProduct->getTypeInstance(true)->getUsedProducts($configProduct);
//echo count($_children);die;
foreach ($_children as $child) {
//echo $child->getSku();die;
if($child->getID()!=''){
$childId = $child->getID();
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$productFactory = $objectManager->create('MagentoCatalogModelProduct');
$productResourceModel = $objectManager->create('MagentoCatalogModelResourceModelProduct');
$productResourceModel->load($productFactory, $childId);
$productFactory->setStoreId($storeId);
$special_price = $price_to_update;
$productFactory->setPrice($special_price);
$productResourceModel->saveAttribute($productFactory, 'price');
echo $child->getSku()."child product updated for store==".$storeId."=with s Price".$special_price.".<br/>";
}
}
}
}
Its update price for all stores but I want to update only for my US(store). Please share your thoughts and let me know what is wrong with code.
magento2 configurable-product price
add a comment |
I want to update price for particular store(us) by programmatically.I used below script and its working but problem is it updates for all stores not for particular
function updateconfigProductPrice($productsku_update,$price_to_update,$storeCode)
{
$proObj = getObjectInstance()->get('MagentoCatalogModelProduct');
if ($proObj->getIdBySku($productsku_update))
{
$productId = $proObj->getIdBySku($productsku_update);
}
else
{
return FALSE;
}
if($storeCode=='us')
{
$storeId = '9';
}
//echo 'store_code'.$storeId;
if ($productId!= '') {
$configProduct = getObjectInstance()->create('MagentoCatalogModelProduct')->load($productId);
//var_dump($configProduct->getWebsiteIds());
//die;
$_children = $configProduct->getTypeInstance(true)->getUsedProducts($configProduct);
//echo count($_children);die;
foreach ($_children as $child) {
//echo $child->getSku();die;
if($child->getID()!=''){
$childId = $child->getID();
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$productFactory = $objectManager->create('MagentoCatalogModelProduct');
$productResourceModel = $objectManager->create('MagentoCatalogModelResourceModelProduct');
$productResourceModel->load($productFactory, $childId);
$productFactory->setStoreId($storeId);
$special_price = $price_to_update;
$productFactory->setPrice($special_price);
$productResourceModel->saveAttribute($productFactory, 'price');
echo $child->getSku()."child product updated for store==".$storeId."=with s Price".$special_price.".<br/>";
}
}
}
}
Its update price for all stores but I want to update only for my US(store). Please share your thoughts and let me know what is wrong with code.
magento2 configurable-product price
add a comment |
I want to update price for particular store(us) by programmatically.I used below script and its working but problem is it updates for all stores not for particular
function updateconfigProductPrice($productsku_update,$price_to_update,$storeCode)
{
$proObj = getObjectInstance()->get('MagentoCatalogModelProduct');
if ($proObj->getIdBySku($productsku_update))
{
$productId = $proObj->getIdBySku($productsku_update);
}
else
{
return FALSE;
}
if($storeCode=='us')
{
$storeId = '9';
}
//echo 'store_code'.$storeId;
if ($productId!= '') {
$configProduct = getObjectInstance()->create('MagentoCatalogModelProduct')->load($productId);
//var_dump($configProduct->getWebsiteIds());
//die;
$_children = $configProduct->getTypeInstance(true)->getUsedProducts($configProduct);
//echo count($_children);die;
foreach ($_children as $child) {
//echo $child->getSku();die;
if($child->getID()!=''){
$childId = $child->getID();
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$productFactory = $objectManager->create('MagentoCatalogModelProduct');
$productResourceModel = $objectManager->create('MagentoCatalogModelResourceModelProduct');
$productResourceModel->load($productFactory, $childId);
$productFactory->setStoreId($storeId);
$special_price = $price_to_update;
$productFactory->setPrice($special_price);
$productResourceModel->saveAttribute($productFactory, 'price');
echo $child->getSku()."child product updated for store==".$storeId."=with s Price".$special_price.".<br/>";
}
}
}
}
Its update price for all stores but I want to update only for my US(store). Please share your thoughts and let me know what is wrong with code.
magento2 configurable-product price
I want to update price for particular store(us) by programmatically.I used below script and its working but problem is it updates for all stores not for particular
function updateconfigProductPrice($productsku_update,$price_to_update,$storeCode)
{
$proObj = getObjectInstance()->get('MagentoCatalogModelProduct');
if ($proObj->getIdBySku($productsku_update))
{
$productId = $proObj->getIdBySku($productsku_update);
}
else
{
return FALSE;
}
if($storeCode=='us')
{
$storeId = '9';
}
//echo 'store_code'.$storeId;
if ($productId!= '') {
$configProduct = getObjectInstance()->create('MagentoCatalogModelProduct')->load($productId);
//var_dump($configProduct->getWebsiteIds());
//die;
$_children = $configProduct->getTypeInstance(true)->getUsedProducts($configProduct);
//echo count($_children);die;
foreach ($_children as $child) {
//echo $child->getSku();die;
if($child->getID()!=''){
$childId = $child->getID();
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$productFactory = $objectManager->create('MagentoCatalogModelProduct');
$productResourceModel = $objectManager->create('MagentoCatalogModelResourceModelProduct');
$productResourceModel->load($productFactory, $childId);
$productFactory->setStoreId($storeId);
$special_price = $price_to_update;
$productFactory->setPrice($special_price);
$productResourceModel->saveAttribute($productFactory, 'price');
echo $child->getSku()."child product updated for store==".$storeId."=with s Price".$special_price.".<br/>";
}
}
}
}
Its update price for all stores but I want to update only for my US(store). Please share your thoughts and let me know what is wrong with code.
magento2 configurable-product price
magento2 configurable-product price
edited 4 mins ago
HIren Kadivar
370110
370110
asked 9 mins ago
akgolaakgola
1,357518
1,357518
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
if price update then just only one change below way then you can try it
Go to System->Configuration->Catalog->Catalog Price Scope
Then in the tab Price, set price scope to Website instead of global.
Will it work without effecting to other stores?
– akgola
3 mins ago
yes working not effecting another store
– Rakesh Donga
2 mins ago
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "479"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f260472%2fmagento-2-programatically-update-price-attribututes-per-store-but-code-is-updati%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
if price update then just only one change below way then you can try it
Go to System->Configuration->Catalog->Catalog Price Scope
Then in the tab Price, set price scope to Website instead of global.
Will it work without effecting to other stores?
– akgola
3 mins ago
yes working not effecting another store
– Rakesh Donga
2 mins ago
add a comment |
if price update then just only one change below way then you can try it
Go to System->Configuration->Catalog->Catalog Price Scope
Then in the tab Price, set price scope to Website instead of global.
Will it work without effecting to other stores?
– akgola
3 mins ago
yes working not effecting another store
– Rakesh Donga
2 mins ago
add a comment |
if price update then just only one change below way then you can try it
Go to System->Configuration->Catalog->Catalog Price Scope
Then in the tab Price, set price scope to Website instead of global.
if price update then just only one change below way then you can try it
Go to System->Configuration->Catalog->Catalog Price Scope
Then in the tab Price, set price scope to Website instead of global.
answered 4 mins ago
Rakesh DongaRakesh Donga
1,041212
1,041212
Will it work without effecting to other stores?
– akgola
3 mins ago
yes working not effecting another store
– Rakesh Donga
2 mins ago
add a comment |
Will it work without effecting to other stores?
– akgola
3 mins ago
yes working not effecting another store
– Rakesh Donga
2 mins ago
Will it work without effecting to other stores?
– akgola
3 mins ago
Will it work without effecting to other stores?
– akgola
3 mins ago
yes working not effecting another store
– Rakesh Donga
2 mins ago
yes working not effecting another store
– Rakesh Donga
2 mins ago
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f260472%2fmagento-2-programatically-update-price-attribututes-per-store-but-code-is-updati%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown