コード例 #1
0
ファイル: ProductContext.php プロジェクト: okwinza/Sylius
 /**
  * @Given /^(this product) has option "([^"]+)" with values "([^"]+)" and "([^"]+)"$/
  */
 public function thisProductHasOptionWithValues(ProductInterface $product, $optionName, $firstValue, $secondValue)
 {
     /** @var OptionInterface $variant */
     $option = $this->productOptionFactory->createNew();
     $option->setName($optionName);
     $option->setCode('PO1');
     /** @var OptionValueInterface $optionValue */
     $firstOptionValue = $this->productOptionValueFactory->createNew();
     $firstOptionValue->setValue($firstValue);
     $firstOptionValue->setCode('POV1');
     $firstOptionValue->setOption($option);
     /** @var OptionValueInterface $optionValue */
     $secondOptionValue = $this->productOptionValueFactory->createNew();
     $secondOptionValue->setValue($secondValue);
     $secondOptionValue->setCode('POV2');
     $secondOptionValue->setOption($option);
     $option->addValue($firstOptionValue);
     $option->addValue($secondOptionValue);
     $product->addOption($option);
     $product->setVariantSelectionMethod(ProductInterface::VARIANT_SELECTION_MATCH);
     $this->sharedStorage->set(sprintf('%s_option', $optionName), $option);
     $this->sharedStorage->set(sprintf('%s_option_value', $firstValue), $firstOptionValue);
     $this->sharedStorage->set(sprintf('%s_option_value', $secondValue), $secondOptionValue);
     $this->objectManager->persist($option);
     $this->objectManager->persist($firstOptionValue);
     $this->objectManager->persist($secondOptionValue);
     $this->objectManager->flush();
 }
コード例 #2
0
 /**
  * @Given /^(this product) has option "([^"]+)" with values "([^"]+)" and "([^"]+)"$/
  * @Given /^(this product) has option "([^"]+)" with values "([^"]+)", "([^"]+)" and "([^"]+)"$/
  */
 public function thisProductHasOptionWithValues(ProductInterface $product, $optionName, $firstValue, $secondValue, $thirdValue = null)
 {
     /** @var ProductOptionInterface $option */
     $option = $this->productOptionFactory->createNew();
     $option->setName($optionName);
     $option->setCode(strtoupper($optionName));
     $firstOptionValue = $this->addProductOption($option, $firstValue, 'POV1');
     $secondOptionValue = $this->addProductOption($option, $secondValue, 'POV2');
     if (null !== $thirdValue) {
         $thirdOptionValue = $this->addProductOption($option, $thirdValue, 'POV3');
     }
     $product->addOption($option);
     $product->setVariantSelectionMethod(ProductInterface::VARIANT_SELECTION_MATCH);
     $this->sharedStorage->set(sprintf('%s_option', $optionName), $option);
     $this->sharedStorage->set(sprintf('%s_option_%s_value', $firstValue, strtolower($optionName)), $firstOptionValue);
     $this->sharedStorage->set(sprintf('%s_option_%s_value', $secondValue, strtolower($optionName)), $secondOptionValue);
     if (null !== $thirdValue) {
         $this->sharedStorage->set(sprintf('%s_option_%s_value', $thirdValue, strtolower($optionName)), $thirdOptionValue);
     }
     $this->objectManager->persist($option);
     $this->objectManager->persist($firstOptionValue);
     $this->objectManager->persist($secondOptionValue);
     $this->objectManager->flush();
 }
コード例 #3
0
ファイル: ProductContext.php プロジェクト: sylius/sylius
 /**
  * @param ProductInterface $product
  * @param $productVariantName
  * @param int $price
  * @param string $code
  * @param ChannelInterface $channel
  */
 private function createProductVariant(ProductInterface $product, $productVariantName, $price, $code, ChannelInterface $channel = null)
 {
     $product->setVariantSelectionMethod(ProductInterface::VARIANT_SELECTION_CHOICE);
     /** @var ProductVariantInterface $variant */
     $variant = $this->productVariantFactory->createNew();
     $variant->setName($productVariantName);
     $variant->setCode($code);
     $variant->setProduct($product);
     $variant->addChannelPricing($this->createChannelPricingForChannel($price, $channel));
     $product->addVariant($variant);
     $this->objectManager->flush();
     $this->sharedStorage->set('variant', $variant);
 }
コード例 #4
0
ファイル: ProductContext.php プロジェクト: loic425/Sylius
 /**
  * @Given /^(this product) has option "([^"]+)" with values "([^"]+)" and "([^"]+)"$/
  * @Given /^(this product) has option "([^"]+)" with values "([^"]+)", "([^"]+)" and "([^"]+)"$/
  */
 public function thisProductHasOptionWithValues(ProductInterface $product, $optionName, ...$values)
 {
     /** @var ProductOptionInterface $option */
     $option = $this->productOptionFactory->createNew();
     $option->setName($optionName);
     $option->setCode(StringInflector::nameToUppercaseCode($optionName));
     $this->sharedStorage->set(sprintf('%s_option', $optionName), $option);
     foreach ($values as $key => $value) {
         $optionValue = $this->addProductOption($option, $value, StringInflector::nameToUppercaseCode($value));
         $this->sharedStorage->set(sprintf('%s_option_%s_value', $value, strtolower($optionName)), $optionValue);
     }
     $product->addOption($option);
     $product->setVariantSelectionMethod(ProductInterface::VARIANT_SELECTION_MATCH);
     $this->objectManager->persist($option);
     $this->objectManager->flush();
 }