示例#1
0
 /**
  * @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);
 }
示例#2
0
 /**
  * @throws \InvalidArgumentException
  *
  * @return Money
  */
 public function linePrice() : Money
 {
     return Money::fromInt((int) $this->amount->amount());
 }
示例#3
0
 /**
  * @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));
 }
示例#4
0
 /**
  * @throws \InvalidArgumentException
  *
  * @return Money
  */
 public function linePrice() : Money
 {
     return Money::fromDecimal($this->price);
 }
示例#5
0
 /**
  * @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();
 }
示例#6
0
 /**
  * @param Money $amount
  *
  * @throws \InvalidArgumentException
  *
  * @return Money
  */
 public function subtract(Money $amount) : Money
 {
     return new self($this->money->subtract($amount->wrapped()));
 }
示例#7
0
 /**
  * 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));
 }
示例#8
0
 /**
  * @throws \InvalidArgumentException
  *
  * @return Money
  */
 public function asMoney() : Money
 {
     return Money::fromSplit((int) $this->units, (int) $this->subunits);
 }
示例#9
0
 /**
  * @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));
 }