1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* TechDivision\Import\Product\Media\Ee\Subjects\EeMediaSubject |
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\Subjects; |
22
|
|
|
|
23
|
|
|
use TechDivision\Import\Utils\RegistryKeys; |
24
|
|
|
use TechDivision\Import\Product\Media\Subjects\MediaSubject; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* A subject that handles the process to import product media. |
28
|
|
|
* |
29
|
|
|
* @author Tim Wagner <[email protected]> |
30
|
|
|
* @copyright 2016 TechDivision GmbH <[email protected]> |
31
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
32
|
|
|
* @link https://github.com/techdivision/import-product-media-ee |
33
|
|
|
* @link http://www.techdivision.com |
34
|
|
|
*/ |
35
|
|
|
class EeMediaSubject extends MediaSubject |
36
|
|
|
{ |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* The mapping for the SKUs to the created entity IDs. |
40
|
|
|
* |
41
|
|
|
* @var array |
42
|
|
|
*/ |
43
|
|
|
protected $skuRowIdMapping = array(); |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Intializes the previously loaded global data for exactly one variants. |
47
|
|
|
* |
48
|
|
|
* @return void |
49
|
|
|
* @see \Importer\Csv\Actions\ProductImportAction::prepare() |
50
|
|
|
*/ |
51
|
1 |
|
public function setUp() |
52
|
|
|
{ |
53
|
|
|
|
54
|
|
|
// invoke the parent method |
55
|
1 |
|
parent::setUp(); |
56
|
|
|
|
57
|
|
|
// load the entity manager and the registry processor |
58
|
1 |
|
$registryProcessor = $this->getRegistryProcessor(); |
59
|
|
|
|
60
|
|
|
// load the status of the actual import process |
61
|
1 |
|
$status = $registryProcessor->getAttribute($this->getSerial()); |
62
|
|
|
|
63
|
|
|
// load the attribute set we've prepared intially |
64
|
1 |
|
$this->skuRowIdMapping = $status[RegistryKeys::SKU_ROW_ID_MAPPING]; |
65
|
1 |
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Load's the product media gallery value with the passed value/store/row ID. |
69
|
|
|
* |
70
|
|
|
* @param integer $valueId The value ID of the product media gallery value to load |
71
|
|
|
* @param string $storeId The store ID of the product media gallery value to load |
72
|
|
|
* @param string $rowId The row ID of the parent product of the product media gallery value to load |
73
|
|
|
* |
74
|
|
|
* @return array The product media gallery value |
75
|
|
|
*/ |
76
|
|
|
public function loadProductMediaGalleryValueByValueIdAndStoreIdAndRowId($valueId, $storeId, $rowId) |
77
|
|
|
{ |
78
|
|
|
return $this->getProductProcessor()->loadProductMediaGalleryValueByValueIdAndStoreIdAndRowId($valueId, $storeId, $rowId); |
|
|
|
|
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Load's the product media gallery with the passed value/entity ID. |
83
|
|
|
* |
84
|
|
|
* @param integer $valueId The value ID of the product media gallery value to entity to load |
85
|
|
|
* @param integer $rowId The row ID of the product media gallery value to entity to load |
86
|
|
|
* |
87
|
|
|
* @return array The product media gallery |
88
|
|
|
*/ |
89
|
|
|
public function loadProductMediaGalleryValueToEntityByValueIdAndRowId($valueId, $rowId) |
90
|
|
|
{ |
91
|
|
|
return $this->getProductProcessor()->loadProductMediaGalleryValueToEntityByValueIdAndRowId($valueId, $rowId); |
|
|
|
|
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Return the row ID for the passed SKU. |
96
|
|
|
* |
97
|
|
|
* @param string $sku The SKU to return the row ID for |
98
|
|
|
* |
99
|
|
|
* @return integer The mapped row ID |
100
|
|
|
* @throws \Exception Is thrown if the SKU is not mapped yet |
101
|
|
|
*/ |
102
|
1 |
|
public function mapSkuToRowId($sku) |
103
|
|
|
{ |
104
|
|
|
|
105
|
|
|
// query weather or not the SKU has been mapped |
106
|
1 |
|
if (isset($this->skuRowIdMapping[$sku])) { |
107
|
1 |
|
return $this->skuRowIdMapping[$sku]; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
// throw an exception if the SKU has not been mapped yet |
111
|
|
|
throw new \Exception(sprintf('Found not mapped SKU %s', $sku)); |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: