public function testGetSubtotals() { $this->translator->expects($this->once())->method('trans')->with(sprintf('orob2b.order.subtotals.%s', Subtotal::TYPE_SUBTOTAL))->willReturn(ucfirst(Subtotal::TYPE_SUBTOTAL)); $order = new Order(); $perUnitLineItem = new OrderLineItem(); $perUnitLineItem->setPriceType(OrderLineItem::PRICE_TYPE_UNIT); $perUnitLineItem->setPrice(Price::create(20, 'USD')); $perUnitLineItem->setQuantity(2); $bundledUnitLineItem = new OrderLineItem(); $bundledUnitLineItem->setPriceType(OrderLineItem::PRICE_TYPE_BUNDLED); $bundledUnitLineItem->setPrice(Price::create(2, 'USD')); $bundledUnitLineItem->setQuantity(10); $otherCurrencyLineItem = new OrderLineItem(); $otherCurrencyLineItem->setPriceType(OrderLineItem::PRICE_TYPE_UNIT); $otherCurrencyLineItem->setPrice(Price::create(10, 'EUR')); $otherCurrencyLineItem->setQuantity(10); $emptyLineItem = new OrderLineItem(); $order->addLineItem($perUnitLineItem); $order->addLineItem($bundledUnitLineItem); $order->addLineItem($emptyLineItem); $order->addLineItem($otherCurrencyLineItem); $order->setCurrency('USD'); $subtotals = $this->provider->getSubtotals($order); $this->assertInstanceOf('Doctrine\\Common\\Collections\\ArrayCollection', $subtotals); $subtotal = $subtotals->get(Subtotal::TYPE_SUBTOTAL); $this->assertInstanceOf('OroB2B\\Bundle\\OrderBundle\\Model\\Subtotal', $subtotal); $this->assertEquals(Subtotal::TYPE_SUBTOTAL, $subtotal->getType()); $this->assertEquals(ucfirst(Subtotal::TYPE_SUBTOTAL), $subtotal->getLabel()); $this->assertEquals($order->getCurrency(), $subtotal->getCurrency()); $this->assertInternalType('float', $subtotal->getAmount()); $this->assertEquals(142.0, $subtotal->getAmount()); }
/** * @return array * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function submitDataProvider() { /** @var Product $product */ $product = $this->getEntity('OroB2B\\Bundle\\ProductBundle\\Entity\\Product', 1, 'id'); $date = \DateTime::createFromFormat('Y-m-d H:i:s', '2015-02-03 00:00:00', new \DateTimeZone('UTC')); $currency = 'USD'; $order = new Order(); $order->setCurrency($currency); return ['default' => ['options' => ['currency' => $currency], 'submittedData' => ['product' => 1, 'quantity' => 10, 'productUnit' => 'item', 'shipBy' => '2015-02-03', 'comment' => 'Comment'], 'expectedData' => (new OrderLineItem())->setProduct($product)->setQuantity(10)->setProductUnit($this->getEntity('OroB2B\\Bundle\\ProductBundle\\Entity\\ProductUnit', 'item', 'code'))->setPriceType(OrderLineItem::PRICE_TYPE_UNIT)->setShipBy($date)->setComment('Comment'), 'data' => null], 'restricted modifications' => ['options' => ['currency' => $currency], 'submittedData' => ['product' => 2, 'quantity' => 10, 'productUnit' => 'item', 'shipBy' => '2015-05-07', 'comment' => 'Comment'], 'expectedData' => (new OrderLineItem())->setOrder($order)->setFromExternalSource(true)->setProduct($product)->setQuantity(5)->setProductUnit($this->getEntity('OroB2B\\Bundle\\ProductBundle\\Entity\\ProductUnit', 'kg', 'code'))->setPriceType(OrderLineItem::PRICE_TYPE_UNIT)->setShipBy($date)->setComment('Comment'), 'data' => (new OrderLineItem())->setOrder($order)->setFromExternalSource(true)->setProduct($product)->setQuantity(5)->setProductUnit($this->getEntity('OroB2B\\Bundle\\ProductBundle\\Entity\\ProductUnit', 'kg', 'code'))->setPriceType(OrderLineItem::PRICE_TYPE_UNIT)->setShipBy($date)->setComment('Comment'), 'choices' => []], 'modifications with choices' => ['options' => ['currency' => $currency], 'submittedData' => ['product' => 2, 'quantity' => 10, 'productUnit' => 'item', 'shipBy' => '2015-05-07', 'comment' => 'Comment'], 'expectedData' => (new OrderLineItem())->setOrder($order)->setFromExternalSource(true)->setProduct($product)->setQuantity(5)->setProductUnit($this->getEntity('OroB2B\\Bundle\\ProductBundle\\Entity\\ProductUnit', 'item', 'code'))->setPriceType(OrderLineItem::PRICE_TYPE_UNIT)->setShipBy($date)->setComment('Comment'), 'data' => (new OrderLineItem())->setOrder($order)->setFromExternalSource(true)->setProduct($product)->setQuantity(5)->setProductUnit($this->getEntity('OroB2B\\Bundle\\ProductBundle\\Entity\\ProductUnit', 'item', 'code'))->setPriceType(OrderLineItem::PRICE_TYPE_UNIT)->setShipBy($date)->setComment('Comment'), 'choices' => [$this->getEntity('OroB2B\\Bundle\\ProductBundle\\Entity\\ProductUnit', 'item', 'code')]], 'free form' => ['options' => ['currency' => $currency], 'submittedData' => ['product' => null, 'quantity' => 10, 'productUnit' => 'item', 'comment' => 'Comment Updated'], 'expectedData' => (new OrderLineItem())->setOrder($order)->setFromExternalSource(false)->setProductSku('SKU')->setFreeFormProduct('Service')->setQuantity(10)->setProductUnit($this->getEntity('OroB2B\\Bundle\\ProductBundle\\Entity\\ProductUnit', 'item', 'code'))->setPriceType(OrderLineItem::PRICE_TYPE_UNIT)->setComment('Comment Updated'), 'data' => (new OrderLineItem())->setOrder($order)->setFromExternalSource(false)->setProductSku('SKU')->setFreeFormProduct('Service')->setQuantity(5)->setProductUnit($this->getEntity('OroB2B\\Bundle\\ProductBundle\\Entity\\ProductUnit', 'item', 'code'))->setPriceType(OrderLineItem::PRICE_TYPE_UNIT)->setComment('Comment'), 'choices' => [$this->getEntity('OroB2B\\Bundle\\ProductBundle\\Entity\\ProductUnit', 'item', 'code')]]]; }
/** * @param Order $order */ public function setOrderCurrency(Order $order) { if (!$order->getCurrency()) { $order->setCurrency($this->localeSettings->getCurrency()); } }