4

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
  • You have create store for that two website ? – Keyul Shah Jan 19 '14 at 9:32
  • Sure, I have created a store and a storeview for each website – perissf Jan 19 '14 at 9:38
  • Then Below code defiantly work. – Keyul Shah Jan 19 '14 at 9:39
7

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.

  • You welcome :) :) – Keyul Shah Jan 19 '14 at 9:50
  • @KeyulShah do you know how to set a store id? separate question, but i think it would be useful here anyway. – ahnbizcad Nov 6 '15 at 19:19

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.