Returns the price of $product for given $currency.
public getPrice ( Sonata\Component\Product\ProductInterface $product, Sonata\Component\Currency\CurrencyInterface $currency, boolean $vat = false ) : float | ||
$product | Sonata\Component\Product\ProductInterface | A product instance |
$currency | Sonata\Component\Currency\CurrencyInterface | A currency instance |
$vat | boolean | Return price including VAT? |
return | float |
/** * {@inheritdoc} */ public function calculatePrice(ProductInterface $product, CurrencyInterface $currency, $vat = false, $quantity = 1) { if (!is_int($quantity) || $quantity < 1) { throw new InvalidParameterException("Expected integer >= 1 for quantity, " . $quantity . " given."); } return floatval(bcmul($this->currencyPriceCalculator->getPrice($product, $currency, $vat), $quantity)); }
/** * {@inheritdoc} */ public function calculatePrice(ProductInterface $product, CurrencyInterface $currency, $vat = false, $quantity = 1) { $event = new BeforeCalculatePriceEvent($product, $currency, $vat, $quantity); $this->getEventDispatcher()->dispatch(BasketEvents::PRE_CALCULATE_PRICE, $event); $vat = $event->getVat(); $quantity = $event->getQuantity(); if (!is_int($quantity) || $quantity < 1) { throw new InvalidParameterException("Expected integer >= 1 for quantity, " . $quantity . " given."); } $price = floatval(bcmul($this->currencyPriceCalculator->getPrice($product, $currency, $vat), $quantity)); $afterEvent = new AfterCalculatePriceEvent($product, $currency, $vat, $quantity, $price); $this->getEventDispatcher()->dispatch(BasketEvents::POST_CALCULATE_PRICE, $afterEvent); return $afterEvent->getPrice(); }