本文整理匯總了PHP中Sylius\Component\Core\Model\ProductInterface::getVariants方法的典型用法代碼示例。如果您正苦於以下問題:PHP ProductInterface::getVariants方法的具體用法?PHP ProductInterface::getVariants怎麽用?PHP ProductInterface::getVariants使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Sylius\Component\Core\Model\ProductInterface
的用法示例。
在下文中一共展示了ProductInterface::getVariants方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: provideVariantsPrices
/**
* {@inheritdoc}
*/
public function provideVariantsPrices(ProductInterface $product)
{
$variantsPrices = [];
/** @var ProductVariantInterface $variant */
foreach ($product->getVariants() as $variant) {
$variantsPrices[] = $this->constructOptionsMap($variant);
}
return $variantsPrices;
}
示例2:
function it_provides_array_containing_product_variant_options_map_with_corresponding_price(ProductInterface $tShirt, ProductOptionValueInterface $black, ProductOptionValueInterface $large, ProductOptionValueInterface $small, ProductOptionValueInterface $white, ProductVariantInterface $blackLargeTShirt, ProductVariantInterface $blackSmallTShirt, ProductVariantInterface $whiteLargeTShirt, ProductVariantInterface $whiteSmallTShirt)
{
$tShirt->getVariants()->willReturn([$blackSmallTShirt, $whiteSmallTShirt, $blackLargeTShirt, $whiteLargeTShirt]);
$blackSmallTShirt->getOptionValues()->willReturn([$black, $small]);
$whiteSmallTShirt->getOptionValues()->willReturn([$white, $small]);
$blackLargeTShirt->getOptionValues()->willReturn([$black, $large]);
$whiteLargeTShirt->getOptionValues()->willReturn([$white, $large]);
$blackSmallTShirt->getPrice()->willReturn(1000);
$whiteSmallTShirt->getPrice()->willReturn(1500);
$blackLargeTShirt->getPrice()->willReturn(2000);
$whiteLargeTShirt->getPrice()->willReturn(2500);
$black->getOptionCode()->willReturn('t_shirt_color');
$white->getOptionCode()->willReturn('t_shirt_color');
$small->getOptionCode()->willReturn('t_shirt_size');
$large->getOptionCode()->willReturn('t_shirt_size');
$black->getValue()->willReturn('Black');
$white->getValue()->willReturn('White');
$small->getValue()->willReturn('Small');
$large->getValue()->willReturn('Large');
$this->provideVariantsPrices($tShirt)->shouldReturn([['t_shirt_color' => 'Black', 't_shirt_size' => 'Small', 'value' => 1000], ['t_shirt_color' => 'White', 't_shirt_size' => 'Small', 'value' => 1500], ['t_shirt_color' => 'Black', 't_shirt_size' => 'Large', 'value' => 2000], ['t_shirt_color' => 'White', 't_shirt_size' => 'Large', 'value' => 2500]]);
}
示例3: thisProductBelongsToShippingCategory
/**
* @Given /^(this product) belongs to ("([^"]+)" shipping category)$/
*/
public function thisProductBelongsToShippingCategory(ProductInterface $product, ShippingCategoryInterface $shippingCategory)
{
$product->getVariants()->first()->setShippingCategory($shippingCategory);
$this->objectManager->flush();
}
示例4: customersHavePlacedOrdersForTotalOfMostlyProduct
/**
* @Given :numberOfCustomers customers have placed :numberOfOrders orders for total of :total mostly :product product
* @Given then :numberOfCustomers more customers have placed :numberOfOrders orders for total of :total mostly :product product
*/
public function customersHavePlacedOrdersForTotalOfMostlyProduct($numberOfCustomers, $numberOfOrders, $total, ProductInterface $product)
{
$customers = $this->generateCustomers($numberOfCustomers);
$sampleProductVariant = $product->getVariants()->first();
$total = $this->getPriceFromString($total);
for ($i = 0; $i < $numberOfOrders; $i++) {
$order = $this->createOrder($customers[rand(0, $numberOfCustomers - 1)], '#' . uniqid(), $product->getChannels()->first());
$order->setState(OrderInterface::STATE_NEW);
$this->applyPaymentTransitionOnOrder($order, PaymentTransitions::TRANSITION_COMPLETE);
$price = $i === $numberOfOrders - 1 ? $total : rand(1, $total);
$total -= $price;
$item = $this->orderItemFactory->createNew();
$item->setVariant($sampleProductVariant);
$item->setUnitPrice($price);
$this->itemQuantityModifier->modify($item, 1);
$order->addItem($item);
$this->orderRepository->add($order);
}
}