How to load products by attribute (sku) or id in Magento

1

This is a quick tutorial for developer on how to load products by SKU, ID, attribute of products in Magento. The tutorial can be applied for loading single product or multiple products.

Load product by Product ID

Normally, we load product by ID. Let’s say that product ID is 88, you can use the following code in app/code/core/Mage/Catalog/Model/Product.php :

Load product by SKU

In case you want to load product/product by its attribute, for example SKU, you can use the following code in app/code/core/Mage/Catalog/Model/Product.php :

Alternatively, you can also use this code to load product by SKU

You can change attribute as you want by replacing SKU variable in the example.

Load multiple products

Load multiple product by Product ID

Similarly, you can load multiple product by Product attribute, like SKU

Conclusion

The examples above will help you load products by ID, SKU, you can customize the code for other attributes according to your requirement.

 

How to load products by attribute (sku) or id in Magento
5 (100%) 1 vote

Share.

About Author

Daniel is a Magento developer with 5 years of experience with customizing Magento extensions, Magento templates. He's main author at Magento explorer

1 Comment

Leave A Reply