@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | */ |
| 29 | 29 | public function getName() |
| 30 | 30 | { |
| 31 | - return $this->getContext()->getI18n()->dt( 'controller/jobs', 'Product import CSV' ); |
|
| 31 | + return $this->getContext()->getI18n()->dt('controller/jobs', 'Product import CSV'); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | */ |
| 40 | 40 | public function getDescription() |
| 41 | 41 | { |
| 42 | - return $this->getContext()->getI18n()->dt( 'controller/jobs', 'Imports new and updates existing products from CSV files' ); |
|
| 42 | + return $this->getContext()->getI18n()->dt('controller/jobs', 'Imports new and updates existing products from CSV files'); |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | $context = $this->getContext(); |
| 55 | 55 | $config = $context->getConfig(); |
| 56 | 56 | $logger = $context->getLogger(); |
| 57 | - $domains = array( 'attribute', 'media', 'price', 'product', 'text' ); |
|
| 57 | + $domains = array('attribute', 'media', 'price', 'product', 'text'); |
|
| 58 | 58 | $mappings = $this->getDefaultMapping(); |
| 59 | 59 | |
| 60 | 60 | |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | * @see controller/common/product/import/csv/converter |
| 75 | 75 | * @see controller/common/product/import/csv/max-size |
| 76 | 76 | */ |
| 77 | - $domains = $config->get( 'controller/common/product/import/csv/domains', $domains ); |
|
| 77 | + $domains = $config->get('controller/common/product/import/csv/domains', $domains); |
|
| 78 | 78 | |
| 79 | 79 | /** controller/jobs/product/import/csv/domains |
| 80 | 80 | * List of item domain names that should be retrieved along with the product items |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | * @see controller/jobs/product/import/csv/backup |
| 95 | 95 | * @see controller/common/product/import/csv/max-size |
| 96 | 96 | */ |
| 97 | - $domains = $config->get( 'controller/jobs/product/import/csv/domains', $domains ); |
|
| 97 | + $domains = $config->get('controller/jobs/product/import/csv/domains', $domains); |
|
| 98 | 98 | |
| 99 | 99 | |
| 100 | 100 | /** controller/common/product/import/csv/mapping |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | * @see controller/common/product/import/csv/converter |
| 123 | 123 | * @see controller/common/product/import/csv/max-size |
| 124 | 124 | */ |
| 125 | - $mappings = $config->get( 'controller/common/product/import/csv/mapping', $mappings ); |
|
| 125 | + $mappings = $config->get('controller/common/product/import/csv/mapping', $mappings); |
|
| 126 | 126 | |
| 127 | 127 | /** controller/jobs/product/import/csv/mapping |
| 128 | 128 | * List of mappings between the position in the CSV file and item keys |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | * @see controller/jobs/product/import/csv/backup |
| 143 | 143 | * @see controller/common/product/import/csv/max-size |
| 144 | 144 | */ |
| 145 | - $mappings = $config->get( 'controller/jobs/product/import/csv/mapping', $mappings ); |
|
| 145 | + $mappings = $config->get('controller/jobs/product/import/csv/mapping', $mappings); |
|
| 146 | 146 | |
| 147 | 147 | |
| 148 | 148 | /** controller/common/product/import/csv/converter |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | * @see controller/common/product/import/csv/mapping |
| 185 | 185 | * @see controller/common/product/import/csv/max-size |
| 186 | 186 | */ |
| 187 | - $converters = $config->get( 'controller/common/product/import/csv/converter', [] ); |
|
| 187 | + $converters = $config->get('controller/common/product/import/csv/converter', []); |
|
| 188 | 188 | |
| 189 | 189 | /** controller/jobs/product/import/csv/converter |
| 190 | 190 | * List of converter names for the values at the position in the CSV file |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | * @see controller/jobs/product/import/csv/backup |
| 205 | 205 | * @see controller/common/product/import/csv/max-size |
| 206 | 206 | */ |
| 207 | - $converters = $config->get( 'controller/jobs/product/import/csv/converter', $converters ); |
|
| 207 | + $converters = $config->get('controller/jobs/product/import/csv/converter', $converters); |
|
| 208 | 208 | |
| 209 | 209 | |
| 210 | 210 | /** controller/common/product/import/csv/max-size |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | * @see controller/common/product/import/csv/mapping |
| 225 | 225 | * @see controller/common/product/import/csv/converter |
| 226 | 226 | */ |
| 227 | - $maxcnt = (int) $config->get( 'controller/common/product/import/csv/max-size', 1000 ); |
|
| 227 | + $maxcnt = (int) $config->get('controller/common/product/import/csv/max-size', 1000); |
|
| 228 | 228 | |
| 229 | 229 | |
| 230 | 230 | /** controller/jobs/product/import/csv/skip-lines |
@@ -246,7 +246,7 @@ discard block |
||
| 246 | 246 | * @see controller/jobs/product/import/csv/backup |
| 247 | 247 | * @see controller/common/product/import/csv/max-size |
| 248 | 248 | */ |
| 249 | - $skiplines = (int) $config->get( 'controller/jobs/product/import/csv/skip-lines', 0 ); |
|
| 249 | + $skiplines = (int) $config->get('controller/jobs/product/import/csv/skip-lines', 0); |
|
| 250 | 250 | |
| 251 | 251 | |
| 252 | 252 | /** controller/jobs/product/import/csv/strict |
@@ -270,7 +270,7 @@ discard block |
||
| 270 | 270 | * @see controller/jobs/product/import/csv/backup |
| 271 | 271 | * @see controller/common/product/import/csv/max-size |
| 272 | 272 | */ |
| 273 | - $strict = (bool) $config->get( 'controller/jobs/product/import/csv/strict', true ); |
|
| 273 | + $strict = (bool) $config->get('controller/jobs/product/import/csv/strict', true); |
|
| 274 | 274 | |
| 275 | 275 | |
| 276 | 276 | /** controller/jobs/product/import/csv/backup |
@@ -303,74 +303,74 @@ discard block |
||
| 303 | 303 | * @see controller/jobs/product/import/csv/strict |
| 304 | 304 | * @see controller/common/product/import/csv/max-size |
| 305 | 305 | */ |
| 306 | - $backup = $config->get( 'controller/jobs/product/import/csv/backup' ); |
|
| 306 | + $backup = $config->get('controller/jobs/product/import/csv/backup'); |
|
| 307 | 307 | |
| 308 | 308 | |
| 309 | - if( !isset( $mappings['item'] ) || !is_array( $mappings['item'] ) ) |
|
| 309 | + if (!isset($mappings['item']) || !is_array($mappings['item'])) |
|
| 310 | 310 | { |
| 311 | - $msg = sprintf( 'Required mapping key "%1$s" is missing or contains no array', 'item' ); |
|
| 312 | - throw new \Aimeos\Controller\Jobs\Exception( $msg ); |
|
| 311 | + $msg = sprintf('Required mapping key "%1$s" is missing or contains no array', 'item'); |
|
| 312 | + throw new \Aimeos\Controller\Jobs\Exception($msg); |
|
| 313 | 313 | } |
| 314 | 314 | |
| 315 | 315 | try |
| 316 | 316 | { |
| 317 | 317 | $procMappings = $mappings; |
| 318 | - unset( $procMappings['item'] ); |
|
| 318 | + unset($procMappings['item']); |
|
| 319 | 319 | |
| 320 | - $codePos = $this->getCodePosition( $mappings['item'] ); |
|
| 321 | - $convlist = $this->getConverterList( $converters ); |
|
| 322 | - $processor = $this->getProcessors( $procMappings ); |
|
| 320 | + $codePos = $this->getCodePosition($mappings['item']); |
|
| 321 | + $convlist = $this->getConverterList($converters); |
|
| 322 | + $processor = $this->getProcessors($procMappings); |
|
| 323 | 323 | $container = $this->getContainer(); |
| 324 | 324 | $path = $container->getName(); |
| 325 | 325 | |
| 326 | - $msg = sprintf( 'Started product import from "%1$s" (%2$s)', $path, __CLASS__ ); |
|
| 327 | - $logger->log( $msg, \Aimeos\MW\Logger\Base::NOTICE ); |
|
| 326 | + $msg = sprintf('Started product import from "%1$s" (%2$s)', $path, __CLASS__); |
|
| 327 | + $logger->log($msg, \Aimeos\MW\Logger\Base::NOTICE); |
|
| 328 | 328 | |
| 329 | - foreach( $container as $content ) |
|
| 329 | + foreach ($container as $content) |
|
| 330 | 330 | { |
| 331 | 331 | $name = $content->getName(); |
| 332 | 332 | |
| 333 | - for( $i = 0; $i < $skiplines; $i++ ) { |
|
| 333 | + for ($i = 0; $i < $skiplines; $i++) { |
|
| 334 | 334 | $content->next(); |
| 335 | 335 | } |
| 336 | 336 | |
| 337 | - while( ( $data = $this->getData( $content, $maxcnt, $codePos ) ) !== [] ) |
|
| 337 | + while (($data = $this->getData($content, $maxcnt, $codePos)) !== []) |
|
| 338 | 338 | { |
| 339 | - $data = $this->convertData( $convlist, $data ); |
|
| 340 | - $products = $this->getProducts( array_keys( $data ), $domains ); |
|
| 341 | - $errcnt = $this->import( $products, $data, $mappings['item'], $processor, $strict ); |
|
| 342 | - $chunkcnt = count( $data ); |
|
| 339 | + $data = $this->convertData($convlist, $data); |
|
| 340 | + $products = $this->getProducts(array_keys($data), $domains); |
|
| 341 | + $errcnt = $this->import($products, $data, $mappings['item'], $processor, $strict); |
|
| 342 | + $chunkcnt = count($data); |
|
| 343 | 343 | |
| 344 | 344 | $msg = 'Imported product lines from "%1$s": %2$d/%3$d (%4$s)'; |
| 345 | - $logger->log( sprintf( $msg, $name, $chunkcnt - $errcnt, $chunkcnt, __CLASS__ ), \Aimeos\MW\Logger\Base::NOTICE ); |
|
| 345 | + $logger->log(sprintf($msg, $name, $chunkcnt - $errcnt, $chunkcnt, __CLASS__), \Aimeos\MW\Logger\Base::NOTICE); |
|
| 346 | 346 | |
| 347 | 347 | $errors += $errcnt; |
| 348 | 348 | $total += $chunkcnt; |
| 349 | - unset( $products, $data ); |
|
| 349 | + unset($products, $data); |
|
| 350 | 350 | } |
| 351 | 351 | } |
| 352 | 352 | |
| 353 | 353 | $container->close(); |
| 354 | 354 | } |
| 355 | - catch( \Exception $e ) |
|
| 355 | + catch (\Exception $e) |
|
| 356 | 356 | { |
| 357 | - $logger->log( 'Product import error: ' . $e->getMessage() ); |
|
| 358 | - $logger->log( $e->getTraceAsString() ); |
|
| 357 | + $logger->log('Product import error: ' . $e->getMessage()); |
|
| 358 | + $logger->log($e->getTraceAsString()); |
|
| 359 | 359 | |
| 360 | - throw new \Aimeos\Controller\Jobs\Exception( $e->getMessage() ); |
|
| 360 | + throw new \Aimeos\Controller\Jobs\Exception($e->getMessage()); |
|
| 361 | 361 | } |
| 362 | 362 | |
| 363 | 363 | $msg = 'Finished product import from "%1$s": %2$d successful, %3$s errors, %4$s total (%5$s)'; |
| 364 | - $logger->log( sprintf( $msg, $path, $total - $errors, $errors, $total, __CLASS__ ), \Aimeos\MW\Logger\Base::NOTICE ); |
|
| 364 | + $logger->log(sprintf($msg, $path, $total - $errors, $errors, $total, __CLASS__), \Aimeos\MW\Logger\Base::NOTICE); |
|
| 365 | 365 | |
| 366 | - if( $errors > 0 ) |
|
| 366 | + if ($errors > 0) |
|
| 367 | 367 | { |
| 368 | - $msg = sprintf( 'Invalid product lines in "%1$s": %2$d/%3$d', $path, $errors, $total ); |
|
| 369 | - throw new \Aimeos\Controller\Jobs\Exception( $msg ); |
|
| 368 | + $msg = sprintf('Invalid product lines in "%1$s": %2$d/%3$d', $path, $errors, $total); |
|
| 369 | + throw new \Aimeos\Controller\Jobs\Exception($msg); |
|
| 370 | 370 | } |
| 371 | 371 | |
| 372 | - if( !empty( $backup ) && @rename( $path, strftime( $backup ) ) === false ) { |
|
| 373 | - throw new \Aimeos\Controller\Jobs\Exception( sprintf( 'Unable to move imported file' ) ); |
|
| 372 | + if (!empty($backup) && @rename($path, strftime($backup)) === false) { |
|
| 373 | + throw new \Aimeos\Controller\Jobs\Exception(sprintf('Unable to move imported file')); |
|
| 374 | 374 | } |
| 375 | 375 | } |
| 376 | 376 | |
@@ -382,16 +382,16 @@ discard block |
||
| 382 | 382 | * @return integer Position of the "product.code" column |
| 383 | 383 | * @throws \Aimeos\Controller\Jobs\Exception If no mapping for "product.code" is found |
| 384 | 384 | */ |
| 385 | - protected function getCodePosition( array $mapping ) |
|
| 385 | + protected function getCodePosition(array $mapping) |
|
| 386 | 386 | { |
| 387 | - foreach( $mapping as $pos => $key ) |
|
| 387 | + foreach ($mapping as $pos => $key) |
|
| 388 | 388 | { |
| 389 | - if( $key === 'product.code' ) { |
|
| 389 | + if ($key === 'product.code') { |
|
| 390 | 390 | return $pos; |
| 391 | 391 | } |
| 392 | 392 | } |
| 393 | 393 | |
| 394 | - throw new \Aimeos\Controller\Jobs\Exception( sprintf( 'No "product.code" column in CSV mapping found' ) ); |
|
| 394 | + throw new \Aimeos\Controller\Jobs\Exception(sprintf('No "product.code" column in CSV mapping found')); |
|
| 395 | 395 | } |
| 396 | 396 | |
| 397 | 397 | |
@@ -426,7 +426,7 @@ discard block |
||
| 426 | 426 | * @see controller/jobs/product/import/csv/container/content |
| 427 | 427 | * @see controller/jobs/product/import/csv/container/options |
| 428 | 428 | */ |
| 429 | - $location = $config->get( 'controller/jobs/product/import/csv/location', '.' ); |
|
| 429 | + $location = $config->get('controller/jobs/product/import/csv/location', '.'); |
|
| 430 | 430 | |
| 431 | 431 | /** controller/jobs/product/import/csv/container/type |
| 432 | 432 | * Nave of the container type to read the data from |
@@ -449,7 +449,7 @@ discard block |
||
| 449 | 449 | * @see controller/jobs/product/import/csv/container/content |
| 450 | 450 | * @see controller/jobs/product/import/csv/container/options |
| 451 | 451 | */ |
| 452 | - $container = $config->get( 'controller/jobs/product/import/csv/container/type', 'Directory' ); |
|
| 452 | + $container = $config->get('controller/jobs/product/import/csv/container/type', 'Directory'); |
|
| 453 | 453 | |
| 454 | 454 | /** controller/jobs/product/import/csv/container/content |
| 455 | 455 | * Name of the content type inside the container to read the data from |
@@ -470,7 +470,7 @@ discard block |
||
| 470 | 470 | * @see controller/jobs/product/import/csv/container/type |
| 471 | 471 | * @see controller/jobs/product/import/csv/container/options |
| 472 | 472 | */ |
| 473 | - $content = $config->get( 'controller/jobs/product/import/csv/container/content', 'CSV' ); |
|
| 473 | + $content = $config->get('controller/jobs/product/import/csv/container/content', 'CSV'); |
|
| 474 | 474 | |
| 475 | 475 | /** controller/jobs/product/import/csv/container/options |
| 476 | 476 | * List of file container options for the product import files |
@@ -488,9 +488,9 @@ discard block |
||
| 488 | 488 | * @see controller/jobs/product/import/csv/container/content |
| 489 | 489 | * @see controller/jobs/product/import/csv/container/type |
| 490 | 490 | */ |
| 491 | - $options = $config->get( 'controller/jobs/product/import/csv/container/options', [] ); |
|
| 491 | + $options = $config->get('controller/jobs/product/import/csv/container/options', []); |
|
| 492 | 492 | |
| 493 | - return \Aimeos\MW\Container\Factory::getContainer( $location, $container, $content, $options ); |
|
| 493 | + return \Aimeos\MW\Container\Factory::getContainer($location, $container, $content, $options); |
|
| 494 | 494 | } |
| 495 | 495 | |
| 496 | 496 | |
@@ -505,54 +505,54 @@ discard block |
||
| 505 | 505 | * @return integer Number of products that couldn't be imported |
| 506 | 506 | * @throws \Aimeos\Controller\Jobs\Exception |
| 507 | 507 | */ |
| 508 | - protected function import( array $products, array $data, array $mapping, |
|
| 509 | - \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $processor, $strict ) |
|
| 508 | + protected function import(array $products, array $data, array $mapping, |
|
| 509 | + \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $processor, $strict) |
|
| 510 | 510 | { |
| 511 | 511 | $errors = 0; |
| 512 | 512 | $context = $this->getContext(); |
| 513 | - $manager = \Aimeos\MShop\Factory::createManager( $context, 'product' ); |
|
| 513 | + $manager = \Aimeos\MShop\Factory::createManager($context, 'product'); |
|
| 514 | 514 | |
| 515 | - foreach( $data as $code => $list ) |
|
| 515 | + foreach ($data as $code => $list) |
|
| 516 | 516 | { |
| 517 | 517 | $manager->begin(); |
| 518 | 518 | |
| 519 | 519 | try |
| 520 | 520 | { |
| 521 | - if( isset( $products[$code] ) ) { |
|
| 521 | + if (isset($products[$code])) { |
|
| 522 | 522 | $product = $products[$code]; |
| 523 | 523 | } else { |
| 524 | 524 | $product = $manager->createItem(); |
| 525 | 525 | } |
| 526 | 526 | |
| 527 | - $map = $this->getMappedChunk( $list, $mapping ); |
|
| 527 | + $map = $this->getMappedChunk($list, $mapping); |
|
| 528 | 528 | |
| 529 | - if( isset( $map[0] ) ) |
|
| 529 | + if (isset($map[0])) |
|
| 530 | 530 | { |
| 531 | 531 | $map = $map[0]; // there can only be one chunk for the base product data |
| 532 | 532 | |
| 533 | - $typecode = ( isset( $map['product.type'] ) ? $map['product.type'] : 'default' ); |
|
| 534 | - $map['product.typeid'] = $this->getTypeId( 'product/type', 'product', $typecode ); |
|
| 533 | + $typecode = (isset($map['product.type']) ? $map['product.type'] : 'default'); |
|
| 534 | + $map['product.typeid'] = $this->getTypeId('product/type', 'product', $typecode); |
|
| 535 | 535 | |
| 536 | - $product->fromArray( $this->addItemDefaults( $map ) ); |
|
| 537 | - $product = $manager->saveItem( $product ); |
|
| 536 | + $product->fromArray($this->addItemDefaults($map)); |
|
| 537 | + $product = $manager->saveItem($product); |
|
| 538 | 538 | |
| 539 | - $list = $processor->process( $product, $list ); |
|
| 539 | + $list = $processor->process($product, $list); |
|
| 540 | 540 | } |
| 541 | 541 | |
| 542 | 542 | $manager->commit(); |
| 543 | 543 | } |
| 544 | - catch( \Exception $e ) |
|
| 544 | + catch (\Exception $e) |
|
| 545 | 545 | { |
| 546 | 546 | $manager->rollback(); |
| 547 | 547 | |
| 548 | - $msg = sprintf( 'Unable to import product with code "%1$s": %2$s', $code, $e->getMessage() ); |
|
| 549 | - $context->getLogger()->log( $msg ); |
|
| 548 | + $msg = sprintf('Unable to import product with code "%1$s": %2$s', $code, $e->getMessage()); |
|
| 549 | + $context->getLogger()->log($msg); |
|
| 550 | 550 | |
| 551 | 551 | $errors++; |
| 552 | 552 | } |
| 553 | 553 | |
| 554 | - if( $strict && !empty( $list ) ) { |
|
| 555 | - $context->getLogger()->log( 'Not imported: ' . print_r( $list, true ) ); |
|
| 554 | + if ($strict && !empty($list)) { |
|
| 555 | + $context->getLogger()->log('Not imported: ' . print_r($list, true)); |
|
| 556 | 556 | } |
| 557 | 557 | } |
| 558 | 558 | |
@@ -566,9 +566,9 @@ discard block |
||
| 566 | 566 | * @param array $list Associative list of domain item keys and their values, e.g. "product.status" => 1 |
| 567 | 567 | * @return array Given associative list enriched by default values if they were not already set |
| 568 | 568 | */ |
| 569 | - protected function addItemDefaults( array $list ) |
|
| 569 | + protected function addItemDefaults(array $list) |
|
| 570 | 570 | { |
| 571 | - if( !isset( $list['product.status'] ) ) { |
|
| 571 | + if (!isset($list['product.status'])) { |
|
| 572 | 572 | $list['product.status'] = 1; |
| 573 | 573 | } |
| 574 | 574 | |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | */ |
| 30 | 30 | public function getName() |
| 31 | 31 | { |
| 32 | - return $this->getContext()->getI18n()->dt( 'controller/jobs', 'Products bought together' ); |
|
| 32 | + return $this->getContext()->getI18n()->dt('controller/jobs', 'Products bought together'); |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | */ |
| 41 | 41 | public function getDescription() |
| 42 | 42 | { |
| 43 | - return $this->getContext()->getI18n()->dt( 'controller/jobs', 'Creates bought together product suggestions' ); |
|
| 43 | + return $this->getContext()->getI18n()->dt('controller/jobs', 'Creates bought together product suggestions'); |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | * @see controller/jobs/product/bought/min-confidence |
| 73 | 73 | * @see controller/jobs/product/bought/limit-days |
| 74 | 74 | */ |
| 75 | - $maxItems = $config->get( 'controller/jobs/product/bought/max-items', 5 ); |
|
| 75 | + $maxItems = $config->get('controller/jobs/product/bought/max-items', 5); |
|
| 76 | 76 | |
| 77 | 77 | /** controller/jobs/product/bought/min-support |
| 78 | 78 | * Minimum support value to sort out all irrelevant combinations |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | * @see controller/jobs/product/bought/min-confidence |
| 102 | 102 | * @see controller/jobs/product/bought/limit-days |
| 103 | 103 | */ |
| 104 | - $minSupport = $config->get( 'controller/jobs/product/bought/min-support', 0.02 ); |
|
| 104 | + $minSupport = $config->get('controller/jobs/product/bought/min-support', 0.02); |
|
| 105 | 105 | |
| 106 | 106 | /** controller/jobs/product/bought/min-confidence |
| 107 | 107 | * Minimum confidence value for high quality suggestions |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | * @see controller/jobs/product/bought/min-support |
| 127 | 127 | * @see controller/jobs/product/bought/limit-days |
| 128 | 128 | */ |
| 129 | - $minConfidence = $config->get( 'controller/jobs/product/bought/min-confidence', 0.66 ); |
|
| 129 | + $minConfidence = $config->get('controller/jobs/product/bought/min-confidence', 0.66); |
|
| 130 | 130 | |
| 131 | 131 | /** controller/jobs/product/bought/limit-days |
| 132 | 132 | * Only use orders placed in the past within the configured number of days for calculating bought together products |
@@ -150,45 +150,45 @@ discard block |
||
| 150 | 150 | * @see controller/jobs/product/bought/min-support |
| 151 | 151 | * @see controller/jobs/product/bought/min-confidence |
| 152 | 152 | */ |
| 153 | - $days = $config->get( 'controller/jobs/product/bought/limit-days', 180 ); |
|
| 154 | - $date = date( 'Y-m-d H:i:s', time() - $days * 86400 ); |
|
| 153 | + $days = $config->get('controller/jobs/product/bought/limit-days', 180); |
|
| 154 | + $date = date('Y-m-d H:i:s', time() - $days * 86400); |
|
| 155 | 155 | |
| 156 | 156 | |
| 157 | - $typeItem = $this->getTypeItem( 'product/lists/type', 'product', 'bought-together' ); |
|
| 157 | + $typeItem = $this->getTypeItem('product/lists/type', 'product', 'bought-together'); |
|
| 158 | 158 | |
| 159 | - $baseManager = \Aimeos\MShop\Factory::createManager( $context, 'order/base' ); |
|
| 159 | + $baseManager = \Aimeos\MShop\Factory::createManager($context, 'order/base'); |
|
| 160 | 160 | $search = $baseManager->createSearch(); |
| 161 | - $search->setConditions( $search->compare( '>', 'order.base.ctime', $date ) ); |
|
| 162 | - $search->setSlice( 0, 0 ); |
|
| 161 | + $search->setConditions($search->compare('>', 'order.base.ctime', $date)); |
|
| 162 | + $search->setSlice(0, 0); |
|
| 163 | 163 | $totalOrders = 0; |
| 164 | - $baseManager->searchItems( $search, [], $totalOrders ); |
|
| 164 | + $baseManager->searchItems($search, [], $totalOrders); |
|
| 165 | 165 | |
| 166 | - $baseProductManager = \Aimeos\MShop\Factory::createManager( $context, 'order/base/product' ); |
|
| 166 | + $baseProductManager = \Aimeos\MShop\Factory::createManager($context, 'order/base/product'); |
|
| 167 | 167 | $search = $baseProductManager->createSearch(); |
| 168 | - $search->setConditions( $search->compare( '>', 'order.base.product.ctime', $date ) ); |
|
| 168 | + $search->setConditions($search->compare('>', 'order.base.product.ctime', $date)); |
|
| 169 | 169 | $start = 0; |
| 170 | 170 | |
| 171 | 171 | do |
| 172 | 172 | { |
| 173 | - $totalCounts = $baseProductManager->aggregate( $search, 'order.base.product.productid' ); |
|
| 174 | - $prodIds = array_keys( $totalCounts ); |
|
| 173 | + $totalCounts = $baseProductManager->aggregate($search, 'order.base.product.productid'); |
|
| 174 | + $prodIds = array_keys($totalCounts); |
|
| 175 | 175 | |
| 176 | - foreach( $totalCounts as $id => $count ) |
|
| 176 | + foreach ($totalCounts as $id => $count) |
|
| 177 | 177 | { |
| 178 | - $this->removeListItems( $id, $typeItem->getId() ); |
|
| 178 | + $this->removeListItems($id, $typeItem->getId()); |
|
| 179 | 179 | |
| 180 | - if( $count / $totalOrders > $minSupport ) |
|
| 180 | + if ($count / $totalOrders > $minSupport) |
|
| 181 | 181 | { |
| 182 | - $productIds = $this->getSuggestions( $id, $prodIds, $count, $totalOrders, $maxItems, $minSupport, $minConfidence, $date ); |
|
| 183 | - $this->addListItems( $id, $typeItem->getId(), $productIds ); |
|
| 182 | + $productIds = $this->getSuggestions($id, $prodIds, $count, $totalOrders, $maxItems, $minSupport, $minConfidence, $date); |
|
| 183 | + $this->addListItems($id, $typeItem->getId(), $productIds); |
|
| 184 | 184 | } |
| 185 | 185 | } |
| 186 | 186 | |
| 187 | - $count = count( $totalCounts ); |
|
| 187 | + $count = count($totalCounts); |
|
| 188 | 188 | $start += $count; |
| 189 | - $search->setSlice( $start ); |
|
| 189 | + $search->setSlice($start); |
|
| 190 | 190 | } |
| 191 | - while( $count >= $search->getSliceSize() ); |
|
| 191 | + while ($count >= $search->getSliceSize()); |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | |
@@ -205,59 +205,59 @@ discard block |
||
| 205 | 205 | * @param string $date Date in YYYY-MM-DD HH:mm:ss format after which orders should be used for calculations |
| 206 | 206 | * @return array List of suggested product IDs as key and their confidence as value |
| 207 | 207 | */ |
| 208 | - protected function getSuggestions( $id, $prodIds, $count, $total, $maxItems, $minSupport, $minConfidence, $date ) |
|
| 208 | + protected function getSuggestions($id, $prodIds, $count, $total, $maxItems, $minSupport, $minConfidence, $date) |
|
| 209 | 209 | { |
| 210 | 210 | $refIds = []; |
| 211 | 211 | $context = $this->getContext(); |
| 212 | 212 | |
| 213 | - $catalogListManager = \Aimeos\MShop\Factory::createManager( $context, 'catalog/lists' ); |
|
| 214 | - $baseProductManager = \Aimeos\MShop\Factory::createManager( $context, 'order/base/product' ); |
|
| 213 | + $catalogListManager = \Aimeos\MShop\Factory::createManager($context, 'catalog/lists'); |
|
| 214 | + $baseProductManager = \Aimeos\MShop\Factory::createManager($context, 'order/base/product'); |
|
| 215 | 215 | |
| 216 | 216 | |
| 217 | 217 | $search = $baseProductManager->createSearch(); |
| 218 | - $func = $search->createFunction( 'order.base.product.count', array( (string) $id ) ); |
|
| 218 | + $func = $search->createFunction('order.base.product.count', array((string) $id)); |
|
| 219 | 219 | $expr = array( |
| 220 | - $search->compare( '==', 'order.base.product.productid', $prodIds ), |
|
| 221 | - $search->compare( '>', 'order.base.product.ctime', $date ), |
|
| 222 | - $search->compare( '==', $func, 1 ), |
|
| 220 | + $search->compare('==', 'order.base.product.productid', $prodIds), |
|
| 221 | + $search->compare('>', 'order.base.product.ctime', $date), |
|
| 222 | + $search->compare('==', $func, 1), |
|
| 223 | 223 | ); |
| 224 | - $search->setConditions( $search->combine( '&&', $expr ) ); |
|
| 224 | + $search->setConditions($search->combine('&&', $expr)); |
|
| 225 | 225 | |
| 226 | - $relativeCounts = $baseProductManager->aggregate( $search, 'order.base.product.productid' ); |
|
| 226 | + $relativeCounts = $baseProductManager->aggregate($search, 'order.base.product.productid'); |
|
| 227 | 227 | |
| 228 | 228 | |
| 229 | 229 | $search = $catalogListManager->createSearch(); |
| 230 | 230 | $expr = array( |
| 231 | - $search->compare( '==', 'catalog.lists.refid', array_keys( $relativeCounts ) ), |
|
| 232 | - $search->compare( '==', 'catalog.lists.domain', 'product' ), |
|
| 231 | + $search->compare('==', 'catalog.lists.refid', array_keys($relativeCounts)), |
|
| 232 | + $search->compare('==', 'catalog.lists.domain', 'product'), |
|
| 233 | 233 | ); |
| 234 | - $search->setConditions( $search->combine( '&&', $expr ) ); |
|
| 234 | + $search->setConditions($search->combine('&&', $expr)); |
|
| 235 | 235 | |
| 236 | - foreach( $catalogListManager->searchItems( $search ) as $listItem ) { |
|
| 236 | + foreach ($catalogListManager->searchItems($search) as $listItem) { |
|
| 237 | 237 | $refIds[$listItem->getRefId()] = true; |
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | |
| 241 | - unset( $relativeCounts[$id] ); |
|
| 241 | + unset($relativeCounts[$id]); |
|
| 242 | 242 | $supportA = $count / $total; |
| 243 | 243 | $products = []; |
| 244 | 244 | |
| 245 | - foreach( $relativeCounts as $prodId => $relCnt ) |
|
| 245 | + foreach ($relativeCounts as $prodId => $relCnt) |
|
| 246 | 246 | { |
| 247 | - if( !isset( $refIds[$prodId] ) ) { |
|
| 247 | + if (!isset($refIds[$prodId])) { |
|
| 248 | 248 | continue; |
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | $supportAB = $relCnt / $total; |
| 252 | 252 | |
| 253 | - if( $supportAB > $minSupport && ( $conf = ( $supportAB / $supportA ) ) > $minConfidence ) { |
|
| 253 | + if ($supportAB > $minSupport && ($conf = ($supportAB / $supportA)) > $minConfidence) { |
|
| 254 | 254 | $products[$prodId] = $conf; |
| 255 | 255 | } |
| 256 | 256 | } |
| 257 | 257 | |
| 258 | - arsort( $products ); |
|
| 258 | + arsort($products); |
|
| 259 | 259 | |
| 260 | - return array_keys( array_slice( $products, 0, $maxItems, true ) ); |
|
| 260 | + return array_keys(array_slice($products, 0, $maxItems, true)); |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | |
@@ -268,26 +268,26 @@ discard block |
||
| 268 | 268 | * @param integer $typeId Unique ID of the list type used for the referenced products |
| 269 | 269 | * @param array $productIds List of position as key and product ID as value |
| 270 | 270 | */ |
| 271 | - protected function addListItems( $productId, $typeId, array $productIds ) |
|
| 271 | + protected function addListItems($productId, $typeId, array $productIds) |
|
| 272 | 272 | { |
| 273 | - if( empty( $productIds ) ) { |
|
| 273 | + if (empty($productIds)) { |
|
| 274 | 274 | return; |
| 275 | 275 | } |
| 276 | 276 | |
| 277 | - $manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'product/lists' ); |
|
| 277 | + $manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'product/lists'); |
|
| 278 | 278 | $item = $manager->createItem(); |
| 279 | 279 | |
| 280 | - foreach( $productIds as $pos => $refid ) |
|
| 280 | + foreach ($productIds as $pos => $refid) |
|
| 281 | 281 | { |
| 282 | - $item->setId( null ); |
|
| 283 | - $item->setParentId( $productId ); |
|
| 284 | - $item->setDomain( 'product' ); |
|
| 285 | - $item->setTypeId( $typeId ); |
|
| 286 | - $item->setPosition( $pos ); |
|
| 287 | - $item->setRefId( $refid ); |
|
| 288 | - $item->setStatus( 1 ); |
|
| 289 | - |
|
| 290 | - $manager->saveItem( $item, false ); |
|
| 282 | + $item->setId(null); |
|
| 283 | + $item->setParentId($productId); |
|
| 284 | + $item->setDomain('product'); |
|
| 285 | + $item->setTypeId($typeId); |
|
| 286 | + $item->setPosition($pos); |
|
| 287 | + $item->setRefId($refid); |
|
| 288 | + $item->setStatus(1); |
|
| 289 | + |
|
| 290 | + $manager->saveItem($item, false); |
|
| 291 | 291 | } |
| 292 | 292 | } |
| 293 | 293 | |
@@ -298,20 +298,20 @@ discard block |
||
| 298 | 298 | * @param string $productId Unique ID of the product the references should be removed from |
| 299 | 299 | * @param integer $typeId Unique ID of the list type the referenced products should be removed from |
| 300 | 300 | */ |
| 301 | - protected function removeListItems( $productId, $typeId ) |
|
| 301 | + protected function removeListItems($productId, $typeId) |
|
| 302 | 302 | { |
| 303 | - $manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'product/lists' ); |
|
| 303 | + $manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'product/lists'); |
|
| 304 | 304 | |
| 305 | 305 | $search = $manager->createSearch(); |
| 306 | 306 | $expr = array( |
| 307 | - $search->compare( '==', 'product.lists.parentid', $productId ), |
|
| 308 | - $search->compare( '==', 'product.lists.domain', 'product' ), |
|
| 309 | - $search->compare( '==', 'product.lists.typeid', $typeId ), |
|
| 307 | + $search->compare('==', 'product.lists.parentid', $productId), |
|
| 308 | + $search->compare('==', 'product.lists.domain', 'product'), |
|
| 309 | + $search->compare('==', 'product.lists.typeid', $typeId), |
|
| 310 | 310 | ); |
| 311 | - $search->setConditions( $search->combine( '&&', $expr ) ); |
|
| 311 | + $search->setConditions($search->combine('&&', $expr)); |
|
| 312 | 312 | |
| 313 | - $listItems = $manager->searchItems( $search ); |
|
| 313 | + $listItems = $manager->searchItems($search); |
|
| 314 | 314 | |
| 315 | - $manager->deleteItems( array_keys( $listItems ) ); |
|
| 315 | + $manager->deleteItems(array_keys($listItems)); |
|
| 316 | 316 | } |
| 317 | 317 | } |
@@ -42,10 +42,10 @@ discard block |
||
| 42 | 42 | * @param array $mapping Associative list of field position in CSV as key and domain item key as value |
| 43 | 43 | * @param \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $object Decorated processor |
| 44 | 44 | */ |
| 45 | - public function __construct( \Aimeos\MShop\Context\Item\Iface $context, array $mapping, |
|
| 46 | - \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $object = null ) |
|
| 45 | + public function __construct(\Aimeos\MShop\Context\Item\Iface $context, array $mapping, |
|
| 46 | + \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $object = null) |
|
| 47 | 47 | { |
| 48 | - parent::__construct( $context, $mapping, $object ); |
|
| 48 | + parent::__construct($context, $mapping, $object); |
|
| 49 | 49 | |
| 50 | 50 | /** controller/common/product/import/csv/processor/text/listtypes |
| 51 | 51 | * Names of the product list types for texts that are updated or removed |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | * @see controller/common/product/import/csv/processor/price/listtypes |
| 67 | 67 | * @see controller/common/product/import/csv/processor/product/listtypes |
| 68 | 68 | */ |
| 69 | - $this->listTypes = $context->getConfig()->get( 'controller/common/product/import/csv/processor/text/listtypes' ); |
|
| 69 | + $this->listTypes = $context->getConfig()->get('controller/common/product/import/csv/processor/text/listtypes'); |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | |
@@ -77,39 +77,39 @@ discard block |
||
| 77 | 77 | * @param array $data List of CSV fields with position as key and data as value |
| 78 | 78 | * @return array List of data which hasn't been imported |
| 79 | 79 | */ |
| 80 | - public function process( \Aimeos\MShop\Product\Item\Iface $product, array $data ) |
|
| 80 | + public function process(\Aimeos\MShop\Product\Item\Iface $product, array $data) |
|
| 81 | 81 | { |
| 82 | - $listManager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'product/lists' ); |
|
| 83 | - $manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'text' ); |
|
| 82 | + $listManager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'product/lists'); |
|
| 83 | + $manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'text'); |
|
| 84 | 84 | $manager->begin(); |
| 85 | 85 | |
| 86 | 86 | try |
| 87 | 87 | { |
| 88 | 88 | $delete = $listMap = []; |
| 89 | - $map = $this->getMappedChunk( $data, $this->getMapping() ); |
|
| 90 | - $listItems = $product->getListItems( 'text', $this->listTypes ); |
|
| 89 | + $map = $this->getMappedChunk($data, $this->getMapping()); |
|
| 90 | + $listItems = $product->getListItems('text', $this->listTypes); |
|
| 91 | 91 | |
| 92 | - foreach( $listItems as $listItem ) |
|
| 92 | + foreach ($listItems as $listItem) |
|
| 93 | 93 | { |
| 94 | - if( ( $refItem = $listItem->getRefItem() ) !== null ) { |
|
| 95 | - $listMap[ $refItem->getContent() ][ $refItem->getType() ][ $listItem->getType() ] = $listItem; |
|
| 94 | + if (($refItem = $listItem->getRefItem()) !== null) { |
|
| 95 | + $listMap[$refItem->getContent()][$refItem->getType()][$listItem->getType()] = $listItem; |
|
| 96 | 96 | } |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | - foreach( $map as $pos => $list ) |
|
| 99 | + foreach ($map as $pos => $list) |
|
| 100 | 100 | { |
| 101 | - if( $this->checkEntry( $list ) === false ) { |
|
| 101 | + if ($this->checkEntry($list) === false) { |
|
| 102 | 102 | continue; |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | - $type = ( isset( $list['text.type'] ) ? $list['text.type'] : 'name' ); |
|
| 106 | - $typecode = ( isset( $list['product.lists.type'] ) ? $list['product.lists.type'] : 'default' ); |
|
| 105 | + $type = (isset($list['text.type']) ? $list['text.type'] : 'name'); |
|
| 106 | + $typecode = (isset($list['product.lists.type']) ? $list['product.lists.type'] : 'default'); |
|
| 107 | 107 | |
| 108 | - if( isset( $listMap[ $list['text.content'] ][$type][$typecode] ) ) |
|
| 108 | + if (isset($listMap[$list['text.content']][$type][$typecode])) |
|
| 109 | 109 | { |
| 110 | - $listItem = $listMap[ $list['text.content'] ][$type][$typecode]; |
|
| 110 | + $listItem = $listMap[$list['text.content']][$type][$typecode]; |
|
| 111 | 111 | $refItem = $listItem->getRefItem(); |
| 112 | - unset( $listItems[ $listItem->getId() ] ); |
|
| 112 | + unset($listItems[$listItem->getId()]); |
|
| 113 | 113 | } |
| 114 | 114 | else |
| 115 | 115 | { |
@@ -117,33 +117,33 @@ discard block |
||
| 117 | 117 | $refItem = $manager->createItem(); |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | - $list['text.typeid'] = $this->getTypeId( 'text/type', 'product', $type ); |
|
| 120 | + $list['text.typeid'] = $this->getTypeId('text/type', 'product', $type); |
|
| 121 | 121 | $list['text.domain'] = 'product'; |
| 122 | 122 | |
| 123 | - $refItem->fromArray( $this->addItemDefaults( $list ) ); |
|
| 124 | - $refItem = $manager->saveItem( $refItem ); |
|
| 123 | + $refItem->fromArray($this->addItemDefaults($list)); |
|
| 124 | + $refItem = $manager->saveItem($refItem); |
|
| 125 | 125 | |
| 126 | - $list['product.lists.typeid'] = $this->getTypeId( 'product/lists/type', 'text', $typecode ); |
|
| 126 | + $list['product.lists.typeid'] = $this->getTypeId('product/lists/type', 'text', $typecode); |
|
| 127 | 127 | $list['product.lists.parentid'] = $product->getId(); |
| 128 | 128 | $list['product.lists.refid'] = $refItem->getId(); |
| 129 | 129 | $list['product.lists.domain'] = 'text'; |
| 130 | 130 | |
| 131 | - $listItem->fromArray( $this->addListItemDefaults( $list, $pos ) ); |
|
| 132 | - $listManager->saveItem( $listItem, false ); |
|
| 131 | + $listItem->fromArray($this->addListItemDefaults($list, $pos)); |
|
| 132 | + $listManager->saveItem($listItem, false); |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | - foreach( $listItems as $listItem ) { |
|
| 135 | + foreach ($listItems as $listItem) { |
|
| 136 | 136 | $delete[] = $listItem->getRefId(); |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | - $manager->deleteItems( $delete ); |
|
| 140 | - $listManager->deleteItems( array_keys( $listItems ) ); |
|
| 139 | + $manager->deleteItems($delete); |
|
| 140 | + $listManager->deleteItems(array_keys($listItems)); |
|
| 141 | 141 | |
| 142 | - $data = $this->getObject()->process( $product, $data ); |
|
| 142 | + $data = $this->getObject()->process($product, $data); |
|
| 143 | 143 | |
| 144 | 144 | $manager->commit(); |
| 145 | 145 | } |
| 146 | - catch( \Exception $e ) |
|
| 146 | + catch (\Exception $e) |
|
| 147 | 147 | { |
| 148 | 148 | $manager->rollback(); |
| 149 | 149 | throw $e; |
@@ -159,17 +159,17 @@ discard block |
||
| 159 | 159 | * @param array $list Associative list of domain item keys and their values, e.g. "text.status" => 1 |
| 160 | 160 | * @return array Given associative list enriched by default values if they were not already set |
| 161 | 161 | */ |
| 162 | - protected function addItemDefaults( array $list ) |
|
| 162 | + protected function addItemDefaults(array $list) |
|
| 163 | 163 | { |
| 164 | - if( !isset( $list['text.label'] ) ) { |
|
| 165 | - $list['text.label'] = mb_strcut( $list['text.content'], 0, 255 ); |
|
| 164 | + if (!isset($list['text.label'])) { |
|
| 165 | + $list['text.label'] = mb_strcut($list['text.content'], 0, 255); |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | - if( !isset( $list['text.languageid'] ) ) { |
|
| 168 | + if (!isset($list['text.languageid'])) { |
|
| 169 | 169 | $list['text.languageid'] = $this->getContext()->getLocale()->getLanguageId(); |
| 170 | 170 | } |
| 171 | 171 | |
| 172 | - if( !isset( $list['text.status'] ) ) { |
|
| 172 | + if (!isset($list['text.status'])) { |
|
| 173 | 173 | $list['text.status'] = 1; |
| 174 | 174 | } |
| 175 | 175 | |
@@ -183,10 +183,10 @@ discard block |
||
| 183 | 183 | * @param array $list Associative list of key/value pairs from the mapping |
| 184 | 184 | * @return boolean True if valid, false if not |
| 185 | 185 | */ |
| 186 | - protected function checkEntry( array $list ) |
|
| 186 | + protected function checkEntry(array $list) |
|
| 187 | 187 | { |
| 188 | - if( !isset( $list['text.content'] ) || $list['text.content'] === '' || isset( $list['product.lists.type'] ) |
|
| 189 | - && $this->listTypes !== null && !in_array( $list['product.lists.type'], (array) $this->listTypes ) |
|
| 188 | + if (!isset($list['text.content']) || $list['text.content'] === '' || isset($list['product.lists.type']) |
|
| 189 | + && $this->listTypes !== null && !in_array($list['product.lists.type'], (array) $this->listTypes) |
|
| 190 | 190 | ) { |
| 191 | 191 | return false; |
| 192 | 192 | } |
@@ -43,10 +43,10 @@ discard block |
||
| 43 | 43 | * @param array $mapping Associative list of field position in CSV as key and domain item key as value |
| 44 | 44 | * @param \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $object Decorated processor |
| 45 | 45 | */ |
| 46 | - public function __construct( \Aimeos\MShop\Context\Item\Iface $context, array $mapping, |
|
| 47 | - \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $object = null ) |
|
| 46 | + public function __construct(\Aimeos\MShop\Context\Item\Iface $context, array $mapping, |
|
| 47 | + \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $object = null) |
|
| 48 | 48 | { |
| 49 | - parent::__construct( $context, $mapping, $object ); |
|
| 49 | + parent::__construct($context, $mapping, $object); |
|
| 50 | 50 | |
| 51 | 51 | /** controller/common/product/import/csv/processor/catalog/listtypes |
| 52 | 52 | * Names of the catalog list types that are updated or removed |
@@ -67,9 +67,9 @@ discard block |
||
| 67 | 67 | * @see controller/common/product/import/csv/processor/product/listtypes |
| 68 | 68 | * @see controller/common/product/import/csv/processor/text/listtypes |
| 69 | 69 | */ |
| 70 | - $this->listTypes = $context->getConfig()->get( 'controller/common/product/import/csv/processor/catalog/listtypes' ); |
|
| 70 | + $this->listTypes = $context->getConfig()->get('controller/common/product/import/csv/processor/catalog/listtypes'); |
|
| 71 | 71 | |
| 72 | - $this->cache = $this->getCache( 'catalog' ); |
|
| 72 | + $this->cache = $this->getCache('catalog'); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | |
@@ -80,11 +80,11 @@ discard block |
||
| 80 | 80 | * @param array $data List of CSV fields with position as key and data as value |
| 81 | 81 | * @return array List of data which hasn't been imported |
| 82 | 82 | */ |
| 83 | - public function process( \Aimeos\MShop\Product\Item\Iface $product, array $data ) |
|
| 83 | + public function process(\Aimeos\MShop\Product\Item\Iface $product, array $data) |
|
| 84 | 84 | { |
| 85 | 85 | $context = $this->getContext(); |
| 86 | - $manager = \Aimeos\MShop\Factory::createManager( $context, 'catalog' ); |
|
| 87 | - $listManager = \Aimeos\MShop\Factory::createManager( $context, 'catalog/lists' ); |
|
| 86 | + $manager = \Aimeos\MShop\Factory::createManager($context, 'catalog'); |
|
| 87 | + $listManager = \Aimeos\MShop\Factory::createManager($context, 'catalog/lists'); |
|
| 88 | 88 | |
| 89 | 89 | /** controller/common/product/import/csv/separator |
| 90 | 90 | * Single separator character for multiple entries in one field of the import file |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | * @category Developer |
| 105 | 105 | * @see controller/common/product/import/csv/domains |
| 106 | 106 | */ |
| 107 | - $separator = $context->getConfig()->get( 'controller/common/product/import/csv/separator', "\n" ); |
|
| 107 | + $separator = $context->getConfig()->get('controller/common/product/import/csv/separator', "\n"); |
|
| 108 | 108 | |
| 109 | 109 | $manager->begin(); |
| 110 | 110 | |
@@ -112,56 +112,56 @@ discard block |
||
| 112 | 112 | { |
| 113 | 113 | $listMap = []; |
| 114 | 114 | $prodid = $product->getId(); |
| 115 | - $map = $this->getMappedChunk( $data, $this->getMapping() ); |
|
| 116 | - $listItems = $this->getListItems( $prodid, $this->listTypes ); |
|
| 115 | + $map = $this->getMappedChunk($data, $this->getMapping()); |
|
| 116 | + $listItems = $this->getListItems($prodid, $this->listTypes); |
|
| 117 | 117 | |
| 118 | - foreach( $listItems as $listItem ) { |
|
| 119 | - $listMap[ $listItem->getParentId() ][ $listItem->getType() ] = $listItem; |
|
| 118 | + foreach ($listItems as $listItem) { |
|
| 119 | + $listMap[$listItem->getParentId()][$listItem->getType()] = $listItem; |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | - foreach( $map as $pos => $list ) |
|
| 122 | + foreach ($map as $pos => $list) |
|
| 123 | 123 | { |
| 124 | - if( $this->checkEntry( $list ) === false ) { |
|
| 124 | + if ($this->checkEntry($list) === false) { |
|
| 125 | 125 | continue; |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | - $codes = explode( $separator, $list['catalog.code'] ); |
|
| 129 | - $type = ( isset( $list['catalog.lists.type'] ) ? $list['catalog.lists.type'] : 'default' ); |
|
| 128 | + $codes = explode($separator, $list['catalog.code']); |
|
| 129 | + $type = (isset($list['catalog.lists.type']) ? $list['catalog.lists.type'] : 'default'); |
|
| 130 | 130 | |
| 131 | - foreach( $codes as $code ) |
|
| 131 | + foreach ($codes as $code) |
|
| 132 | 132 | { |
| 133 | - if( ( $catid = $this->cache->get( $code ) ) === null ) |
|
| 133 | + if (($catid = $this->cache->get($code)) === null) |
|
| 134 | 134 | { |
| 135 | 135 | $msg = 'No category for code "%1$s" available when importing product with code "%2$s"'; |
| 136 | - throw new \Aimeos\Controller\Jobs\Exception( sprintf( $msg, $code, $product->getCode() ) ); |
|
| 136 | + throw new \Aimeos\Controller\Jobs\Exception(sprintf($msg, $code, $product->getCode())); |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | - $list['catalog.lists.typeid'] = $this->getTypeId( 'catalog/lists/type', 'product', $type ); |
|
| 139 | + $list['catalog.lists.typeid'] = $this->getTypeId('catalog/lists/type', 'product', $type); |
|
| 140 | 140 | $list['catalog.lists.parentid'] = $catid; |
| 141 | 141 | $list['catalog.lists.refid'] = $prodid; |
| 142 | 142 | $list['catalog.lists.domain'] = 'product'; |
| 143 | 143 | |
| 144 | - if( isset( $listMap[$catid][$type] ) ) |
|
| 144 | + if (isset($listMap[$catid][$type])) |
|
| 145 | 145 | { |
| 146 | 146 | $listItem = $listMap[$catid][$type]; |
| 147 | - unset( $listItems[ $listItem->getId() ] ); |
|
| 147 | + unset($listItems[$listItem->getId()]); |
|
| 148 | 148 | } |
| 149 | 149 | else |
| 150 | 150 | { |
| 151 | 151 | $listItem = $listManager->createItem(); |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | - $listItem->fromArray( $this->addListItemDefaults( $list, $pos++ ) ); |
|
| 155 | - $listManager->saveItem( $listItem, false ); |
|
| 154 | + $listItem->fromArray($this->addListItemDefaults($list, $pos++)); |
|
| 155 | + $listManager->saveItem($listItem, false); |
|
| 156 | 156 | } |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | - $listManager->deleteItems( array_keys( $listItems ) ); |
|
| 160 | - $data = $this->getObject()->process( $product, $data ); |
|
| 159 | + $listManager->deleteItems(array_keys($listItems)); |
|
| 160 | + $data = $this->getObject()->process($product, $data); |
|
| 161 | 161 | |
| 162 | 162 | $manager->commit(); |
| 163 | 163 | } |
| 164 | - catch( \Exception $e ) |
|
| 164 | + catch (\Exception $e) |
|
| 165 | 165 | { |
| 166 | 166 | $manager->rollback(); |
| 167 | 167 | throw $e; |
@@ -178,13 +178,13 @@ discard block |
||
| 178 | 178 | * @param integer $pos Computed position of the list item in the associated list of items |
| 179 | 179 | * @return array Given associative list enriched by default values if they were not already set |
| 180 | 180 | */ |
| 181 | - protected function addListItemDefaults( array $list, $pos ) |
|
| 181 | + protected function addListItemDefaults(array $list, $pos) |
|
| 182 | 182 | { |
| 183 | - if( !isset( $list['catalog.lists.position'] ) ) { |
|
| 183 | + if (!isset($list['catalog.lists.position'])) { |
|
| 184 | 184 | $list['catalog.lists.position'] = $pos; |
| 185 | 185 | } |
| 186 | 186 | |
| 187 | - if( !isset( $list['catalog.lists.status'] ) ) { |
|
| 187 | + if (!isset($list['catalog.lists.status'])) { |
|
| 188 | 188 | $list['catalog.lists.status'] = 1; |
| 189 | 189 | } |
| 190 | 190 | |
@@ -198,10 +198,10 @@ discard block |
||
| 198 | 198 | * @param array $list Associative list of key/value pairs from the mapped data |
| 199 | 199 | * @return boolean True if the entry is valid, false if not |
| 200 | 200 | */ |
| 201 | - protected function checkEntry( array $list ) |
|
| 201 | + protected function checkEntry(array $list) |
|
| 202 | 202 | { |
| 203 | - if( !isset( $list['catalog.code'] ) || $list['catalog.code'] === '' || isset( $list['catalog.lists.type'] ) |
|
| 204 | - && $this->listTypes !== null && !in_array( $list['catalog.lists.type'], (array) $this->listTypes ) |
|
| 203 | + if (!isset($list['catalog.code']) || $list['catalog.code'] === '' || isset($list['catalog.lists.type']) |
|
| 204 | + && $this->listTypes !== null && !in_array($list['catalog.lists.type'], (array) $this->listTypes) |
|
| 205 | 205 | ) { |
| 206 | 206 | return false; |
| 207 | 207 | } |
@@ -217,24 +217,24 @@ discard block |
||
| 217 | 217 | * @param array|null $types List of catalog list types |
| 218 | 218 | * @return array List of catalog list items |
| 219 | 219 | */ |
| 220 | - protected function getListItems( $prodid, $types ) |
|
| 220 | + protected function getListItems($prodid, $types) |
|
| 221 | 221 | { |
| 222 | - $manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'catalog/lists' ); |
|
| 222 | + $manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'catalog/lists'); |
|
| 223 | 223 | $search = $manager->createSearch(); |
| 224 | 224 | |
| 225 | 225 | $expr = array( |
| 226 | - $search->compare( '==', 'catalog.lists.domain', 'product' ), |
|
| 227 | - $search->compare( '==', 'catalog.lists.refid', $prodid ), |
|
| 226 | + $search->compare('==', 'catalog.lists.domain', 'product'), |
|
| 227 | + $search->compare('==', 'catalog.lists.refid', $prodid), |
|
| 228 | 228 | ); |
| 229 | 229 | |
| 230 | - if( $types !== null ) { |
|
| 231 | - $expr[] = $search->compare( '==', 'catalog.lists.type.code', $types ); |
|
| 230 | + if ($types !== null) { |
|
| 231 | + $expr[] = $search->compare('==', 'catalog.lists.type.code', $types); |
|
| 232 | 232 | } |
| 233 | 233 | |
| 234 | - $search->setConditions( $search->combine( '&&', $expr ) ); |
|
| 235 | - $search->setSortations( array( $search->sort( '+', 'catalog.lists.position' ) ) ); |
|
| 236 | - $search->setSlice( 0, 0x7FFFFFFF ); |
|
| 234 | + $search->setConditions($search->combine('&&', $expr)); |
|
| 235 | + $search->setSortations(array($search->sort('+', 'catalog.lists.position'))); |
|
| 236 | + $search->setSlice(0, 0x7FFFFFFF); |
|
| 237 | 237 | |
| 238 | - return $manager->searchItems( $search ); |
|
| 238 | + return $manager->searchItems($search); |
|
| 239 | 239 | } |
| 240 | 240 | } |
@@ -42,10 +42,10 @@ discard block |
||
| 42 | 42 | * @param array $mapping Associative list of field position in CSV as key and domain item key as value |
| 43 | 43 | * @param \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $object Decorated processor |
| 44 | 44 | */ |
| 45 | - public function __construct( \Aimeos\MShop\Context\Item\Iface $context, array $mapping, |
|
| 46 | - \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $object = null ) |
|
| 45 | + public function __construct(\Aimeos\MShop\Context\Item\Iface $context, array $mapping, |
|
| 46 | + \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $object = null) |
|
| 47 | 47 | { |
| 48 | - parent::__construct( $context, $mapping, $object ); |
|
| 48 | + parent::__construct($context, $mapping, $object); |
|
| 49 | 49 | |
| 50 | 50 | /** controller/common/product/import/csv/processor/price/listtypes |
| 51 | 51 | * Names of the product list types for prices that are updated or removed |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | * @see controller/common/product/import/csv/processor/product/listtypes |
| 67 | 67 | * @see controller/common/product/import/csv/processor/text/listtypes |
| 68 | 68 | */ |
| 69 | - $this->listTypes = $context->getConfig()->get( 'controller/common/product/import/csv/processor/price/listtypes' ); |
|
| 69 | + $this->listTypes = $context->getConfig()->get('controller/common/product/import/csv/processor/price/listtypes'); |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | |
@@ -77,40 +77,40 @@ discard block |
||
| 77 | 77 | * @param array $data List of CSV fields with position as key and data as value |
| 78 | 78 | * @return array List of data which hasn't been imported |
| 79 | 79 | */ |
| 80 | - public function process( \Aimeos\MShop\Product\Item\Iface $product, array $data ) |
|
| 80 | + public function process(\Aimeos\MShop\Product\Item\Iface $product, array $data) |
|
| 81 | 81 | { |
| 82 | - $listManager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'product/lists' ); |
|
| 83 | - $manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'price' ); |
|
| 82 | + $listManager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'product/lists'); |
|
| 83 | + $manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'price'); |
|
| 84 | 84 | $manager->begin(); |
| 85 | 85 | |
| 86 | 86 | try |
| 87 | 87 | { |
| 88 | 88 | $delete = $listMap = []; |
| 89 | - $map = $this->getMappedChunk( $data, $this->getMapping() ); |
|
| 90 | - $listItems = $product->getListItems( 'price', $this->listTypes ); |
|
| 89 | + $map = $this->getMappedChunk($data, $this->getMapping()); |
|
| 90 | + $listItems = $product->getListItems('price', $this->listTypes); |
|
| 91 | 91 | |
| 92 | - foreach( $listItems as $listItem ) |
|
| 92 | + foreach ($listItems as $listItem) |
|
| 93 | 93 | { |
| 94 | - if( ( $refItem = $listItem->getRefItem() ) !== null ) { |
|
| 95 | - $listMap[ $refItem->getValue() ][ $refItem->getType() ][ $listItem->getType() ] = $listItem; |
|
| 94 | + if (($refItem = $listItem->getRefItem()) !== null) { |
|
| 95 | + $listMap[$refItem->getValue()][$refItem->getType()][$listItem->getType()] = $listItem; |
|
| 96 | 96 | } |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | - foreach( $map as $pos => $list ) |
|
| 99 | + foreach ($map as $pos => $list) |
|
| 100 | 100 | { |
| 101 | - if( $this->checkEntry( $list ) === false ) { |
|
| 101 | + if ($this->checkEntry($list) === false) { |
|
| 102 | 102 | continue; |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | - $value = ( isset( $list['price.value'] ) ? $list['price.value'] : '0.00' ); |
|
| 106 | - $type = ( isset( $list['price.type'] ) ? $list['price.type'] : 'default' ); |
|
| 107 | - $typecode = ( isset( $list['product.lists.type'] ) ? $list['product.lists.type'] : 'default' ); |
|
| 105 | + $value = (isset($list['price.value']) ? $list['price.value'] : '0.00'); |
|
| 106 | + $type = (isset($list['price.type']) ? $list['price.type'] : 'default'); |
|
| 107 | + $typecode = (isset($list['product.lists.type']) ? $list['product.lists.type'] : 'default'); |
|
| 108 | 108 | |
| 109 | - if( isset( $listMap[$value][$type][$typecode] ) ) |
|
| 109 | + if (isset($listMap[$value][$type][$typecode])) |
|
| 110 | 110 | { |
| 111 | 111 | $listItem = $listMap[$value][$type][$typecode]; |
| 112 | 112 | $refItem = $listItem->getRefItem(); |
| 113 | - unset( $listItems[ $listItem->getId() ] ); |
|
| 113 | + unset($listItems[$listItem->getId()]); |
|
| 114 | 114 | } |
| 115 | 115 | else |
| 116 | 116 | { |
@@ -118,33 +118,33 @@ discard block |
||
| 118 | 118 | $refItem = $manager->createItem(); |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | - $list['price.typeid'] = $this->getTypeId( 'price/type', 'product', $type ); |
|
| 121 | + $list['price.typeid'] = $this->getTypeId('price/type', 'product', $type); |
|
| 122 | 122 | $list['price.domain'] = 'product'; |
| 123 | 123 | |
| 124 | - $refItem->fromArray( $this->addItemDefaults( $list ) ); |
|
| 125 | - $refItem = $manager->saveItem( $refItem ); |
|
| 124 | + $refItem->fromArray($this->addItemDefaults($list)); |
|
| 125 | + $refItem = $manager->saveItem($refItem); |
|
| 126 | 126 | |
| 127 | - $list['product.lists.typeid'] = $this->getTypeId( 'product/lists/type', 'price', $typecode ); |
|
| 127 | + $list['product.lists.typeid'] = $this->getTypeId('product/lists/type', 'price', $typecode); |
|
| 128 | 128 | $list['product.lists.parentid'] = $product->getId(); |
| 129 | 129 | $list['product.lists.refid'] = $refItem->getId(); |
| 130 | 130 | $list['product.lists.domain'] = 'price'; |
| 131 | 131 | |
| 132 | - $listItem->fromArray( $this->addListItemDefaults( $list, $pos ) ); |
|
| 133 | - $listManager->saveItem( $listItem, false ); |
|
| 132 | + $listItem->fromArray($this->addListItemDefaults($list, $pos)); |
|
| 133 | + $listManager->saveItem($listItem, false); |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | - foreach( $listItems as $listItem ) { |
|
| 136 | + foreach ($listItems as $listItem) { |
|
| 137 | 137 | $delete[] = $listItem->getRefId(); |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | - $manager->deleteItems( $delete ); |
|
| 141 | - $listManager->deleteItems( array_keys( $listItems ) ); |
|
| 140 | + $manager->deleteItems($delete); |
|
| 141 | + $listManager->deleteItems(array_keys($listItems)); |
|
| 142 | 142 | |
| 143 | - $data = $this->getObject()->process( $product, $data ); |
|
| 143 | + $data = $this->getObject()->process($product, $data); |
|
| 144 | 144 | |
| 145 | 145 | $manager->commit(); |
| 146 | 146 | } |
| 147 | - catch( \Exception $e ) |
|
| 147 | + catch (\Exception $e) |
|
| 148 | 148 | { |
| 149 | 149 | $manager->rollback(); |
| 150 | 150 | throw $e; |
@@ -160,17 +160,17 @@ discard block |
||
| 160 | 160 | * @param array $list Associative list of domain item keys and their values, e.g. "price.status" => 1 |
| 161 | 161 | * @return array Given associative list enriched by default values if they were not already set |
| 162 | 162 | */ |
| 163 | - protected function addItemDefaults( array $list ) |
|
| 163 | + protected function addItemDefaults(array $list) |
|
| 164 | 164 | { |
| 165 | - if( !isset( $list['price.currencyid'] ) ) { |
|
| 165 | + if (!isset($list['price.currencyid'])) { |
|
| 166 | 166 | $list['price.currencyid'] = $this->getContext()->getLocale()->getCurrencyId(); |
| 167 | 167 | } |
| 168 | 168 | |
| 169 | - if( !isset( $list['price.label'] ) ) { |
|
| 169 | + if (!isset($list['price.label'])) { |
|
| 170 | 170 | $list['price.label'] = $list['price.currencyid'] . ' ' . $list['price.value']; |
| 171 | 171 | } |
| 172 | 172 | |
| 173 | - if( !isset( $list['price.status'] ) ) { |
|
| 173 | + if (!isset($list['price.status'])) { |
|
| 174 | 174 | $list['price.status'] = 1; |
| 175 | 175 | } |
| 176 | 176 | |
@@ -184,10 +184,10 @@ discard block |
||
| 184 | 184 | * @param array $list Associative list of key/value pairs from the mapping |
| 185 | 185 | * @return boolean True if valid, false if not |
| 186 | 186 | */ |
| 187 | - protected function checkEntry( array $list ) |
|
| 187 | + protected function checkEntry(array $list) |
|
| 188 | 188 | { |
| 189 | - if( !isset( $list['price.value'] ) || $list['price.value'] === '' || isset( $list['product.lists.type'] ) |
|
| 190 | - && $this->listTypes !== null && !in_array( $list['product.lists.type'], (array) $this->listTypes ) |
|
| 189 | + if (!isset($list['price.value']) || $list['price.value'] === '' || isset($list['product.lists.type']) |
|
| 190 | + && $this->listTypes !== null && !in_array($list['product.lists.type'], (array) $this->listTypes) |
|
| 191 | 191 | ) { |
| 192 | 192 | return false; |
| 193 | 193 | } |
@@ -42,12 +42,12 @@ discard block |
||
| 42 | 42 | * @param array $mapping Associative list of field position in CSV as key and domain item key as value |
| 43 | 43 | * @param \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $object Decorated processor |
| 44 | 44 | */ |
| 45 | - public function __construct( \Aimeos\MShop\Context\Item\Iface $context, array $mapping, |
|
| 46 | - \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $object = null ) |
|
| 45 | + public function __construct(\Aimeos\MShop\Context\Item\Iface $context, array $mapping, |
|
| 46 | + \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $object = null) |
|
| 47 | 47 | { |
| 48 | - parent::__construct( $context, $mapping, $object ); |
|
| 48 | + parent::__construct($context, $mapping, $object); |
|
| 49 | 49 | |
| 50 | - $this->cache = $this->getCache( 'stocktype' ); |
|
| 50 | + $this->cache = $this->getCache('stocktype'); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | |
@@ -58,53 +58,53 @@ discard block |
||
| 58 | 58 | * @param array $data List of CSV fields with position as key and data as value |
| 59 | 59 | * @return array List of data which hasn't been imported |
| 60 | 60 | */ |
| 61 | - public function process( \Aimeos\MShop\Product\Item\Iface $product, array $data ) |
|
| 61 | + public function process(\Aimeos\MShop\Product\Item\Iface $product, array $data) |
|
| 62 | 62 | { |
| 63 | - $manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'stock' ); |
|
| 63 | + $manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'stock'); |
|
| 64 | 64 | $manager->begin(); |
| 65 | 65 | |
| 66 | 66 | try |
| 67 | 67 | { |
| 68 | - $map = $this->getMappedChunk( $data, $this->getMapping() ); |
|
| 69 | - $items = $this->getStockItems( $product->getCode() ); |
|
| 68 | + $map = $this->getMappedChunk($data, $this->getMapping()); |
|
| 69 | + $items = $this->getStockItems($product->getCode()); |
|
| 70 | 70 | |
| 71 | - foreach( $map as $pos => $list ) |
|
| 71 | + foreach ($map as $pos => $list) |
|
| 72 | 72 | { |
| 73 | - if( !array_key_exists( 'stock.stocklevel', $list ) ) { |
|
| 73 | + if (!array_key_exists('stock.stocklevel', $list)) { |
|
| 74 | 74 | continue; |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - $stockType = ( isset( $list['stock.type'] ) ? $list['stock.type'] : 'default' ); |
|
| 77 | + $stockType = (isset($list['stock.type']) ? $list['stock.type'] : 'default'); |
|
| 78 | 78 | |
| 79 | - if( !isset( $list['stock.typeid'] ) ) { |
|
| 80 | - $list['stock.typeid'] = $this->cache->get( $stockType ); |
|
| 79 | + if (!isset($list['stock.typeid'])) { |
|
| 80 | + $list['stock.typeid'] = $this->cache->get($stockType); |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | - if( isset( $list['stock.dateback'] ) && $list['stock.dateback'] === '' ) { |
|
| 83 | + if (isset($list['stock.dateback']) && $list['stock.dateback'] === '') { |
|
| 84 | 84 | $list['stock.dateback'] = null; |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | - if( $list['stock.stocklevel'] === '' ) { |
|
| 87 | + if ($list['stock.stocklevel'] === '') { |
|
| 88 | 88 | $list['stock.stocklevel'] = null; |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | $list['stock.productcode'] = $product->getCode(); |
| 92 | 92 | |
| 93 | - if( ( $item = array_pop( $items ) ) === null ) { |
|
| 93 | + if (($item = array_pop($items)) === null) { |
|
| 94 | 94 | $item = $manager->createItem(); |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | - $item->fromArray( $list ); |
|
| 98 | - $manager->saveItem( $item, false ); |
|
| 97 | + $item->fromArray($list); |
|
| 98 | + $manager->saveItem($item, false); |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | - $manager->deleteItems( array_keys( $items ) ); |
|
| 101 | + $manager->deleteItems(array_keys($items)); |
|
| 102 | 102 | |
| 103 | - $data = $this->getObject()->process( $product, $data ); |
|
| 103 | + $data = $this->getObject()->process($product, $data); |
|
| 104 | 104 | |
| 105 | 105 | $manager->commit(); |
| 106 | 106 | } |
| 107 | - catch( \Exception $e ) |
|
| 107 | + catch (\Exception $e) |
|
| 108 | 108 | { |
| 109 | 109 | $manager->rollback(); |
| 110 | 110 | throw $e; |
@@ -120,13 +120,13 @@ discard block |
||
| 120 | 120 | * @param string $code Unique product code |
| 121 | 121 | * @return \Aimeos\MShop\Stock\Item\Iface[] Associative list of stock items |
| 122 | 122 | */ |
| 123 | - protected function getStockItems( $code ) |
|
| 123 | + protected function getStockItems($code) |
|
| 124 | 124 | { |
| 125 | - $manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'stock' ); |
|
| 125 | + $manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'stock'); |
|
| 126 | 126 | |
| 127 | 127 | $search = $manager->createSearch(); |
| 128 | - $search->setConditions( $search->compare( '==', 'stock.productcode', $code ) ); |
|
| 128 | + $search->setConditions($search->compare('==', 'stock.productcode', $code)); |
|
| 129 | 129 | |
| 130 | - return $manager->searchItems( $search ); |
|
| 130 | + return $manager->searchItems($search); |
|
| 131 | 131 | } |
| 132 | 132 | } |
@@ -40,52 +40,52 @@ discard block |
||
| 40 | 40 | * @param array $data List of CSV fields with position as key and data as value |
| 41 | 41 | * @return array List of data which hasn't been imported |
| 42 | 42 | */ |
| 43 | - public function process( \Aimeos\MShop\Product\Item\Iface $product, array $data ) |
|
| 43 | + public function process(\Aimeos\MShop\Product\Item\Iface $product, array $data) |
|
| 44 | 44 | { |
| 45 | - $manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'product/property' ); |
|
| 45 | + $manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'product/property'); |
|
| 46 | 46 | $manager->begin(); |
| 47 | 47 | |
| 48 | 48 | try |
| 49 | 49 | { |
| 50 | 50 | $propMap = []; |
| 51 | - $map = $this->getMappedChunk( $data, $this->getMapping() ); |
|
| 52 | - $items = $this->getPropertyItems( $product->getId() ); |
|
| 51 | + $map = $this->getMappedChunk($data, $this->getMapping()); |
|
| 52 | + $items = $this->getPropertyItems($product->getId()); |
|
| 53 | 53 | |
| 54 | - foreach( $items as $item ) { |
|
| 55 | - $propMap[ $item->getValue() ][ $item->getType() ] = $item; |
|
| 54 | + foreach ($items as $item) { |
|
| 55 | + $propMap[$item->getValue()][$item->getType()] = $item; |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | - foreach( $map as $list ) |
|
| 58 | + foreach ($map as $list) |
|
| 59 | 59 | { |
| 60 | - if( $list['product.property.type'] == '' || $list['product.property.value'] == '' ) { |
|
| 60 | + if ($list['product.property.type'] == '' || $list['product.property.value'] == '') { |
|
| 61 | 61 | continue; |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | $typecode = $list['product.property.type']; |
| 65 | - $list['product.property.typeid'] = $this->getTypeId( 'product/property/type', 'product', $typecode ); |
|
| 65 | + $list['product.property.typeid'] = $this->getTypeId('product/property/type', 'product', $typecode); |
|
| 66 | 66 | $list['product.property.parentid'] = $product->getId(); |
| 67 | 67 | |
| 68 | - if( isset( $propMap[ $list['product.property.value'] ][$typecode] ) ) |
|
| 68 | + if (isset($propMap[$list['product.property.value']][$typecode])) |
|
| 69 | 69 | { |
| 70 | - $item = $propMap[ $list['product.property.value'] ][$typecode]; |
|
| 71 | - unset( $items[ $item->getId() ] ); |
|
| 70 | + $item = $propMap[$list['product.property.value']][$typecode]; |
|
| 71 | + unset($items[$item->getId()]); |
|
| 72 | 72 | } |
| 73 | 73 | else |
| 74 | 74 | { |
| 75 | 75 | $item = $manager->createItem(); |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - $item->fromArray( $list ); |
|
| 79 | - $manager->saveItem( $item, false ); |
|
| 78 | + $item->fromArray($list); |
|
| 79 | + $manager->saveItem($item, false); |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | - $manager->deleteItems( array_keys( $items ) ); |
|
| 82 | + $manager->deleteItems(array_keys($items)); |
|
| 83 | 83 | |
| 84 | - $data = $this->getObject()->process( $product, $data ); |
|
| 84 | + $data = $this->getObject()->process($product, $data); |
|
| 85 | 85 | |
| 86 | 86 | $manager->commit(); |
| 87 | 87 | } |
| 88 | - catch( \Exception $e ) |
|
| 88 | + catch (\Exception $e) |
|
| 89 | 89 | { |
| 90 | 90 | $manager->rollback(); |
| 91 | 91 | throw $e; |
@@ -101,13 +101,13 @@ discard block |
||
| 101 | 101 | * @param string $prodid Unique product ID |
| 102 | 102 | * @return array Associative list of product property items |
| 103 | 103 | */ |
| 104 | - protected function getPropertyItems( $prodid ) |
|
| 104 | + protected function getPropertyItems($prodid) |
|
| 105 | 105 | { |
| 106 | - $manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'product/property' ); |
|
| 106 | + $manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'product/property'); |
|
| 107 | 107 | |
| 108 | 108 | $search = $manager->createSearch(); |
| 109 | - $search->setConditions( $search->compare( '==', 'product.property.parentid', $prodid ) ); |
|
| 109 | + $search->setConditions($search->compare('==', 'product.property.parentid', $prodid)); |
|
| 110 | 110 | |
| 111 | - return $manager->searchItems( $search ); |
|
| 111 | + return $manager->searchItems($search); |
|
| 112 | 112 | } |
| 113 | 113 | } |
@@ -42,10 +42,10 @@ discard block |
||
| 42 | 42 | * @param array $mapping Associative list of field position in CSV as key and domain item key as value |
| 43 | 43 | * @param \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $object Decorated processor |
| 44 | 44 | */ |
| 45 | - public function __construct( \Aimeos\MShop\Context\Item\Iface $context, array $mapping, |
|
| 46 | - \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $object = null ) |
|
| 45 | + public function __construct(\Aimeos\MShop\Context\Item\Iface $context, array $mapping, |
|
| 46 | + \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $object = null) |
|
| 47 | 47 | { |
| 48 | - parent::__construct( $context, $mapping, $object ); |
|
| 48 | + parent::__construct($context, $mapping, $object); |
|
| 49 | 49 | |
| 50 | 50 | /** controller/common/product/import/csv/processor/media/listtypes |
| 51 | 51 | * Names of the product list types for media that are updated or removed |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | * @see controller/common/product/import/csv/processor/price/listtypes |
| 67 | 67 | * @see controller/common/product/import/csv/processor/text/listtypes |
| 68 | 68 | */ |
| 69 | - $this->listTypes = $context->getConfig()->get( 'controller/common/product/import/csv/processor/media/listtypes' ); |
|
| 69 | + $this->listTypes = $context->getConfig()->get('controller/common/product/import/csv/processor/media/listtypes'); |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | |
@@ -77,45 +77,45 @@ discard block |
||
| 77 | 77 | * @param array $data List of CSV fields with position as key and data as value |
| 78 | 78 | * @return array List of data which hasn't been imported |
| 79 | 79 | */ |
| 80 | - public function process( \Aimeos\MShop\Product\Item\Iface $product, array $data ) |
|
| 80 | + public function process(\Aimeos\MShop\Product\Item\Iface $product, array $data) |
|
| 81 | 81 | { |
| 82 | 82 | $context = $this->getContext(); |
| 83 | - $manager = \Aimeos\MShop\Factory::createManager( $context, 'media' ); |
|
| 84 | - $listManager = \Aimeos\MShop\Factory::createManager( $context, 'product/lists' ); |
|
| 85 | - $separator = $context->getConfig()->get( 'controller/common/product/import/csv/separator', "\n" ); |
|
| 83 | + $manager = \Aimeos\MShop\Factory::createManager($context, 'media'); |
|
| 84 | + $listManager = \Aimeos\MShop\Factory::createManager($context, 'product/lists'); |
|
| 85 | + $separator = $context->getConfig()->get('controller/common/product/import/csv/separator', "\n"); |
|
| 86 | 86 | |
| 87 | 87 | $manager->begin(); |
| 88 | 88 | |
| 89 | 89 | try |
| 90 | 90 | { |
| 91 | 91 | $delete = $listMap = []; |
| 92 | - $map = $this->getMappedChunk( $data, $this->getMapping() ); |
|
| 93 | - $listItems = $product->getListItems( 'media', $this->listTypes ); |
|
| 92 | + $map = $this->getMappedChunk($data, $this->getMapping()); |
|
| 93 | + $listItems = $product->getListItems('media', $this->listTypes); |
|
| 94 | 94 | |
| 95 | - foreach( $listItems as $listItem ) |
|
| 95 | + foreach ($listItems as $listItem) |
|
| 96 | 96 | { |
| 97 | - if( ( $refItem = $listItem->getRefItem() ) !== null ) { |
|
| 98 | - $listMap[ $refItem->getUrl() ][ $refItem->getType() ][ $listItem->getType() ] = $listItem; |
|
| 97 | + if (($refItem = $listItem->getRefItem()) !== null) { |
|
| 98 | + $listMap[$refItem->getUrl()][$refItem->getType()][$listItem->getType()] = $listItem; |
|
| 99 | 99 | } |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | - foreach( $map as $pos => $list ) |
|
| 102 | + foreach ($map as $pos => $list) |
|
| 103 | 103 | { |
| 104 | - if( $this->checkEntry( $list ) === false ) { |
|
| 104 | + if ($this->checkEntry($list) === false) { |
|
| 105 | 105 | continue; |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | - $urls = explode( $separator, $list['media.url'] ); |
|
| 109 | - $type = $this->getValue( $list, 'media.type', 'default' ); |
|
| 110 | - $typecode = $this->getValue( $list, 'product.lists.type', 'default' ); |
|
| 108 | + $urls = explode($separator, $list['media.url']); |
|
| 109 | + $type = $this->getValue($list, 'media.type', 'default'); |
|
| 110 | + $typecode = $this->getValue($list, 'product.lists.type', 'default'); |
|
| 111 | 111 | |
| 112 | - foreach( $urls as $url ) |
|
| 112 | + foreach ($urls as $url) |
|
| 113 | 113 | { |
| 114 | - if( isset( $listMap[$url][$type][$typecode] ) ) |
|
| 114 | + if (isset($listMap[$url][$type][$typecode])) |
|
| 115 | 115 | { |
| 116 | 116 | $listItem = $listMap[$url][$type][$typecode]; |
| 117 | 117 | $refItem = $listItem->getRefItem(); |
| 118 | - unset( $listItems[ $listItem->getId() ] ); |
|
| 118 | + unset($listItems[$listItem->getId()]); |
|
| 119 | 119 | } |
| 120 | 120 | else |
| 121 | 121 | { |
@@ -123,35 +123,35 @@ discard block |
||
| 123 | 123 | $refItem = $manager->createItem(); |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | - $list['media.typeid'] = $this->getTypeId( 'media/type', 'product', $type ); |
|
| 126 | + $list['media.typeid'] = $this->getTypeId('media/type', 'product', $type); |
|
| 127 | 127 | $list['media.domain'] = 'product'; |
| 128 | 128 | $list['media.url'] = $url; |
| 129 | 129 | |
| 130 | - $refItem->fromArray( $this->addItemDefaults( $list ) ); |
|
| 131 | - $refItem = $manager->saveItem( $refItem ); |
|
| 130 | + $refItem->fromArray($this->addItemDefaults($list)); |
|
| 131 | + $refItem = $manager->saveItem($refItem); |
|
| 132 | 132 | |
| 133 | - $list['product.lists.typeid'] = $this->getTypeId( 'product/lists/type', 'media', $typecode ); |
|
| 133 | + $list['product.lists.typeid'] = $this->getTypeId('product/lists/type', 'media', $typecode); |
|
| 134 | 134 | $list['product.lists.parentid'] = $product->getId(); |
| 135 | 135 | $list['product.lists.refid'] = $refItem->getId(); |
| 136 | 136 | $list['product.lists.domain'] = 'media'; |
| 137 | 137 | |
| 138 | - $listItem->fromArray( $this->addListItemDefaults( $list, $pos++ ) ); |
|
| 139 | - $listManager->saveItem( $listItem, false ); |
|
| 138 | + $listItem->fromArray($this->addListItemDefaults($list, $pos++)); |
|
| 139 | + $listManager->saveItem($listItem, false); |
|
| 140 | 140 | } |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | - foreach( $listItems as $listItem ) { |
|
| 143 | + foreach ($listItems as $listItem) { |
|
| 144 | 144 | $delete[] = $listItem->getRefId(); |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | - $manager->deleteItems( $delete ); |
|
| 148 | - $listManager->deleteItems( array_keys( $listItems ) ); |
|
| 147 | + $manager->deleteItems($delete); |
|
| 148 | + $listManager->deleteItems(array_keys($listItems)); |
|
| 149 | 149 | |
| 150 | - $data = $this->getObject()->process( $product, $data ); |
|
| 150 | + $data = $this->getObject()->process($product, $data); |
|
| 151 | 151 | |
| 152 | 152 | $manager->commit(); |
| 153 | 153 | } |
| 154 | - catch( \Exception $e ) |
|
| 154 | + catch (\Exception $e) |
|
| 155 | 155 | { |
| 156 | 156 | $manager->rollback(); |
| 157 | 157 | throw $e; |
@@ -167,17 +167,17 @@ discard block |
||
| 167 | 167 | * @param array $list Associative list of domain item keys and their values, e.g. "media.status" => 1 |
| 168 | 168 | * @return array Given associative list enriched by default values if they were not already set |
| 169 | 169 | */ |
| 170 | - protected function addItemDefaults( array $list ) |
|
| 170 | + protected function addItemDefaults(array $list) |
|
| 171 | 171 | { |
| 172 | - if( !isset( $list['media.label'] ) ) { |
|
| 172 | + if (!isset($list['media.label'])) { |
|
| 173 | 173 | $list['media.label'] = $list['media.url']; |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | - if( !isset( $list['media.preview'] ) ) { |
|
| 176 | + if (!isset($list['media.preview'])) { |
|
| 177 | 177 | $list['media.preview'] = $list['media.url']; |
| 178 | 178 | } |
| 179 | 179 | |
| 180 | - if( !isset( $list['media.status'] ) ) { |
|
| 180 | + if (!isset($list['media.status'])) { |
|
| 181 | 181 | $list['media.status'] = 1; |
| 182 | 182 | } |
| 183 | 183 | |
@@ -191,10 +191,10 @@ discard block |
||
| 191 | 191 | * @param array $list Associative list of key/value pairs from the mapping |
| 192 | 192 | * @return boolean True if valid, false if not |
| 193 | 193 | */ |
| 194 | - protected function checkEntry( array $list ) |
|
| 194 | + protected function checkEntry(array $list) |
|
| 195 | 195 | { |
| 196 | - if( !isset( $list['media.url'] ) || $list['media.url'] === '' || isset( $list['product.lists.type'] ) |
|
| 197 | - && $this->listTypes !== null && !in_array( $list['product.lists.type'], (array) $this->listTypes ) |
|
| 196 | + if (!isset($list['media.url']) || $list['media.url'] === '' || isset($list['product.lists.type']) |
|
| 197 | + && $this->listTypes !== null && !in_array($list['product.lists.type'], (array) $this->listTypes) |
|
| 198 | 198 | ) { |
| 199 | 199 | return false; |
| 200 | 200 | } |
@@ -43,10 +43,10 @@ discard block |
||
| 43 | 43 | * @param array $mapping Associative list of field position in CSV as key and domain item key as value |
| 44 | 44 | * @param \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $object Decorated processor |
| 45 | 45 | */ |
| 46 | - public function __construct( \Aimeos\MShop\Context\Item\Iface $context, array $mapping, |
|
| 47 | - \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $object = null ) |
|
| 46 | + public function __construct(\Aimeos\MShop\Context\Item\Iface $context, array $mapping, |
|
| 47 | + \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $object = null) |
|
| 48 | 48 | { |
| 49 | - parent::__construct( $context, $mapping, $object ); |
|
| 49 | + parent::__construct($context, $mapping, $object); |
|
| 50 | 50 | |
| 51 | 51 | /** controller/common/product/import/csv/processor/attribute/listtypes |
| 52 | 52 | * Names of the product list types for attributes that are updated or removed |
@@ -67,9 +67,9 @@ discard block |
||
| 67 | 67 | * @see controller/common/product/import/csv/processor/price/listtypes |
| 68 | 68 | * @see controller/common/product/import/csv/processor/text/listtypes |
| 69 | 69 | */ |
| 70 | - $this->listTypes = $context->getConfig()->get( 'controller/common/product/import/csv/processor/attribute/listtypes'); |
|
| 70 | + $this->listTypes = $context->getConfig()->get('controller/common/product/import/csv/processor/attribute/listtypes'); |
|
| 71 | 71 | |
| 72 | - $this->cache = $this->getCache( 'attribute' ); |
|
| 72 | + $this->cache = $this->getCache('attribute'); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | |
@@ -80,71 +80,71 @@ discard block |
||
| 80 | 80 | * @param array $data List of CSV fields with position as key and data as value |
| 81 | 81 | * @return array List of data which hasn't been imported |
| 82 | 82 | */ |
| 83 | - public function process( \Aimeos\MShop\Product\Item\Iface $product, array $data ) |
|
| 83 | + public function process(\Aimeos\MShop\Product\Item\Iface $product, array $data) |
|
| 84 | 84 | { |
| 85 | 85 | $context = $this->getContext(); |
| 86 | - $manager = \Aimeos\MShop\Factory::createManager( $context, 'attribute' ); |
|
| 87 | - $listManager = \Aimeos\MShop\Factory::createManager( $context, 'product/lists' ); |
|
| 88 | - $separator = $context->getConfig()->get( 'controller/common/product/import/csv/separator', "\n" ); |
|
| 86 | + $manager = \Aimeos\MShop\Factory::createManager($context, 'attribute'); |
|
| 87 | + $listManager = \Aimeos\MShop\Factory::createManager($context, 'product/lists'); |
|
| 88 | + $separator = $context->getConfig()->get('controller/common/product/import/csv/separator', "\n"); |
|
| 89 | 89 | |
| 90 | 90 | $manager->begin(); |
| 91 | 91 | |
| 92 | 92 | try |
| 93 | 93 | { |
| 94 | 94 | $listMap = []; |
| 95 | - $map = $this->getMappedChunk( $data, $this->getMapping() ); |
|
| 96 | - $listItems = $product->getListItems( 'attribute', $this->listTypes ); |
|
| 95 | + $map = $this->getMappedChunk($data, $this->getMapping()); |
|
| 96 | + $listItems = $product->getListItems('attribute', $this->listTypes); |
|
| 97 | 97 | |
| 98 | - foreach( $listItems as $listItem ) |
|
| 98 | + foreach ($listItems as $listItem) |
|
| 99 | 99 | { |
| 100 | - if( ( $refItem = $listItem->getRefItem() ) !== null ) { |
|
| 101 | - $listMap[ $refItem->getCode() ][ $listItem->getType() ] = $listItem; |
|
| 100 | + if (($refItem = $listItem->getRefItem()) !== null) { |
|
| 101 | + $listMap[$refItem->getCode()][$listItem->getType()] = $listItem; |
|
| 102 | 102 | } |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | - foreach( $map as $pos => $list ) |
|
| 105 | + foreach ($map as $pos => $list) |
|
| 106 | 106 | { |
| 107 | - if( $this->checkEntry( $list ) === false ) { |
|
| 107 | + if ($this->checkEntry($list) === false) { |
|
| 108 | 108 | continue; |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | - $codes = explode( $separator, $list['attribute.code'] ); |
|
| 111 | + $codes = explode($separator, $list['attribute.code']); |
|
| 112 | 112 | |
| 113 | - foreach( $codes as $code ) |
|
| 113 | + foreach ($codes as $code) |
|
| 114 | 114 | { |
| 115 | - $attrItem = $this->getAttributeItem( $code, $list['attribute.type'] ); |
|
| 116 | - $attrItem->fromArray( $list ); |
|
| 117 | - $attrItem->setCode( $code ); |
|
| 118 | - $attrItem = $manager->saveItem( $attrItem ); |
|
| 115 | + $attrItem = $this->getAttributeItem($code, $list['attribute.type']); |
|
| 116 | + $attrItem->fromArray($list); |
|
| 117 | + $attrItem->setCode($code); |
|
| 118 | + $attrItem = $manager->saveItem($attrItem); |
|
| 119 | 119 | |
| 120 | - $typecode = $this->getValue( $list, 'product.lists.type', 'default' ); |
|
| 121 | - $list['product.lists.typeid'] = $this->getTypeId( 'product/lists/type', 'attribute', $typecode ); |
|
| 120 | + $typecode = $this->getValue($list, 'product.lists.type', 'default'); |
|
| 121 | + $list['product.lists.typeid'] = $this->getTypeId('product/lists/type', 'attribute', $typecode); |
|
| 122 | 122 | $list['product.lists.refid'] = $attrItem->getId(); |
| 123 | 123 | $list['product.lists.parentid'] = $product->getId(); |
| 124 | 124 | $list['product.lists.domain'] = 'attribute'; |
| 125 | 125 | |
| 126 | - if( isset( $listMap[$code][$typecode] ) ) |
|
| 126 | + if (isset($listMap[$code][$typecode])) |
|
| 127 | 127 | { |
| 128 | 128 | $listItem = $listMap[$code][$typecode]; |
| 129 | - unset( $listItems[ $listItem->getId() ] ); |
|
| 129 | + unset($listItems[$listItem->getId()]); |
|
| 130 | 130 | } |
| 131 | 131 | else |
| 132 | 132 | { |
| 133 | 133 | $listItem = $listManager->createItem(); |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | - $listItem->fromArray( $this->addListItemDefaults( $list, $pos ) ); |
|
| 137 | - $listManager->saveItem( $listItem, false ); |
|
| 136 | + $listItem->fromArray($this->addListItemDefaults($list, $pos)); |
|
| 137 | + $listManager->saveItem($listItem, false); |
|
| 138 | 138 | } |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | - $listManager->deleteItems( array_keys( $listItems ) ); |
|
| 141 | + $listManager->deleteItems(array_keys($listItems)); |
|
| 142 | 142 | |
| 143 | - $data = $this->getObject()->process( $product, $data ); |
|
| 143 | + $data = $this->getObject()->process($product, $data); |
|
| 144 | 144 | |
| 145 | 145 | $manager->commit(); |
| 146 | 146 | } |
| 147 | - catch( \Exception $e ) |
|
| 147 | + catch (\Exception $e) |
|
| 148 | 148 | { |
| 149 | 149 | $manager->rollback(); |
| 150 | 150 | throw $e; |
@@ -160,11 +160,11 @@ discard block |
||
| 160 | 160 | * @param array $list Associative list of key/value pairs from the mapped data |
| 161 | 161 | * @return boolean True if the entry is valid, false if not |
| 162 | 162 | */ |
| 163 | - protected function checkEntry( array $list ) |
|
| 163 | + protected function checkEntry(array $list) |
|
| 164 | 164 | { |
| 165 | - if( !isset( $list['attribute.code'] ) || $list['attribute.code'] === '' || $list['attribute.type'] === '' |
|
| 166 | - || isset( $list['product.lists.type'] ) && $this->listTypes !== null |
|
| 167 | - && !in_array( $list['product.lists.type'], (array) $this->listTypes ) |
|
| 165 | + if (!isset($list['attribute.code']) || $list['attribute.code'] === '' || $list['attribute.type'] === '' |
|
| 166 | + || isset($list['product.lists.type']) && $this->listTypes !== null |
|
| 167 | + && !in_array($list['product.lists.type'], (array) $this->listTypes) |
|
| 168 | 168 | ) { |
| 169 | 169 | return false; |
| 170 | 170 | } |
@@ -180,22 +180,22 @@ discard block |
||
| 180 | 180 | * @param string $type Attribute type |
| 181 | 181 | * @return \Aimeos\MShop\Attribute\Item\Iface Attribute item object |
| 182 | 182 | */ |
| 183 | - protected function getAttributeItem( $code, $type ) |
|
| 183 | + protected function getAttributeItem($code, $type) |
|
| 184 | 184 | { |
| 185 | - if( ( $item = $this->cache->get( $code, $type ) ) === null ) |
|
| 185 | + if (($item = $this->cache->get($code, $type)) === null) |
|
| 186 | 186 | { |
| 187 | - $manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'attribute' ); |
|
| 187 | + $manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'attribute'); |
|
| 188 | 188 | |
| 189 | 189 | $item = $manager->createItem(); |
| 190 | - $item->setTypeId( $this->getTypeId( 'attribute/type', 'product', $type ) ); |
|
| 191 | - $item->setDomain( 'product' ); |
|
| 192 | - $item->setLabel( $type . ' ' . $code ); |
|
| 193 | - $item->setCode( $code ); |
|
| 194 | - $item->setStatus( 1 ); |
|
| 190 | + $item->setTypeId($this->getTypeId('attribute/type', 'product', $type)); |
|
| 191 | + $item->setDomain('product'); |
|
| 192 | + $item->setLabel($type . ' ' . $code); |
|
| 193 | + $item->setCode($code); |
|
| 194 | + $item->setStatus(1); |
|
| 195 | 195 | |
| 196 | - $item = $manager->saveItem( $item ); |
|
| 196 | + $item = $manager->saveItem($item); |
|
| 197 | 197 | |
| 198 | - $this->cache->set( $item ); |
|
| 198 | + $this->cache->set($item); |
|
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | return $item; |