Sonata\Component\Currency\CurrencyPriceCalculator::getPrice PHP Method

getPrice() public method

public getPrice ( Sonata\Component\Product\ProductInterface $product, Sonata\Component\Currency\CurrencyInterface $currency, $vat = false )
$product Sonata\Component\Product\ProductInterface
$currency Sonata\Component\Currency\CurrencyInterface
    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;
    }

Usage Example

 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));
 }
CurrencyPriceCalculator