2

I have setup my Magento with 2 websites, with ID 1 and 4, and one store for each website.

Default website is 1.

My product has a Default price.

How can I set programmatically a price for website 4 without touching website 1?

See what I have tried so far:

$product = Mage::getModel('catalog/product')->loadByAttribute('sku', $sku);
$product->setWebsiteId(4)->setPrice($newPrice)->save();   

Unfortunately the code above leaves unchanged the price for website 4, and overrides Default price for website 1 with $newPrice!

2

I had to set the StoreId, not the websiteId. Just needed to choose a store belonging to the desired website:

$product = Mage::getModel('catalog/product') -> loadByAttribute('sku', $sku);
$product->setStoreId(1) -> setPrice($price1) ->save() ;
$product->setStoreId(9) -> setPrice($price9) ->save();
| improve this answer | |
1

For This you need below code

<?php
 $product = Mage::getModel('catalog/product')
        ->setStoreId($storeId)
        ->load($Id); 

 $product->setPrice('Yor price');
 $product->save();
 unset($product);
 ?>
| improve this answer | |
  • hmm I think you did not get the idea so Just prepare answer for you Thanks :) – Keyul Shah Jan 19 '14 at 9:54
  • It looks like this solution has changed the Visibility status to all products!! – perissf Jan 20 '14 at 12:40
  • not sure for that but if it will change then set them again – Keyul Shah Jan 20 '14 at 12:46
1

I have been doing exactly this on the latest version (1.9.3.1) and the only way i could get it working was to set and unset the store id's as below, this was so i could post a different price in store 2 vs all the other stores (10 on this system)

Mage::app()->setCurrentStore(2);
$product = Mage::getModel('catalog/product')->loadByAttribute('sku', $this->p_sku);
if ($product) {
    $product->setData('price', 19.99);
    $product->save();
}
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.