Magento 1.8 – How to Get Product Prices for Multiple Websites

apimagento-1.8PHPpriceproduct

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

My product has 3 prices: a Default price, and a price for each website.

How can I get these 3 prices programmatically?

See what I have tried so far:

$product = Mage::getModel('catalog/product')->loadByAttribute('sku', $sku);
echo $product->getPrice() . "</br>" ;      // prints price of default website != default price
echo $product->setWebsiteId(1).getPrice() . "</br>" ; // throws exception

Best Answer

If you know the storeId, set in setStoreId :

/**
 * call the Magento catalog/product model
 * set the current store ID
 * load the product
 */
$product = Mage::getModel('catalog/product')
            ->setStoreId($storeId)
            ->load($key); 

Display in a block :

echo $product->getName();
echo $product->getPrice();

We can also use print_r to see the values :

print_r($product->getData()); 

The following code will show current store ID :

$storeId    = Mage::app()->getStore()->getId();

If you change the $storeId will show different product.