|
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 Transaction |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* @var string The transaction ID. (e.g. 1234) Required |
|
13
|
|
|
*/ |
|
14
|
|
|
protected $id; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @var string The store or affiliation from which this transaction occurred (e.g. Acme Clothing). |
|
18
|
|
|
*/ |
|
19
|
|
|
protected $affiliation; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @var float Specifies the total revenue or grand total associated with the transaction (e.g. 11.99). |
|
23
|
|
|
*/ |
|
24
|
|
|
protected $revenue; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @var float Specifies the total shipping cost of the transaction. (e.g. 5) |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $shipping; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var float Specifies the total tax of the transaction. (e.g. 1.29) |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $tax; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @var string The local currency must be specified in the ISO 4217 standard. |
|
38
|
|
|
*/ |
|
39
|
|
|
protected $currency; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @var Item[] |
|
43
|
|
|
*/ |
|
44
|
|
|
protected $items = []; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @param $params |
|
48
|
|
|
* @return static |
|
49
|
|
|
*/ |
|
50
|
2 |
|
public static function createFromArray($params) |
|
51
|
|
|
{ |
|
52
|
2 |
|
$transaction = new static(); |
|
53
|
2 |
|
$transaction->populateFromParams($params); |
|
54
|
2 |
|
return $transaction; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @param $params |
|
59
|
|
|
*/ |
|
60
|
2 |
|
public function populateFromParams($params) |
|
61
|
|
|
{ |
|
62
|
2 |
|
foreach ($params as $key => $param) { |
|
63
|
2 |
|
if (property_exists($this, $key)) { |
|
64
|
2 |
|
$this->{$key} = $param; |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
2 |
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @return string |
|
71
|
|
|
*/ |
|
72
|
2 |
|
public function getId() |
|
73
|
|
|
{ |
|
74
|
2 |
|
return $this->id; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @param string $id |
|
79
|
|
|
*/ |
|
80
|
|
|
public function setId(string $id) |
|
81
|
|
|
{ |
|
82
|
|
|
$this->id = $id; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @return string |
|
87
|
|
|
*/ |
|
88
|
2 |
|
public function getAffiliation() |
|
89
|
|
|
{ |
|
90
|
2 |
|
return $this->affiliation; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* @param string $affiliation |
|
95
|
|
|
*/ |
|
96
|
|
|
public function setAffiliation(string $affiliation) |
|
97
|
|
|
{ |
|
98
|
|
|
$this->affiliation = $affiliation; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* @return float |
|
103
|
|
|
*/ |
|
104
|
2 |
|
public function getRevenue() |
|
105
|
|
|
{ |
|
106
|
2 |
|
return $this->revenue; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* @param float $revenue |
|
111
|
|
|
*/ |
|
112
|
|
|
public function setRevenue(float $revenue) |
|
113
|
|
|
{ |
|
114
|
|
|
$this->revenue = $revenue; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* @return float |
|
119
|
|
|
*/ |
|
120
|
2 |
|
public function getShipping() |
|
121
|
|
|
{ |
|
122
|
2 |
|
return $this->shipping; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* @param float $shipping |
|
127
|
|
|
*/ |
|
128
|
|
|
public function setShipping(float $shipping) |
|
129
|
|
|
{ |
|
130
|
|
|
$this->shipping = $shipping; |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* @return float |
|
135
|
|
|
*/ |
|
136
|
2 |
|
public function getTax() |
|
137
|
|
|
{ |
|
138
|
2 |
|
return $this->tax; |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* @param float $tax |
|
143
|
|
|
*/ |
|
144
|
|
|
public function setTax(float $tax) |
|
145
|
|
|
{ |
|
146
|
|
|
$this->tax = $tax; |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
/** |
|
150
|
|
|
* @return string |
|
151
|
|
|
*/ |
|
152
|
2 |
|
public function getCurrency() |
|
153
|
|
|
{ |
|
154
|
2 |
|
return $this->currency; |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
/** |
|
158
|
|
|
* @param string $currency |
|
159
|
|
|
*/ |
|
160
|
|
|
public function setCurrency(string $currency) |
|
161
|
|
|
{ |
|
162
|
|
|
$this->currency = $currency; |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
/** |
|
166
|
|
|
* @return Item[] |
|
167
|
|
|
*/ |
|
168
|
|
|
public function getItems(): array |
|
169
|
|
|
{ |
|
170
|
|
|
return $this->items; |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
/** |
|
174
|
|
|
* @param Item $item |
|
175
|
|
|
*/ |
|
176
|
|
|
public function addItem(Item $item) |
|
177
|
|
|
{ |
|
178
|
|
|
$sku = $item->getSku(); |
|
179
|
|
|
if ($sku) { |
|
180
|
|
|
$this->items[$sku] = $item; |
|
181
|
|
|
} else { |
|
182
|
|
|
$this->items[] = $item; |
|
183
|
|
|
} |
|
184
|
|
|
} |
|
185
|
|
|
} |
|
186
|
|
|
|