예제 #1
0
 public function testProperties()
 {
     $subtotal = new Subtotal();
     $this->assertEquals(Subtotal::TYPE_SUBTOTAL, $subtotal->setType(Subtotal::TYPE_SUBTOTAL)->getType());
     $this->assertEquals('Subtotal', $subtotal->setLabel('Subtotal')->getLabel());
     $this->assertEquals('USD', $subtotal->setCurrency('USD')->getCurrency());
     $this->assertEquals(999.99, $subtotal->setAmount(999.99)->getAmount());
 }
 /**
  * Get order subtotal
  *
  * @param Order $order
  *
  * @return Subtotal
  */
 protected function getSubtotal(Order $order)
 {
     $subtotal = new Subtotal();
     $subtotal->setType(Subtotal::TYPE_SUBTOTAL);
     $translation = sprintf('orob2b.order.subtotals.%s', $subtotal->getType());
     $subtotal->setLabel($this->translator->trans($translation));
     $subtotalAmount = 0.0;
     foreach ($order->getLineItems() as $lineItem) {
         if (!$lineItem->getPrice()) {
             continue;
         }
         $rowTotal = $lineItem->getPrice()->getValue();
         if ($lineItem->getPriceType() === OrderLineItem::PRICE_TYPE_UNIT) {
             $rowTotal *= $lineItem->getQuantity();
         }
         if ($order->getCurrency() !== $lineItem->getPrice()->getCurrency()) {
             $rowTotal *= $this->getExchangeRate($lineItem->getPrice()->getCurrency(), $order->getCurrency());
         }
         $subtotalAmount += $rowTotal;
     }
     $subtotal->setAmount($subtotalAmount);
     $subtotal->setCurrency($order->getCurrency());
     return $subtotal;
 }