/** * Buckets for each potential offer, keeping duplicate offers. * * @throws \InvalidArgumentException * * @return Collection|PotentialOffer[] */ private function potentials() : Collection { return $this->components->map(function (OfferComponent $component) { return $component->product(); })->filter(function (Product $product) { return $product->offers->count(); })->reduce(function (Collection $potentials, Product $product) { return $potentials->push(new PotentialOffer($product->offers->first())); }, new Collection()); }
/** * 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)); }