public function getPrice(ProductInterface $product, CurrencyInterface $currency, $vat = false) { $price = $product->getPrice(); if ($vat && false === $product->isPriceIncludingVat()) { $price = $price * (1 + $product->getVatRate() / 100); } if (!$vat && true === $product->isPriceIncludingVat()) { $price = $price * (1 - $product->getVatRate() / 100); } return $price; }
public function testGetPrice() { $currencyPriceCalculator = new CurrencyPriceCalculator(); $product = $this->getMock('Sonata\\Component\\Product\\ProductInterface'); $currency = new Currency(); $currency->setLabel('EUR'); $product->expects($this->once())->method('getPrice')->will($this->returnValue(42.0)); $this->assertEquals(42.0, $currencyPriceCalculator->getPrice($product, $currency)); }