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

conedevelopment / bazar / 20213722262

14 Dec 2025 08:30PM UTC coverage: 63.031% (-0.4%) from 63.48%
20213722262

Pull #235

github

web-flow
Merge 03c6b2b10 into 090ff8496
Pull Request #235: Coupons & Discounts

0 of 3 new or added lines in 2 files covered. (0.0%)

53 existing lines in 11 files now uncovered.

965 of 1531 relevant lines covered (63.03%)

15.16 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\Bazar\Support\Currency;
11
use Cone\Root\Fields\MorphMany;
12
use Cone\Root\Fields\MorphTo;
13
use Cone\Root\Fields\Number;
14
use Cone\Root\Fields\Text;
15
use Illuminate\Database\Eloquent\Model;
16
use Illuminate\Http\Request;
17

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

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

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

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

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

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

70
            Number::make(__('Tax'), function (Request $request, Model $model): float {
64✔
UNCOV
71
                return $model->getTax();
×
72
            })->format(static function (Request $request, Model $model, float $value): string {
64✔
UNCOV
73
                return (new Currency($value, $model->checkoutable->currency))->format();
×
74
            }),
64✔
75

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

82
            Number::make(__('Total'), function (Request $request, Model $model): float {
64✔
UNCOV
83
                return $model->getTotal();
×
84
            })->format(static function (Request $request, Model $model, float $value): string {
64✔
UNCOV
85
                return (new Currency($value, $model->checkoutable->currency))->format();
×
86
            }),
64✔
87
        ];
64✔
88
    }
89
}
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