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