コード例 #1
0
 /**
  * See if Customer Address already exists by searching for passed information.
  * If not, we create it.
  * @param null $config
  * @return CustomerAddress|null
  */
 public static function findOrCreate($config = null)
 {
     if (is_null($config)) {
         return null;
     }
     //Search. If successful, return object, otherwise save (to create new object) and return that
     $obj = new CustomerAddress();
     $obj->attributes = $config;
     if ($obj->validate() === false) {
         return $obj;
     }
     $dataProvider = $obj->search();
     $arrAdd = $dataProvider->getData();
     if (count($arrAdd)) {
         return $arrAdd[0];
     } else {
         $obj->save();
         return $obj;
     }
 }