Source of file PriceInfo.php
Size: 1,584 Bytes - Last Modified: 2021-12-23T10:25:05+00:00
/var/www/docs.ssmods.com/process/src/src/PriceInfo.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 | <?php namespace SilverShop\Discounts; /** * Represent a price, along with adjustments made to it. */ class PriceInfo { protected $originalprice; protected $currentprice; //for compounding discounts protected $adjustments = []; protected $bestadjustment; public function __construct($price) { $this->currentprice = $this->originalprice = $price; } public function getOriginalPrice() { return $this->originalprice; } public function getPrice() { return $this->currentprice; } public function adjustPrice(Adjustment $a) { $this->currentprice -= $a->getValue(); $this->setBestAdjustment($a); $this->adjustments[] = $a; } public function getCompoundedDiscount() { return $this->originalprice - $this->currentprice; } public function getBestDiscount() { if ($this->bestadjustment) { return $this->bestadjustment->getValue(); } return 0; } public function getBestAdjustment() { return $this->bestadjustment; } public function getAdjustments() { return $this->adjustments; } /** * Sets the best adjustment, if the passed adjustment * is indeed better. * * @param Adjustment $candidate for better adjustment */ protected function setBestAdjustment(Adjustment $candidate) { $this->bestadjustment = $this->bestadjustment ? Adjustment::better_of($this->bestadjustment, $candidate) : $candidate; } } |