Author: Adam Piotrowski (adam@wellcommerce.org)
Inheritance: implements WellCommerce\Bundle\CategoryBundle\Entity\CategoryInterface, use trait Knp\DoctrineBehaviors\Model\Translatable\Translatable, use trait Knp\DoctrineBehaviors\Model\Timestampable\Timestampable, use trait Knp\DoctrineBehaviors\Model\Blameable\Blameable, use trait WellCommerce\Bundle\AppBundle\Doctrine\ORM\Behaviours\EnableableTrait, use trait WellCommerce\Bundle\ShopBundle\Entity\ShopCollectionAwareTrait, use trait WellCommerce\Bundle\AppBundle\Entity\HierarchyAwareTrait
Example #1
0
 public function testNewEntityFailsValidation()
 {
     $entity = new Category();
     $entity->translate('en')->setName('Test');
     $entity->mergeNewTranslations();
     $errors = $this->validator->validate($entity);
     $this->assertFalse(0 === count($errors));
 }
 /**
  * Translates the category
  *
  * @param Locale   $locale
  * @param Category $category
  * @param string   $name
  */
 protected function translateCategory(Locale $locale, Category $category, $name)
 {
     /**
      * @var $translation \WellCommerce\Bundle\CategoryBundle\Entity\CategoryTranslation
      */
     $translation = $category->translate($locale->getCode());
     $slug = $this->getLocaleSlug($locale, $name);
     $translation->setName($name);
     $translation->setSlug($slug);
     $category->mergeNewTranslations();
 }
 public function addAction(Request $request)
 {
     $name = $request->request->get('name');
     $em = $this->getEntityManager();
     $category = new Category();
     $category->setHierarchy(0);
     $category->translate()->setName($name);
     $category->mergeNewTranslations();
     $em->persist($category);
     $em->flush();
     return new JsonResponse(['id' => $category->getId()]);
 }
 public function create() : CategoryInterface
 {
     $category = new Category();
     $category->setEnabled(true);
     $category->setHierarchy(0);
     $category->setParent(null);
     $category->setShops($this->createEmptyCollection());
     $category->setChildren($this->createEmptyCollection());
     $category->setProducts($this->createEmptyCollection());
     $category->setProductsCount(0);
     $category->setChildrenCount(0);
     return $category;
 }
Example #5
0
 /**
  * @return Category
  */
 public function create()
 {
     $category = new Category();
     $category->setChildren(new ArrayCollection());
     $category->setProducts(new ArrayCollection());
     $category->setEnabled(true);
     $category->setHierarchy(0);
     $category->setParent(null);
     $category->setShops(new ArrayCollection());
     return $category;
 }
 /**
  * {@inheritDoc}
  */
 public function load(ObjectManager $manager)
 {
     $shop = $this->getReference('shop');
     foreach (self::$samples as $hierarchy => $name) {
         $category = new Category();
         $category->setEnabled(true);
         $category->setHierarchy($hierarchy);
         $category->setParent(null);
         $category->addShop($shop);
         $category->translate('en')->setName($name);
         $category->translate('en')->setSlug(Sluggable::makeSlug($name));
         $category->mergeNewTranslations();
         $manager->persist($category);
         $this->setReference('category_' . $name, $category);
     }
     $manager->flush();
 }
 /**
  * {@inheritDoc}
  */
 public function load(ObjectManager $manager)
 {
     if (!$this->isEnabled()) {
         return;
     }
     $shop = $this->getReference('shop');
     foreach (self::$samples as $hierarchy => $name) {
         $category = new Category();
         $category->setEnabled(true);
         $category->setHierarchy($hierarchy);
         $category->setParent(null);
         $category->setProducts(new ArrayCollection());
         $category->setChildren(new ArrayCollection());
         $category->setChildrenCount(0);
         $category->setProductsCount(0);
         $category->addShop($shop);
         $category->translate($this->container->getParameter('locale'))->setName($name);
         $category->translate($this->container->getParameter('locale'))->setSlug(Sluggable::makeSlug($name));
         $category->translate($this->container->getParameter('locale'))->setShortDescription('');
         $category->translate($this->container->getParameter('locale'))->setDescription('');
         $category->mergeNewTranslations();
         $manager->persist($category);
         $this->setReference('category_' . $name, $category);
     }
     $manager->flush();
 }
Example #8
0
 /**
  * Adds new child to category
  *
  * @param Category $child
  */
 public function addChild(Category $child)
 {
     $this->children[] = $child;
     $child->setParent($this);
 }