|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* TechDivision\Import\Product\Grouped\Services\ProductGroupedProcessor |
|
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 2019 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-grouped |
|
18
|
|
|
* @link http://www.techdivision.com |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
namespace TechDivision\Import\Product\Grouped\Services; |
|
22
|
|
|
|
|
23
|
|
|
use TechDivision\Import\Dbal\Actions\ActionInterface; |
|
24
|
|
|
use TechDivision\Import\Dbal\Connection\ConnectionInterface; |
|
25
|
|
|
use TechDivision\Import\Product\Repositories\ProductRelationRepositoryInterface; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* The product link processor implementation. |
|
29
|
|
|
* |
|
30
|
|
|
* @author Tim Wagner <[email protected]> |
|
31
|
|
|
* @copyright 2019 TechDivision GmbH <[email protected]> |
|
32
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
33
|
|
|
* @link https://github.com/techdivision/import-product-grouped |
|
34
|
|
|
* @link http://www.techdivision.com |
|
35
|
|
|
*/ |
|
36
|
|
|
class ProductGroupedProcessor implements ProductGroupedProcessorInterface |
|
37
|
|
|
{ |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* A PDO connection initialized with the values from the Doctrine EntityManager. |
|
41
|
|
|
* |
|
42
|
|
|
* @var \TechDivision\Import\Dbal\Connection\ConnectionInterface |
|
43
|
|
|
*/ |
|
44
|
|
|
protected $connection; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Initialize the processor with the necessary assembler and repository instances. |
|
48
|
|
|
* |
|
49
|
|
|
* @param \TechDivision\Import\Dbal\Connection\ConnectionInterface $connection The connection to use |
|
50
|
|
|
* @param \TechDivision\Import\Product\Repositories\ProductRelationRepositoryInterface $productRelationRepository The product relation repository to use |
|
51
|
|
|
* @param \TechDivision\Import\Dbal\Actions\ActionInterface $productRelationAction The product relation action to use |
|
52
|
|
|
*/ |
|
53
|
|
|
public function __construct( |
|
54
|
|
|
ConnectionInterface $connection, |
|
55
|
|
|
ProductRelationRepositoryInterface $productRelationRepository, |
|
56
|
|
|
ActionInterface $productRelationAction |
|
57
|
|
|
) { |
|
58
|
|
|
$this->setConnection($connection); |
|
59
|
|
|
$this->setProductRelationRepository($productRelationRepository); |
|
60
|
|
|
$this->setProductRelationAction($productRelationAction); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Set's the passed connection. |
|
65
|
|
|
* |
|
66
|
|
|
* @param \TechDivision\Import\Dbal\Connection\ConnectionInterface $connection The connection to set |
|
67
|
|
|
* |
|
68
|
|
|
* @return void |
|
69
|
|
|
*/ |
|
70
|
|
|
public function setConnection(ConnectionInterface $connection) |
|
71
|
|
|
{ |
|
72
|
|
|
$this->connection = $connection; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Return's the connection. |
|
77
|
|
|
* |
|
78
|
|
|
* @return \TechDivision\Import\Dbal\Connection\ConnectionInterface The connection instance |
|
79
|
|
|
*/ |
|
80
|
|
|
public function getConnection() |
|
81
|
|
|
{ |
|
82
|
|
|
return $this->connection; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Turns off autocommit mode. While autocommit mode is turned off, changes made to the database via the PDO |
|
87
|
|
|
* object instance are not committed until you end the transaction by calling ProductProcessor::commit(). |
|
88
|
|
|
* Calling ProductProcessor::rollBack() will roll back all changes to the database and return the connection |
|
89
|
|
|
* to autocommit mode. |
|
90
|
|
|
* |
|
91
|
|
|
* @return boolean Returns TRUE on success or FALSE on failure |
|
92
|
|
|
* @link http://php.net/manual/en/pdo.begintransaction.php |
|
93
|
|
|
*/ |
|
94
|
|
|
public function beginTransaction() |
|
95
|
|
|
{ |
|
96
|
|
|
return $this->connection->beginTransaction(); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* Commits a transaction, returning the database connection to autocommit mode until the next call to |
|
101
|
|
|
* ProductProcessor::beginTransaction() starts a new transaction. |
|
102
|
|
|
* |
|
103
|
|
|
* @return boolean Returns TRUE on success or FALSE on failure |
|
104
|
|
|
* @link http://php.net/manual/en/pdo.commit.php |
|
105
|
|
|
*/ |
|
106
|
|
|
public function commit() |
|
107
|
|
|
{ |
|
108
|
|
|
return $this->connection->commit(); |
|
|
|
|
|
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* Rolls back the current transaction, as initiated by ProductProcessor::beginTransaction(). |
|
113
|
|
|
* |
|
114
|
|
|
* If the database was set to autocommit mode, this function will restore autocommit mode after it has |
|
115
|
|
|
* rolled back the transaction. |
|
116
|
|
|
* |
|
117
|
|
|
* Some databases, including MySQL, automatically issue an implicit COMMIT when a database definition |
|
118
|
|
|
* language (DDL) statement such as DROP TABLE or CREATE TABLE is issued within a transaction. The implicit |
|
119
|
|
|
* COMMIT will prevent you from rolling back any other changes within the transaction boundary. |
|
120
|
|
|
* |
|
121
|
|
|
* @return boolean Returns TRUE on success or FALSE on failure |
|
122
|
|
|
* @link http://php.net/manual/en/pdo.rollback.php |
|
123
|
|
|
*/ |
|
124
|
|
|
public function rollBack() |
|
125
|
|
|
{ |
|
126
|
|
|
return $this->connection->rollBack(); |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* Set's the repository to access product relations. |
|
131
|
|
|
* |
|
132
|
|
|
* @param \TechDivision\Import\Product\Repositories\ProductRelationRepositoryInterface $productRelationRepository The repository instance |
|
133
|
|
|
* |
|
134
|
|
|
* @return void |
|
135
|
|
|
*/ |
|
136
|
|
|
public function setProductRelationRepository(ProductRelationRepositoryInterface $productRelationRepository) |
|
137
|
|
|
{ |
|
138
|
|
|
$this->productRelationRepository = $productRelationRepository; |
|
|
|
|
|
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* Return's the repository to access product relations. |
|
143
|
|
|
* |
|
144
|
|
|
* @return \TechDivision\Import\Product\Repositories\ProductRelationRepositoryInterface The repository instance |
|
145
|
|
|
*/ |
|
146
|
|
|
public function getProductRelationRepository() |
|
147
|
|
|
{ |
|
148
|
|
|
return $this->productRelationRepository; |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
/** |
|
152
|
|
|
* Set's the action with the product relation CRUD methods. |
|
153
|
|
|
* |
|
154
|
|
|
* @param \TechDivision\Import\Dbal\Actions\ActionInterface $productRelationAction The action with the product relation CRUD methods |
|
155
|
|
|
* |
|
156
|
|
|
* @return void |
|
157
|
|
|
*/ |
|
158
|
|
|
public function setProductRelationAction(ActionInterface $productRelationAction) |
|
159
|
|
|
{ |
|
160
|
|
|
$this->productRelationAction = $productRelationAction; |
|
|
|
|
|
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
/** |
|
164
|
|
|
* Return's the action with the product relation CRUD methods. |
|
165
|
|
|
* |
|
166
|
|
|
* @return \TechDivision\Import\Dbal\Actions\ActionInterface The action instance |
|
167
|
|
|
*/ |
|
168
|
|
|
public function getProductRelationAction() |
|
169
|
|
|
{ |
|
170
|
|
|
return $this->productRelationAction; |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
/** |
|
174
|
|
|
* Load's the product relation with the passed parent/child ID. |
|
175
|
|
|
* |
|
176
|
|
|
* @param integer $parentId The entity ID of the product relation's parent product |
|
177
|
|
|
* @param integer $childId The entity ID of the product relation's child product |
|
178
|
|
|
* |
|
179
|
|
|
* @return array The product relation |
|
180
|
|
|
*/ |
|
181
|
|
|
public function loadProductRelation($parentId, $childId) |
|
182
|
|
|
{ |
|
183
|
|
|
return $this->getProductRelationRepository()->findOneByParentIdAndChildId($parentId, $childId); |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
/** |
|
187
|
|
|
* Persist's the passed product relation data and return's the ID. |
|
188
|
|
|
* |
|
189
|
|
|
* @param array $productRelation The product relation data to persist |
|
190
|
|
|
* @param string|null $name The name of the prepared statement that has to be executed |
|
191
|
|
|
* |
|
192
|
|
|
* @return void |
|
193
|
|
|
*/ |
|
194
|
|
|
public function persistProductRelation($productRelation, $name = null) |
|
195
|
|
|
{ |
|
196
|
|
|
return $this->getProductRelationAction()->persist($productRelation, $name); |
|
|
|
|
|
|
197
|
|
|
} |
|
198
|
|
|
} |
|
199
|
|
|
|