Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgergo committed Apr 2, 2024
1 parent edee319 commit 329b4b5
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/Models/Variant.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,20 @@ public function product(): BelongsTo
->withDefault();
}

/**
* Get the name attribute.
*
* @return \Illuminate\Database\Eloquent\Casts\Attribute<string, never>
*/
protected function name(): Attribute
{
return new Attribute(
get: function (): string {
return sprintf('%s - %s', $this->product->name, $this->alias);
}
);
}

/**
* Get the alias attribute.
*
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 329b4b5

Please sign in to comment.