2

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

Are AUD prices the default ones? To me it looks like you're loading the default data with this:

$product = Mage::getModel('catalog/product')->loadByAttribute('sku',$p['sku']);

It should be something like this:

$product = Mage::getModel('catalog/product')->setWebsiteId($websiteid)->loadByAttribute('sku',$p['sku']);

I think this loop should work:

if ( $basecurrency == "USD" ) { 

$product = Mage::getModel('catalog/product')->setWebsiteId($websiteid)->loadByAttribute('sku',$p['sku']);
$product->setPrice($price_usd)->save();
                }
                elseif  ( $basecurrency == “AUD" ) { 
$product = Mage::getModel('catalog/product')->setWebsiteId($websiteid)->loadByAttribute('sku',$p['sku']);
                    $product->setPrice($price_aud)->save();
                }

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.