Source of file ProductDiscountExtension.php
Size: 0,967 Bytes - Last Modified: 2021-12-24T06:35:13+00:00
/var/www/docs.ssmods.com/process/src/src/Extensions/ProductDiscountExtension.php
12345678910111213141516171819202122232425262728293031323334353637383940414243444546 | <?php namespace SilverShop\Discounts\Extensions; use SilverStripe\ORM\DataExtension; class ProductDiscountExtension extends DataExtension { private static $casting = [ 'TotalReduction' => 'Currency' ]; /** * Get the difference between the original price and the new price. * * @param string $original * * @return float */ public function getTotalReduction($original = 'BasePrice') { $reduction = $this->owner->{$original} - $this->owner->sellingPrice(); //keep it above 0; $reduction = $reduction < 0 ? 0 : $reduction; return $reduction; } /** * Check if this product or variation has a reduced price. * * @return bool */ public function IsReduced() { return (bool) $this->getTotalReduction(); } /** * @return int */ public function getDiscountedProductID() { return $this->owner->ID; } } |