本文整理汇总了PHP中Sylius\Component\Core\Model\OrderItemInterface::getInventoryUnits方法的典型用法代码示例。如果您正苦于以下问题:PHP OrderItemInterface::getInventoryUnits方法的具体用法?PHP OrderItemInterface::getInventoryUnits怎么用?PHP OrderItemInterface::getInventoryUnits使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sylius\Component\Core\Model\OrderItemInterface
的用法示例。
在下文中一共展示了OrderItemInterface::getInventoryUnits方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: processInventoryUnits
/**
* {@inheritdoc}
*/
public function processInventoryUnits(OrderItemInterface $item)
{
$nbUnits = $item->getInventoryUnits()->count();
if ($item->getQuantity() > $nbUnits) {
$this->createInventoryUnits($item, $item->getQuantity() - $nbUnits);
} elseif ($item->getQuantity() < $nbUnits) {
foreach ($item->getInventoryUnits()->slice(0, $nbUnits - $item->getQuantity()) as $unit) {
$item->removeInventoryUnit($unit);
}
}
foreach ($item->getInventoryUnits() as $unit) {
if ($unit->getStockable() !== $item->getVariant()) {
$unit->setStockable($item->getVariant());
}
}
}
示例2:
function it_decreases_the_variant_stock_via_inventory_operator($inventoryOperator, $factory, OrderInterface $order, OrderItemInterface $item, ProductVariantInterface $variant, InventoryUnitInterface $unit1, InventoryUnitInterface $unit2, StateMachineInterface $sm1, StateMachineInterface $sm2)
{
$order->getItems()->willReturn(array($item));
$item->getVariant()->willReturn($variant);
$item->getQuantity()->willReturn(2);
$item->getInventoryUnits()->shouldBeCalled()->willReturn(array($unit1, $unit2));
$factory->get($unit1, InventoryUnitTransitions::GRAPH)->willReturn($sm1);
$sm1->can(InventoryUnitTransitions::SYLIUS_SELL)->willReturn(true);
$sm1->can(InventoryUnitTransitions::SYLIUS_RELEASE)->willReturn(true);
$sm1->apply(InventoryUnitTransitions::SYLIUS_SELL)->shouldBeCalled();
$factory->get($unit2, InventoryUnitTransitions::GRAPH)->willReturn($sm2);
$sm2->can(InventoryUnitTransitions::SYLIUS_SELL)->willReturn(true);
$sm2->can(InventoryUnitTransitions::SYLIUS_RELEASE)->willReturn(false);
$sm2->apply(InventoryUnitTransitions::SYLIUS_SELL)->shouldBeCalled();
$inventoryOperator->decrease(array($unit1, $unit2))->shouldBeCalled();
$inventoryOperator->release($variant, 1)->shouldBeCalled();
$this->updateInventory($order);
}
示例3:
function it_not_a_backorder_if_contains_no_backordered_units(InventoryUnitInterface $unit1, InventoryUnitInterface $unit2, OrderItemInterface $item)
{
$unit1->getInventoryState()->willReturn(InventoryUnitInterface::STATE_SOLD);
$unit2->getInventoryState()->willReturn(InventoryUnitInterface::STATE_SOLD);
$item->getInventoryUnits()->willReturn(array($unit1, $unit2));
$item->setOrder($this)->shouldBeCalled();
$this->addItem($item);
$this->shouldNotBeBackorder();
}