Skip to content

Commit

Permalink
default item attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgergo committed Mar 28, 2024
1 parent de8f0ca commit 28bdd25
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/Models/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,10 @@ public function toItem(Itemable $itemable, array $attributes = []): Item
return $variant->toItem($itemable, $attributes);
}

return $this->items()->make(array_merge($attributes, [
return $this->items()->make(array_merge([
'name' => $this->name,
'price' => $this->getPrice($itemable->getCurrency()),
]))->setRelation('buyable', $this);
'quantity' => 1,
], $attributes))->setRelation('buyable', $this);
}
}
5 changes: 3 additions & 2 deletions src/Models/Variant.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,10 @@ public function getPrice(?string $currency = null): ?float
*/
public function toItem(Itemable $itemable, array $attributes = []): Item
{
return $this->items()->make(array_merge($attributes, [
return $this->items()->make(array_merge([
'name' => sprintf('%s - %s', $this->product->name, $this->alias),
'price' => $this->getPrice($itemable->getCurrency()),
]))->setRelation('buyable', $this);
'quantity' => 1,
], $attributes))->setRelation('buyable', $this);
}
}

0 comments on commit 28bdd25

Please sign in to comment.