/**
  * {@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();
 }
Пример #2
0
 /**
  * {@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();
 }
Пример #3
0
 public function testNewEntityFailsValidation()
 {
     $entity = new Category();
     $entity->translate('en')->setName('Test');
     $entity->mergeNewTranslations();
     $errors = $this->validator->validate($entity);
     $this->assertFalse(0 === count($errors));
 }
Пример #4
0
 /**
  * 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();
 }
Пример #5
0
 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()]);
 }