1 | <?php |
||
40 | class ProductUrlRewriteProcessor implements ProductUrlRewriteProcessorInterface |
||
41 | { |
||
42 | |||
43 | /** |
||
44 | * A PDO connection initialized with the values from the Doctrine EntityManager. |
||
45 | * |
||
46 | * @var \TechDivision\Import\Connection\ConnectionInterface |
||
47 | */ |
||
48 | protected $connection; |
||
49 | |||
50 | /** |
||
51 | * The primary key util instance. |
||
52 | * |
||
53 | * @var \TechDivision\Import\Utils\PrimaryKeyUtilInterface |
||
54 | */ |
||
55 | protected $primaryKeyUtil; |
||
56 | |||
57 | /** |
||
58 | * The action for URL rewrite CRUD methods. |
||
59 | * |
||
60 | * @var \TechDivision\Import\Actions\ActionInterface |
||
61 | */ |
||
62 | protected $urlRewriteAction; |
||
63 | |||
64 | /** |
||
65 | * The action for URL rewrite product category CRUD methods. |
||
66 | * |
||
67 | * @var \TechDivision\Import\Actions\ActionInterface |
||
68 | */ |
||
69 | protected $urlRewriteProductCategoryAction; |
||
70 | |||
71 | /** |
||
72 | * The repository to load the products with. |
||
73 | * |
||
74 | * @var \TechDivision\Import\Product\Repositories\ProductRepositoryInterface |
||
75 | */ |
||
76 | protected $productRepository; |
||
77 | |||
78 | /** |
||
79 | * The repository to load the URL rewrites with. |
||
80 | * |
||
81 | * @var \TechDivision\Import\Product\UrlRewrite\Repositories\UrlRewriteRepositoryInterface |
||
82 | */ |
||
83 | protected $urlRewriteRepository; |
||
84 | |||
85 | /** |
||
86 | * The repository to load the URL rewrite product category relations with. |
||
87 | * |
||
88 | * @var \TechDivision\Import\Product\UrlRewrite\Repositories\UrlRewriteProductCategoryRepositoryInterface |
||
89 | */ |
||
90 | protected $urlRewriteProductCategoryRepository; |
||
91 | |||
92 | /** |
||
93 | * Initialize the processor with the necessary assembler and repository instances. |
||
94 | * |
||
95 | * @param \TechDivision\Import\Connection\ConnectionInterface $connection The connection to use |
||
96 | * @param \TechDivision\Import\Product\Repositories\ProductRepositoryInterface $productRepository The product repository to use |
||
97 | * @param \TechDivision\Import\Product\Repositories\ProductVarcharRepositoryInterface $productVarcharRepository The product varchar repository to use |
||
98 | * @param \TechDivision\Import\Product\UrlRewrite\Repositories\UrlRewriteRepositoryInterface $urlRewriteRepository The URL rewrite repository to use |
||
99 | * @param \TechDivision\Import\Product\UrlRewrite\Repositories\UrlRewriteProductCategoryRepositoryInterface $urlRewriteProductCategoryRepository The URL rewrite product category repository to use |
||
100 | * @param \TechDivision\Import\Actions\ActionInterface $urlRewriteAction The URL rewrite action to use |
||
101 | * @param \TechDivision\Import\Actions\ActionInterface $urlRewriteProductCategoryAction The URL rewrite product category action to use |
||
102 | * @param \TechDivision\Import\Utils\PrimaryKeyUtilInterface $primaryKeyUtil The primary key util |
||
103 | */ |
||
104 | public function __construct( |
||
123 | |||
124 | /** |
||
125 | * Set's the passed connection. |
||
126 | * |
||
127 | * @param \TechDivision\Import\Connection\ConnectionInterface $connection The connection to set |
||
128 | * |
||
129 | * @return void |
||
130 | */ |
||
131 | public function setConnection(ConnectionInterface $connection) |
||
135 | |||
136 | /** |
||
137 | * Return's the connection. |
||
138 | * |
||
139 | * @return \TechDivision\Import\Connection\ConnectionInterface The connection instance |
||
140 | */ |
||
141 | public function getConnection() |
||
145 | |||
146 | /** |
||
147 | * Turns off autocommit mode. While autocommit mode is turned off, changes made to the database via the PDO |
||
148 | * object instance are not committed until you end the transaction by calling ProductProcessor::commit(). |
||
149 | * Calling ProductProcessor::rollBack() will roll back all changes to the database and return the connection |
||
150 | * to autocommit mode. |
||
151 | * |
||
152 | * @return boolean Returns TRUE on success or FALSE on failure |
||
153 | * @link http://php.net/manual/en/pdo.begintransaction.php |
||
154 | */ |
||
155 | public function beginTransaction() |
||
159 | |||
160 | /** |
||
161 | * Commits a transaction, returning the database connection to autocommit mode until the next call to |
||
162 | * ProductProcessor::beginTransaction() starts a new transaction. |
||
163 | * |
||
164 | * @return boolean Returns TRUE on success or FALSE on failure |
||
165 | * @link http://php.net/manual/en/pdo.commit.php |
||
166 | */ |
||
167 | public function commit() |
||
171 | |||
172 | /** |
||
173 | * Rolls back the current transaction, as initiated by ProductProcessor::beginTransaction(). |
||
174 | * |
||
175 | * If the database was set to autocommit mode, this function will restore autocommit mode after it has |
||
176 | * rolled back the transaction. |
||
177 | * |
||
178 | * Some databases, including MySQL, automatically issue an implicit COMMIT when a database definition |
||
179 | * language (DDL) statement such as DROP TABLE or CREATE TABLE is issued within a transaction. The implicit |
||
180 | * COMMIT will prevent you from rolling back any other changes within the transaction boundary. |
||
181 | * |
||
182 | * @return boolean Returns TRUE on success or FALSE on failure |
||
183 | * @link http://php.net/manual/en/pdo.rollback.php |
||
184 | */ |
||
185 | public function rollBack() |
||
189 | |||
190 | /** |
||
191 | * Set's the action with the URL rewrite CRUD methods. |
||
192 | * |
||
193 | * @param \TechDivision\Import\Actions\ActionInterface $urlRewriteAction The action with the URL rewrite CRUD methods |
||
194 | * |
||
195 | * @return void |
||
196 | */ |
||
197 | public function setUrlRewriteAction(ActionInterface $urlRewriteAction) |
||
201 | |||
202 | /** |
||
203 | * Return's the action with the URL rewrite CRUD methods. |
||
204 | * |
||
205 | * @return \TechDivision\Import\Actions\ActionInterface The action instance |
||
206 | */ |
||
207 | public function getUrlRewriteAction() |
||
211 | |||
212 | /** |
||
213 | * Set's the action with the URL rewrite product category CRUD methods. |
||
214 | * |
||
215 | * @param \TechDivision\Import\Actions\ActionInterface $urlRewriteProductCategoryAction The action with the URL rewrite CRUD methods |
||
216 | * |
||
217 | * @return void |
||
218 | */ |
||
219 | public function setUrlRewriteProductCategoryAction(ActionInterface $urlRewriteProductCategoryAction) |
||
223 | |||
224 | /** |
||
225 | * Return's the action with the URL rewrite product category CRUD methods. |
||
226 | * |
||
227 | * @return \TechDivision\Import\Actions\ActionInterface The action instance |
||
228 | */ |
||
229 | public function getUrlRewriteProductCategoryAction() |
||
233 | |||
234 | /** |
||
235 | * Set's the repository to load the product varchar attribute with. |
||
236 | * |
||
237 | * @param \TechDivision\Import\Product\Repositories\ProductVarcharRepositoryInterface $productVarcharRepository The repository instance |
||
238 | * |
||
239 | * @return void |
||
240 | */ |
||
241 | public function setProductVarcharRepository(ProductVarcharRepositoryInterface $productVarcharRepository) |
||
245 | |||
246 | /** |
||
247 | * Return's the repository to load the product varchar attribute with. |
||
248 | * |
||
249 | * @return \TechDivision\Import\Product\Repositories\ProductVarcharRepositoryInterface The repository instance |
||
250 | */ |
||
251 | public function getProductVarcharRepository() |
||
255 | |||
256 | /** |
||
257 | * Set's the repository to load the URL rewrites with. |
||
258 | * |
||
259 | * @param \TechDivision\Import\Product\UrlRewrite\Repositories\UrlRewriteRepositoryInterface $urlRewriteRepository The repository instance |
||
260 | * |
||
261 | * @return void |
||
262 | */ |
||
263 | public function setUrlRewriteRepository(UrlRewriteRepositoryInterface $urlRewriteRepository) |
||
267 | |||
268 | /** |
||
269 | * Return's the repository to load the URL rewrites with. |
||
270 | * |
||
271 | * @return \TechDivision\Import\Product\UrlRewrite\Repositories\UrlRewriteRepositoryInterface The repository instance |
||
272 | */ |
||
273 | public function getUrlRewriteRepository() |
||
277 | |||
278 | /** |
||
279 | * Set's the repository to load the URL rewrite product category relations with. |
||
280 | * |
||
281 | * @param \TechDivision\Import\Product\UrlRewrite\Repositories\UrlRewriteProductCategoryRepositoryInterface $urlRewriteProductCategoryRepository The repository instance |
||
282 | * |
||
283 | * @return void |
||
284 | */ |
||
285 | public function setUrlRewriteProductCategoryRepository(UrlRewriteProductCategoryRepositoryInterface $urlRewriteProductCategoryRepository) |
||
289 | |||
290 | /** |
||
291 | * Return's the repository to load the URL rewrite product category relations with. |
||
292 | * |
||
293 | * @return \TechDivision\Import\Product\UrlRewrite\Repositories\UrlRewriteProductCategoryRepositoryInterface The repository instance |
||
294 | */ |
||
295 | public function getUrlRewriteProductCategoryRepository() |
||
299 | |||
300 | /** |
||
301 | * Set's the repository to load the products with. |
||
302 | * |
||
303 | * @param \TechDivision\Import\Product\Repositories\ProductRepositoryInterface $productRepository The repository instance |
||
304 | * |
||
305 | * @return void |
||
306 | */ |
||
307 | public function setProductRepository(ProductRepositoryInterface $productRepository) |
||
311 | |||
312 | /** |
||
313 | * Return's the repository to load the products with. |
||
314 | * |
||
315 | * @return \TechDivision\Import\Product\Repositories\ProductRepositoryInterface The repository instance |
||
316 | */ |
||
317 | public function getProductRepository() |
||
321 | |||
322 | /** |
||
323 | * Return's the URL rewrites for the passed URL entity type and ID. |
||
324 | * |
||
325 | * @param string $entityType The entity type to load the URL rewrites for |
||
326 | * @param integer $entityId The entity ID to laod the rewrites for |
||
327 | * |
||
328 | * @return array The URL rewrites |
||
329 | */ |
||
330 | public function getUrlRewritesByEntityTypeAndEntityId($entityType, $entityId) |
||
334 | |||
335 | /** |
||
336 | * Return's the URL rewrites for the passed URL entity type and ID. |
||
337 | * |
||
338 | * @param string $entityType The entity type to load the URL rewrites for |
||
339 | * @param integer $entityId The entity ID to load the URL rewrites for |
||
340 | * @param integer $storeId The store ID to load the URL rewrites for |
||
341 | * |
||
342 | * @return array The URL rewrites |
||
343 | */ |
||
344 | public function getUrlRewritesByEntityTypeAndEntityIdAndStoreId($entityType, $entityId, $storeId) |
||
348 | |||
349 | /** |
||
350 | * Return's an array with the URL rewrites for the passed SKU. |
||
351 | * |
||
352 | * @param string $sku The SKU to load the URL rewrites for |
||
353 | * |
||
354 | * @return array The URL rewrites |
||
355 | */ |
||
356 | public function getUrlRewritesBySku($sku) |
||
360 | |||
361 | /** |
||
362 | * Return's an array with the URL rewrite product category relations for the passed SKU. |
||
363 | * |
||
364 | * @param string $sku The SKU to load the URL rewrite product category relations for |
||
365 | * |
||
366 | * @return array The URL rewrite product category relations |
||
367 | */ |
||
368 | public function getUrlRewriteProductCategoriesBySku($sku) |
||
372 | |||
373 | /** |
||
374 | * Load's and return's the product with the passed SKU. |
||
375 | * |
||
376 | * @param string $sku The SKU of the product to load |
||
377 | * |
||
378 | * @return array The product |
||
379 | */ |
||
380 | public function loadProduct($sku) |
||
384 | |||
385 | /** |
||
386 | * Load's and return's the varchar attribute with the passed params. |
||
387 | * |
||
388 | * @param integer $attributeCode The attribute code of the varchar attribute |
||
389 | * @param integer $entityTypeId The entity type ID of the varchar attribute |
||
390 | * @param integer $storeId The store ID of the varchar attribute |
||
391 | * @param string $pk The primary key of the product |
||
392 | * |
||
393 | * @return array|null The varchar attribute |
||
394 | */ |
||
395 | public function loadProductVarcharAttributeByAttributeCodeAndEntityTypeIdAndStoreIdAndPK($attributeCode, $entityTypeId, $storeId, $pk) |
||
399 | |||
400 | /** |
||
401 | * Load's and return's the varchar attribute with the passed params. |
||
402 | * |
||
403 | * @param integer $attributeCode The attribute code of the varchar attribute |
||
404 | * @param integer $entityTypeId The entity type ID of the varchar attribute |
||
405 | * @param integer $storeId The store ID of the varchar attribute |
||
406 | * @param string $value The value of the varchar attribute |
||
407 | * |
||
408 | * @return array|null The varchar attribute |
||
409 | */ |
||
410 | public function loadProductVarcharAttributeByAttributeCodeAndEntityTypeIdAndStoreIdAndValue($attributeCode, $entityTypeId, $storeId, $value) |
||
414 | |||
415 | /** |
||
416 | * Return's the URL rewrite product category relation for the passed |
||
417 | * URL rewrite ID. |
||
418 | * |
||
419 | * @param integer $urlRewriteId The URL rewrite ID to load the URL rewrite product category relation for |
||
420 | * |
||
421 | * @return array|false The URL rewrite product category relation |
||
422 | */ |
||
423 | public function loadUrlRewriteProductCategory($urlRewriteId) |
||
427 | |||
428 | /** |
||
429 | * Persist's the URL write with the passed data. |
||
430 | * |
||
431 | * @param array $row The URL rewrite to persist |
||
432 | * @param string|null $name The name of the prepared statement that has to be executed |
||
433 | * |
||
434 | * @return string The ID of the persisted entity |
||
435 | */ |
||
436 | public function persistUrlRewrite($row, $name = null) |
||
440 | |||
441 | /** |
||
442 | * Persist's the URL rewrite product => category relation with the passed data. |
||
443 | * |
||
444 | * @param array $row The URL rewrite product => category relation to persist |
||
445 | * @param string|null $name The name of the prepared statement that has to be executed |
||
446 | * |
||
447 | * @return void |
||
448 | */ |
||
449 | public function persistUrlRewriteProductCategory($row, $name = null) |
||
453 | |||
454 | /** |
||
455 | * Delete's the URL rewrite with the passed attributes. |
||
456 | * |
||
457 | * @param array $row The attributes of the entity to delete |
||
458 | * @param string|null $name The name of the prepared statement that has to be executed |
||
459 | * |
||
460 | * @return void |
||
461 | */ |
||
462 | public function deleteUrlRewrite($row, $name = null) |
||
466 | |||
467 | /** |
||
468 | * Sets the passed primary key util instance. |
||
469 | * |
||
470 | * @param \TechDivision\Import\Utils\PrimaryKeyUtilInterface $primaryKeyUtil The primary key util instance |
||
471 | * |
||
472 | * @return void |
||
473 | */ |
||
474 | public function setPrimaryKeyUtil(PrimaryKeyUtilInterface $primaryKeyUtil) |
||
478 | |||
479 | /** |
||
480 | * Returns the primary key util instance. |
||
481 | * |
||
482 | * @return \TechDivision\Import\Utils\PrimaryKeyUtilInterface The primary key util instance |
||
483 | */ |
||
484 | public function getPrimaryKeyUtil() |
||
488 | |||
489 | /** |
||
490 | * Returns the primary key member name for the actual Magento edition. |
||
491 | * |
||
492 | * @return string The primary key member name |
||
493 | * @see \TechDivision\Import\Utils\PrimaryKeyUtilInterface::getPrimaryKeyMemberName() |
||
494 | */ |
||
495 | public function getPrimaryKeyMemberName() |
||
499 | } |
||
500 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: