@@ -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,69 +77,69 @@ 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 | - $map = $this->getMappedChunk( $data ); |
|
| 92 | - $listItems = $product->getListItems( 'media' ); |
|
| 91 | + $map = $this->getMappedChunk($data); |
|
| 92 | + $listItems = $product->getListItems('media'); |
|
| 93 | 93 | |
| 94 | - foreach( $map as $pos => $list ) |
|
| 94 | + foreach ($map as $pos => $list) |
|
| 95 | 95 | { |
| 96 | - if( $this->checkEntry( $list ) === false ) { |
|
| 96 | + if ($this->checkEntry($list) === false) { |
|
| 97 | 97 | continue; |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | - $urls = explode( $separator, $list['media.url'] ); |
|
| 101 | - $type = ( isset( $list['media.type'] ) ? $list['media.type'] : 'default' ); |
|
| 102 | - $typecode = ( isset( $list['product.lists.type'] ) ? $list['product.lists.type'] : 'default' ); |
|
| 103 | - $langid = ( isset( $list['media.languageid'] ) && $list['media.languageid'] !== '' ? $list['media.languageid'] : null ); |
|
| 100 | + $urls = explode($separator, $list['media.url']); |
|
| 101 | + $type = (isset($list['media.type']) ? $list['media.type'] : 'default'); |
|
| 102 | + $typecode = (isset($list['product.lists.type']) ? $list['product.lists.type'] : 'default'); |
|
| 103 | + $langid = (isset($list['media.languageid']) && $list['media.languageid'] !== '' ? $list['media.languageid'] : null); |
|
| 104 | 104 | |
| 105 | - foreach( $urls as $url ) |
|
| 105 | + foreach ($urls as $url) |
|
| 106 | 106 | { |
| 107 | - if( ( $listItem = array_shift( $listItems ) ) !== null ) { |
|
| 107 | + if (($listItem = array_shift($listItems)) !== null) { |
|
| 108 | 108 | $refItem = $listItem->getRefItem(); |
| 109 | 109 | } else { |
| 110 | 110 | $listItem = $listManager->createItem(); |
| 111 | 111 | $refItem = $manager->createItem(); |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | - $list['media.typeid'] = $this->getTypeId( 'media/type', 'product', $type ); |
|
| 114 | + $list['media.typeid'] = $this->getTypeId('media/type', 'product', $type); |
|
| 115 | 115 | $list['media.languageid'] = $langid; |
| 116 | 116 | $list['media.domain'] = 'product'; |
| 117 | 117 | $list['media.url'] = $url; |
| 118 | 118 | |
| 119 | - $refItem->fromArray( $this->addItemDefaults( $list ) ); |
|
| 120 | - $manager->saveItem( $refItem ); |
|
| 119 | + $refItem->fromArray($this->addItemDefaults($list)); |
|
| 120 | + $manager->saveItem($refItem); |
|
| 121 | 121 | |
| 122 | - $list['product.lists.typeid'] = $this->getTypeId( 'product/lists/type', 'media', $typecode ); |
|
| 122 | + $list['product.lists.typeid'] = $this->getTypeId('product/lists/type', 'media', $typecode); |
|
| 123 | 123 | $list['product.lists.parentid'] = $product->getId(); |
| 124 | 124 | $list['product.lists.refid'] = $refItem->getId(); |
| 125 | 125 | $list['product.lists.domain'] = 'media'; |
| 126 | 126 | |
| 127 | - $listItem->fromArray( $this->addListItemDefaults( $list, $pos++ ) ); |
|
| 128 | - $listManager->saveItem( $listItem ); |
|
| 127 | + $listItem->fromArray($this->addListItemDefaults($list, $pos++)); |
|
| 128 | + $listManager->saveItem($listItem); |
|
| 129 | 129 | } |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | - foreach( $listItems as $listItem ) |
|
| 132 | + foreach ($listItems as $listItem) |
|
| 133 | 133 | { |
| 134 | - $manager->deleteItem( $listItem->getRefItem()->getId() ); |
|
| 135 | - $listManager->deleteItem( $listItem->getId() ); |
|
| 134 | + $manager->deleteItem($listItem->getRefItem()->getId()); |
|
| 135 | + $listManager->deleteItem($listItem->getId()); |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | - $remaining = $this->getObject()->process( $product, $data ); |
|
| 138 | + $remaining = $this->getObject()->process($product, $data); |
|
| 139 | 139 | |
| 140 | 140 | $manager->commit(); |
| 141 | 141 | } |
| 142 | - catch( \Exception $e ) |
|
| 142 | + catch (\Exception $e) |
|
| 143 | 143 | { |
| 144 | 144 | $manager->rollback(); |
| 145 | 145 | throw $e; |
@@ -155,17 +155,17 @@ discard block |
||
| 155 | 155 | * @param array $list Associative list of domain item keys and their values, e.g. "media.status" => 1 |
| 156 | 156 | * @return array Given associative list enriched by default values if they were not already set |
| 157 | 157 | */ |
| 158 | - protected function addItemDefaults( array $list ) |
|
| 158 | + protected function addItemDefaults(array $list) |
|
| 159 | 159 | { |
| 160 | - if( !isset( $list['media.label'] ) ) { |
|
| 160 | + if (!isset($list['media.label'])) { |
|
| 161 | 161 | $list['media.label'] = $list['media.url']; |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | - if( !isset( $list['media.preview'] ) ) { |
|
| 164 | + if (!isset($list['media.preview'])) { |
|
| 165 | 165 | $list['media.preview'] = $list['media.url']; |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | - if( !isset( $list['media.status'] ) ) { |
|
| 168 | + if (!isset($list['media.status'])) { |
|
| 169 | 169 | $list['media.status'] = 1; |
| 170 | 170 | } |
| 171 | 171 | |
@@ -179,10 +179,10 @@ discard block |
||
| 179 | 179 | * @param array $list Associative list of key/value pairs from the mapping |
| 180 | 180 | * @return boolean True if valid, false if not |
| 181 | 181 | */ |
| 182 | - protected function checkEntry( array $list ) |
|
| 182 | + protected function checkEntry(array $list) |
|
| 183 | 183 | { |
| 184 | - if( !isset( $list['media.url'] ) || $list['media.url'] === '' || isset( $list['product.lists.type'] ) |
|
| 185 | - && $this->listTypes !== null && !in_array( $list['product.lists.type'], (array) $this->listTypes ) |
|
| 184 | + if (!isset($list['media.url']) || $list['media.url'] === '' || isset($list['product.lists.type']) |
|
| 185 | + && $this->listTypes !== null && !in_array($list['product.lists.type'], (array) $this->listTypes) |
|
| 186 | 186 | ) { |
| 187 | 187 | return false; |
| 188 | 188 | } |