silvercommerce /
discounts
| 1 | <?php |
||
| 2 | |||
| 3 | namespace SilverCommerce\Discounts\Extensions; |
||
| 4 | |||
| 5 | use SilverStripe\ORM\DataExtension; |
||
| 6 | use SilverCommerce\Discounts\Model\AppliedDiscount; |
||
| 7 | |||
| 8 | class LineItemExtension extends DataExtension |
||
| 9 | { |
||
| 10 | private static $belongs_many_many = [ |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 11 | 'Discounts' => AppliedDiscount::class |
||
| 12 | ]; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * Get the amount of tax for a single unit of this item |
||
| 16 | * |
||
| 17 | * @return float |
||
| 18 | */ |
||
| 19 | public function updateUnitTax(&$total) |
||
| 20 | { |
||
| 21 | $percent = $this->getOwner()->TaxPercentage; |
||
| 22 | $price = $this->getOwner()->UnitPrice; |
||
| 23 | $total = (($price - $this->getDiscountTotal()) / 100) * $percent; |
||
| 24 | |||
| 25 | return $total; |
||
| 26 | } |
||
| 27 | |||
| 28 | public function getDiscountTotal() |
||
| 29 | { |
||
| 30 | $parent = $this->getOwner()->Parent(); |
||
| 31 | $total = $parent->getDiscountTotal(); |
||
| 32 | $count = $parent->getTotalItems(); |
||
| 33 | if ($count > 0) { |
||
| 34 | return $total/$count; |
||
| 35 | } |
||
| 36 | return 0; |
||
| 37 | } |
||
| 38 | } |
||
| 39 |