1 | <?php |
||
36 | class BundleSubject extends AbstractProductSubject |
||
37 | { |
||
38 | |||
39 | /** |
||
40 | * The value for the price type 'fixed'. |
||
41 | * |
||
42 | * @var integer |
||
43 | */ |
||
44 | const PRICE_TYPE_FIXED = 0; |
||
45 | |||
46 | /** |
||
47 | * The value for the price type 'percent'. |
||
48 | * |
||
49 | * @var integer |
||
50 | */ |
||
51 | const PRICE_TYPE_PERCENT = 1; |
||
52 | |||
53 | /** |
||
54 | * The mapping for the SKUs to the created entity IDs. |
||
55 | * |
||
56 | * @var array |
||
57 | */ |
||
58 | protected $skuEntityIdMapping = array(); |
||
59 | |||
60 | /** |
||
61 | * The option name => option ID mapping. |
||
62 | * |
||
63 | * @var array |
||
64 | */ |
||
65 | protected $nameOptionIdMapping = array(); |
||
66 | |||
67 | /** |
||
68 | * The ID of the last created selection. |
||
69 | * |
||
70 | * @var integer |
||
71 | */ |
||
72 | protected $childSkuSelectionIdMapping = array(); |
||
73 | |||
74 | /** |
||
75 | * The position counter, if no position for the bundle selection has been specified. |
||
76 | * |
||
77 | * @var integer |
||
78 | */ |
||
79 | protected $positionCounter = 1; |
||
80 | |||
81 | /** |
||
82 | * The mapping for the price type. |
||
83 | * |
||
84 | * @var array |
||
85 | */ |
||
86 | protected $priceTypeMapping = array( |
||
87 | 'fixed' => BundleSubject::PRICE_TYPE_FIXED, |
||
88 | 'percent' => BundleSubject::PRICE_TYPE_PERCENT |
||
89 | ); |
||
90 | |||
91 | /** |
||
92 | * Intializes the previously loaded global data for exactly one variants. |
||
93 | * |
||
94 | * @return void |
||
95 | * @see \Importer\Csv\Actions\ProductImportAction::prepare() |
||
96 | */ |
||
97 | public function setUp() |
||
112 | |||
113 | /** |
||
114 | * Reset the position counter to 1. |
||
115 | * |
||
116 | * @return void |
||
117 | */ |
||
118 | public function resetPositionCounter() |
||
122 | |||
123 | /** |
||
124 | * Returns the acutal value of the position counter and raise's it by one. |
||
125 | * |
||
126 | * @return integer The actual value of the position counter |
||
127 | */ |
||
128 | public function raisePositionCounter() |
||
132 | |||
133 | /** |
||
134 | * Save's the mapping of the child SKU and the selection ID. |
||
135 | * |
||
136 | * @param string $childSku The child SKU of the selection |
||
137 | * @param integer $selectionId The selection ID to save |
||
138 | * |
||
139 | * @return void |
||
140 | */ |
||
141 | public function addChildSkuSelectionIdMapping($childSku, $selectionId) |
||
145 | |||
146 | /** |
||
147 | * Return's the selection ID for the passed child SKU. |
||
148 | * |
||
149 | * @param string $childSku The child SKU to return the selection ID for |
||
150 | * |
||
151 | * @return integer The last created selection ID |
||
152 | */ |
||
153 | public function getChildSkuSelectionMapping($childSku) |
||
157 | |||
158 | /** |
||
159 | * Return the entity ID for the passed SKU. |
||
160 | * |
||
161 | * @param string $sku The SKU to return the entity ID for |
||
162 | * |
||
163 | * @return integer The mapped entity ID |
||
164 | * @throws \Exception Is thrown if the SKU is not mapped yet |
||
165 | */ |
||
166 | public function mapSkuToEntityId($sku) |
||
177 | |||
178 | /** |
||
179 | * Return's the mapping for the passed price type. |
||
180 | * |
||
181 | * @param string $priceType The price type to map |
||
182 | * |
||
183 | * @return integer The mapped price type |
||
184 | * @throws \Exception Is thrown, if the passed price type can't be mapped |
||
185 | */ |
||
186 | public function mapPriceType($priceType) |
||
197 | |||
198 | /** |
||
199 | * Return's the store for the passed store code. |
||
200 | * |
||
201 | * @param string $storeCode The store code to return the store for |
||
202 | * |
||
203 | * @return array The requested store |
||
204 | * @throws \Exception Is thrown, if the requested store is not available |
||
205 | */ |
||
206 | public function getStoreByStoreCode($storeCode) |
||
217 | |||
218 | /** |
||
219 | * Add's the mapping for the passed name => option ID. |
||
220 | * |
||
221 | * @param string $name The name of the option |
||
222 | * @param integer $optionId The created option ID |
||
223 | * |
||
224 | * @return void |
||
225 | */ |
||
226 | public function addNameOptionIdMapping($name, $optionId) |
||
230 | |||
231 | /** |
||
232 | * Query whether or not the option with the passed name has already been created. |
||
233 | * |
||
234 | * @param string $name The option name to query for |
||
235 | * |
||
236 | * @return boolean TRUE if the option already exists, else FALSE |
||
237 | */ |
||
238 | public function exists($name) |
||
242 | |||
243 | /** |
||
244 | * Return's the last created option ID. |
||
245 | * |
||
246 | * @return integer $optionId The last created option ID |
||
247 | */ |
||
248 | public function getLastOptionId() |
||
252 | |||
253 | /** |
||
254 | * Return's the option ID for the passed name. |
||
255 | * |
||
256 | * @param string $name The name to return the option ID for |
||
257 | * |
||
258 | * @return integer The option ID for the passed name |
||
259 | * @throws \Exception Is thrown, if no option ID for the passed name is available |
||
260 | */ |
||
261 | public function getOptionIdForName($name) |
||
272 | |||
273 | /** |
||
274 | * Persist's the passed product bundle option data and return's the ID. |
||
275 | * |
||
276 | * @param array $productBundleOption The product bundle option data to persist |
||
277 | * |
||
278 | * @return string The ID of the persisted entity |
||
279 | */ |
||
280 | public function persistProductBundleOption($productBundleOption) |
||
284 | |||
285 | /** |
||
286 | * Persist's the passed product bundle option value data. |
||
287 | * |
||
288 | * @param array $productBundleOptionValue The product bundle option value data to persist |
||
289 | * |
||
290 | * @return void |
||
291 | */ |
||
292 | public function persistProductBundleOptionValue($productBundleOptionValue) |
||
296 | |||
297 | /** |
||
298 | * Persist's the passed product bundle selection data and return's the ID. |
||
299 | * |
||
300 | * @param array $productBundleSelection The product bundle selection data to persist |
||
301 | * |
||
302 | * @return string The ID of the persisted entity |
||
303 | */ |
||
304 | public function persistProductBundleSelection($productBundleSelection) |
||
308 | |||
309 | /** |
||
310 | * Persist's the passed product bundle selection price data and return's the ID. |
||
311 | * |
||
312 | * @param array $productBundleSelectionPrice The product bundle selection price data to persist |
||
313 | * |
||
314 | * @return void |
||
315 | */ |
||
316 | public function persistProductBundleSelectionPrice($productBundleSelectionPrice) |
||
320 | } |
||
321 |
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: