Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento: Get record of my model by custom Field

Is it possible to get a record of my model by another field of my model?

The normal way

$model = Mage::getModel('foo_bar/baz');
$model->load($id);
// do something with the loaded record

But i need something like this

$model = Mage::getModel('foo_bar/baz');
$model->loadByAnotherFieldOfModel($value)
// do something with the loaded record

is that possible?

like image 881
rayphi Avatar asked Jul 17 '14 06:07

rayphi


2 Answers

$model = Mage::getModel('foo_bar/baz');
$model->load('field_value', 'field_name');
like image 190
OSdave Avatar answered Oct 14 '22 11:10

OSdave


use this

$_category = Mage::getModel('catalog/category')->loadByAttribute('name', 'computer');  
$_product = Mage::getModel('catalog/product')->loadByAttribute('name', 'hp2312');  

// Load by SKU  
$_product = Mage::getModel('catalog/product')->loadByAttribute('sku', 'computer123');  
like image 36
Karan Adhikari Avatar answered Oct 14 '22 12:10

Karan Adhikari