Example #1
0
 /**
  * @param array $params
  * @return \Shopware\Models\Category\Category
  * @throws \Shopware\Components\Api\Exception\ValidationException
  * @throws \Exception
  */
 public function create(array $params)
 {
     $this->checkPrivilege('create');
     $params = $this->prepareCategoryData($params);
     $category = new \Shopware\Models\Category\Category();
     $category->fromArray($params);
     if (isset($params['id'])) {
         $metaData = $this->getManager()->getMetadataFactory()->getMetadataFor('Shopware\\Models\\Category\\Category');
         $metaData->setIdGeneratorType(\Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_NONE);
         $category->setPrimaryIdentifier($params['id']);
     }
     $violations = $this->getManager()->validate($category);
     if ($violations->count() > 0) {
         throw new ApiException\ValidationException($violations);
     }
     $this->getManager()->persist($category);
     $this->flush();
     return $category;
 }
 /**
  * {@inheritDoc}
  */
 public function setPrimaryIdentifier($id)
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'setPrimaryIdentifier', array($id));
     return parent::setPrimaryIdentifier($id);
 }