Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
57.14% |
4 / 7 |
|
25.00% |
1 / 4 |
CRAP | |
0.00% |
0 / 1 |
| CustomerGroup | |
57.14% |
4 / 7 |
|
25.00% |
1 / 4 |
6.97 | |
0.00% |
0 / 1 |
| booted | |
75.00% |
3 / 4 |
|
0.00% |
0 / 1 |
2.06 | |||
| auditName | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| priceLists | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| customers | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Models; |
| 4 | |
| 5 | use App\Models\admin\Customer; |
| 6 | use App\Support\Auditable; |
| 7 | use Illuminate\Database\Eloquent\Model; |
| 8 | use Illuminate\Support\Str; |
| 9 | |
| 10 | /** |
| 11 | * A pricing tier a customer can be assigned to (Retail, Wholesale, Dealer…). |
| 12 | * Only meaningful while the `wholesale_pricing` feature is on — see |
| 13 | * App\Services\Pricing\PriceService, which is the only thing that reads |
| 14 | * price_lists rows. |
| 15 | */ |
| 16 | class CustomerGroup extends Model |
| 17 | { |
| 18 | use Auditable; |
| 19 | |
| 20 | protected $fillable = ['name', 'slug', 'is_default', 'sort_order']; |
| 21 | |
| 22 | protected $casts = [ |
| 23 | 'is_default' => 'boolean', |
| 24 | 'sort_order' => 'integer', |
| 25 | ]; |
| 26 | |
| 27 | protected static function booted(): void |
| 28 | { |
| 29 | static::creating(function (CustomerGroup $group) { |
| 30 | if (empty($group->slug)) { |
| 31 | $group->slug = Str::slug($group->name); |
| 32 | } |
| 33 | }); |
| 34 | } |
| 35 | |
| 36 | protected function auditName(): string |
| 37 | { |
| 38 | return 'customer_group'; |
| 39 | } |
| 40 | |
| 41 | public function priceLists() |
| 42 | { |
| 43 | return $this->hasMany(PriceList::class); |
| 44 | } |
| 45 | |
| 46 | public function customers() |
| 47 | { |
| 48 | return $this->hasMany(Customer::class, 'customer_group_id'); |
| 49 | } |
| 50 | } |