From 329b4b50f9be75ee4263f6e09494d38c37bdb0c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=2E=20Nagy=20Gerg=C5=91?= Date: Tue, 2 Apr 2024 15:46:40 +0200 Subject: [PATCH] wip --- src/Models/Variant.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Models/Variant.php b/src/Models/Variant.php index 4717d867..b779a2e7 100644 --- a/src/Models/Variant.php +++ b/src/Models/Variant.php @@ -83,6 +83,20 @@ public function product(): BelongsTo ->withDefault(); } + /** + * Get the name attribute. + * + * @return \Illuminate\Database\Eloquent\Casts\Attribute + */ + protected function name(): Attribute + { + return new Attribute( + get: function (): string { + return sprintf('%s - %s', $this->product->name, $this->alias); + } + ); + } + /** * Get the alias attribute. * @@ -111,7 +125,7 @@ public function getPrice(?string $currency = null): ?float public function toItem(Itemable $itemable, array $attributes = []): Item { return $this->items()->make(array_merge([ - 'name' => sprintf('%s - %s', $this->product->name, $this->alias), + 'name' => $this->name, 'price' => $this->getPrice($itemable->getCurrency()), 'quantity' => 1, ], $attributes))->setRelation('buyable', $this);