/**
  * 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();
     }
 }
示例#2
0
文件: Money.php 项目: xphere/elcodi
 /**
  * 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());
 }
示例#3
0
 /**
  * {@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]);
 }