當前位置: 首頁>>代碼示例>>PHP>>正文


PHP ProductInterface::getVariants方法代碼示例

本文整理匯總了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;
 }
開發者ID:gabiudrescu,項目名稱:Sylius,代碼行數:12,代碼來源:ProductVariantsPricesProvider.php

示例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]]);
 }
開發者ID:TheMadeleine,項目名稱:Sylius,代碼行數:21,代碼來源:ProductVariantsPricesProviderSpec.php

示例3: thisProductBelongsToShippingCategory

 /**
  * @Given /^(this product) belongs to ("([^"]+)" shipping category)$/
  */
 public function thisProductBelongsToShippingCategory(ProductInterface $product, ShippingCategoryInterface $shippingCategory)
 {
     $product->getVariants()->first()->setShippingCategory($shippingCategory);
     $this->objectManager->flush();
 }
開發者ID:sylius,項目名稱:sylius,代碼行數:8,代碼來源:ProductContext.php

示例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);
     }
 }
開發者ID:NeverResponse,項目名稱:Sylius,代碼行數:23,代碼來源:OrderContext.php


注:本文中的Sylius\Component\Core\Model\ProductInterface::getVariants方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。