Last active
August 29, 2015 14:06
-
-
Save ryaan-anthony/04d4d644594e89430b4c to your computer and use it in GitHub Desktop.
Magento - create entity if doesnt exist
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 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