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
Không có nhận xét nào:
Đăng nhận xét