Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/Core/Baskets/Factories/BasketLineFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,16 @@ public function get()

foreach ($this->discounts->get() as $discount) {
foreach ($discount->rewards as $reward) {
$method = 'apply'.ucfirst($reward->type);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you just change it to Str::camelCase and ucfirst so fixed_amount becomes FixedAmount?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would be better, although I appreciate this PR is quite old now so might need revisiting in full.

if (method_exists($this, $method)) {
$line = $this->{$method}($line, $reward);
switch ($reward['type']) {
case 'percentage_amount':
$line = $this->applyPercentage($line, $reward);
break;
case 'fixed_amount':
$line = $this->applyFixedAmount($line, $reward);
break;
case 'to_fixed_price':
$line = $this->applyToFixedAmount($line, $reward);
break;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Controllers/Baskets/BasketController.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function addDiscount($basketId, AddDiscountRequest $request, DiscountServ
$factory = $this->factory->init($basket);
$factory->lines->discount($discount->set->discount);

$discount->uses ? $discount->increment('uses') : 1;
$discount->set->discount->increment('uses');

if (! $basket->discount($request->coupon)) {
$basket->discounts()->attach($discount->set->discount->id, ['coupon' => $request->coupon]);
Expand Down