本文整理匯總了PHP中Sylius\Component\Core\Model\OrderInterface::addItem方法的典型用法代碼示例。如果您正苦於以下問題:PHP OrderInterface::addItem方法的具體用法?PHP OrderInterface::addItem怎麽用?PHP OrderInterface::addItem使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Sylius\Component\Core\Model\OrderInterface
的用法示例。
在下文中一共展示了OrderInterface::addItem方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1:
function it_does_not_add_product_if_exists($orderItemQuantityModifier, $variantRepository, FactoryInterface $itemFactory, OrderInterface $order, OrderItemInterface $item, ProductVariantInterface $variant, PromotionInterface $promotion)
{
$variantRepository->find(500)->willReturn($variant);
$itemFactory->createNew()->willReturn($item);
$item->setUnitPrice(1)->willReturn($item);
$item->setVariant($variant)->willReturn($item);
$orderItemQuantityModifier->modify($item, 2)->shouldBeCalled();
$item->equals($item)->willReturn(true);
$order->getItems()->willReturn([$item]);
$order->addItem($item)->shouldNotBeCalled();
$this->execute($order, ['variant' => 500, 'quantity' => 2, 'price' => 1], $promotion);
}
示例2: array
function it_does_not_add_product_if_exists(RepositoryInterface $variantRepository, RepositoryInterface $itemRepository, OrderInterface $order, OrderItemInterface $item, ProductVariantInterface $variant, PromotionInterface $promotion)
{
$configuration = array('variant' => 500, 'quantity' => 2, 'price' => 1);
$variantRepository->find($configuration['variant'])->willReturn($variant);
$itemRepository->createNew()->willReturn($item);
$item->setUnitPrice($configuration['price'])->shouldBeCalled()->willReturn($item);
$item->setVariant($variant)->shouldBeCalled()->willReturn($item);
$item->setQuantity($configuration['quantity'])->shouldBeCalled()->willReturn($item);
$item->equals($item)->willReturn(true);
$order->getItems()->willReturn(array($item));
$order->addItem($item)->shouldNotBeCalled();
$this->execute($order, $configuration, $promotion);
}
示例3: generateItems
/**
* @param OrderInterface $order
*/
private function generateItems(OrderInterface $order)
{
$numberOfItems = rand(1, 5);
$products = $this->productRepository->findAll();
for ($i = 0; $i < $numberOfItems; $i++) {
$item = $this->orderItemFactory->createNew();
$product = $this->faker->randomElement($products);
$variant = $this->faker->randomElement($product->getVariants()->toArray());
$item->setVariant($variant);
$this->orderItemQuantityModifier->modify($item, rand(1, 5));
$order->addItem($item);
}
}