本文整理汇总了PHP中Sylius\Component\Core\Model\ProductInterface::setVariantSelectionMethod方法的典型用法代码示例。如果您正苦于以下问题:PHP ProductInterface::setVariantSelectionMethod方法的具体用法?PHP ProductInterface::setVariantSelectionMethod怎么用?PHP ProductInterface::setVariantSelectionMethod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sylius\Component\Core\Model\ProductInterface
的用法示例。
在下文中一共展示了ProductInterface::setVariantSelectionMethod方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: thisProductHasOptionWithValues
/**
* @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: thisProductHasOptionWithValues
/**
* @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: createProductVariant
/**
* @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: thisProductHasOptionWithValues
/**
* @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();
}