1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* TechDivision\Import\Product\Variant\Observers\VariantUpdateObserver |
5
|
|
|
* |
6
|
|
|
* NOTICE OF LICENSE |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
9
|
|
|
* that is available through the world-wide-web at this URL: |
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
11
|
|
|
* |
12
|
|
|
* PHP version 5 |
13
|
|
|
* |
14
|
|
|
* @author Tim Wagner <[email protected]> |
15
|
|
|
* @copyright 2016 TechDivision GmbH <[email protected]> |
16
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
17
|
|
|
* @link https://github.com/techdivision/import-product-variant |
18
|
|
|
* @link http://www.techdivision.com |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace TechDivision\Import\Product\Variant\Observers; |
22
|
|
|
|
23
|
|
|
use TechDivision\Import\Product\Variant\Utils\MemberNames; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Oberserver that provides functionality for the product variant add/update operation. |
27
|
|
|
* |
28
|
|
|
* @author Tim Wagner <[email protected]> |
29
|
|
|
* @copyright 2016 TechDivision GmbH <[email protected]> |
30
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
31
|
|
|
* @link https://github.com/techdivision/import-product-variant |
32
|
|
|
* @link http://www.techdivision.com |
33
|
|
|
*/ |
34
|
|
|
class VariantUpdateObserver extends VariantObserver |
35
|
|
|
{ |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Initialize the product relation with the passed attributes and returns an instance. |
39
|
|
|
* |
40
|
|
|
* @param array $attr The product relation attributes |
41
|
|
|
* |
42
|
|
|
* @return array|null The initialized product relation, or null if the relation already exsist |
43
|
|
|
*/ |
44
|
|
|
protected function initializeProductRelation(array $attr) |
45
|
|
|
{ |
46
|
|
|
|
47
|
|
|
// laod child/parent ID |
48
|
|
|
$childId = $attr[MemberNames::CHILD_ID]; |
49
|
|
|
$parentId = $attr[MemberNames::PARENT_ID]; |
50
|
|
|
|
51
|
|
|
// query whether or not the product relation already exists |
52
|
|
|
if ($this->loadProductRelation($parentId, $childId)) { |
53
|
|
|
return; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
// simply return the attributes |
57
|
|
|
return $attr; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Initialize the product super link with the passed attributes and returns an instance. |
62
|
|
|
* |
63
|
|
|
* @param array $attr The product super link attributes |
64
|
|
|
* |
65
|
|
|
* @return array|null The initialized product super link, or null if the super link already exsist |
66
|
|
|
*/ |
67
|
|
|
protected function initializeProductSuperLink(array $attr) |
68
|
|
|
{ |
69
|
|
|
|
70
|
|
|
// laod parent/product ID |
71
|
|
|
$parentId = $attr[MemberNames::PARENT_ID]; |
72
|
|
|
$productId = $attr[MemberNames::PRODUCT_ID]; |
73
|
|
|
|
74
|
|
|
// query whether or not the product super link already exists |
75
|
|
|
if ($this->loadProductSuperLink($productId, $parentId)) { |
76
|
|
|
return; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
// simply return the attributes |
80
|
|
|
return $attr; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Load's the product relation with the passed parent/child ID. |
85
|
|
|
* |
86
|
|
|
* @param integer $parentId The entity ID of the product relation's parent product |
87
|
|
|
* @param integer $childId The entity ID of the product relation's child product |
88
|
|
|
* |
89
|
|
|
* @return array The product relation |
90
|
|
|
*/ |
91
|
|
|
protected function loadProductRelation($parentId, $childId) |
92
|
|
|
{ |
93
|
|
|
return $this->getSubject()->loadProductRelation($parentId, $childId); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Load's the product super link with the passed product/parent ID. |
98
|
|
|
* |
99
|
|
|
* @param integer $productId The entity ID of the product super link's product |
100
|
|
|
* @param integer $parentId The entity ID of the product super link's parent product |
101
|
|
|
* |
102
|
|
|
* @return array The product super link |
103
|
|
|
*/ |
104
|
|
|
protected function loadProductSuperLink($productId, $parentId) |
105
|
|
|
{ |
106
|
|
|
return $this->getSubject()->loadProductSuperLink($productId, $parentId); |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|