| Conditions | 2 |
| Paths | 2 |
| Total Lines | 141 |
| Code Lines | 90 |
| Lines | 15 |
| Ratio | 10.64 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 155 | private function insertVariants() |
||
| 156 | { |
||
| 157 | //clear connect_change table |
||
| 158 | $this->db->exec('DELETE FROM sw_connect_change WHERE c_entity_id LIKE "llc1408017%"'); |
||
| 159 | //clear s_articles table |
||
| 160 | $this->db->exec('DELETE FROM s_articles WHERE name = "LifecycleArticle"'); |
||
| 161 | //clear s_articles_detail table |
||
| 162 | $this->db->exec('DELETE FROM s_articles_details WHERE ordernumber LIKE "llc1408017%"'); |
||
| 163 | //clear connect_items table |
||
| 164 | $this->db->exec('DELETE FROM s_plugin_connect_items WHERE source_id LIKE "llc1408017%"'); |
||
| 165 | |||
| 166 | $minimalTestArticle = [ |
||
| 167 | 'name' => 'LifecycleArticle', |
||
| 168 | 'active' => true, |
||
| 169 | 'tax' => 19, |
||
| 170 | 'supplier' => 'LifecycleArticle Inc.', |
||
| 171 | 'categories' => [ |
||
| 172 | ['id' => 15], |
||
| 173 | ], |
||
| 174 | 'mainDetail' => [ |
||
| 175 | 'number' => 'llc1408017', |
||
| 176 | ], |
||
| 177 | ]; |
||
| 178 | |||
| 179 | $articleResource = \Shopware\Components\Api\Manager::getResource('article'); |
||
| 180 | /** @var \Shopware\Models\Article\Article $article */ |
||
| 181 | $article = $articleResource->create($minimalTestArticle); |
||
| 182 | |||
| 183 | $updateArticle = [ |
||
| 184 | 'configuratorSet' => [ |
||
| 185 | 'groups' => [ |
||
| 186 | [ |
||
| 187 | 'name' => 'Größe', |
||
| 188 | 'options' => [ |
||
| 189 | ['name' => 'S'], |
||
| 190 | ['name' => 'M'], |
||
| 191 | ['name' => 'L'], |
||
| 192 | ['name' => 'XL'], |
||
| 193 | ['name' => 'XXL'], |
||
| 194 | ] |
||
| 195 | ], |
||
| 196 | [ |
||
| 197 | 'name' => 'Farbe', |
||
| 198 | 'options' => [ |
||
| 199 | ['name' => 'Weiß'], |
||
| 200 | ['name' => 'Gelb'], |
||
| 201 | ['name' => 'Blau'], |
||
| 202 | ['name' => 'Schwarz'], |
||
| 203 | ['name' => 'Rot'], |
||
| 204 | ] |
||
| 205 | ], |
||
| 206 | ] |
||
| 207 | ], |
||
| 208 | 'taxId' => 1, |
||
| 209 | 'variants' => [ |
||
| 210 | [ |
||
| 211 | 'isMain' => true, |
||
| 212 | 'number' => 'llc1408017', |
||
| 213 | 'inStock' => 15, |
||
| 214 | 'standard' => null, |
||
| 215 | 'additionaltext' => 'L / Schwarz', |
||
| 216 | 'purchasePrice' => 38.99, |
||
| 217 | 'configuratorOptions' => [ |
||
| 218 | ['group' => 'Größe', 'groupId' => null, 'optionId' => null, 'option' => 'L'], |
||
| 219 | ['group' => 'Farbe', 'groupId' => null, 'optionId' => null, 'option' => 'Schwarz'], |
||
| 220 | ], |
||
| 221 | ], |
||
| 222 | [ |
||
| 223 | 'isMain' => false, |
||
| 224 | 'number' => 'llc1408017-1', |
||
| 225 | 'inStock' => 15, |
||
| 226 | 'standard' => null, |
||
| 227 | 'additionnaltext' => 'S / Schwarz', |
||
| 228 | 'purchasePrice' => 38.99, |
||
| 229 | 'configuratorOptions' => [ |
||
| 230 | ['group' => 'Größe', 'groupId' => null, 'optionId' => null,'option' => 'S'], |
||
| 231 | ['group' => 'Farbe', 'groupId' => null, 'optionId' => null, 'option' => 'Schwarz'], |
||
| 232 | ], |
||
| 233 | ], |
||
| 234 | [ |
||
| 235 | 'isMain' => false, |
||
| 236 | 'number' => 'llc1408017-2', |
||
| 237 | 'inStock' => 15, |
||
| 238 | 'standard' => null, |
||
| 239 | 'additionnaltext' => 'S / Rot', |
||
| 240 | 'purchasePrice' => 38.99, |
||
| 241 | 'configuratorOptions' => [ |
||
| 242 | ['group' => 'Größe', 'groupId' => null, 'optionId' => null,'option' => 'S'], |
||
| 243 | ['group' => 'Farbe', 'groupId' => null, 'optionId' => null,'option' => 'Rot'], |
||
| 244 | ], |
||
| 245 | ], |
||
| 246 | [ |
||
| 247 | 'isMain' => false, |
||
| 248 | 'number' => 'llc1408017-3', |
||
| 249 | 'inStock' => 15, |
||
| 250 | 'standard' => null, |
||
| 251 | 'additionnaltext' => 'XL / Rot', |
||
| 252 | 'purchasePrice' => 38.99, |
||
| 253 | 'configuratorOptions' => [ |
||
| 254 | ['group' => 'Größe', 'groupId' => null, 'optionId' => null, 'option' => 'XL'], |
||
| 255 | ['group' => 'Farbe', 'groupId' => null, 'optionId' => null,'option' => 'Rot'], |
||
| 256 | ], |
||
| 257 | ] |
||
| 258 | ] |
||
| 259 | ]; |
||
| 260 | |||
| 261 | /** @var \Shopware\Models\Article\Article $article */ |
||
| 262 | $article = $articleResource->update($article->getId(), $updateArticle); |
||
| 263 | |||
| 264 | $this->db->insert( |
||
| 265 | 's_articles_prices', |
||
| 266 | [ |
||
| 267 | 'pricegroup' => 'EK', |
||
| 268 | 'from' => 1, |
||
| 269 | 'to' => 5, |
||
| 270 | 'price' => 123.99, |
||
| 271 | 'articleID' => $article->getId(), |
||
| 272 | 'articledetailsID' => $article->getMainDetail()->getId(), |
||
| 273 | 'pseudoprice' => 0 |
||
| 274 | ] |
||
| 275 | ); |
||
| 276 | |||
| 277 | /** @var \Shopware\Models\Article\Detail $detail */ |
||
| 278 | foreach ($article->getDetails() as $detail) { |
||
| 279 | $this->db->executeQuery( |
||
| 280 | 'INSERT INTO s_plugin_connect_items (article_id, article_detail_id, source_id, category, exported) |
||
| 281 | VALUES (?, ?, ?, ?, ?) |
||
| 282 | ON DUPLICATE KEY UPDATE |
||
| 283 | `category` = VALUES(`category`), |
||
| 284 | `exported` = VALUES(`exported`)', |
||
| 285 | [ |
||
| 286 | $article->getId(), |
||
| 287 | $detail->getId(), |
||
| 288 | $detail->getNumber(), |
||
| 289 | '/bücher', |
||
| 290 | 1 |
||
| 291 | ]); |
||
| 292 | } |
||
| 293 | |||
| 294 | return $article->getId(); |
||
| 295 | } |
||
| 296 | } |