/** * Return a formatted price given an Money object * * If money is null, print empty string * * @param MoneyInterface $money the Money object to print * * @return string The formatted price */ public function printMoney(MoneyInterface $money = null) { if (!$money instanceof MoneyInterface) { return ''; } if (!$money->getCurrency() instanceof CurrencyInterface) { return $money->getAmount(); } $formatter = new NumberFormatter($this->localeProviderAdapter->getLocaleIso(), NumberFormatter::CURRENCY); $formatter->setSymbol(NumberFormatter::CURRENCY_SYMBOL, $money->getCurrency()->getSymbol()); /** * The precision of the integer amount for a given Money * (cents, thousandths, 10-thousandths, etc) should be * stored in the Currency object. We assume amounts are * represented in cents * * Loss of precision due to conversion is possible, but only when * displaying prices. This operation does not affect amounts */ return $formatter->format($money->getAmount() / 100); }
/** * Sets the total amount with tax * * @param \Elcodi\Component\Currency\Entity\Interfaces\MoneyInterface $amount amount without tax * * @return $this Self object */ public function setAmount(\Elcodi\Component\Currency\Entity\Interfaces\MoneyInterface $amount) { $this->amount = $amount->getAmount(); $this->currency = $amount->getCurrency(); return $this; }
/** * Returns a new WrappedMoney given a MoneyInterface * * @param MoneyInterface $money Money * * @return WrappedMoney WrappedMoney new instance */ private function newWrappedMoneyFromMoney(MoneyInterface $money) { return new WrappedMoney($money->getAmount(), new WrappedCurrency($money->getCurrency()->getIso())); }
/** * Sets the Coupon amount with tax * * @param MoneyInterface $amount coupon amount * * @return OrderInterface */ public function setCouponAmount(MoneyInterface $amount) { $this->couponAmount = $amount->getAmount(); $this->couponCurrency = $amount->getCurrency(); return $this; }
/** * Set price * * @param \Elcodi\Component\Currency\Entity\Interfaces\MoneyInterface $amount Reduced Price * * @return $this Self object */ public function setReducedPrice(\Elcodi\Component\Currency\Entity\Interfaces\MoneyInterface $amount) { $this->reducedPrice = $amount->getAmount(); $this->reducedPriceCurrency = $amount->getCurrency(); return $this; }
/** * Given an amount, convert it to desired Currency * * If amount currency is the same as desired Currency, return itself * * If is impossible to convert to desired Currency, throw Exception * * @param MoneyInterface $money * @param CurrencyInterface $currencyTo * * @return MoneyInterface Money converted * * @throws CurrencyNotConvertibleException Currencies cannot be converted */ public function convertMoney(MoneyInterface $money, CurrencyInterface $currencyTo) { $currencyFrom = $money->getCurrency(); $amount = $money->getAmount(); return $this->convertCurrency($currencyFrom, $currencyTo, $amount); }
/** * Set price * * @param MoneyInterface $amount Price * * @return $this Self object */ public function setPrice(MoneyInterface $amount) { $this->priceAmount = $amount->getAmount(); $this->priceCurrency = $amount->getCurrency(); return $this; }
/** * Sets the Shipping amount with tax * * @param MoneyInterface $amount shipping amount * * @return OrderInterface */ public function setShippingAmount(MoneyInterface $amount) { $this->shippingAmount = $amount->getAmount(); $this->shippingCurrency = $amount->getCurrency(); return $this; }
/** * Sets to price * * @param \Elcodi\Component\Currency\Entity\Interfaces\MoneyInterface $price Price * * @return $this Self object */ public function setToPrice(\Elcodi\Component\Currency\Entity\Interfaces\MoneyInterface $price) { $this->toPriceAmount = $price->getAmount(); $this->toPriceCurrency = $price->getCurrency(); return $this; }
/** * Set minimum purchase * * @param MoneyInterface $amount Absolute Price * * @return $this Self object */ public function setMinimumPurchase(MoneyInterface $amount) { $this->minimumPurchaseAmount = $amount->getAmount(); $this->minimumPurchaseCurrency = $amount->getCurrency(); return $this; }