Completed
Push — symfony-fqcn-sylius-4 ( 896d93...f41f61 )
by Kamil
18:34
created

ProductVariant::getShippingWidth()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
nc 1
cc 1
eloc 2
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sylius\Component\Core\Model;
13
14
use Sylius\Component\Core\Pricing\Calculators;
15
use Sylius\Component\Product\Model\ProductVariant as BaseVariant;
16
use Sylius\Component\Shipping\Model\ShippingCategoryInterface;
17
use Sylius\Component\Taxation\Model\TaxCategoryInterface;
18
use Webmozart\Assert\Assert;
19
20
/**
21
 * @author Paweł Jędrzejewski <[email protected]>
22
 */
23
class ProductVariant extends BaseVariant implements ProductVariantInterface
24
{
25
    /**
26
     * @var int
27
     */
28
    protected $price;
29
30
    /**
31
     * @var string
32
     */
33
    protected $pricingCalculator = Calculators::STANDARD;
34
35
    /**
36
     * @var array
37
     */
38
    protected $pricingConfiguration = [];
39
40
    /**
41
     * @var int
42
     */
43
    protected $onHold = 0;
44
45
    /**
46
     * @var int
47
     */
48
    protected $onHand = 0;
49
50
    /**
51
     * @var bool
52
     */
53
    protected $tracked = false;
54
55
    /**
56
     * @var float
57
     */
58
    protected $weight;
59
60
    /**
61
     * @var float
62
     */
63
    protected $width;
64
65
    /**
66
     * @var float
67
     */
68
    protected $height;
69
70
    /**
71
     * @var float
72
     */
73
    protected $depth;
74
75
    /**
76
     * @var TaxCategoryInterface
77
     */
78
    protected $taxCategory;
79
80
    /**
81
     * @var ShippingCategoryInterface
82
     */
83
    protected $shippingCategory;
84
85
    /**
86
     * @return string
87
     */
88
    public function __toString()
89
    {
90
        $string = $this->getProduct()->getName();
91
92
        if (!$this->getOptionValues()->isEmpty()) {
93
            $string .= '(';
94
95
            foreach ($this->getOptionValues() as $option) {
96
                $string .= $option->getOption()->getName().': '.$option->getValue().', ';
97
            }
98
99
            $string = substr($string, 0, -2).')';
100
        }
101
102
        return $string;
103
    }
104
105
    /**
106
     * {@inheritdoc}
107
     */
108
    public function getPrice()
109
    {
110
        return $this->price;
111
    }
112
113
    /**
114
     * {@inheritdoc}
115
     */
116
    public function setPrice($price)
117
    {
118
        if (!is_int($price)) {
119
            throw new \InvalidArgumentException('Price must be an integer.');
120
        }
121
122
        $this->price = $price;
123
    }
124
125
    /**
126
     * {@inheritdoc}
127
     */
128
    public function getPricingCalculator()
129
    {
130
        return $this->pricingCalculator;
131
    }
132
133
    /**
134
     * {@inheritdoc}
135
     */
136
    public function setPricingCalculator($calculator)
137
    {
138
        $this->pricingCalculator = $calculator;
139
    }
140
141
    /**
142
     * {@inheritdoc}
143
     */
144
    public function getPricingConfiguration()
145
    {
146
        return $this->pricingConfiguration;
147
    }
148
149
    /**
150
     * {@inheritdoc}
151
     */
152
    public function setPricingConfiguration(array $configuration)
153
    {
154
        $this->pricingConfiguration = $configuration;
155
    }
156
157
    /**
158
     * {@inheritdoc}
159
     */
160
    public function isInStock()
161
    {
162
        return 0 < $this->onHand;
163
    }
164
165
    /**
166
     * {@inheritdoc}
167
     */
168
    public function getOnHold()
169
    {
170
        return $this->onHold;
171
    }
172
173
    /**
174
     * {@inheritdoc}
175
     */
176
    public function setOnHold($onHold)
177
    {
178
        $this->onHold = $onHold;
179
    }
180
181
    /**
182
     * {@inheritdoc}
183
     */
184
    public function getOnHand()
185
    {
186
        return $this->onHand;
187
    }
188
189
    /**
190
     * {@inheritdoc}
191
     */
192
    public function setOnHand($onHand)
193
    {
194
        $this->onHand = (0 > $onHand) ? 0 : $onHand;
195
    }
196
197
    /**
198
     * {@inheritdoc}
199
     */
200
    public function isTracked()
201
    {
202
        return $this->tracked;
203
    }
204
205
    /**
206
     * {@inheritdoc}
207
     */
208
    public function setTracked($tracked)
209
    {
210
        Assert::boolean($tracked);
211
212
        $this->tracked = $tracked;
213
    }
214
215
    /**
216
     * {@inheritdoc}
217
     */
218
    public function getInventoryName()
219
    {
220
        return $this->getProduct()->getName();
221
    }
222
    
223
    /**
224
     * {@inheritdoc}
225
     */
226
    public function getShippingCategory()
227
    {
228
        return $this->shippingCategory;
229
    }
230
231
    /**
232
     * {@inheritdoc}
233
     */
234
    public function setShippingCategory(ShippingCategoryInterface $category = null)
235
    {
236
        $this->shippingCategory = $category;
237
    }
238
239
    /**
240
     * {@inheritdoc}
241
     */
242
    public function getWeight()
243
    {
244
        return $this->weight;
245
    }
246
247
    /**
248
     * {@inheritdoc}
249
     */
250
    public function setWeight($weight)
251
    {
252
        $this->weight = $weight;
253
    }
254
255
    /**
256
     * {@inheritdoc}
257
     */
258
    public function getWidth()
259
    {
260
        return $this->width;
261
    }
262
263
    /**
264
     * {@inheritdoc}
265
     */
266
    public function setWidth($width)
267
    {
268
        $this->width = $width;
269
    }
270
271
    /**
272
     * {@inheritdoc}
273
     */
274
    public function getHeight()
275
    {
276
        return $this->height;
277
    }
278
279
    /**
280
     * {@inheritdoc}
281
     */
282
    public function setHeight($height)
283
    {
284
        $this->height = $height;
285
    }
286
287
    /**
288
     * {@inheritdoc}
289
     */
290
    public function getDepth()
291
    {
292
        return $this->depth;
293
    }
294
295
    /**
296
     * {@inheritdoc}
297
     */
298
    public function setDepth($depth)
299
    {
300
        $this->depth = $depth;
301
    }
302
303
    /**
304
     * {@inheritdoc}
305
     */
306
    public function getShippingWeight()
307
    {
308
        return $this->getWeight();
309
    }
310
311
    /**
312
     * {@inheritdoc}
313
     */
314
    public function getShippingWidth()
315
    {
316
        return $this->getWidth();
317
    }
318
319
    /**
320
     * {@inheritdoc}
321
     */
322
    public function getShippingHeight()
323
    {
324
        return $this->getHeight();
325
    }
326
327
    /**
328
     * {@inheritdoc}
329
     */
330
    public function getShippingDepth()
331
    {
332
        return $this->getDepth();
333
    }
334
335
    /**
336
     * {@inheritdoc}
337
     */
338
    public function getShippingVolume()
339
    {
340
        return $this->depth * $this->height * $this->width;
341
    }
342
343
    /**
344
     * {@inheritdoc}
345
     */
346
    public function getTaxCategory()
347
    {
348
        return $this->taxCategory;
349
    }
350
351
    /**
352
     * {@inheritdoc}
353
     */
354
    public function setTaxCategory(TaxCategoryInterface $category = null)
355
    {
356
        $this->taxCategory = $category;
357
    }
358
}
359