Author: Adam Piotrowski (adam@wellcommerce.org)
Inheritance: implements WellCommerce\Bundle\ProductBundle\Entity\ProductInterface, use trait WellCommerce\Bundle\DoctrineBundle\Entity\IdentifiableTrait, 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\MediaBundle\Entity\MediaAwareTrait, use trait WellCommerce\Bundle\DoctrineBundle\Behaviours\Enableable\EnableableTrait, use trait WellCommerce\Bundle\AppBundle\Entity\HierarchyAwareTrait, use trait WellCommerce\Bundle\ShopBundle\Entity\ShopCollectionAwareTrait, use trait WellCommerce\Bundle\ProducerBundle\Entity\ProducerAwareTrait, use trait WellCommerce\Bundle\UnitBundle\Entity\UnitAwareTrait, use trait WellCommerce\Bundle\AvailabilityBundle\Entity\AvailabilityAwareTrait, use trait WellCommerce\Bundle\ProductBundle\Entity\Extra\ProductExtraTrait
示例#1
0
 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);
 }
示例#2
0
 /**
  * @return \WellCommerce\Bundle\ProductBundle\Entity\ProductInterface
  */
 public function create()
 {
     $product = new Product();
     $product->setCategories(new ArrayCollection());
     $product->setProductPhotos(new ArrayCollection());
     $product->setStatuses(new ArrayCollection());
     $product->setAttributes(new ArrayCollection());
     $product->setShops(new ArrayCollection());
     $product->setEnabled(true);
     return $product;
 }
 public function create() : ProductInterface
 {
     $product = new Product();
     $product->setCategories($this->createEmptyCollection());
     $product->setProductPhotos($this->createEmptyCollection());
     $product->setDistinctions($this->createEmptyCollection());
     $product->setVariants($this->createEmptyCollection());
     $product->setShops($this->createEmptyCollection());
     $product->setEnabled(true);
     $product->setSellPrice(new DiscountablePrice());
     $product->setDimension(new Dimension());
     $product->setBuyPrice(new Price());
     $product->setBuyPriceTax(null);
     $product->setSellPriceTax(null);
     $product->setUnit(null);
     $product->setHierarchy(0);
     return $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;
 }