/** * {@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(); }
/** * {@inheritDoc} */ public function load(ObjectManager $manager) { if (!$this->isEnabled()) { return; } foreach (self::$samples as $name) { $status = new ProductStatus(); $status->translate($this->getDefaultLocale())->setName($name); $status->translate($this->getDefaultLocale())->setSlug($slug = Sluggable::makeSlug($name)); $status->translate($this->getDefaultLocale())->setCssClass($slug); $status->mergeNewTranslations(); $manager->persist($status); $this->addReference('product_status_' . $name, $status); } $manager->flush(); }
/** * Creates a cms page * * @param string $name * @param int $hierarchy * @param PageInterface $parent * * @return PageInterface */ protected function createPage($name, $hierarchy, PageInterface $parent = null) { $page = new Page(); $page->setParent($parent); $page->setHierarchy($hierarchy); $page->setPublish(1); $page->setRedirectType(0); $page->setSection(''); $page->addShop($this->shop); $page->translate('en')->setName($name); $page->translate('en')->setSlug(Sluggable::makeSlug($name)); $page->translate('en')->setContent($this->defaultText); $page->mergeNewTranslations(); $this->manager->persist($page); return $page; }
/** * {@inheritDoc} */ public function load(ObjectManager $manager) { if (!$this->isEnabled()) { return; } $shop = $this->getReference('shop'); foreach (self::$samples as $name) { $producer = new Producer(); $producer->addShop($shop); $producer->translate($this->getDefaultLocale())->setName($name); $producer->translate($this->getDefaultLocale())->setSlug(Sluggable::makeSlug($name)); $producer->mergeNewTranslations(); $manager->persist($producer); $this->setReference('producer_' . $name, $producer); } $manager->flush(); }
public function generate(string $name, $id, string $locale, $values, int $iteration = 0) : string { $slug = Sluggable::makeSlug($name); $existsInValues = in_array($slug, (array) $values); // if slug is the same as other values, try to add locale part if ($existsInValues) { $slug = sprintf('%s-%s', $slug, $locale); } $route = $this->manager->getRepository()->findOneBy(['path' => $slug]); if (null !== $route) { // if passed identifier and locale are same as in route, assume we can change the slug directly if ($this->hasRouteSameLocaleAndId($route, $locale, $id)) { return $slug; } else { $iteration++; $slug = $this->makeSlugIterated($slug, $iteration); return $this->generate($slug, $id, $locale, $values, $iteration); } } return $slug; }
/** * Returns category slug * * @param Locale $locale * @param string $categoryName * * @return mixed|string */ protected function getLocaleSlug(Locale $locale, $categoryName) { $slug = Sluggable::makeSlug($categoryName); $currentLocale = $this->getRequestHelper()->getCurrentLocale(); if ($locale->getCode() != $currentLocale) { $slug = Sluggable::makeSlug(sprintf('%s-%s', $categoryName, $locale->getCode())); } return $slug; }
protected function createRandomProduct(ObjectManager $manager) { $faker = $this->getFakerGenerator(); $sentence = $faker->unique()->sentence(3); $name = substr($sentence, 0, strlen($sentence) - 1); $shortDescription = $faker->text(100); $description = $faker->text(1000); $sku = $this->getFakerGenerator()->creditCardNumber(); $shop = $this->getReference('shop'); $currency = $this->randomizeSamples('currency', LoadCurrencyData::$samples); $producer = $this->randomizeSamples('producer', LoadProducerData::$samples); $availability = $this->randomizeSamples('availability', LoadAvailabilityData::$samples); $categories = $this->randomizeSamples('category', $s = LoadCategoryData::$samples, rand(2, 4)); $statuses = $this->randomizeSamples('product_status', LoadProductStatusData::$samples, rand(2, 3)); $tax = $this->randomizeSamples('tax', LoadTaxData::$samples); $unit = $this->randomizeSamples('unit', LoadUnitData::$samples); $dimension = new Dimension(); $dimension->setDepth(rand(10, 100)); $dimension->setHeight(rand(10, 100)); $dimension->setWidth(rand(10, 100)); $buyPrice = new Price(); $buyPrice->setGrossAmount(rand(50, 80)); $buyPrice->setCurrency($currency->getCode()); $sellPrice = new DiscountablePrice(); $sellPrice->setGrossAmount($price = rand(100, 200)); $sellPrice->setCurrency($currency->getCode()); foreach ($statuses as $status) { if ($status->translate()->getName() === 'Promotions') { $sellPrice->setDiscountedGrossAmount($price * (rand(80, 95) / 100)); $sellPrice->setValidFrom(new \DateTime()); $sellPrice->setValidTo((new \DateTime())->modify('+30 days')); } } $product = new Product(); $product->setSKU($sku); $product->setHierarchy(rand(0, 10)); $product->setEnabled(true); $product->setAvailability($availability); $product->setBuyPrice($buyPrice); $product->setBuyPriceTax($tax); $product->setSellPrice($sellPrice); $product->setSellPriceTax($tax); $product->setCategories($categories); $product->addShop($shop); $product->setStatuses($statuses); $product->translate('en')->setName($name); $product->translate('en')->setSlug(Sluggable::makeSlug($name)); $product->translate('en')->setShortDescription($shortDescription); $product->translate('en')->setDescription($description); $product->mergeNewTranslations(); $product->setProductPhotos($this->getPhotos($product, $manager)); $product->setProducer($producer); $product->setStock(rand(0, 1000)); $product->setUnit($unit); $product->setDimension($dimension); $product->setTrackStock(true); $product->setPackageSize(1); $product->setWeight(rand(0, 5)); $manager->persist($product); }
protected function createRandomProduct(string $name, ObjectManager $manager) { $faker = $this->getFakerGenerator(); $shortDescription = $faker->text(100); $description = $faker->text(1000); $sku = $faker->creditCardNumber(); $shop = $this->getReference('shop'); $currency = $this->randomizeSamples('currency', LoadCurrencyData::$samples); $producer = $this->randomizeSamples('producer', LoadProducerData::$samples); $availability = $this->randomizeSamples('availability', LoadAvailabilityData::$samples); $categories = $this->randomizeSamples('category', $s = LoadCategoryData::$samples, rand(2, 4)); $tax = $this->randomizeSamples('tax', LoadTaxData::$samples); $unit = $this->randomizeSamples('unit', LoadUnitData::$samples); $dimension = new Dimension(); $dimension->setDepth(rand(10, 100)); $dimension->setHeight(rand(10, 100)); $dimension->setWidth(rand(10, 100)); $buyPrice = new Price(); $buyPrice->setGrossAmount(rand(50, 80)); $buyPrice->setCurrency($currency->getCode()); $sellPrice = new DiscountablePrice(); $sellPrice->setGrossAmount($price = rand(100, 200)); $sellPrice->setCurrency($currency->getCode()); $sellPrice->setDiscountedGrossAmount($price * (rand(80, 95) / 100)); $sellPrice->setValidFrom(new \DateTime()); $sellPrice->setValidTo((new \DateTime())->modify('+30 days')); $product = new Product(); $product->setSku($sku); $product->setHierarchy(rand(0, 10)); $product->setEnabled(true); $product->setAvailability($availability); $product->setBuyPrice($buyPrice); $product->setBuyPriceTax($tax); $product->setSellPrice($sellPrice); $product->setSellPriceTax($tax); $product->setCategories($categories); $product->addShop($shop); $product->translate($this->getDefaultLocale())->setName($name); $product->translate($this->getDefaultLocale())->setSlug(Sluggable::makeSlug($name)); $product->translate($this->getDefaultLocale())->setShortDescription($shortDescription); $product->translate($this->getDefaultLocale())->setDescription($description); $product->mergeNewTranslations(); $product->setProductPhotos($this->getPhotos($product, $manager)); $product->setProducer($producer); $product->setStock(rand(0, 1000)); $product->setUnit($unit); $product->setDimension($dimension); $product->setTrackStock(true); $product->setPackageSize(1); $product->setWeight(rand(0, 5)); $distinctions = new ArrayCollection(); $distinction = new ProductDistinction(); $distinction->setProduct($product); $distinction->setStatus($this->getReference('product_status_bestseller')); $manager->persist($distinction); $distinctions->add($distinction); $distinction = new ProductDistinction(); $distinction->setProduct($product); $distinction->setStatus($this->getReference('product_status_featured')); $manager->persist($distinction); $distinctions->add($distinction); $distinction = new ProductDistinction(); $distinction->setProduct($product); $distinction->setStatus($this->getReference('product_status_novelty')); $manager->persist($distinction); $distinctions->add($distinction); $distinction = new ProductDistinction(); $distinction->setProduct($product); $distinction->setStatus($this->getReference('product_status_promotion')); $manager->persist($distinction); $distinctions->add($distinction); $product->setDistinctions($distinctions); $manager->persist($product); return $product; }