|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* TechDivision\Import\Product\Media\Observers\MediaGalleryValueUpdateObserver |
|
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 |
|
18
|
|
|
* @link http://www.techdivision.com |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
namespace TechDivision\Import\Product\Media\Observers; |
|
22
|
|
|
|
|
23
|
|
|
use TechDivision\Import\Product\Media\Utils\MemberNames; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Observer that creates/updates the product's media gallery value information. |
|
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 |
|
32
|
|
|
* @link http://www.techdivision.com |
|
33
|
|
|
*/ |
|
34
|
|
|
class MediaGalleryValueUpdateObserver extends MediaGalleryValueObserver |
|
35
|
|
|
{ |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Initialize the product media gallery value with the passed attributes and returns an instance. |
|
39
|
|
|
* |
|
40
|
|
|
* @param array $attr The product media gallery value attributes |
|
41
|
|
|
* |
|
42
|
|
|
* @return array The initialized product media gallery value |
|
43
|
|
|
*/ |
|
44
|
|
|
protected function initializeProductMediaGalleryValue(array $attr) |
|
45
|
|
|
{ |
|
46
|
|
|
|
|
47
|
|
|
// load the value/store/parent ID |
|
48
|
|
|
$valueId = $attr[MemberNames::VALUE_ID]; |
|
49
|
|
|
$storeId = $attr[MemberNames::STORE_ID]; |
|
50
|
|
|
$entityId = $attr[MemberNames::ENTITY_ID]; |
|
51
|
|
|
|
|
52
|
|
|
// query whether the product media gallery value already exists or not |
|
53
|
|
|
if ($entity = $this->loadProductMediaGalleryValue($valueId, $storeId, $entityId)) { |
|
54
|
|
|
return $this->mergeEntity($entity, $attr); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
// simply return the attributes |
|
58
|
|
|
return $attr; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Load's the product media gallery value with the passed value/store/parent ID. |
|
63
|
|
|
* |
|
64
|
|
|
* @param integer $valueId The value ID of the product media gallery value to load |
|
65
|
|
|
* @param string $storeId The store ID of the product media gallery value to load |
|
66
|
|
|
* @param string $entityId The entity ID of the parent product of the product media gallery value to load |
|
67
|
|
|
* |
|
68
|
|
|
* @return array The product media gallery value |
|
69
|
|
|
*/ |
|
70
|
|
|
protected function loadProductMediaGalleryValue($valueId, $storeId, $entityId) |
|
71
|
|
|
{ |
|
72
|
|
|
return $this->getSubject()->loadProductMediaGalleryValue($valueId, $storeId, $entityId); |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|