|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @author @jayS-de <[email protected]> |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
namespace Commercetools\Core\Model\Product; |
|
7
|
|
|
|
|
8
|
|
|
use Commercetools\Core\Model\Common\Collection; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* @package Commercetools\Core\Model\Product |
|
12
|
|
|
* @method ProductVariant current() |
|
13
|
|
|
* @method ProductVariantCollection add(ProductVariant $element) |
|
14
|
|
|
* @method ProductVariant getAt($offset) |
|
15
|
|
|
*/ |
|
16
|
|
|
class ProductVariantCollection extends Collection |
|
17
|
|
|
{ |
|
18
|
|
|
const ID = 'id'; |
|
19
|
|
|
const SKU = 'sku'; |
|
20
|
|
|
const MATCHING = 'isMatchingVariant'; |
|
21
|
|
|
protected $type = '\Commercetools\Core\Model\Product\ProductVariant'; |
|
22
|
|
|
|
|
23
|
|
|
protected function indexRow($offset, $row) |
|
24
|
|
|
{ |
|
25
|
|
|
if ($row instanceof ProductVariant) { |
|
26
|
|
|
$id = $row->getId(); |
|
27
|
|
|
$sku = $row->getSku(); |
|
28
|
|
|
$matching = $row->getIsMatchingVariant(); |
|
29
|
|
|
} else { |
|
30
|
|
|
$id = isset($row[static::ID])? $row[static::ID] : null; |
|
31
|
|
|
$sku = isset($row[static::SKU])? $row[static::SKU] : null; |
|
32
|
|
|
$matching = isset($row[static::MATCHING])? $row[static::MATCHING] : false; |
|
33
|
|
|
} |
|
34
|
|
|
$this->addToIndex(static::ID, $offset, $id); |
|
35
|
|
|
$this->addToIndex(static::SKU, $offset, $sku); |
|
36
|
|
|
$this->addToIndex(static::MATCHING, $offset, $matching); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @param $id |
|
41
|
|
|
* @return ProductVariant |
|
42
|
|
|
*/ |
|
43
|
|
|
public function getById($id) |
|
44
|
|
|
{ |
|
45
|
|
|
return $this->getBy(static::ID, $id); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @param $id |
|
50
|
|
|
* @return ProductVariant |
|
51
|
|
|
*/ |
|
52
|
|
|
public function getBySku($id) |
|
53
|
|
|
{ |
|
54
|
|
|
return $this->getBy(static::SKU, $id); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function getMatchingVariant() |
|
58
|
|
|
{ |
|
59
|
|
|
return $this->getBy(static::MATCHING, true); |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|