/** * {@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(); }
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; }