2

So I'm quite new to magento. I know that with <?php $_product = $this->getProduct(); ?> you get the currently loaded product and with $product_id = $this->getProduct()->getId(); you get the ID. However, I need to load only a specific product by its ID. So for example load the product with the ID 20. Would it be something like this:

$_product = Mage::getModel('catalog/product')->load($productID, '20');

Any help is appreciated!

2 Answers 2

10

Magento Load Product by ID:

 $productId = 20;
 $product = Mage::getModel('catalog/product')->load($productId);

Load Product Storewise by ID

 $productId = 20;
 $product = Mage::getModel('catalog/product')->setStoreId(1)->load($productId);  

You can display product Name and Sku using these:

 echo $product->getSku();
 echo $product->getName(); 
2
$_product = Mage::getModel('catalog/product')->load(20);  

or if you need the values for a specific store view

$_product = Mage::getModel('catalog/product')->setStoreId(1)->load(20);  
1
  • How to apply a filter using the above code for show a different message to a product page based on product id. code : app/design/frontend/default/theme/template/catalog/product/view.phtml paste.ofcode.org/axc2fhGxRnTiQyVSKwdK2k @Marius
    – Gem
    Jun 3, 2019 at 6:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.