Exemple #1
0
 /**
  * @param string $productName
  * @param int $price
  *
  * @return ProductInterface
  */
 private function createProduct($productName, $price = 0)
 {
     /** @var ProductInterface $product */
     $product = $this->productFactory->createWithVariant();
     $product->setName($productName);
     $product->getFirstVariant()->setPrice($price);
     $product->setCode($this->convertToCode($productName));
     $product->getFirstVariant()->setCode($product->getCode());
     return $product;
 }
 /**
  * @param string $productName
  * @param int $price
  *
  * @return ProductInterface
  */
 private function createProduct($productName, $price = 0, $date = null)
 {
     /** @var ProductInterface $product */
     $product = $this->productFactory->createWithVariant();
     $product->setName($productName);
     $product->setCode($this->convertToCode($productName));
     $product->setCreatedAt(new \DateTime($date));
     $variant = $this->defaultVariantResolver->getVariant($product);
     $variant->setPrice($price);
     $variant->setCode($product->getCode());
     return $product;
 }
Exemple #3
0
 /**
  * @param string $productName
  * @param int $price
  *
  * @return ProductInterface
  */
 private function createProduct($productName, $price = 0, $date = null)
 {
     /** @var ProductInterface $product */
     $product = $this->productFactory->createWithVariant();
     $product->setName($productName);
     $product->setCode(StringInflector::nameToUppercaseCode($productName));
     $product->setSlug($this->slugGenerator->generate($productName));
     $product->setCreatedAt(new \DateTime($date));
     /** @var ProductVariantInterface $productVariant */
     $productVariant = $this->defaultVariantResolver->getVariant($product);
     $productVariant->setPrice($price);
     $productVariant->setCode($product->getCode());
     return $product;
 }
Exemple #4
0
 /**
  * @param string $productName
  * @param int $price
  * @param string|null $date
  * @param ChannelInterface|null $channel
  *
  * @return ProductInterface
  */
 private function createProduct($productName, $price = 100, $date = null, ChannelInterface $channel = null)
 {
     /** @var ProductInterface $product */
     $product = $this->productFactory->createWithVariant();
     $product->setName($productName);
     $product->setCode(StringInflector::nameToUppercaseCode($productName));
     $product->setSlug($this->slugGenerator->generate($productName));
     $product->setCreatedAt(new \DateTime($date));
     /** @var ProductVariantInterface $productVariant */
     $productVariant = $this->defaultVariantResolver->getVariant($product);
     if (null === $channel && $this->sharedStorage->has('channel')) {
         $channel = $this->sharedStorage->get('channel');
     }
     if (null !== $channel) {
         $productVariant->addChannelPricing($this->createChannelPricingForChannel($price, $channel));
     }
     $productVariant->setCode($product->getCode());
     return $product;
 }