|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* TechDivision\Import\Product\Media\Ee\Observers\EeMediaGalleryUpdateObserver |
|
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-media-ee |
|
18
|
|
|
* @link http://www.techdivision.com |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
namespace TechDivision\Import\Product\Media\Ee\Observers; |
|
22
|
|
|
|
|
23
|
|
|
use TechDivision\Import\Product\Media\Ee\Utils\MemberNames; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Observer that provides extended mapping functionality to map a SKU to a row ID (EE Feature). |
|
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-media-ee |
|
32
|
|
|
* @link http://www.techdivision.com |
|
33
|
|
|
*/ |
|
34
|
|
|
class EeMediaGalleryUpdateObserver extends EeMediaGalleryObserver |
|
35
|
|
|
{ |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Merge's and return's the entity with the passed attributes and set's the |
|
39
|
|
|
* passed status. |
|
40
|
|
|
* |
|
41
|
|
|
* @param array $entity The entity to merge the attributes into |
|
42
|
|
|
* @param array $attr The attributes to be merged |
|
43
|
|
|
* @param string|null $changeSetName The change set name to use |
|
44
|
|
|
* |
|
45
|
|
|
* @return array The merged entity |
|
46
|
|
|
*/ |
|
47
|
|
|
protected function mergeEntity(array $entity, array $attr, $changeSetName = null) |
|
48
|
|
|
{ |
|
49
|
|
|
|
|
50
|
|
|
// temporary persist the parent value ID |
|
51
|
|
|
$this->setParentValueId($entity[MemberNames::VALUE_ID]); |
|
52
|
|
|
|
|
53
|
|
|
// merge and return the entity |
|
54
|
|
|
return parent::mergeEntity($entity, $attr, $changeSetName); |
|
|
|
|
|
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Initialize the product media gallery with the passed attributes and returns an instance. |
|
59
|
|
|
* |
|
60
|
|
|
* @param array $attr The product media gallery attributes |
|
61
|
|
|
* |
|
62
|
|
|
* @return array The initialized product media gallery |
|
63
|
|
|
*/ |
|
64
|
|
|
protected function initializeProductMediaGallery(array $attr) |
|
65
|
|
|
{ |
|
66
|
|
|
|
|
67
|
|
|
// load the value and the attribute ID |
|
68
|
|
|
$value = $attr[MemberNames::VALUE]; |
|
69
|
|
|
$attributeId = $attr[MemberNames::ATTRIBUTE_ID]; |
|
70
|
|
|
|
|
71
|
|
|
// query whether the product media gallery entity already exists or not |
|
72
|
|
|
if ($entity = $this->loadProductMediaGallery($attributeId, $value)) { |
|
73
|
|
|
return $this->mergeEntity($entity, $attr); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
// simply return the attributes |
|
77
|
|
|
return $attr; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Initialize the product media gallery value to entity with the passed attributes and returns an instance. |
|
82
|
|
|
* |
|
83
|
|
|
* @param array $attr The product media gallery value to entity attributes |
|
84
|
|
|
* |
|
85
|
|
|
* @return array|null The initialized product media gallery value to entity, or NULL if the product media gallery value to entity already exists |
|
86
|
|
|
*/ |
|
87
|
|
|
protected function initializeProductMediaGalleryValueToEntity(array $attr) |
|
88
|
|
|
{ |
|
89
|
|
|
|
|
90
|
|
|
// load the row/value ID |
|
91
|
|
|
$rowId = $attr[MemberNames::ROW_ID]; |
|
92
|
|
|
$valueId = $attr[MemberNames::VALUE_ID]; |
|
93
|
|
|
|
|
94
|
|
|
// query whether the product media gallery value to entity entity already exists or not |
|
95
|
|
|
if ($this->loadProductMediaGalleryValueToEntityByValueIdAndRowId($valueId, $rowId)) { |
|
96
|
|
|
return; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
// simply return the attributes |
|
100
|
|
|
return $attr; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Load's the product media gallery with the passed attribute ID + value. |
|
105
|
|
|
* |
|
106
|
|
|
* @param integer $attributeId The attribute ID of the product media gallery to load |
|
107
|
|
|
* @param string $value The value of the product media gallery to load |
|
108
|
|
|
* |
|
109
|
|
|
* @return array The product media gallery |
|
110
|
|
|
*/ |
|
111
|
|
|
protected function loadProductMediaGallery($attributeId, $value) |
|
112
|
|
|
{ |
|
113
|
|
|
return $this->getProductMediaProcessor()->loadProductMediaGallery($attributeId, $value); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* Load's the product media gallery with the passed value/entity ID. |
|
118
|
|
|
* |
|
119
|
|
|
* @param integer $valueId The value ID of the product media gallery value to entity to load |
|
120
|
|
|
* @param integer $rowId The row ID of the product media gallery value to entity to load |
|
121
|
|
|
* |
|
122
|
|
|
* @return array The product media gallery |
|
123
|
|
|
*/ |
|
124
|
|
|
protected function loadProductMediaGalleryValueToEntityByValueIdAndRowId($valueId, $rowId) |
|
125
|
|
|
{ |
|
126
|
|
|
return $this->getProductMediaProcessor()->loadProductMediaGalleryValueToEntityByValueIdAndRowId($valueId, $rowId); |
|
|
|
|
|
|
127
|
|
|
} |
|
128
|
|
|
} |
|
129
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignorePhpDoc annotation to the duplicate definition and it will be ignored.