Magento World

As a Magento parner, we are very honoured to offer you the best Magento Extensions, Magento Modules, Magento Themes and Magento Templates. You will get full support until you feel satisfied! View our Magento page to find what you need!

Thứ Sáu, 23 tháng 3, 2012

Single Magento Products with loadByAttribute

In the last few weeks I’ve not had much time to spend on Magento, I’ve been balls-deep in custom WordPress, Paypal and Google Maps API. One thing I do like actually is the simplicity of the WordPress database for custom MySQL queries. After using the Magento database for the last few years it’s like going from flying a commercial aircraft to driving a golf cart.

Anyway, loading a single product on a webpage is a very basic thing to do for anyone who develops websites with Magento, but using the loadByAttribute function is by far the cleanest method of doing it.

// load by SKU$_product = Mage::getModel('catalog/product')->loadByAttribute('sku', 'ABCDEF');// load by product name$_product = Mage::getModel('catalog/product')->loadByAttribute('name', 'My Single Product');// load by product ID$_product = Mage::getModel('catalog/product')->load(938);

It’s a much less-intensive method than filtering the product collection, and now it’s here if anyone needs it.

Thanks for reading the Magento Blog at E-commerce Website Design.

Adam Moss Author Page


View the original article here

Không có nhận xét nào:

Đăng nhận xét