简体   繁体   中英

Get product id from custom unique attribute magento

In my magento site,i have created an attribute named barcode and is set unique just as sku. Is there any code to get product id from the barcode value.ie, if the barcode i assigned for a product is 12121, then i need to get the product id based on that value. Is it possible?

There is a function called loadByAttribute of model Mage_Catalog_Model_Abstract (line 224) that you can use like that :

Mage::getModel('catalog/product')->loadByAttribute('barcode', '12121');

Mage_Catalog_Model_Abstract is extended by Mage_Catalog_Model_Product

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM