1
|
|
|
<?php
|
2
|
|
|
|
3
|
|
|
namespace Swader\Diffbot\Entity;
|
4
|
|
|
|
5
|
|
|
use Swader\Diffbot\Abstracts\Entity;
|
6
|
|
|
use Swader\Diffbot\Traits\StandardEntity;
|
7
|
|
|
|
8
|
|
|
class Product extends Entity
|
9
|
|
|
{
|
10
|
|
|
use StandardEntity;
|
11
|
|
|
|
12
|
|
|
/** @var Discussion */
|
13
|
|
|
protected $discussion = null;
|
14
|
|
|
|
15
|
62 |
|
public function __construct(array $data)
|
16
|
|
|
{
|
17
|
62 |
|
parent::__construct($data);
|
18
|
62 |
|
if (isset($this->data['discussion'])) {
|
19
|
25 |
|
$this->discussion = new Discussion($this->data['discussion']);
|
20
|
25 |
|
}
|
21
|
|
|
|
22
|
62 |
|
if (!isset($this->data['offerPrice'])) {
|
23
|
1 |
|
$this->data['availability'] = false;
|
24
|
1 |
|
$this->data['offerPrice'] = null;
|
25
|
1 |
|
$this->data['offerPriceDetails'] = [];
|
26
|
1 |
|
}
|
27
|
62 |
|
}
|
28
|
|
|
|
29
|
|
|
/**
|
30
|
|
|
* Should always return "product"
|
31
|
|
|
* @return string
|
32
|
|
|
*/
|
33
|
2 |
|
public function getType()
|
34
|
|
|
{
|
35
|
2 |
|
return $this->data['type'];
|
36
|
|
|
}
|
37
|
|
|
|
38
|
|
|
/**
|
39
|
|
|
* Text description, if available, of the product
|
40
|
|
|
* @return string|null
|
41
|
|
|
*/
|
42
|
2 |
|
public function getText()
|
43
|
|
|
{
|
44
|
2 |
|
return (isset($this->data['text'])) ? $this->data['text'] : null;
|
45
|
|
|
}
|
46
|
|
|
|
47
|
|
|
/**
|
48
|
|
|
* Regular or original price of the product, if available.
|
49
|
|
|
* If not available, offerPrice is returned instead.
|
50
|
|
|
*
|
51
|
|
|
* @return string
|
52
|
|
|
*/
|
53
|
2 |
|
public function getRegularPrice()
|
54
|
|
|
{
|
55
|
2 |
|
return (isset($this->data['regularPrice']))
|
56
|
2 |
|
? $this->data['regularPrice'] : $this->data['offerPrice'];
|
57
|
|
|
}
|
58
|
|
|
|
59
|
|
|
/**
|
60
|
|
|
* regularPrice separated into its constituent parts: amount, symbol, and full text.
|
61
|
|
|
*
|
62
|
|
|
* @return array
|
63
|
|
|
*/
|
64
|
2 |
|
public function getRegularPriceDetails()
|
65
|
|
|
{
|
66
|
2 |
|
return (isset($this->data['regularPriceDetails']))
|
67
|
2 |
|
? $this->data['regularPriceDetails'] : $this->getOfferPriceDetails();
|
68
|
|
|
}
|
69
|
|
|
|
70
|
|
|
/**
|
71
|
|
|
* Returns the shipping amount, if available. If not available, returns null.
|
72
|
|
|
* @return string|null
|
73
|
|
|
*/
|
74
|
2 |
|
public function getShippingAmount()
|
75
|
|
|
{
|
76
|
2 |
|
return (isset($this->data['shippingAmount'])) ? $this->data['shippingAmount'] : null;
|
77
|
|
|
}
|
78
|
|
|
|
79
|
|
|
/**
|
80
|
|
|
* Discount or amount saved off the regular price.
|
81
|
|
|
* Recommended to use getSaveAmountDetails instead
|
82
|
|
|
* @see getSaveAmountDetails()
|
83
|
|
|
* @return string|null
|
84
|
|
|
*/
|
85
|
2 |
|
public function getSaveAmount()
|
86
|
|
|
{
|
87
|
2 |
|
return (isset($this->data['saveAmount'])) ? $this->data['saveAmount'] : null;
|
88
|
|
|
}
|
89
|
|
|
|
90
|
|
|
/**
|
91
|
|
|
* saveAmount separated into its constituent parts: amount, symbol, full text,
|
92
|
|
|
* and whether or not it is a percentage value.
|
93
|
|
|
* @return array
|
94
|
|
|
*/
|
95
|
2 |
|
public function getSaveAmountDetails()
|
96
|
|
|
{
|
97
|
2 |
|
return (isset($this->data['saveAmountDetails'])) ? $this->data['saveAmountDetails'] : [];
|
98
|
|
|
}
|
99
|
|
|
|
100
|
|
|
/**
|
101
|
|
|
* Diffbot-determined unique product ID. If upc, isbn, mpn or sku are identified on the page,
|
102
|
|
|
* productId will select from these values in the above order.
|
103
|
|
|
* @return string|null
|
104
|
|
|
*/
|
105
|
2 |
|
public function getProductId()
|
106
|
|
|
{
|
107
|
2 |
|
return (isset($this->data['productId'])) ? $this->data['productId'] : null;
|
108
|
|
|
}
|
109
|
|
|
|
110
|
|
|
/**
|
111
|
|
|
* Universal Product Code (UPC/EAN), if available.
|
112
|
|
|
* @return string|null
|
113
|
|
|
*/
|
114
|
2 |
|
public function getUpc()
|
115
|
|
|
{
|
116
|
2 |
|
return (isset($this->data['upc'])) ? $this->data['upc'] : null;
|
117
|
|
|
}
|
118
|
|
|
|
119
|
|
|
/**
|
120
|
|
|
* Manufacturer's Product Number.
|
121
|
|
|
* @return string|null
|
122
|
|
|
*/
|
123
|
2 |
|
public function getMpn()
|
124
|
|
|
{
|
125
|
2 |
|
return (isset($this->data['mpn'])) ? $this->data['mpn'] : null;
|
126
|
|
|
}
|
127
|
|
|
|
128
|
|
|
/**
|
129
|
|
|
* International Standard Book Number (ISBN), if available.
|
130
|
|
|
* @return string|null
|
131
|
|
|
*/
|
132
|
2 |
|
public function getIsbn()
|
133
|
|
|
{
|
134
|
2 |
|
return (isset($this->data['isbn'])) ? $this->data['isbn'] : null;
|
135
|
|
|
}
|
136
|
|
|
|
137
|
|
|
/**
|
138
|
|
|
* If a specifications table or similar data is available on the product page,
|
139
|
|
|
* individual specifications will be returned in the specs object as name/value pairs.
|
140
|
|
|
* Names will be normalized to lowercase with spaces replaced by underscores, e.g. display_resolution.
|
141
|
|
|
*
|
142
|
|
|
* @return array
|
143
|
|
|
*/
|
144
|
2 |
|
public function getSpecs()
|
145
|
|
|
{
|
146
|
2 |
|
return (isset($this->data['specs'])) ? $this->data['specs'] : [];
|
147
|
|
|
}
|
148
|
|
|
|
149
|
|
|
/**
|
150
|
|
|
* Returns an array of images found in the page's content.
|
151
|
|
|
*
|
152
|
|
|
* Note that this (tries) to ignore content-unrelated images like ads arounds the page, etc.
|
153
|
|
|
* The format of the array will be:
|
154
|
|
|
*
|
155
|
|
|
* [
|
156
|
|
|
* {
|
157
|
|
|
* "height": 808,
|
158
|
|
|
* "diffbotUri": "image|3|-543943368",
|
159
|
|
|
* "naturalHeight": 808,
|
160
|
|
|
* "width": 717,
|
161
|
|
|
* "primary": true,
|
162
|
|
|
* "naturalWidth": 717,
|
163
|
|
|
* "url": "https://example.com/image1.png"
|
164
|
|
|
* },
|
165
|
|
|
* {
|
166
|
|
|
* "height": 506,
|
167
|
|
|
* "diffbotUri": "image|3|-844014913",
|
168
|
|
|
* "naturalHeight": 506,
|
169
|
|
|
* "width": 715,
|
170
|
|
|
* "naturalWidth": 715,
|
171
|
|
|
* "url": "https://example.com/image1.jpeg"
|
172
|
|
|
* }
|
173
|
|
|
* ]
|
174
|
|
|
*
|
175
|
|
|
* @return array
|
176
|
|
|
*/
|
177
|
2 |
|
public function getImages()
|
178
|
|
|
{
|
179
|
2 |
|
return (isset($this->data['images'])) ? $this->data['images'] : [];
|
180
|
|
|
}
|
181
|
|
|
|
182
|
|
|
/**
|
183
|
|
|
* Country of origin as identified by UPC/ISBN. Null if not present.
|
184
|
|
|
* @return string|null
|
185
|
|
|
*/
|
186
|
2 |
|
public function getPrefixCode()
|
187
|
|
|
{
|
188
|
2 |
|
return (isset($this->data['prefixCode'])) ? $this->data['prefixCode'] : null;
|
189
|
|
|
}
|
190
|
|
|
|
191
|
|
|
/**
|
192
|
|
|
* If available, two-character ISO country code where the product was produced. Null if not present.
|
193
|
|
|
* @return string|null
|
194
|
|
|
*/
|
195
|
2 |
|
public function getProductOrigin()
|
196
|
|
|
{
|
197
|
2 |
|
return (isset($this->data['productOrigin'])) ? $this->data['productOrigin'] : null;
|
198
|
|
|
}
|
199
|
|
|
|
200
|
|
|
/**
|
201
|
|
|
* If the product is available in a range of prices, the minimum and maximum values will be returned.
|
202
|
|
|
* The lowest price will also be returned as the offerPrice.
|
203
|
|
|
* @return array|null
|
204
|
|
|
*/
|
205
|
2 |
|
public function getPriceRange()
|
206
|
|
|
{
|
207
|
2 |
|
return (isset($this->data['priceRange'])) ? $this->data['priceRange'] : null;
|
208
|
|
|
}
|
209
|
|
|
|
210
|
|
|
/**
|
211
|
|
|
* If the product is available with quantity-based discounts, all identifiable price points will be returned.
|
212
|
|
|
* The lowest price will also be returned as the offerPrice.
|
213
|
|
|
*
|
214
|
|
|
* @return array|null
|
215
|
|
|
*/
|
216
|
2 |
|
public function getQuantityPrices()
|
217
|
|
|
{
|
218
|
2 |
|
return (isset($this->data['quantityPrices'])) ? $this->data['quantityPrices'] : null;
|
219
|
|
|
}
|
220
|
|
|
|
221
|
|
|
/**
|
222
|
|
|
* Checks if the product has been determined available. Null if it wasn't determined.
|
223
|
|
|
* @return bool|null
|
224
|
|
|
*/
|
225
|
2 |
|
public function isAvailable()
|
226
|
|
|
{
|
227
|
2 |
|
return (isset($this->data['availability'])) ? (bool)$this->data['availability'] : null;
|
228
|
|
|
}
|
229
|
|
|
|
230
|
|
|
/**
|
231
|
|
|
* Offer or actual/final price of the product.
|
232
|
|
|
* @return string | null
|
233
|
|
|
*/
|
234
|
2 |
|
public function getOfferPrice()
|
235
|
|
|
{
|
236
|
2 |
|
return $this->data['offerPrice'];
|
237
|
|
|
}
|
238
|
|
|
|
239
|
|
|
/**
|
240
|
|
|
* Size(s) available, if identified on the page.
|
241
|
|
|
* @return null|array
|
242
|
|
|
*/
|
243
|
2 |
|
public function getSize()
|
244
|
|
|
{
|
245
|
2 |
|
return (isset($this->data['size'])) ? $this->data['size'] : null;
|
246
|
|
|
}
|
247
|
|
|
|
248
|
|
|
/**
|
249
|
|
|
* Returns array of product color options.
|
250
|
|
|
* @return null|array
|
251
|
|
|
*/
|
252
|
2 |
|
public function getColors()
|
253
|
|
|
{
|
254
|
2 |
|
return (isset($this->data['colors'])) ? $this->data['colors'] : null;
|
255
|
|
|
}
|
256
|
|
|
|
257
|
|
|
/**
|
258
|
|
|
* Returns the brand, as determined by Diffbot
|
259
|
|
|
* @return string
|
260
|
|
|
*/
|
261
|
2 |
|
public function getBrand()
|
262
|
|
|
{
|
263
|
2 |
|
return (isset($this->data['brand'])) ? $this->data['brand'] : null;
|
264
|
|
|
}
|
265
|
|
|
|
266
|
|
|
/**
|
267
|
|
|
* Returns Stock Keeping Unit -- store/vendor inventory number or identifier.
|
268
|
|
|
* @return string
|
269
|
|
|
*/
|
270
|
2 |
|
public function getSku()
|
271
|
|
|
{
|
272
|
2 |
|
return (isset($this->data['sku'])) ? $this->data['sku'] : null;
|
273
|
|
|
}
|
274
|
|
|
|
275
|
|
|
/**
|
276
|
|
|
* offerPrice separated into its constituent parts: amount, symbol, and full text.
|
277
|
|
|
* @return array
|
278
|
|
|
*/
|
279
|
3 |
|
public function getOfferPriceDetails()
|
280
|
|
|
{
|
281
|
3 |
|
return $this->data['offerPriceDetails'];
|
282
|
|
|
}
|
283
|
|
|
|
284
|
|
|
/**
|
285
|
|
|
* Returns the Discussion entity - comments of the product
|
286
|
|
|
* @return Discussion
|
287
|
|
|
*/
|
288
|
2 |
|
public function getDiscussion()
|
289
|
|
|
{
|
290
|
2 |
|
return $this->discussion;
|
291
|
|
|
}
|
292
|
|
|
|
293
|
|
|
}
|
294
|
|
|
|