/** * Update the purchasable total on the purchasable holder * @param bool|void $saveState * @throws \SebastianBergmann\Money\OverflowException * @return void */ public function updateTotal($saveState = true) { $this->total = $this->currencyService->getZeroMoney(); if ($this->purchasables) { foreach ($this->purchasables as $purchasable) { $this->total = $this->total->add($purchasable->getTotal()); } } $this->eventService->dispatch(Events::UPDATED); if ($saveState) { $this->saveState(); } }
/** * Adds a Money and returns the result as a new Money * * @param MoneyInterface $other Other money * * @return MoneyInterface New money instance as a result of addition * between current object and given as a parameter */ public function add(MoneyInterface $other) { $wrappedMoney = $this->wrappedMoney->add($this->newWrappedMoneyFromMoney($other)); return Money::create($wrappedMoney->getAmount(), $other->getCurrency()); }
/** * {@inheritdoc} */ public function add(Money $other) { $toAdd = new BaseMoney($other->getAmount(), $other->getCurrency()); $result = $this->valueObject->add($toAdd); return new static(['amount' => $result->getAmount(), 'currency' => $this->currency]); }