silvercommerce /
discounts
| 1 | <?php |
||||||
| 2 | |||||||
| 3 | namespace SilverCommerce\Discounts\Model; |
||||||
| 4 | |||||||
| 5 | use SilverStripe\ORM\DataObject; |
||||||
| 6 | use SilverCommerce\Discounts\DiscountFactory; |
||||||
| 7 | use SilverCommerce\OrdersAdmin\Model\Estimate; |
||||||
| 8 | use SilverCommerce\OrdersAdmin\Model\LineItem; |
||||||
| 9 | |||||||
| 10 | class AppliedDiscount extends DataObject |
||||||
| 11 | { |
||||||
| 12 | private static $table_name = 'AppliedDiscount'; |
||||||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||||||
| 13 | |||||||
| 14 | private static $db = [ |
||||||
|
0 ignored issues
–
show
|
|||||||
| 15 | 'Title' => 'Varchar', |
||||||
| 16 | 'Code' => 'Varchar', |
||||||
| 17 | 'Value' => 'Currency' |
||||||
| 18 | ]; |
||||||
| 19 | |||||||
| 20 | private static $has_one = [ |
||||||
|
0 ignored issues
–
show
|
|||||||
| 21 | 'Estimate' => Estimate::class |
||||||
| 22 | ]; |
||||||
| 23 | |||||||
| 24 | private static $many_many = [ |
||||||
|
0 ignored issues
–
show
|
|||||||
| 25 | 'Items' => LineItem::class |
||||||
| 26 | ]; |
||||||
| 27 | |||||||
| 28 | private static $summary_fields = [ |
||||||
|
0 ignored issues
–
show
|
|||||||
| 29 | 'Title', |
||||||
| 30 | 'Code', |
||||||
| 31 | 'Value' |
||||||
| 32 | ]; |
||||||
| 33 | |||||||
| 34 | public function appliedAmount(AppliedDiscount $item) |
||||||
| 35 | { |
||||||
| 36 | return $this->calculateValue($item->Estimate()->getTotal()); |
||||||
|
0 ignored issues
–
show
The method
Estimate() does not exist on SilverCommerce\Discounts\Model\AppliedDiscount. Since you implemented __call, consider adding a @method annotation.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
The method
calculateValue() does not exist on SilverCommerce\Discounts\Model\AppliedDiscount. Since you implemented __call, consider adding a @method annotation.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 37 | } |
||||||
| 38 | |||||||
| 39 | public function updateDiscount() |
||||||
| 40 | { |
||||||
| 41 | $discount = $this->getDiscount(); |
||||||
| 42 | if ($discount->exists()) { |
||||||
| 43 | $value = $discount->appliedAmount($this); |
||||||
| 44 | |||||||
| 45 | $this->Value = $value; |
||||||
|
0 ignored issues
–
show
|
|||||||
| 46 | $this->write(); |
||||||
| 47 | } |
||||||
| 48 | } |
||||||
| 49 | |||||||
| 50 | public function getDiscount() |
||||||
| 51 | { |
||||||
| 52 | return DiscountFactory::create()->getByIdent($this->Code); |
||||||
|
0 ignored issues
–
show
The property
Code does not exist on SilverCommerce\Discounts\Model\AppliedDiscount. Since you implemented __get, consider adding a @property annotation.
Loading history...
|
|||||||
| 53 | } |
||||||
| 54 | } |
||||||
| 55 |