• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

conedevelopment / bazar / 20312410163

17 Dec 2025 05:58PM UTC coverage: 64.395% (+0.9%) from 63.48%
20312410163

push

github

web-flow
Merge pull request #235 from conedevelopment/coupons

Coupons & Discounts

204 of 260 new or added lines in 23 files covered. (78.46%)

8 existing lines in 1 file now uncovered.

1096 of 1702 relevant lines covered (64.39%)

18.27 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

75.61
/src/Fields/Items.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Cone\Bazar\Fields;
6

7
use Closure;
8
use Cone\Bazar\Models\Product;
9
use Cone\Bazar\Models\Variant;
10
use Cone\Root\Fields\MorphMany;
11
use Cone\Root\Fields\MorphTo;
12
use Cone\Root\Fields\Number;
13
use Cone\Root\Fields\Text;
14
use Illuminate\Database\Eloquent\Model;
15
use Illuminate\Http\Request;
16

17
class Items extends MorphMany
18
{
19
    /**
20
     * The relations to eager load on every query.
21
     */
22
    protected array $with = [
23
        'buyable',
24
        'checkoutable',
25
        'taxes',
26
    ];
27

28
    /**
29
     * Create a new relation field instance.
30
     */
31
    public function __construct(?string $label = null, Closure|string|null $modelAttribute = null, Closure|string|null $relation = null)
32
    {
33
        parent::__construct($label ?: __('Products'), $modelAttribute ?: 'items', $relation);
70✔
34

35
        $this->display('name');
70✔
36
        $this->asSubResource();
70✔
37
    }
38

39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function fields(Request $request): array
43
    {
44
        return [
70✔
45
            MorphTo::make(__('Buyable Item'), 'buyable')
70✔
46
                ->required()
70✔
47
                ->types([
70✔
48
                    Product::getProxiedClass(),
70✔
49
                    Variant::getProxiedClass(),
70✔
50
                ])
70✔
51
                ->display(static function (Model $relatable): string {
70✔
52
                    return (string) match ($relatable::class) {
×
53
                        Product::getProxiedClass() => $relatable->name,
×
54
                        Variant::getProxiedClass() => $relatable->alias,
×
55
                        default => $relatable->getKey(),
×
56
                    };
×
57
                }),
70✔
58

59
            Text::make(__('Name'), 'name')
70✔
60
                ->required(),
70✔
61

62
            Number::make(__('Price'), 'price')
70✔
63
                ->min(0)
70✔
64
                ->required()
70✔
65
                ->format(static function (Request $request, Model $model, ?float $value): string {
70✔
NEW
66
                    return $model->checkoutable->getCurrency()->format($value ?? 0);
×
67
                }),
70✔
68

69
            Number::make(__('Tax'), function (Request $request, Model $model): float {
70✔
70
                return $model->getTax();
×
71
            })->format(static function (Request $request, Model $model, float $value): string {
70✔
NEW
72
                return $model->checkoutable->getCurrency()->format($value ?? 0);
×
73
            }),
70✔
74

75
            Number::make(__('Quantity'), 'quantity')
70✔
76
                ->required()
70✔
77
                ->default(1)
70✔
78
                ->rules(['required', 'numeric', 'gt:0'])
70✔
79
                ->min(0),
70✔
80

81
            Number::make(__('Total'), function (Request $request, Model $model): float {
70✔
82
                return $model->getTotal();
×
83
            })->format(static function (Request $request, Model $model, float $value): string {
70✔
NEW
84
                return $model->checkoutable->getCurrency()->format($value ?? 0);
×
85
            }),
70✔
86
        ];
70✔
87
    }
88
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc