Skip to content

Commit d698488

Browse files
committed
wip
1 parent 0168b80 commit d698488

File tree

5 files changed

+25
-19
lines changed

5 files changed

+25
-19
lines changed

src/Interfaces/Discountable.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Cone\Bazar\Interfaces;
66

7+
use Cone\Bazar\Enums\Currency;
78
use Cone\Bazar\Models\DiscountRule;
89
use Illuminate\Database\Eloquent\Relations\MorphToMany;
910
use Illuminate\Support\Collection;
@@ -64,4 +65,9 @@ public function getDiscountableQuantity(): float;
6465
* Get the applicable discount rules.
6566
*/
6667
public function getApplicableDiscountRules(): Collection;
68+
69+
/**
70+
* Get the discountable currency.
71+
*/
72+
public function getDiscountableCurrency(): Currency;
6773
}

src/Models/Item.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Cone\Bazar\Models;
66

77
use Cone\Bazar\Database\Factories\ItemFactory;
8+
use Cone\Bazar\Enums\Currency;
89
use Cone\Bazar\Interfaces\Buyable;
910
use Cone\Bazar\Interfaces\Models\Item as Contract;
1011
use Cone\Bazar\Traits\InteractsWithDiscounts;
@@ -350,10 +351,10 @@ public function getApplicableDiscountRules(): Collection
350351
}
351352

352353
/**
353-
* Get the formatted discount.
354+
* Get the discountable currency.
354355
*/
355-
public function getFormattedDiscount(): string
356+
public function getDiscountableCurrency(): Currency
356357
{
357-
return $this->checkoutable->getCurrency()->format($this->getDiscount());
358+
return $this->checkoutable->getCurrency();
358359
}
359360
}

src/Models/Shipping.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Cone\Bazar\Models;
66

77
use Cone\Bazar\Database\Factories\ShippingFactory;
8+
use Cone\Bazar\Enums\Currency;
89
use Cone\Bazar\Interfaces\Models\Shipping as Contract;
910
use Cone\Bazar\Support\Facades\Shipping as Manager;
1011
use Cone\Bazar\Traits\Addressable;
@@ -350,11 +351,11 @@ public function getDiscountableQuantity(): float
350351
}
351352

352353
/**
353-
* Get the formatted discount.
354+
* Get the discountable currency.
354355
*/
355-
public function getFormattedDiscount(): string
356+
public function getDiscountableCurrency(): Currency
356357
{
357-
return $this->shippable->getCurrency()->format($this->getDiscount());
358+
return $this->shippable->getCurrency();
358359
}
359360

360361
/**

src/Traits/AsOrder.php

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
use Illuminate\Support\Arr;
3030
use Illuminate\Support\Collection;
3131
use Illuminate\Support\Facades\App;
32-
use Illuminate\Support\Number;
3332
use Throwable;
3433

3534
trait AsOrder
@@ -342,7 +341,6 @@ public function calculateTax(): float
342341
*/
343342
public function findItem(array $attributes): ?Item
344343
{
345-
346344
$attributes = array_merge(['properties' => null], $attributes, [
347345
'checkoutable_id' => $this->getKey(),
348346
'checkoutable_type' => static::class,
@@ -459,19 +457,11 @@ public function getDiscount(): float
459457
}
460458

461459
/**
462-
* Get the formatted discount.
463-
*/
464-
public function getFormattedDiscount(): string
465-
{
466-
return $this->getCurrency()->format($this->getDiscount());
467-
}
468-
469-
/**
470-
* Get the formatted discount rate.
460+
* Get the discountable currency.
471461
*/
472-
public function getFormattedDiscountRate(): string
462+
public function getDiscountableCurrency(): Currency
473463
{
474-
return Number::percentage($this->getDiscountRate());
464+
return $this->getCurrency();
475465
}
476466

477467
/**

src/Traits/InteractsWithDiscounts.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,12 @@ public function calculateDiscount(): float
110110

111111
return $this->getDiscount();
112112
}
113+
114+
/**
115+
* Get the formatted discount.
116+
*/
117+
public function getFormattedDiscount(): string
118+
{
119+
return $this->getDiscountableCurrency()->format($this->getDiscount());
120+
}
113121
}

0 commit comments

Comments
 (0)