0

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')
1
$_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/>';
}
  • Thanks, but I must get the website code from a certain SKU, if it's possible? – Magento Learner Feb 2 '18 at 11:03
  • Okay. Please check. I updated answer. – Kishan Patadia Feb 2 '18 at 11:08
  • Great, I'll test and get back. – Magento Learner Feb 2 '18 at 11:30
  • Sorry I missed something when I did test of your code. Your code get me the Store Code not the website Code. I need website code. – Magento Learner Feb 5 '18 at 12:58
  • I have edited your answer so it gets Website Code instead. – Magento Learner Feb 5 '18 at 13:15
1

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

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.