silvercommerce /
discounts
| 1 | <?php |
||||||
| 2 | |||||||
| 3 | namespace SilverCommerce\Discounts\Model; |
||||||
| 4 | |||||||
| 5 | use SilverStripe\ORM\ArrayList; |
||||||
| 6 | use SilverCommerce\Discounts\Model\Discount; |
||||||
| 7 | use SilverCommerce\OrdersAdmin\Model\Estimate; |
||||||
| 8 | |||||||
| 9 | class FixedRateDiscount extends Discount |
||||||
| 10 | { |
||||||
| 11 | private static $table_name = 'Discount_FixedRate'; |
||||||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||||||
| 12 | |||||||
| 13 | private static $description = "Simple fixed value discount"; |
||||||
|
0 ignored issues
–
show
|
|||||||
| 14 | |||||||
| 15 | private static $db = [ |
||||||
|
0 ignored issues
–
show
|
|||||||
| 16 | "Amount" => "Decimal" |
||||||
| 17 | ]; |
||||||
| 18 | |||||||
| 19 | public function calculateAmount(Estimate $estimate) |
||||||
| 20 | { |
||||||
| 21 | $cats = $this->Categories(); |
||||||
|
0 ignored issues
–
show
The method
Categories() does not exist on SilverCommerce\Discounts\Model\FixedRateDiscount. 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...
|
|||||||
| 22 | $all_products = ArrayList::create(); |
||||||
| 23 | $value = $estimate->getSubTotal(); |
||||||
| 24 | $min = (float) $this->MinOrder; |
||||||
|
0 ignored issues
–
show
The property
MinOrder does not exist on SilverCommerce\Discounts\Model\FixedRateDiscount. Since you implemented __get, consider adding a @property annotation.
Loading history...
|
|||||||
| 25 | |||||||
| 26 | if ($cats->count() > 0) { |
||||||
| 27 | $value = 0; |
||||||
| 28 | foreach ($cats as $cat) { |
||||||
| 29 | $all_products->merge($cat->Products()); |
||||||
| 30 | } |
||||||
| 31 | |||||||
| 32 | foreach ($estimate->Items() as $line_item) { |
||||||
| 33 | $match = $line_item->FindStockItem(); |
||||||
| 34 | if ($all_products->find('ID', $match->ID)) { |
||||||
| 35 | $value += ($line_item->Quantity * $line_item->UnitPrice); |
||||||
| 36 | } |
||||||
| 37 | } |
||||||
| 38 | } |
||||||
| 39 | |||||||
| 40 | $amount = $this->Amount; |
||||||
|
0 ignored issues
–
show
The property
Amount does not exist on SilverCommerce\Discounts\Model\FixedRateDiscount. Since you implemented __get, consider adding a @property annotation.
Loading history...
|
|||||||
| 41 | |||||||
| 42 | if ($value < $min) { |
||||||
| 43 | $amount = 0; |
||||||
| 44 | } |
||||||
| 45 | |||||||
| 46 | if ($amount > $value) { |
||||||
| 47 | $amount = $value; |
||||||
| 48 | } |
||||||
| 49 | |||||||
| 50 | return $amount; |
||||||
| 51 | } |
||||||
| 52 | |||||||
| 53 | public function appliedAmount(AppliedDiscount $item) |
||||||
| 54 | { |
||||||
| 55 | return $this->calculateAmount($item->Estimate()); |
||||||
|
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...
|
|||||||
| 56 | } |
||||||
| 57 | } |
||||||
| 58 |