本文整理汇总了PHP中Sylius\Component\Core\Model\OrderItemInterface::getUnits方法的典型用法代码示例。如果您正苦于以下问题:PHP OrderItemInterface::getUnits方法的具体用法?PHP OrderItemInterface::getUnits怎么用?PHP OrderItemInterface::getUnits使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sylius\Component\Core\Model\OrderItemInterface
的用法示例。
在下文中一共展示了OrderItemInterface::getUnits方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUnitsAdjustments
/**
* @param OrderItemInterface $item
* @param array $distributedAmounts
* @param PromotionInterface $promotion
*/
private function setUnitsAdjustments(OrderItemInterface $item, array $distributedAmounts, PromotionInterface $promotion)
{
$i = 0;
foreach ($item->getUnits() as $unit) {
if (0 === $distributedAmounts[$i]) {
break;
}
$this->addAdjustmentToUnit($unit, $distributedAmounts[$i], $promotion);
$i++;
}
}
示例2: applyAdjustmentsOnItemUnits
/**
* @param OrderItemInterface $item
* @param PromotionInterface $promotion
* @param int $itemPromotionAmount
*/
private function applyAdjustmentsOnItemUnits(OrderItemInterface $item, PromotionInterface $promotion, $itemPromotionAmount)
{
$splitPromotionAmount = $this->distributor->distribute($itemPromotionAmount, $item->getQuantity());
$i = 0;
foreach ($item->getUnits() as $unit) {
$promotionAmount = $splitPromotionAmount[$i++];
if (0 === $promotionAmount) {
continue;
}
$this->addAdjustment($promotion, $unit, $promotionAmount);
}
}
示例3:
function it_reverts_order_units_order_promotion_adjustments(AdjustmentInterface $firstAdjustment, AdjustmentInterface $secondAdjustment, OrderInterface $order, OrderItemInterface $item, OrderItemUnitInterface $unit, OriginatorInterface $originator, PromotionInterface $otherPromotion, PromotionInterface $promotion)
{
$order->countItems()->willReturn(1);
$order->getItems()->willReturn(new \ArrayIterator([$item->getWrappedObject()]));
$item->getUnits()->willReturn(new \ArrayIterator([$unit->getWrappedObject()]));
$unit->getAdjustments(AdjustmentInterface::ORDER_PROMOTION_ADJUSTMENT)->willReturn(new \ArrayIterator([$firstAdjustment->getWrappedObject(), $secondAdjustment->getWrappedObject()]));
$originator->getOrigin($firstAdjustment)->willReturn($promotion);
$originator->getOrigin($secondAdjustment)->willReturn($otherPromotion);
$unit->removeAdjustment($firstAdjustment)->shouldBeCalled();
$unit->removeAdjustment($secondAdjustment)->shouldNotBeCalled();
$this->revert($order, [], $promotion);
}
示例4:
function it_removes_units_if_target_quantity_is_greater_than_current(Collection $orderItemUnits, \Iterator $iterator, OrderItemInterface $orderItem, OrderItemUnitInterface $unit1, OrderItemUnitInterface $unit2, OrderItemUnitInterface $unit3, OrderItemUnitInterface $unit4)
{
$orderItem->getQuantity()->willReturn(4);
$orderItem->getUnits()->willReturn($orderItemUnits);
$orderItemUnits->count()->willReturn(4);
$orderItemUnits->getIterator()->willReturn($iterator);
$iterator->rewind()->shouldBeCalled();
$iterator->valid()->willReturn(true, true, true, true, false);
$iterator->current()->willReturn($unit1, $unit2, $unit3, $unit4);
$iterator->next()->shouldBeCalled();
$orderItem->removeUnit($unit1)->shouldBeCalled();
$this->modify($orderItem, 3);
}
示例5:
function it_reverts_order_units_order_promotion_adjustments(AdjustmentInterface $firstAdjustment, AdjustmentInterface $secondAdjustment, OrderInterface $order, OrderItemInterface $item, OrderItemUnitInterface $unit, PromotionInterface $promotion)
{
$order->countItems()->willReturn(1);
$order->getItems()->willReturn([$item]);
$item->getUnits()->willReturn([$unit]);
$unit->getAdjustments(AdjustmentInterface::ORDER_PROMOTION_ADJUSTMENT)->willReturn([$firstAdjustment, $secondAdjustment]);
$promotion->getCode()->willReturn('PROMOTION');
$firstAdjustment->getOriginCode()->willReturn('PROMOTION');
$secondAdjustment->getOriginCode()->willReturn('OTHER_PROMOTION');
$unit->removeAdjustment($firstAdjustment)->shouldBeCalled();
$unit->removeAdjustment($secondAdjustment)->shouldNotBeCalled();
$this->revert($order, [], $promotion);
}
示例6:
function it_reverts_proper_promotion_adjustment_from_all_units($originator, AdjustmentInterface $promotionAdjustment1, AdjustmentInterface $promotionAdjustment2, Collection $items, Collection $units, Collection $adjustments, OrderInterface $order, OrderItemInterface $orderItem, OrderItemUnitInterface $unit, PromotionInterface $promotion, PromotionInterface $someOtherPromotion)
{
$order->getItems()->willReturn($items);
$items->getIterator()->willReturn(new \ArrayIterator([$orderItem->getWrappedObject()]));
$orderItem->getUnits()->willReturn($units);
$units->getIterator()->willReturn(new \ArrayIterator([$unit->getWrappedObject()]));
$unit->getAdjustments(AdjustmentInterface::ORDER_UNIT_PROMOTION_ADJUSTMENT)->willReturn($adjustments);
$adjustments->getIterator()->willReturn(new \ArrayIterator([$promotionAdjustment1->getWrappedObject(), $promotionAdjustment2->getWrappedObject()]));
$originator->getOrigin($promotionAdjustment1)->willReturn($promotion);
$unit->removeAdjustment($promotionAdjustment1)->shouldBeCalled();
$originator->getOrigin($promotionAdjustment2)->willReturn($someOtherPromotion);
$unit->removeAdjustment($promotionAdjustment2)->shouldNotBeCalled();
$this->revert($order, ['percentage' => 0.2], $promotion);
}
示例7: ArrayCollection
function it_holds_the_variant_stock_via_inventory_operator($inventoryOperator, $stateMachineFactory, OrderInterface $order, OrderItemInterface $item, ProductVariantInterface $variant, OrderItemUnitInterface $unit1, OrderItemUnitInterface $unit2, StateMachineInterface $sm1, StateMachineInterface $sm2)
{
$order->getItems()->willReturn([$item]);
$item->getVariant()->willReturn($variant);
$item->getQuantity()->willReturn(2);
$item->getUnits()->willReturn(new ArrayCollection([$unit1, $unit2]));
$stateMachineFactory->get($unit1, InventoryUnitTransitions::GRAPH)->willReturn($sm1);
$sm1->can(InventoryUnitTransitions::SYLIUS_HOLD)->willReturn(false);
$sm1->apply(InventoryUnitTransitions::SYLIUS_HOLD)->shouldNotBeCalled();
$stateMachineFactory->get($unit2, InventoryUnitTransitions::GRAPH)->willReturn($sm2);
$sm1->can(InventoryUnitTransitions::SYLIUS_HOLD)->willReturn(true);
$sm1->apply(InventoryUnitTransitions::SYLIUS_HOLD)->shouldBeCalled();
$inventoryOperator->hold($variant, 1)->shouldBeCalled();
$this->holdInventory($order);
}
示例8: processInventoryUnits
/**
* {@inheritdoc}
*/
public function processInventoryUnits(OrderItemInterface $item)
{
$nbUnits = $item->getUnits()->count();
if ($item->getQuantity() > $nbUnits) {
$this->createInventoryUnits($item, $item->getQuantity() - $nbUnits);
} elseif ($item->getQuantity() < $nbUnits) {
foreach ($item->getUnits()->slice(0, $nbUnits - $item->getQuantity()) as $unit) {
$item->removeUnit($unit);
}
}
foreach ($item->getUnits() as $unit) {
if ($unit->getStockable() !== $item->getVariant()) {
$unit->setStockable($item->getVariant());
}
}
}
示例9:
function it_decreases_the_variant_stock_via_inventory_operator($inventoryOperator, $stateMachineFactory, OrderInterface $order, OrderItemInterface $item, ProductVariantInterface $variant, OrderItemUnitInterface $unit1, OrderItemUnitInterface $unit2, StateMachineInterface $sm1, StateMachineInterface $sm2)
{
$order->getItems()->willReturn([$item]);
$item->getVariant()->willReturn($variant);
$item->getQuantity()->willReturn(2);
$item->getUnits()->shouldBeCalled()->willReturn([$unit1, $unit2]);
$stateMachineFactory->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();
$stateMachineFactory->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([$unit1, $unit2])->shouldBeCalled();
$inventoryOperator->release($variant, 1)->shouldBeCalled();
$this->updateInventory($order);
}
示例10:
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->getUnits()->willReturn(array($unit1, $unit2));
$item->setOrder($this)->shouldBeCalled();
$this->addItem($item);
$this->shouldNotBeBackorder();
}
示例11: setUnitsAdjustments
/**
* @param OrderItemInterface $item
* @param int $promotionAmount
* @param PromotionInterface $promotion
*/
private function setUnitsAdjustments(OrderItemInterface $item, $promotionAmount, PromotionInterface $promotion)
{
foreach ($item->getUnits() as $unit) {
$this->addAdjustmentToUnit($unit, $promotionAmount, $promotion);
}
}
示例12: ArrayCollection
function it_does_not_distribute_0_amount_to_unit_even_if_its_middle_element(AdjustmentFactoryInterface $adjustmentFactory, AdjustmentInterface $adjustment, IntegerDistributorInterface $distributor, OrderInterface $order, OrderItemInterface $coltItem, OrderItemUnitInterface $firstColtUnit, OrderItemUnitInterface $secondColtUnit, PromotionInterface $promotion)
{
$order->countItems()->willReturn(1);
$order->getItems()->willReturn(new ArrayCollection([$coltItem->getWrappedObject()]));
$coltItem->getQuantity()->willReturn(2);
$distributor->distribute(1, 2)->willReturn([1, 0]);
$coltItem->getUnits()->willReturn(new ArrayCollection([$firstColtUnit->getWrappedObject(), $secondColtUnit->getWrappedObject()]));
$promotion->getName()->willReturn('Winter guns promotion!');
$promotion->getCode()->willReturn('WINTER_GUNS_PROMOTION');
$adjustmentFactory->createWithData(AdjustmentInterface::ORDER_PROMOTION_ADJUSTMENT, 'Winter guns promotion!', 1)->willReturn($adjustment);
$adjustment->setOriginCode('WINTER_GUNS_PROMOTION')->shouldBeCalled();
$firstColtUnit->addAdjustment($adjustment)->shouldBeCalled();
$secondColtUnit->addAdjustment(Argument::any())->shouldNotBeCalled();
$this->apply($order, $promotion, [1]);
}
示例13:
function it_revert_proper_promotion_adjustment_from_all_units(AdjustmentInterface $promotionAdjustment1, AdjustmentInterface $promotionAdjustment2, Collection $items, Collection $units, Collection $adjustments, OrderInterface $order, OrderItemInterface $orderItem, OrderItemUnitInterface $unit, PromotionInterface $promotion)
{
$order->getItems()->willReturn($items);
$items->getIterator()->willReturn(new \ArrayIterator([$orderItem->getWrappedObject()]));
$orderItem->getUnits()->willReturn($units);
$units->getIterator()->willReturn(new \ArrayIterator([$unit->getWrappedObject()]));
$unit->getAdjustments(AdjustmentInterface::ORDER_UNIT_PROMOTION_ADJUSTMENT)->willReturn($adjustments);
$adjustments->getIterator()->willReturn(new \ArrayIterator([$promotionAdjustment1->getWrappedObject(), $promotionAdjustment2->getWrappedObject()]));
$promotion->getCode()->willReturn('PROMOTION');
$promotionAdjustment1->getOriginCode()->willReturn('PROMOTION');
$unit->removeAdjustment($promotionAdjustment1)->shouldBeCalled();
$promotionAdjustment2->getOriginCode()->willReturn('OTHER_PROMOTION');
$unit->removeAdjustment($promotionAdjustment2)->shouldNotBeCalled();
$this->revert($order, ['amount' => 1000], $promotion);
}
示例14: ArrayCollection
function it_reverts_a_proper_promotion_adjustment_from_all_units(AdjustmentInterface $promotionAdjustment1, AdjustmentInterface $promotionAdjustment2, ChannelInterface $channel, OrderInterface $order, OrderItemInterface $orderItem, OrderItemUnitInterface $unit, PromotionInterface $promotion)
{
$order->getChannel()->willReturn($channel);
$channel->getCode()->willReturn('WEB_US');
$order->getItems()->willReturn(new ArrayCollection([$orderItem->getWrappedObject()]));
$orderItem->getUnits()->willReturn(new ArrayCollection([$unit->getWrappedObject()]));
$unit->getAdjustments(AdjustmentInterface::ORDER_UNIT_PROMOTION_ADJUSTMENT)->willReturn(new ArrayCollection([$promotionAdjustment1->getWrappedObject(), $promotionAdjustment2->getWrappedObject()]));
$promotion->getCode()->willReturn('PROMOTION');
$promotionAdjustment1->getOriginCode()->willReturn('PROMOTION');
$unit->removeAdjustment($promotionAdjustment1)->shouldBeCalled();
$promotionAdjustment2->getOriginCode()->willReturn('OTHER_PROMOTION');
$unit->removeAdjustment($promotionAdjustment2)->shouldNotBeCalled();
$this->revert($order, ['WEB_US' => ['amount' => 1000]], $promotion);
}
示例15: removeUnitsAdjustment
/**
* @param OrderItemInterface $item
* @param PromotionInterface $promotion
*/
protected function removeUnitsAdjustment(OrderItemInterface $item, PromotionInterface $promotion)
{
foreach ($item->getUnits() as $unit) {
$this->removeUnitOrderItemAdjustments($unit, $promotion);
}
}