Example #1
0
 /**
  * Create a new Category.
  *
  * @example
  *     $category = Subbly\Model\Category;
  *     Subbly::api('subbly.category')->create($category);
  *
  *     Subbly::api('subbly.category')->create(array(
  *         'label'  => 'Men Shoes',
  *         'parent' => 1,
  *     ), 'en');
  *
  * @param array $category
  * @param \Subbly\Model\Category|null     $
  *
  * @return \Subbly\Model\ProductCategory
  *
  * @throws \Subbly\Api\Service\Exception
  *
  * @api
  */
 public function create($category, $locale = null)
 {
     if (!$category instanceof Category) {
         $category = new Category($category);
     }
     // set locale
     if (!is_null($locale)) {
         $category->setFrontLocale($locale);
     }
     if ($category instanceof Category) {
         if ($this->fireEvent('creating', array($category)) === false) {
             return false;
         }
         $category->setCaller($this);
         $category->saveWithTranslation();
         $this->fireEvent('created', array($category));
         $category = $this->find($category->id);
         return $category;
     }
     throw new Exception(sprintf(Exception::CANT_CREATE_MODEL, $this->modelClass, $this->name()));
 }