This repository was archived by the owner on Aug 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuoteManager.php
More file actions
58 lines (48 loc) · 1.48 KB
/
QuoteManager.php
File metadata and controls
58 lines (48 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
/**
* Created on 01/10/17 by enea dhack.
*/
namespace Enea\Cashier;
use Enea\Cashier\Contracts\{KeyableContract, QuoteContract, QuotedProductContract};
use Enea\Cashier\Items\QuotedProductCartItem;
use Illuminate\Contracts\Support\{Arrayable, Jsonable};
use Illuminate\Support\Collection;
class QuoteManager extends ProductCollection implements Arrayable, Jsonable, KeyableContract
{
use IsJsonable;
protected QuoteContract $account;
public function __construct(QuoteContract $account)
{
parent::__construct(new Collection());
$this->loadQuotedProductsFrom($account);
$this->account = $account;
}
public function getUniqueIdentificationKey(): string
{
return $this->getQuote()->getUniqueIdentificationKey();
}
public function find(string $productID): ?QuotedProductCartItem
{
return $this->products()->get($productID);
}
public function getQuote(): QuoteContract
{
return $this->account;
}
/**
* {@inheritdoc}
*/
public function toArray()
{
return array_merge([
'id' => $this->getUniqueIdentificationKey(),
'properties' => $this->getQuote()->getProperties(),
], parent::toArray());
}
private function loadQuotedProductsFrom(QuoteContract $quote): void
{
$quote->getQuotedProducts()->map(fn(
QuotedProductContract $quoted
) => $this->addToCollection(new QuotedProductCartItem($quoted)));
}
}