Skip to content

Instantly share code, notes, and snippets.

@ryaan-anthony
Last active August 29, 2015 14:06
Show Gist options
  • Select an option

  • Save ryaan-anthony/04d4d644594e89430b4c to your computer and use it in GitHub Desktop.

Select an option

Save ryaan-anthony/04d4d644594e89430b4c to your computer and use it in GitHub Desktop.
Magento - create entity if doesnt exist
/**
* Load object data and create if doesnt exist
*
* @param integer $id
* @return Mage_Core_Model_Abstract
*/
public function createIfDoesntExist($id, $field=null)
{
$this->load($id, $field);
if(!$this->getId()){
$this->setData($field, $id);
$this->save();
}
return $this;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment