| Conditions | 2 |
| Paths | 2 |
| Total Lines | 122 |
| Code Lines | 84 |
| Lines | 12 |
| Ratio | 9.84 % |
| 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 |
||
| 191 | private function insertVariants() |
||
| 192 | { |
||
| 193 | //clear connect_change table |
||
| 194 | Shopware()->Db()->exec('DELETE FROM sw_connect_change WHERE c_entity_id LIKE "1919%"'); |
||
| 195 | //clear s_articles table |
||
| 196 | Shopware()->Db()->exec('DELETE FROM s_articles WHERE name = "Turnschuh"'); |
||
| 197 | //clear s_articles_detail table |
||
| 198 | Shopware()->Db()->exec('DELETE FROM s_articles_details WHERE ordernumber LIKE "1919%"'); |
||
| 199 | //clear connect_items table |
||
| 200 | Shopware()->Db()->exec('DELETE FROM s_plugin_connect_items WHERE source_id LIKE "1919%"'); |
||
| 201 | |||
| 202 | |||
| 203 | $minimalTestArticle = array( |
||
| 204 | 'name' => 'Turnschuh', |
||
| 205 | 'active' => true, |
||
| 206 | 'tax' => 19, |
||
| 207 | 'supplier' => 'Turnschuh Inc.', |
||
| 208 | 'categories' => array( |
||
| 209 | array('id' => 15), |
||
| 210 | ), |
||
| 211 | 'mainDetail' => array( |
||
| 212 | 'number' => '1919', |
||
| 213 | ), |
||
| 214 | ); |
||
| 215 | |||
| 216 | $articleResource = \Shopware\Components\Api\Manager::getResource('article'); |
||
| 217 | /** @var \Shopware\Models\Article\Article $article */ |
||
| 218 | $article = $articleResource->create($minimalTestArticle); |
||
| 219 | |||
| 220 | $updateArticle = array( |
||
| 221 | 'configuratorSet' => array( |
||
| 222 | 'groups' => array( |
||
| 223 | array( |
||
| 224 | 'name' => 'Größe', |
||
| 225 | 'options' => array( |
||
| 226 | array('name' => 'S'), |
||
| 227 | array('name' => 'M'), |
||
| 228 | array('name' => 'L'), |
||
| 229 | array('name' => 'XL'), |
||
| 230 | array('name' => 'XXL'), |
||
| 231 | ) |
||
| 232 | ), |
||
| 233 | array( |
||
| 234 | 'name' => 'Farbe', |
||
| 235 | 'options' => array( |
||
| 236 | array('name' => 'Weiß'), |
||
| 237 | array('name' => 'Gelb'), |
||
| 238 | array('name' => 'Blau'), |
||
| 239 | array('name' => 'Schwarz'), |
||
| 240 | array('name' => 'Rot'), |
||
| 241 | ) |
||
| 242 | ), |
||
| 243 | ) |
||
| 244 | ), |
||
| 245 | 'taxId' => 1, |
||
| 246 | 'variants' => array( |
||
| 247 | array( |
||
| 248 | 'isMain' => true, |
||
| 249 | 'number' => '1919', |
||
| 250 | 'inStock' => 15, |
||
| 251 | 'standard' => null, |
||
| 252 | 'additionaltext' => 'L / Schwarz', |
||
| 253 | 'configuratorOptions' => array( |
||
| 254 | array('group' => 'Größe', 'groupId' => null, 'optionId' => null, 'option' => 'L'), |
||
| 255 | array('group' => 'Farbe', 'groupId' => null, 'optionId' => null, 'option' => 'Schwarz'), |
||
| 256 | ), |
||
| 257 | ), |
||
| 258 | array( |
||
| 259 | 'isMain' => false, |
||
| 260 | 'number' => '1919-1', |
||
| 261 | 'inStock' => 15, |
||
| 262 | 'standard' => null, |
||
| 263 | 'additionnaltext' => 'S / Schwarz', |
||
| 264 | 'configuratorOptions' => array( |
||
| 265 | array('group' => 'Größe', 'groupId' => null, 'optionId' => null,'option' => 'S'), |
||
| 266 | array('group' => 'Farbe', 'groupId' => null, 'optionId' => null, 'option' => 'Schwarz'), |
||
| 267 | ), |
||
| 268 | ), |
||
| 269 | array( |
||
| 270 | 'isMain' => false, |
||
| 271 | 'number' => '1919-2', |
||
| 272 | 'inStock' => 15, |
||
| 273 | 'standard' => null, |
||
| 274 | 'additionnaltext' => 'S / Rot', |
||
| 275 | 'configuratorOptions' => array( |
||
| 276 | array('group' => 'Größe', 'groupId' => null, 'optionId' => null,'option' => 'S'), |
||
| 277 | array('group' => 'Farbe', 'groupId' => null, 'optionId' => null,'option' => 'Rot'), |
||
| 278 | ), |
||
| 279 | ), |
||
| 280 | array( |
||
| 281 | 'isMain' => false, |
||
| 282 | 'number' => '1919-3', |
||
| 283 | 'inStock' => 15, |
||
| 284 | 'standard' => null, |
||
| 285 | 'additionnaltext' => 'XL / Rot', |
||
| 286 | 'configuratorOptions' => array( |
||
| 287 | array('group' => 'Größe', 'groupId' => null, 'optionId' => null, 'option' => 'XL'), |
||
| 288 | array('group' => 'Farbe', 'groupId' => null, 'optionId' => null,'option' => 'Rot'), |
||
| 289 | ), |
||
| 290 | ) |
||
| 291 | ) |
||
| 292 | ); |
||
| 293 | |||
| 294 | /** @var \Shopware\Models\Article\Article $article */ |
||
| 295 | $article = $articleResource->update($article->getId(), $updateArticle); |
||
| 296 | |||
| 297 | /** @var \Shopware\Models\Article\Detail $detail */ |
||
| 298 | foreach ($article->getDetails() as $detail) { |
||
| 299 | Shopware()->Db()->executeQuery( |
||
| 300 | 'INSERT INTO s_plugin_connect_items (article_id, article_detail_id, source_id, category, exported) |
||
| 301 | VALUES (?, ?, ?, ?, ?)', |
||
| 302 | array( |
||
| 303 | $article->getId(), |
||
| 304 | $detail->getId(), |
||
| 305 | $detail->getNumber(), |
||
| 306 | '/bücher', |
||
| 307 | 1 |
||
| 308 | )); |
||
| 309 | } |
||
| 310 | |||
| 311 | return $article->getId(); |
||
| 312 | } |
||
| 313 | |||
| 317 |