Magento - custom (non eav) model, load by multiple fields?

, , No Comments
Step 1:

$attributes = array('name'=> $name'store_id'=> store_id);

$model = mage::getmodel('module/modelname')->loadbyattributes($attributes);

Step 2:

public function loadbyattributes($attributes)

{

$this->setdata($this->getresource()->loadbyattributes($this,$attributes));

return $this;

}

Step 3:

public function loadbyattributes(Custom_Ccms_Model_Ccms $ccmsObj, $attributes)

{

$adapter = $this->_getreadadapter();

$where = array();

foreach ($attributes as $attributecode=> $value) {

$where[] = sprintf('%s=%s', $attributecode, '"'.$value.'"');

}

$select = $adapter->select()->from($this->getmaintable())->where(implode(' and ', $where));

$binds = $attributes;

$id=$adapter->fetchOne($select,$binds);

if($id){

$this->load($ccmsObj, $id);

}

return $this;

}

0 comments:

Post a Comment