|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* TechDivision\Import\Product\Media\Ee\Observers\EeMediaGalleryValueObserver |
|
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\Utils\StoreViewCodes; |
|
24
|
|
|
use TechDivision\Import\Product\Media\Utils\ColumnKeys; |
|
25
|
|
|
use TechDivision\Import\Product\Media\Ee\Utils\MemberNames; |
|
26
|
|
|
use TechDivision\Import\Product\Media\Observers\MediaGalleryValueObserver; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Observer that provides extended mapping functionality to map a SKU to a row ID (EE Feature). |
|
30
|
|
|
* |
|
31
|
|
|
* @author Tim Wagner <[email protected]> |
|
32
|
|
|
* @copyright 2016 TechDivision GmbH <[email protected]> |
|
33
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
34
|
|
|
* @link https://github.com/techdivision/import-product-media-ee |
|
35
|
|
|
* @link http://www.techdivision.com |
|
36
|
|
|
*/ |
|
37
|
|
|
class EeMediaGalleryValueObserver extends MediaGalleryValueObserver |
|
38
|
|
|
{ |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Prepare the product media gallery value that has to be persisted. |
|
42
|
|
|
* |
|
43
|
|
|
* @return array The prepared product media gallery value attributes |
|
44
|
|
|
*/ |
|
45
|
|
|
protected function prepareAttributes() |
|
46
|
|
|
{ |
|
47
|
|
|
|
|
48
|
|
|
// load the product SKU and map it the entity ID |
|
49
|
|
|
$parentId = $this->getValue(ColumnKeys::IMAGE_PARENT_SKU, null, array($this, 'mapParentSku')); |
|
50
|
|
|
|
|
51
|
|
|
// load the store ID |
|
52
|
|
|
$storeId = $this->getRowStoreId(StoreViewCodes::ADMIN); |
|
53
|
|
|
|
|
54
|
|
|
// load the value ID and the position counter |
|
55
|
|
|
$valueId = $this->getParentValueId(); |
|
56
|
|
|
$position = $this->raisePositionCounter(); |
|
57
|
|
|
|
|
58
|
|
|
// load the image label |
|
59
|
|
|
$imageLabel = $this->getValue(ColumnKeys::IMAGE_LABEL); |
|
60
|
|
|
|
|
61
|
|
|
// prepare the media gallery value |
|
62
|
|
|
return $this->initializeEntity( |
|
63
|
|
|
array( |
|
64
|
|
|
MemberNames::VALUE_ID => $valueId, |
|
65
|
|
|
MemberNames::STORE_ID => $storeId, |
|
66
|
|
|
MemberNames::ROW_ID => $parentId, |
|
67
|
|
|
MemberNames::LABEL => $imageLabel, |
|
68
|
|
|
MemberNames::POSITION => $position, |
|
69
|
|
|
MemberNames::DISABLED => 0 |
|
70
|
|
|
) |
|
71
|
|
|
); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Map's the passed SKU of the parent product to it's PK. |
|
76
|
|
|
* |
|
77
|
|
|
* @param string $parentSku The SKU of the parent product |
|
78
|
|
|
* |
|
79
|
|
|
* @return integer The primary key used to create relations |
|
80
|
|
|
*/ |
|
81
|
|
|
protected function mapParentSku($parentSku) |
|
82
|
|
|
{ |
|
83
|
|
|
return $this->mapSkuToRowId($parentSku); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Return the row ID for the passed SKU. |
|
88
|
|
|
* |
|
89
|
|
|
* @param string $sku The SKU to return the row ID for |
|
90
|
|
|
* |
|
91
|
|
|
* @return integer The mapped row ID |
|
92
|
|
|
* @throws \Exception Is thrown if the SKU is not mapped yet |
|
93
|
|
|
*/ |
|
94
|
|
|
protected function mapSkuToRowId($sku) |
|
95
|
|
|
{ |
|
96
|
|
|
return $this->getSubject()->mapSkuToRowId($sku); |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|