/** * @throws \InvalidArgumentException * * @return Money */ public function getPriceAttribute() { if (array_key_exists('price', $this->attributes)) { return Money::fromInt((int) $this->attributes['price'] ?? 0); } return Money::fromInt(0); }
/** * @throws \InvalidArgumentException * * @return Money */ public function linePrice() : Money { return Money::fromInt((int) $this->amount->amount()); }
/** * @throws \InvalidArgumentException * * @return Money */ public function totalPrice() : Money { return $this->lines()->reduce(function (Money $total, LinePriced $line) { return $total->add($line->linePrice()); }, Money::fromInt(0)); }
/** * @throws \InvalidArgumentException * * @return Money */ public function linePrice() : Money { return Money::fromDecimal($this->price); }
/** * @throws \InvalidArgumentException * * @return Money */ public function linePrice() : Money { /* @noinspection IsEmptyFunctionUsageInspection */ if (empty($this->productOption->product->prices)) { return Money::fromInt(0); } if (!$this->productOption->product->prices->first() instanceof Price) { return Money::fromInt(0); } return $this->productOption->product->price()->asMoney(); }
/** * @param Money $amount * * @throws \InvalidArgumentException * * @return Money */ public function subtract(Money $amount) : Money { return new self($this->money->subtract($amount->wrapped())); }
/** * What would the offer components have cost without the offer? * * @throws \InvalidArgumentException * * @return Money */ public function originalPrice() : Money { return $this->components->reduce(function (Money $price, OfferComponent $component) { return $price->add($component->product()->price()->asMoney()); }, Money::fromInt(0)); }
/** * @throws \InvalidArgumentException * * @return Money */ public function asMoney() : Money { return Money::fromSplit((int) $this->units, (int) $this->subunits); }
/** * @throws \InvalidArgumentException * * @return Money */ public function totalPrice() : Money { return (new \Illuminate\Support\Collection())->merge($this->orderItems)->merge($this->orderOffers)->reduce(function (Money $total, LinePriced $item) { return $total->add($item->linePrice()); }, Money::fromInt(0)); }