1 | <?php |
||
36 | class VariantSubject extends AbstractProductSubject |
||
37 | { |
||
38 | |||
39 | /** |
||
40 | * The ID of the parent product to relate the variant with. |
||
41 | * |
||
42 | * @var integer |
||
43 | */ |
||
44 | protected $parentId; |
||
45 | |||
46 | /** |
||
47 | * The mapping for the SKUs to the created entity IDs. |
||
48 | * |
||
49 | * @var array |
||
50 | */ |
||
51 | protected $skuEntityIdMapping = array(); |
||
52 | |||
53 | /** |
||
54 | * Intializes the previously loaded global data for exactly one variants. |
||
55 | * |
||
56 | * @return void |
||
57 | * @see \Importer\Csv\Actions\ProductImportAction::prepare() |
||
58 | */ |
||
59 | public function setUp() |
||
60 | { |
||
61 | |||
62 | // invoke parent method |
||
63 | parent::setUp(); |
||
64 | |||
65 | // load the entity manager and the registry processor |
||
66 | $registryProcessor = $this->getRegistryProcessor(); |
||
67 | |||
68 | // load the status of the actual import process |
||
69 | $status = $registryProcessor->getAttribute($this->getSerial()); |
||
70 | |||
71 | // load the attribute set we've prepared intially |
||
72 | $this->skuEntityIdMapping = $status[RegistryKeys::SKU_ENTITY_ID_MAPPING]; |
||
73 | } |
||
74 | |||
75 | /** |
||
76 | * Set's the ID of the parent product to relate the variant with. |
||
77 | * |
||
78 | * @param integer $parentId The ID of the parent product |
||
79 | * |
||
80 | * @return void |
||
81 | */ |
||
82 | public function setParentId($parentId) |
||
83 | { |
||
84 | $this->parentId = $parentId; |
||
85 | } |
||
86 | |||
87 | /** |
||
88 | * Return's the ID of the parent product to relate the variant with. |
||
89 | * |
||
90 | * @return integer The ID of the parent product |
||
91 | */ |
||
92 | public function getParentId() |
||
96 | |||
97 | /** |
||
98 | * Return the entity ID for the passed SKU. |
||
99 | * |
||
100 | * @param string $sku The SKU to return the entity ID for |
||
101 | * |
||
102 | * @return integer The mapped entity ID |
||
103 | * @throws \Exception Is thrown if the SKU is not mapped yet |
||
104 | */ |
||
105 | public function mapSkuToEntityId($sku) |
||
106 | { |
||
107 | |||
108 | // query weather or not the SKU has been mapped |
||
109 | if (isset($this->skuEntityIdMapping[$sku])) { |
||
110 | return $this->skuEntityIdMapping[$sku]; |
||
111 | } |
||
112 | |||
113 | // throw an exception if the SKU has not been mapped yet |
||
114 | throw new \Exception(sprintf('Found not mapped SKU %s', $sku)); |
||
115 | } |
||
116 | |||
117 | /** |
||
118 | * Return's the store for the passed store code. |
||
119 | * |
||
120 | * @param string $storeCode The store code to return the store for |
||
121 | * |
||
122 | * @return array The requested store |
||
123 | * @throws \Exception Is thrown, if the requested store is not available |
||
124 | */ |
||
125 | public function getStoreByStoreCode($storeCode) |
||
136 | |||
137 | /** |
||
138 | * Return's the EAV attribute with the passed attribute code. |
||
139 | * |
||
140 | * @param string $attributeCode The attribute code |
||
141 | * |
||
142 | * @return array The array with the EAV attribute |
||
143 | * @throws \Exception Is thrown if the attribute with the passed code is not available |
||
144 | */ |
||
145 | public function getEavAttributeByAttributeCode($attributeCode) |
||
169 | |||
170 | /** |
||
171 | * Load's the product relation with the passed parent/child ID. |
||
172 | * |
||
173 | * @param integer $parentId The entity ID of the product relation's parent product |
||
174 | * @param integer $childId The entity ID of the product relation's child product |
||
175 | * |
||
176 | * @return array The product relation |
||
177 | */ |
||
178 | public function loadProductRelation($parentId, $childId) |
||
182 | |||
183 | /** |
||
184 | * Load's the product super link with the passed product/parent ID. |
||
185 | * |
||
186 | * @param integer $productId The entity ID of the product super link's product |
||
187 | * @param integer $parentId The entity ID of the product super link's parent product |
||
188 | * |
||
189 | * @return array The product super link |
||
190 | */ |
||
191 | public function loadProductSuperLink($productId, $parentId) |
||
195 | |||
196 | /** |
||
197 | * Load's the product super attribute with the passed product/attribute ID. |
||
198 | * |
||
199 | * @param integer $productId The entity ID of the product super attribute's product |
||
200 | * @param integer $attributeId The attribute ID of the product super attributes attribute |
||
201 | * |
||
202 | * @return array The product super attribute |
||
203 | */ |
||
204 | public function loadProductSuperAttribute($productId, $attributeId) |
||
208 | |||
209 | /** |
||
210 | * Load's the product super attribute label with the passed product super attribute/store ID. |
||
211 | * |
||
212 | * @param integer $productSuperAttributeId The product super attribute ID of the product super attribute label |
||
213 | * @param integer $storeId The store ID of the product super attribute label |
||
214 | * |
||
215 | * @return array The product super attribute label |
||
216 | */ |
||
217 | public function loadProductSuperAttributeLabel($productSuperAttributeId, $storeId) |
||
221 | |||
222 | /** |
||
223 | * Persist's the passed product relation data and return's the ID. |
||
224 | * |
||
225 | * @param array $productRelation The product relation data to persist |
||
226 | * |
||
227 | * @return void |
||
228 | */ |
||
229 | public function persistProductRelation($productRelation) |
||
233 | |||
234 | /** |
||
235 | * Persist's the passed product super link data and return's the ID. |
||
236 | * |
||
237 | * @param array $productSuperLink The product super link data to persist |
||
238 | * |
||
239 | * @return void |
||
240 | */ |
||
241 | public function persistProductSuperLink($productSuperLink) |
||
245 | |||
246 | /** |
||
247 | * Persist's the passed product super attribute data and return's the ID. |
||
248 | * |
||
249 | * @param array $productSuperAttribute The product super attribute data to persist |
||
250 | * |
||
251 | * @return string The ID of the persisted product super attribute entity |
||
252 | */ |
||
253 | public function persistProductSuperAttribute($productSuperAttribute) |
||
257 | |||
258 | /** |
||
259 | * Persist's the passed product super attribute label data and return's the ID. |
||
260 | * |
||
261 | * @param array $productSuperAttributeLabel The product super attribute label data to persist |
||
262 | * |
||
263 | * @return void |
||
264 | */ |
||
265 | public function persistProductSuperAttributeLabel($productSuperAttributeLabel) |
||
269 | } |
||
270 |
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: