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

conedevelopment / bazar / 20694116184

04 Jan 2026 02:08PM UTC coverage: 68.615% (+4.5%) from 64.117%
20694116184

push

github

iamgergo
version

1679 of 2447 relevant lines covered (68.61%)

25.06 hits per line

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

12.82
/src/Fields/VariantProperties.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Cone\Bazar\Fields;
6

7
use Closure;
8
use Cone\Root\Fields\MorphToMany;
9
use Cone\Root\Fields\Select;
10
use Illuminate\Database\Eloquent\Builder;
11
use Illuminate\Database\Eloquent\Model;
12
use Illuminate\Http\Request;
13
use Illuminate\Support\Collection;
14

15
class VariantProperties extends MorphToMany
16
{
17
    /**
18
     * The Blade template.
19
     */
20
    protected string $template = 'root::fields.fieldset';
21

22
    /**
23
     * The relations to eager load on every query.
24
     */
25
    protected array $with = [
26
        'property',
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)
101✔
33
    {
34
        parent::__construct($label, $modelAttribute, $relation);
101✔
35

36
        $this->display('name');
101✔
37
    }
38

39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function fields(Request $request): array
101✔
43
    {
44
        return [];
101✔
45
    }
46

47
    /**
48
     * {@inheritdoc}
49
     */
50
    public function resolveOptions(Request $request, Model $model): array
×
51
    {
52
        return [];
×
53
    }
54

55
    /**
56
     * {@inheritdoc}
57
     */
58
    public function getValueForHydrate(Request $request): mixed
×
59
    {
60
        $value = (array) $request->input($this->getRequestKey());
×
61

62
        $value = array_filter($value, static function (mixed $value): bool {
×
63
            return ! is_null($value);
×
64
        });
×
65

66
        return $this->mergePivotValues(array_values($value));
×
67
    }
68

69
    /**
70
     * Resolve the property fields.
71
     */
72
    public function resolvePropertyFields(Request $request, Model $model): array
×
73
    {
74
        $values = $this->resolveRelatableQuery($request, $model)->get();
×
75

76
        $value = $this->resolveValue($request, $model);
×
77

78
        return $values->groupBy('property_id')
×
79
            ->map(function (Collection $group) use ($request, $model, $value): array {
×
80
                return Select::make($group->first()->property->name, $this->modelAttribute.'.'.$group->first()->property->slug)
×
81
                    ->value(static function () use ($value, $group): ?int {
×
82
                        return $value->firstWhere('property_id', $group->first()->property_id)?->getKey();
×
83
                    })
×
84
                    ->options($group->pluck('name', 'id')->toArray())
×
85
                    ->nullable()
×
86
                    ->toInput($request, $model);
×
87
            })->toArray();
×
88
    }
89

90
    /**
91
     * {@inheritdoc}
92
     */
93
    public function resolveRelatableQuery(Request $request, Model $model): Builder
×
94
    {
95
        $query = parent::resolveRelatableQuery($request, $model);
×
96

97
        $product = $model->relationLoaded('product')
×
98
            ? $model->product
×
99
            : $model->product()->make()->forceFill(['id' => $model->product_id]);
×
100

101
        return $query->whereIn(
×
102
            $query->qualifyColumn('id'),
×
103
            $product->propertyValues()->select('bazar_property_values.id')
×
104
        );
×
105
    }
106

107
    /**
108
     * {@inheritdoc}
109
     */
110
    public function toInput(Request $request, Model $model): array
×
111
    {
112
        return array_merge(parent::toInput($request, $model), [
×
113
            'fields' => $this->resolvePropertyFields($request, $model),
×
114
        ]);
×
115
    }
116
}
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