Completed
Push — 9.x ( 2209b0 )
by Tim
03:29
created

getBundleSelectionPriceRepository()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
/**
4
 * TechDivision\Import\Product\Bundle\Services\ProductProcessor
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-bundle
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Product\Bundle\Services;
22
23
use TechDivision\Import\Actions\ActionInterface;
24
use TechDivision\Import\Connection\ConnectionInterface;
25
use TechDivision\Import\Product\Repositories\ProductRelationRepositoryInterface;
26
use TechDivision\Import\Product\Bundle\Repositories\BundleOptionRepositoryInterface;
27
use TechDivision\Import\Product\Bundle\Repositories\BundleOptionValueRepositoryInterface;
28
use TechDivision\Import\Product\Bundle\Repositories\BundleSelectionRepositoryInterface;
29
use TechDivision\Import\Product\Bundle\Repositories\BundleSelectionPriceRepositoryInterface;
30
31
/**
32
 * The product bundle processor implementation.
33
 *
34
 * @author    Tim Wagner <[email protected]>
35
 * @copyright 2016 TechDivision GmbH <[email protected]>
36
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
37
 * @link      https://github.com/techdivision/import-product-bundle
38
 * @link      http://www.techdivision.com
39
 */
40
class ProductBundleProcessor implements ProductBundleProcessorInterface
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 action for product bundle option CRUD methods.
52
     *
53
     * @var \TechDivision\Import\Actions\ActionInterface
54
     */
55
    protected $productBundleOptionAction;
56
57
    /**
58
     * The action for product bundle option value CRUD methods.
59
     *
60
     * @var \TechDivision\Import\Actions\ActionInterface
61
     */
62
    protected $productBundleOptionValueAction;
63
64
    /**
65
     * The action for product bundle selection CRUD methods.
66
     *
67
     * @var \TechDivision\Import\Actions\ActionInterface
68
     */
69
    protected $productBundleSelectionAction;
70
71
    /**
72
     * The action for product bundle selection price CRUD methods.
73
     *
74
     * @var \TechDivision\Import\Actions\ActionInterface
75
     */
76
    protected $productBundleSelectionPriceAction;
77
78
    /**
79
     * The action for product relation CRUD methods.
80
     *
81
     * @var \TechDivision\Import\Actions\ActionInterface
82
     */
83
    protected $productRelationAction;
84
85
    /**
86
     * The repository to load bundle option data.
87
     *
88
     * @var \TechDivision\Import\Product\Bundle\Repositories\BundleOptionRepositoryInterface
89
     */
90
    protected $bundleOptionRespository;
91
92
    /**
93
     * The repository to load bundle option value data.
94
     *
95
     * @var \TechDivision\Import\Product\Bundle\Repositories\BundleOptionValueRepositoryInterface
96
     */
97
    protected $bundleOptionValueRespository;
98
99
    /**
100
     * The repository to load bundle selection data.
101
     *
102
     * @var \TechDivision\Import\Product\Bundle\Repositories\BundleSelectionRepositoryInterface
103
     */
104
    protected $bundleSelectionRespository;
105
106
    /**
107
     * The repository to load bundle selection price data.
108
     *
109
     * @var \TechDivision\Import\Product\Bundle\Repositories\BundleSelectionPriceRepositoryInterface
110
     */
111
    protected $bundleSelectionPriceRespository;
112
113
    /**
114
     * The repository to access product relations.
115
     *
116
     * @var \TechDivision\Import\Product\Repositories\ProductRelationRepositoryInterface
117
     */
118
    protected $productRelationRepository;
119
120
    /**
121
     * Initialize the processor with the necessary assembler and repository instances.
122
     *
123
     * @param \TechDivision\Import\Connection\ConnectionInterface                                      $connection                        The connection to use
124
     * @param \TechDivision\Import\Product\Bundle\Repositories\BundleOptionRepositoryInterface         $bundleOptionRepository            The bundle option repository to use
125
     * @param \TechDivision\Import\Product\Bundle\Repositories\BundleOptionValueRepositoryInterface    $bundleOptionValueRepository       The bundle option value repository to use
126
     * @param \TechDivision\Import\Product\Bundle\Repositories\BundleSelectionRepositoryInterface      $bundleSelectionRepository         The bundle selection repository to use
127
     * @param \TechDivision\Import\Product\Bundle\Repositories\BundleSelectionPriceRepositoryInterface $bundleSelectionPriceRepository    The bundle selection price repository to use
128
     * @param \TechDivision\Import\Product\Repositories\ProductRelationRepositoryInterface             $productRelationRepository         The product relation repository to use
129
     * @param \TechDivision\Import\Actions\ActionInterface                                             $productBundleOptionAction         The product bundle option action to use
130
     * @param \TechDivision\Import\Actions\ActionInterface                                             $productBundleOptionValueAction    The product bundle option value action to use
131
     * @param \TechDivision\Import\Actions\ActionInterface                                             $productBundleSelectionAction      The product bundle selection action to use
132
     * @param \TechDivision\Import\Actions\ActionInterface                                             $productBundleSelectionPriceAction The product bundle selection price action to use
133
     * @param \TechDivision\Import\Actions\ActionInterface                                             $productRelationAction             The product relation action to use
134
     */
135
    public function __construct(
136
        ConnectionInterface $connection,
137
        BundleOptionRepositoryInterface $bundleOptionRepository,
138
        BundleOptionValueRepositoryInterface $bundleOptionValueRepository,
139
        BundleSelectionRepositoryInterface $bundleSelectionRepository,
140
        BundleSelectionPriceRepositoryInterface $bundleSelectionPriceRepository,
141
        ProductRelationRepositoryInterface $productRelationRepository,
142
        ActionInterface $productBundleOptionAction,
143
        ActionInterface $productBundleOptionValueAction,
144
        ActionInterface $productBundleSelectionAction,
145
        ActionInterface $productBundleSelectionPriceAction,
146
        ActionInterface $productRelationAction
147
    ) {
148
        $this->setConnection($connection);
149
        $this->setBundleOptionRepository($bundleOptionRepository);
150
        $this->setBundleOptionValueRepository($bundleOptionValueRepository);
151
        $this->setBundleSelectionRepository($bundleSelectionRepository);
152
        $this->setBundleSelectionPriceRepository($bundleSelectionPriceRepository);
153
        $this->setProductRelationRepository($productRelationRepository);
154
        $this->setProductBundleOptionAction($productBundleOptionAction);
155
        $this->setProductBundleOptionValueAction($productBundleOptionValueAction);
156
        $this->setProductBundleSelectionAction($productBundleSelectionAction);
157
        $this->setProductBundleSelectionPriceAction($productBundleSelectionPriceAction);
158
        $this->setProductRelationAction($productRelationAction);
159
    }
160
161
    /**
162
     * Set's the passed connection.
163
     *
164
     * @param \TechDivision\Import\Connection\ConnectionInterface $connection The connection to set
165
     *
166
     * @return void
167
     */
168
    public function setConnection(ConnectionInterface $connection)
169
    {
170
        $this->connection = $connection;
171
    }
172
173
    /**
174
     * Return's the connection.
175
     *
176
     * @return \TechDivision\Import\Connection\ConnectionInterface The connection instance
177
     */
178
    public function getConnection()
179
    {
180
        return $this->connection;
181
    }
182
183
    /**
184
     * Turns off autocommit mode. While autocommit mode is turned off, changes made to the database via the PDO
185
     * object instance are not committed until you end the transaction by calling ProductProcessor::commit().
186
     * Calling ProductProcessor::rollBack() will roll back all changes to the database and return the connection
187
     * to autocommit mode.
188
     *
189
     * @return boolean Returns TRUE on success or FALSE on failure
190
     * @link http://php.net/manual/en/pdo.begintransaction.php
191
     */
192
    public function beginTransaction()
193
    {
194
        return $this->connection->beginTransaction();
195
    }
196
197
    /**
198
     * Commits a transaction, returning the database connection to autocommit mode until the next call to
199
     * ProductProcessor::beginTransaction() starts a new transaction.
200
     *
201
     * @return boolean Returns TRUE on success or FALSE on failure
202
     * @link http://php.net/manual/en/pdo.commit.php
203
     */
204
    public function commit()
205
    {
206
        return $this->connection->commit();
207
    }
208
209
    /**
210
     * Rolls back the current transaction, as initiated by ProductProcessor::beginTransaction().
211
     *
212
     * If the database was set to autocommit mode, this function will restore autocommit mode after it has
213
     * rolled back the transaction.
214
     *
215
     * Some databases, including MySQL, automatically issue an implicit COMMIT when a database definition
216
     * language (DDL) statement such as DROP TABLE or CREATE TABLE is issued within a transaction. The implicit
217
     * COMMIT will prevent you from rolling back any other changes within the transaction boundary.
218
     *
219
     * @return boolean Returns TRUE on success or FALSE on failure
220
     * @link http://php.net/manual/en/pdo.rollback.php
221
     */
222
    public function rollBack()
223
    {
224
        return $this->connection->rollBack();
225
    }
226
227
    /**
228
     * Set's the action with the product bundle option CRUD methods.
229
     *
230
     * @param \TechDivision\Import\Actions\ActionInterface $productBundleOptionAction The action with the product bundle option CRUD methods
231
     *
232
     * @return void
233
     */
234
    public function setProductBundleOptionAction(ActionInterface $productBundleOptionAction)
235
    {
236
        $this->productBundleOptionAction = $productBundleOptionAction;
237
    }
238
239
    /**
240
     * Return's the action with the product bundle option CRUD methods.
241
     *
242
     * @return \TechDivision\Import\Actions\ActionInterface The action instance
243
     */
244
    public function getProductBundleOptionAction()
245
    {
246
        return $this->productBundleOptionAction;
247
    }
248
249
    /**
250
     * Set's the action with the product bundle option value CRUD methods.
251
     *
252
     * @param \TechDivision\Import\Actions\ActionInterface $productBundleOptionValueAction The action with the product bundle option value CRUD methods
253
     *
254
     * @return void
255
     */
256
    public function setProductBundleOptionValueAction(ActionInterface $productBundleOptionValueAction)
257
    {
258
        $this->productBundleOptionValueAction = $productBundleOptionValueAction;
259
    }
260
261
    /**
262
     * Return's the action with the product bundle option value CRUD methods.
263
     *
264
     * @return \TechDivision\Import\Actions\ActionInterface The action instance
265
     */
266
    public function getProductBundleOptionValueAction()
267
    {
268
        return $this->productBundleOptionValueAction;
269
    }
270
271
    /**
272
     * Set's the action with the product bundle selection CRUD methods.
273
     *
274
     * @param \TechDivision\Import\Actions\ActionInterface $productBundleSelectionAction The action with the product bundle selection CRUD methods
275
     *
276
     * @return void
277
     */
278
    public function setProductBundleSelectionAction(ActionInterface $productBundleSelectionAction)
279
    {
280
        $this->productBundleSelectionAction = $productBundleSelectionAction;
281
    }
282
283
    /**
284
     * Return's the action with the product bundle selection CRUD methods.
285
     *
286
     * @return \TechDivision\Import\Actions\ActionInterface The action instance
287
     */
288
    public function getProductBundleSelectionAction()
289
    {
290
        return $this->productBundleSelectionAction;
291
    }
292
293
    /**
294
     * Set's the action with the product bundle selection price CRUD methods.
295
     *
296
     * @param \TechDivision\Import\Actions\ActionInterface $productBundleSelectionPriceAction The action with the product bundle selection price CRUD methods
297
     *
298
     * @return void
299
     */
300
    public function setProductBundleSelectionPriceAction(ActionInterface $productBundleSelectionPriceAction)
301
    {
302
        $this->productBundleSelectionPriceAction = $productBundleSelectionPriceAction;
303
    }
304
305
    /**
306
     * Return's the action with the product bundle selection price CRUD methods.
307
     *
308
     * @return \TechDivision\Import\Actions\ActionInterface The action instance
309
     */
310
    public function getProductBundleSelectionPriceAction()
311
    {
312
        return $this->productBundleSelectionPriceAction;
313
    }
314
315
    /**
316
     * Set's the action with the product relation CRUD methods.
317
     *
318
     * @param \TechDivision\Import\Actions\ActionInterface $productRelationAction The action with the product relation CRUD methods
319
     *
320
     * @return void
321
     */
322
    public function setProductRelationAction(ActionInterface $productRelationAction)
323
    {
324
        $this->productRelationAction = $productRelationAction;
325
    }
326
327
    /**
328
     * Return's the action with the product relation CRUD methods.
329
     *
330
     * @return \TechDivision\Import\Actions\ActionInterface The action instance
331
     */
332
    public function getProductRelationAction()
333
    {
334
        return $this->productRelationAction;
335
    }
336
337
    /**
338
     * Set's the repository to load bundle option data.
339
     *
340
     * @param \TechDivision\Import\Product\Bundle\Repositories\BundleOptionRepositoryInterface $bundleOptionRespository The repository instance
341
     *
342
     * @return void
343
     */
344
    public function setBundleOptionRepository(BundleOptionRepositoryInterface $bundleOptionRespository)
345
    {
346
        $this->bundleOptionRespository = $bundleOptionRespository;
347
    }
348
349
    /**
350
     * Return's the respository to load bundle option data.
351
     *
352
     * @return \TechDivision\Import\Product\Bundle\Repositories\BundleOptionRepositoryInterface The repository instance
353
     */
354
    public function getBundleOptionRepository()
355
    {
356
        return $this->bundleOptionRespository;
357
    }
358
359
    /**
360
     * Set's the repository to load bundle option value data.
361
     *
362
     * @param \TechDivision\Import\Product\Bundle\Repositories\BundleOptionValueRepositoryInterface $bundleOptionValueRespository The repository instance
363
     *
364
     * @return void
365
     */
366
    public function setBundleOptionValueRepository(BundleOptionValueRepositoryInterface $bundleOptionValueRespository)
367
    {
368
        $this->bundleOptionValueRespository = $bundleOptionValueRespository;
369
    }
370
371
    /**
372
     * Return's the respository to load bundle option value data.
373
     *
374
     * @return \TechDivision\Import\Product\Bundle\Repositories\BundleOptionValueRepositoryInterface The repository instance
375
     */
376
    public function getBundleOptionValueRepository()
377
    {
378
        return $this->bundleOptionValueRespository;
379
    }
380
381
    /**
382
     * Set's the repository to load bundle selection data.
383
     *
384
     * @param \TechDivision\Import\Product\Bundle\Repositories\BundleSelectionRepositoryInterface $bundleSelectionRespository The repository instance
385
     *
386
     * @return void
387
     */
388
    public function setBundleSelectionRepository(BundleSelectionRepositoryInterface $bundleSelectionRespository)
389
    {
390
        $this->bundleSelectionRespository = $bundleSelectionRespository;
391
    }
392
393
    /**
394
     * Return's the respository to load bundle selection data.
395
     *
396
     * @return \TechDivision\Import\Product\Bundle\Repositories\BundleSelectionRepositoryInterface The repository instance
397
     */
398
    public function getBundleSelectionRepository()
399
    {
400
        return $this->bundleSelectionRespository;
401
    }
402
403
    /**
404
     * Set's the repository to load bundle selection price data.
405
     *
406
     * @param \TechDivision\Import\Product\Bundle\Repositories\BundleSelectionPriceRepositoryInterface $bundleSelectionPriceRespository The repository instance
407
     *
408
     * @return void
409
     */
410
    public function setBundleSelectionPriceRepository(BundleSelectionPriceRepositoryInterface $bundleSelectionPriceRespository)
411
    {
412
        $this->bundleSelectionPriceRespository = $bundleSelectionPriceRespository;
413
    }
414
415
    /**
416
     * Return's the respository to load bundle selection price data.
417
     *
418
     * @return \TechDivision\Import\Product\Bundle\Repositories\BundleSelectionPriceRepositoryInterface The repository instance
419
     */
420
    public function getBundleSelectionPriceRepository()
421
    {
422
        return $this->bundleSelectionPriceRespository;
423
    }
424
425
    /**
426
     * Set's the repository to access product relations.
427
     *
428
     * @param \TechDivision\Import\Product\Repositories\ProductRelationRepositoryInterface $productRelationRepository The repository instance
429
     *
430
     * @return void
431
     */
432
    public function setProductRelationRepository(ProductRelationRepositoryInterface $productRelationRepository)
433
    {
434
        $this->productRelationRepository = $productRelationRepository;
435
    }
436
437
    /**
438
     * Return's the repository to access product relations.
439
     *
440
     * @return \TechDivision\Import\Product\Repositories\ProductRelationRepositoryInterface The repository instance
441
     */
442
    public function getProductRelationRepository()
443
    {
444
        return $this->productRelationRepository;
445
    }
446
447
    /**
448
     * Load's the bundle option with the passed name, store + parent ID.
449
     *
450
     * @param string  $title    The title of the bundle option to be returned
451
     * @param integer $storeId  The store ID of the bundle option to be returned
452
     * @param integer $parentId The entity of the product the bundle option is related with
453
     *
454
     * @return array The bundle option
455
     */
456
    public function loadBundleOption($title, $storeId, $parentId)
457
    {
458
        return $this->getBundleOptionRepository()->findOneByNameAndStoreIdAndParentId($title, $storeId, $parentId);
459
    }
460
461
    /**
462
     * Load's the bundle option value with the passed name, store + parent ID.
463
     *
464
     * @param string  $title    The title of the bundle option value to be returned
465
     * @param integer $storeId  The store ID of the bundle option value to be returned
466
     * @param integer $parentId The entity of the product the bundle option value is related with
467
     *
468
     * @return array The bundle option
469
     */
470
    public function loadBundleOptionValue($title, $storeId, $parentId)
471
    {
472
        return $this->getBundleOptionValueRepository()->findOneByNameAndStoreIdAndParentId($title, $storeId, $parentId);
473
    }
474
475
    /**
476
     * Load's the bundle selection value with the passed option/product/parent product ID.
477
     *
478
     * @param integer $optionId        The option ID of the bundle selection to be returned
479
     * @param integer $productId       The product ID of the bundle selection to be returned
480
     * @param integer $parentProductId The parent product ID of the bundle selection to be returned
481
     *
482
     * @return array The bundle selection
483
     */
484
    public function loadBundleSelection($optionId, $productId, $parentProductId)
485
    {
486
        return $this->getBundleSelectionRepository()->findOneByOptionIdAndProductIdAndParentProductId($optionId, $productId, $parentProductId);
487
    }
488
489
    /**
490
     * Load's the bundle selection price with the passed selection/parent product/website ID.
491
     *
492
     * @param integer $selectionId     The selection ID of the bundle selection price to be returned
493
     * @param integer $parentProductId The parent product ID of the bundle selection price to be returned
494
     * @param integer $websiteId       The website ID of the bundle selection price to be returned
495
     *
496
     * @return array The bundle selection price
497
     */
498
    public function loadBundleSelectionPrice($selectionId, $parentProductId, $websiteId)
499
    {
500
        return $this->getBundleSelectionPriceRepository()->findOneByOptionIdAndProductIdAndParentProductId($selectionId, $parentProductId, $websiteId);
501
    }
502
503
    /**
504
     * Load's the product relation with the passed parent/child ID.
505
     *
506
     * @param integer $parentId The entity ID of the product relation's parent product
507
     * @param integer $childId  The entity ID of the product relation's child product
508
     *
509
     * @return array The product relation
510
     */
511
    public function loadProductRelation($parentId, $childId)
512
    {
513
        return $this->getProductRelationRepository()->findOneByParentIdAndChildId($parentId, $childId);
514
    }
515
516
    /**
517
     * Persist's the passed product bundle option data and return's the ID.
518
     *
519
     * @param array $productBundleOption The product bundle option data to persist
520
     *
521
     * @return string The ID of the persisted entity
522
     */
523
    public function persistProductBundleOption($productBundleOption)
524
    {
525
        return $this->getProductBundleOptionAction()->persist($productBundleOption);
526
    }
527
528
    /**
529
     * Persist's the passed product bundle option value data.
530
     *
531
     * @param array $productBundleOptionValue The product bundle option value data to persist
532
     *
533
     * @return void
534
     */
535
    public function persistProductBundleOptionValue($productBundleOptionValue)
536
    {
537
        $this->getProductBundleOptionValueAction()->persist($productBundleOptionValue);
538
    }
539
540
    /**
541
     * Persist's the passed product bundle selection data and return's the ID.
542
     *
543
     * @param array $productBundleSelection The product bundle selection data to persist
544
     *
545
     * @return string The ID of the persisted entity
546
     */
547
    public function persistProductBundleSelection($productBundleSelection)
548
    {
549
        return $this->getProductBundleSelectionAction()->persist($productBundleSelection);
550
    }
551
552
    /**
553
     * Persist's the passed product bundle selection price data and return's the ID.
554
     *
555
     * @param array $productBundleSelectionPrice The product bundle selection price data to persist
556
     *
557
     * @return void
558
     */
559
    public function persistProductBundleSelectionPrice($productBundleSelectionPrice)
560
    {
561
        return $this->getProductBundleSelectionPriceAction()->persist($productBundleSelectionPrice);
562
    }
563
564
    /**
565
     * Persist's the passed product relation data and return's the ID.
566
     *
567
     * @param array       $productRelation The product relation data to persist
568
     * @param string|null $name            The name of the prepared statement that has to be executed
569
     *
570
     * @return void
571
     */
572
    public function persistProductRelation($productRelation, $name = null)
573
    {
574
        return $this->getProductRelationAction()->persist($productRelation, $name);
0 ignored issues
show
Unused Code introduced by
The call to ActionInterface::persist() has too many arguments starting with $name.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
575
    }
576
}
577