Source of file ProductVariationDiscountExtension.php
Size: 0,834 Bytes - Last Modified: 2021-12-24T06:35:13+00:00
/var/www/docs.ssmods.com/process/src/src/Extensions/ProductVariationDiscountExtension.php
1234567891011121314151617181920212223242526272829303132333435363738 | <?php namespace SilverShop\Discounts\Extensions; use SilverStripe\ORM\DataExtension; class ProductVariationDiscountExtension 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 = 'Price') { $reduction = $this->owner->{$original} - $this->owner->sellingPrice(); //keep it above 0; $reduction = $reduction < 0 ? 0 : $reduction; return $reduction; } /** * Check if this variation has a reduced price. * * @return bool */ public function IsReduced() { return (bool)$this->getTotalReduction(); } } |