yaroslawww /
laravel-quick-checkout
| 1 | <?php |
||
| 2 | |||
| 3 | namespace QuickCheckout\Eloquent; |
||
| 4 | |||
| 5 | use QuickCheckout\CartProduct; |
||
| 6 | use QuickCheckout\Contracts\ProductInterface; |
||
| 7 | use QuickCheckout\Product; |
||
| 8 | |||
| 9 | trait AsCheckoutProduct |
||
| 10 | { |
||
| 11 | 5 | public function checkoutProductTitle(): string |
|
| 12 | { |
||
| 13 | 5 | return (string) $this->title; |
|
| 14 | } |
||
| 15 | |||
| 16 | 5 | public function checkoutProductPrice(): int |
|
| 17 | { |
||
| 18 | 5 | return (int) $this->price; |
|
| 19 | } |
||
| 20 | |||
| 21 | 5 | public function checkoutProductMeta(): array |
|
| 22 | { |
||
| 23 | 5 | return array_merge(CartProduct::getModelDataAsEntity($this), $this->checkoutProductGeneralMeta()); |
|
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 24 | } |
||
| 25 | |||
| 26 | 4 | public function checkoutProductGeneralMeta(): array |
|
| 27 | { |
||
| 28 | 4 | return []; |
|
| 29 | } |
||
| 30 | |||
| 31 | 5 | public function checkoutProductClass(): string |
|
| 32 | { |
||
| 33 | 5 | return Product::class; |
|
| 34 | } |
||
| 35 | |||
| 36 | 5 | public function toCheckoutProduct(array $meta = []): ProductInterface |
|
| 37 | { |
||
| 38 | 5 | $class = $this->checkoutProductClass(); |
|
| 39 | |||
| 40 | 5 | return new $class( |
|
| 41 | 5 | $this->checkoutProductTitle(), |
|
| 42 | 5 | $this->checkoutProductPrice(), |
|
| 43 | 5 | array_merge($this->checkoutProductMeta(), $meta), |
|
| 44 | ); |
||
| 45 | } |
||
| 46 | } |
||
| 47 |