Question

I have a Magento 1.9 site that I have created 4 websites (UK, USA, etc..) in admin.

I have products added to only a certain website.

How can I get website code by product SKU programmatically? So I can see which website that a product is associated to?

Is it possible with product model?

$products = Mage::getModel('catalog/product')
Was it helpful?

Solution

$_product = Mage::getModel('catalog/product')->load(10); //10 is product id
$websiteIds = $_product->getWebsiteIds();
foreach($websiteIds as $websiteId){
    echo Mage::getModel('core/website')->load($websiteId)->getData("code").'<br/>';
}

OTHER TIPS

If you have only sku,You can try this code.

$_product = Mage::getModel('catalog/product')->loadByAttribute('sku', $your_sku);

instead of

$_product = Mage::getModel('catalog/product')->load(10); //10 is product id

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top