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);