|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace ByTIC\GoogleAnalytics\Tracking\Data\Ecommerce; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Class Transaction |
|
7
|
|
|
* @package ByTIC\GoogleAnalytics\Tracking\Data\Ecommerce |
|
8
|
|
|
*/ |
|
9
|
|
|
class Item |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* @var string The transaction ID. This ID is what links items to the transactions to which they belong. (e.g. 1234) |
|
13
|
|
|
*/ |
|
14
|
|
|
protected $transactionId; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @var string The item name. (e.g. Fluffy Pink Bunnies) |
|
18
|
|
|
*/ |
|
19
|
|
|
protected $name; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @var string Specifies the SKU or item code. (e.g. SKU47) |
|
23
|
|
|
*/ |
|
24
|
|
|
protected $sku; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var string The category to which the item belongs (e.g. Party Toys) |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $category; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var float The individual, unit, price for each item. (e.g. 11.99) |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $price; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @var int The number of units purchased in the transaction. |
|
38
|
|
|
* If a non-integer value is passed into this field (e.g. 1.5), it will be rounded to the closest integer value. |
|
39
|
|
|
*/ |
|
40
|
|
|
protected $quantity; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @param $params |
|
44
|
|
|
* @return static |
|
45
|
|
|
*/ |
|
46
|
|
|
public static function createFromArray($params) |
|
47
|
|
|
{ |
|
48
|
|
|
$transaction = new static(); |
|
49
|
|
|
$transaction->populateFromParams($params); |
|
50
|
|
|
return $transaction; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @param $params |
|
55
|
|
|
*/ |
|
56
|
|
|
public function populateFromParams($params) |
|
57
|
|
|
{ |
|
58
|
|
|
foreach ($params as $key => $param) { |
|
59
|
|
|
if (property_exists($this, $key)) { |
|
60
|
|
|
$this->{$key} = $param; |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @return string |
|
67
|
|
|
*/ |
|
68
|
|
|
public function getTransactionId(): string |
|
69
|
|
|
{ |
|
70
|
|
|
return $this->transactionId; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @param string $transactionId |
|
75
|
|
|
*/ |
|
76
|
|
|
public function setTransactionId(string $transactionId) |
|
77
|
|
|
{ |
|
78
|
|
|
$this->transactionId = $transactionId; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @return string |
|
83
|
|
|
*/ |
|
84
|
|
|
public function getName(): string |
|
85
|
|
|
{ |
|
86
|
|
|
return $this->name; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @param string $name |
|
91
|
|
|
*/ |
|
92
|
|
|
public function setName(string $name) |
|
93
|
|
|
{ |
|
94
|
|
|
$this->name = $name; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @return string |
|
99
|
|
|
*/ |
|
100
|
|
|
public function getSku() |
|
101
|
|
|
{ |
|
102
|
|
|
return $this->sku; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* @param string $sku |
|
107
|
|
|
*/ |
|
108
|
|
|
public function setSku(string $sku) |
|
109
|
|
|
{ |
|
110
|
|
|
$this->sku = $sku; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* @return string |
|
115
|
|
|
*/ |
|
116
|
|
|
public function getCategory() |
|
117
|
|
|
{ |
|
118
|
|
|
return $this->category; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* @param string $category |
|
123
|
|
|
*/ |
|
124
|
|
|
public function setCategory(string $category) |
|
125
|
|
|
{ |
|
126
|
|
|
$this->category = $category; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* @return float |
|
131
|
|
|
*/ |
|
132
|
|
|
public function getPrice() |
|
133
|
|
|
{ |
|
134
|
|
|
return $this->price; |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* @param float $price |
|
139
|
|
|
*/ |
|
140
|
|
|
public function setPrice(float $price) |
|
141
|
|
|
{ |
|
142
|
|
|
$this->price = $price; |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
/** |
|
146
|
|
|
* @return int |
|
147
|
|
|
*/ |
|
148
|
|
|
public function getQuantity() |
|
149
|
|
|
{ |
|
150
|
|
|
return $this->quantity; |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
/** |
|
154
|
|
|
* @param int $quantity |
|
155
|
|
|
*/ |
|
156
|
|
|
public function setQuantity(int $quantity) |
|
157
|
|
|
{ |
|
158
|
|
|
$this->quantity = $quantity; |
|
159
|
|
|
} |
|
160
|
|
|
} |
|
161
|
|
|
|