Magento 1.8 API – Set Product Price with Multiple Websites

apimagento-1.8PHPpriceproduct

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!

Best Answer

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();