Skip to content

Commit b250e08

Browse files
Merge pull request #81 from findologic/SW-797_add_variants_logic
SW-797 Add variants logic
2 parents bcf89e7 + ea2c2ef commit b250e08

File tree

5 files changed

+333
-195
lines changed

5 files changed

+333
-195
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
<?php
2+
3+
namespace FINDOLOGIC\Api\Responses\Json10\Properties;
4+
5+
use FINDOLOGIC\Api\Helpers\ResponseHelper;
6+
7+
class BaseItem
8+
{
9+
/** @var string */
10+
private $id;
11+
12+
/** @var float */
13+
private $score;
14+
15+
/** @var ?string */
16+
private $url;
17+
18+
/** @var ?string */
19+
private $name;
20+
21+
/** @var string[] */
22+
private $ordernumbers = [];
23+
24+
/** @var ?string */
25+
private $matchingOrdernumber;
26+
27+
/** @var float */
28+
private $price;
29+
30+
/** @var ?string */
31+
private $summary;
32+
33+
/** @var array<string, array<string>> */
34+
private $attributes = [];
35+
36+
/** @var array<string, string> */
37+
private $properties = [];
38+
39+
/** @var ?string */
40+
private $imageUrl;
41+
42+
public function __construct(array $item)
43+
{
44+
$this->id = ResponseHelper::getStringProperty($item, 'id');
45+
$this->score = ResponseHelper::getFloatProperty($item, 'score', true);
46+
$this->url = ResponseHelper::getStringProperty($item, 'url');
47+
$this->name = ResponseHelper::getStringProperty($item, 'name');
48+
49+
if (isset($item['ordernumbers'])) {
50+
foreach ($item['ordernumbers'] as $ordernumber) {
51+
$this->ordernumbers[] = $ordernumber;
52+
}
53+
}
54+
$this->matchingOrdernumber = ResponseHelper::getStringProperty($item, 'matchingOrdernumber');
55+
$this->price = ResponseHelper::getFloatProperty($item, 'price', true);
56+
$this->summary = ResponseHelper::getStringProperty($item, 'summary');
57+
58+
if (isset($item['attributes'])) {
59+
$this->attributes = $item['attributes'];
60+
}
61+
if (isset($item['properties'])) {
62+
$this->properties = $item['properties'];
63+
}
64+
65+
$this->imageUrl = ResponseHelper::getStringProperty($item, 'imageUrl');
66+
}
67+
68+
/**
69+
* @return string
70+
*/
71+
public function getId()
72+
{
73+
return $this->id;
74+
}
75+
76+
/**
77+
* @return float
78+
*/
79+
public function getScore()
80+
{
81+
return $this->score;
82+
}
83+
84+
/**
85+
* @return string
86+
*/
87+
public function getUrl()
88+
{
89+
return $this->url;
90+
}
91+
92+
/**
93+
* @return string
94+
*/
95+
public function getName()
96+
{
97+
return $this->name;
98+
}
99+
100+
101+
/**
102+
* @return string[]
103+
*/
104+
public function getOrdernumbers()
105+
{
106+
return $this->ordernumbers;
107+
}
108+
109+
/**
110+
* @return string|null
111+
*/
112+
public function getMatchingOrdernumber()
113+
{
114+
return $this->matchingOrdernumber;
115+
}
116+
117+
/**
118+
* @return float
119+
*/
120+
public function getPrice()
121+
{
122+
return $this->price;
123+
}
124+
125+
/**
126+
* @return string|null
127+
*/
128+
public function getSummary()
129+
{
130+
return $this->summary;
131+
}
132+
133+
/**
134+
* Returns filters that are assigned to a product e.g.
135+
* ```
136+
* [
137+
* 'filter-name' => [
138+
* 'value1',
139+
* 'value2',
140+
* // ...
141+
* ]
142+
* ];
143+
* ```
144+
*
145+
* An attribute may only be returned when explicitly adding it to the request with
146+
* `$searchRequest->addOutputAttrib($filterName)`.
147+
*
148+
* @return array<string, array<string>>
149+
*/
150+
public function getAttributes()
151+
{
152+
return $this->attributes;
153+
}
154+
155+
/**
156+
* Returns the attribute/filter by the given name. If the attribute does not exist, the default may be returned.
157+
*
158+
* @param string $attributeName
159+
* @param mixed|null $default
160+
* @return array|mixed
161+
*/
162+
public function getAttribute($attributeName, $default = null)
163+
{
164+
if (!isset($this->attributes[$attributeName])) {
165+
return $default;
166+
}
167+
168+
return $this->attributes[$attributeName];
169+
}
170+
171+
/**
172+
* Returns properties that are assigned to a product e.g.
173+
* ```
174+
* [
175+
* 'property-1' => 'some-value',
176+
* 'property-2' => 'some-value',
177+
* // ...
178+
* ];
179+
* ```
180+
*
181+
* A property may only be returned when explicitly adding it to the request with
182+
* `$searchRequest->addProperty($propertyName)`.
183+
*
184+
* @return array<string, string>
185+
*/
186+
public function getProperties()
187+
{
188+
return $this->properties;
189+
}
190+
191+
/**
192+
* Returns the property by the given name. If the property does not exist, the default will be returned.
193+
*
194+
* @param string $propertyName
195+
* @param mixed|null $default
196+
* @return string|mixed
197+
*/
198+
public function getProperty($propertyName, $default = null)
199+
{
200+
if (!isset($this->properties[$propertyName])) {
201+
return $default;
202+
}
203+
204+
return $this->properties[$propertyName];
205+
}
206+
207+
/**
208+
* @return string
209+
*/
210+
public function getImageUrl()
211+
{
212+
return $this->imageUrl;
213+
}
214+
}

0 commit comments

Comments
 (0)