1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace GGGGino\SkuskuCartBundle\Model; |
4
|
|
|
|
5
|
|
|
use Doctrine\ORM\Mapping as ORM; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* SkuskuCartProductBase |
9
|
|
|
* @ORM\MappedSuperclass() |
10
|
|
|
*/ |
11
|
|
|
abstract class SkuskuCartProductBase implements SkuskuCartProductInterface |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @ORM\ManyToOne(targetEntity="SkuskuCart", inversedBy="products") |
15
|
|
|
* @ORM\JoinColumn(name="cart_id", referencedColumnName="id") |
16
|
|
|
* @var SkuskuCart |
17
|
|
|
*/ |
18
|
|
|
protected $cart; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @ORM\ManyToOne(targetEntity="SkuskuProductInterface", cascade={"persist"}) |
22
|
|
|
* @ORM\JoinColumn(name="product_id", referencedColumnName="id") |
23
|
|
|
* @var SkuskuProductInterface |
24
|
|
|
*/ |
25
|
|
|
protected $product; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var int |
29
|
|
|
* |
30
|
|
|
* @ORM\Column(name="quantity", type="integer") |
31
|
|
|
*/ |
32
|
|
|
private $quantity; |
33
|
|
|
|
34
|
|
|
public function __toString() |
35
|
|
|
{ |
36
|
|
|
return "SkuskuCartProductBase"; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @return mixed |
41
|
|
|
*/ |
42
|
|
|
public function getProduct() |
43
|
|
|
{ |
44
|
|
|
return $this->product; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param mixed $product |
49
|
|
|
* @return SkuskuCartProductBase |
50
|
|
|
*/ |
51
|
|
|
public function setProduct($product) |
52
|
|
|
{ |
53
|
|
|
$this->product = $product; |
54
|
|
|
return $this; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @return int |
59
|
|
|
*/ |
60
|
|
|
public function getQuantity() |
61
|
|
|
{ |
62
|
|
|
return $this->quantity; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param int $quantity |
67
|
|
|
* @return SkuskuCartProductBase |
68
|
|
|
*/ |
69
|
|
|
public function setQuantity($quantity) |
70
|
|
|
{ |
71
|
|
|
$this->quantity = $quantity; |
72
|
|
|
return $this; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @return mixed |
77
|
|
|
*/ |
78
|
|
|
public function getCart() |
79
|
|
|
{ |
80
|
|
|
return $this->cart; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @param mixed $cart |
85
|
|
|
* @return SkuskuCartProductBase |
86
|
|
|
*/ |
87
|
|
|
public function setCart($cart) |
88
|
|
|
{ |
89
|
|
|
$this->cart = $cart; |
90
|
|
|
return $this; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Get the amount of price of the product in the cart |
95
|
|
|
* |
96
|
|
|
* @return float |
97
|
|
|
*/ |
98
|
|
|
public function getSubtotal() |
99
|
|
|
{ |
100
|
|
|
return $this->getProductPrice() * $this->quantity; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Get the amount of price of the single product |
105
|
|
|
* |
106
|
|
|
* @return float |
107
|
|
|
*/ |
108
|
|
|
public function getProductPrice() |
109
|
|
|
{ |
110
|
|
|
return $this->getProduct()->getPrice(); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
public function getProductAttribute(){} |
114
|
|
|
} |
115
|
|
|
|