I have a multi store with following structure. The ID is obtain by hovering mouse over the link in the store management.
WebsiteA (http://www.websitea.com/), ID 2
StoreA, ID 2
StoreB, ID 4
StoreC, ID 6
WebsiteB (http://www.websiteb.com/), ID 3
StoreD, ID 3
StoreE, ID 5
StoreF, ID 7
WebsiteA is using USD as base currency while WebsiteB is using AUD. I have another database which host the price list based on the SKU. Catalog Price Scope is configured to “Website”.
I have the following code created as cron to update the price however it doesn’t appear to work properly. Instead it updated all websites with aud price.
foreach($data as $p) {
$price_usd = $p[‘usdprice’];
$price_aud = $p[‘audprice’];
$product = Mage::getModel('catalog/product')->loadByAttribute('sku',$p['sku']);
$websites = Mage::app()->getWebsites();
if ($product) {
$product->setPrice($price_usd)->save();
foreach ( $websites as $website ) {
$basecurrency = Mage::app()->getWebsite($website)->getBaseCurrencyCode();
$websiteid = Mage::app()->getWebsite($website)->getId();
if ( $basecurrency == "USD" ) {
$product->setWebsiteId($websiteid)->setPrice($price_usd)->save();
}
elseif ( $basecurrency == “AUD" ) {
$product->setWebsiteId($websiteid)->setPrice($price_aud)->save();
}
}
}
}