@@ -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,12 +80,12 @@ 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 | |
@@ -93,20 +93,20 @@ discard block |
||
| 93 | 93 | { |
| 94 | 94 | $pos = 0; |
| 95 | 95 | $delete = array(); |
| 96 | - $map = $this->getMappedChunk( $data ); |
|
| 97 | - $listItems = $product->getListItems( 'attribute', $this->listTypes ); |
|
| 96 | + $map = $this->getMappedChunk($data); |
|
| 97 | + $listItems = $product->getListItems('attribute', $this->listTypes); |
|
| 98 | 98 | |
| 99 | - foreach( $listItems as $listId => $listItem ) |
|
| 99 | + foreach ($listItems as $listId => $listItem) |
|
| 100 | 100 | { |
| 101 | - if( isset( $map[$pos] ) ) |
|
| 101 | + if (isset($map[$pos])) |
|
| 102 | 102 | { |
| 103 | - if( !isset( $map[$pos]['attribute.code'] ) || !isset( $map[$pos]['attribute.type'] ) ) |
|
| 103 | + if (!isset($map[$pos]['attribute.code']) || !isset($map[$pos]['attribute.type'])) |
|
| 104 | 104 | { |
| 105 | - unset( $map[$pos] ); |
|
| 105 | + unset($map[$pos]); |
|
| 106 | 106 | continue; |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | - if( $this->checkMatch( $listItem, $map[$pos] ) === true ) |
|
| 109 | + if ($this->checkMatch($listItem, $map[$pos]) === true) |
|
| 110 | 110 | { |
| 111 | 111 | $pos++; |
| 112 | 112 | continue; |
@@ -118,43 +118,43 @@ discard block |
||
| 118 | 118 | $pos++; |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | - $listManager->deleteItems( $delete ); |
|
| 121 | + $listManager->deleteItems($delete); |
|
| 122 | 122 | |
| 123 | - foreach( $map as $pos => $list ) |
|
| 123 | + foreach ($map as $pos => $list) |
|
| 124 | 124 | { |
| 125 | - if( $this->checkEntry( $list ) === false ) { |
|
| 125 | + if ($this->checkEntry($list) === false) { |
|
| 126 | 126 | continue; |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | - $codes = explode( $separator, $list['attribute.code'] ); |
|
| 129 | + $codes = explode($separator, $list['attribute.code']); |
|
| 130 | 130 | |
| 131 | - foreach( $codes as $code ) |
|
| 131 | + foreach ($codes as $code) |
|
| 132 | 132 | { |
| 133 | - $attrItem = $this->getAttributeItem( $code, $list['attribute.type'] ); |
|
| 134 | - $attrItem->fromArray( $list ); |
|
| 135 | - $attrItem->setCode( $code ); |
|
| 136 | - $manager->saveItem( $attrItem ); |
|
| 133 | + $attrItem = $this->getAttributeItem($code, $list['attribute.type']); |
|
| 134 | + $attrItem->fromArray($list); |
|
| 135 | + $attrItem->setCode($code); |
|
| 136 | + $manager->saveItem($attrItem); |
|
| 137 | 137 | |
| 138 | - if( ( $listItem = array_shift( $listItems ) ) === null ) { |
|
| 138 | + if (($listItem = array_shift($listItems)) === null) { |
|
| 139 | 139 | $listItem = $listManager->createItem(); |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | - $typecode = $this->getValue( $list, 'product.lists.type', 'default' ); |
|
| 143 | - $list['product.lists.typeid'] = $this->getTypeId( 'product/lists/type', 'attribute', $typecode ); |
|
| 142 | + $typecode = $this->getValue($list, 'product.lists.type', 'default'); |
|
| 143 | + $list['product.lists.typeid'] = $this->getTypeId('product/lists/type', 'attribute', $typecode); |
|
| 144 | 144 | $list['product.lists.refid'] = $attrItem->getId(); |
| 145 | 145 | $list['product.lists.parentid'] = $product->getId(); |
| 146 | 146 | $list['product.lists.domain'] = 'attribute'; |
| 147 | 147 | |
| 148 | - $listItem->fromArray( $this->addListItemDefaults( $list, $pos ) ); |
|
| 149 | - $listManager->saveItem( $listItem ); |
|
| 148 | + $listItem->fromArray($this->addListItemDefaults($list, $pos)); |
|
| 149 | + $listManager->saveItem($listItem); |
|
| 150 | 150 | } |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | - $remaining = $this->getObject()->process( $product, $data ); |
|
| 153 | + $remaining = $this->getObject()->process($product, $data); |
|
| 154 | 154 | |
| 155 | 155 | $manager->commit(); |
| 156 | 156 | } |
| 157 | - catch( \Exception $e ) |
|
| 157 | + catch (\Exception $e) |
|
| 158 | 158 | { |
| 159 | 159 | $manager->rollback(); |
| 160 | 160 | throw $e; |
@@ -170,11 +170,11 @@ discard block |
||
| 170 | 170 | * @param array $list Associative list of key/value pairs from the mapped data |
| 171 | 171 | * @return boolean True if the entry is valid, false if not |
| 172 | 172 | */ |
| 173 | - protected function checkEntry( array $list ) |
|
| 173 | + protected function checkEntry(array $list) |
|
| 174 | 174 | { |
| 175 | - if( !isset( $list['attribute.code'] ) || $list['attribute.code'] === '' || $list['attribute.type'] === '' |
|
| 176 | - || isset( $list['product.lists.type'] ) && $this->listTypes !== null |
|
| 177 | - && !in_array( $list['product.lists.type'], (array) $this->listTypes ) |
|
| 175 | + if (!isset($list['attribute.code']) || $list['attribute.code'] === '' || $list['attribute.type'] === '' |
|
| 176 | + || isset($list['product.lists.type']) && $this->listTypes !== null |
|
| 177 | + && !in_array($list['product.lists.type'], (array) $this->listTypes) |
|
| 178 | 178 | ) { |
| 179 | 179 | return false; |
| 180 | 180 | } |
@@ -190,14 +190,14 @@ discard block |
||
| 190 | 190 | * @param array $list Associative list of key/value pairs from the mapped data |
| 191 | 191 | * @return boolean True if the list item matches the values in the list, false if not |
| 192 | 192 | */ |
| 193 | - protected function checkMatch( \Aimeos\MShop\Common\Item\Lists\Iface $listItem, array $list ) |
|
| 193 | + protected function checkMatch(\Aimeos\MShop\Common\Item\Lists\Iface $listItem, array $list) |
|
| 194 | 194 | { |
| 195 | 195 | $refItem = $listItem->getRefItem(); |
| 196 | 196 | |
| 197 | - if( $refItem !== null && $list['attribute.code'] === $refItem->getCode() |
|
| 197 | + if ($refItem !== null && $list['attribute.code'] === $refItem->getCode() |
|
| 198 | 198 | && $list['attribute.type'] === $refItem->getType() |
| 199 | - && ( !isset( $list['product.lists.type'] ) || isset( $list['product.lists.type'] ) |
|
| 200 | - && $list['product.lists.type'] === $listItem->getType() ) |
|
| 199 | + && (!isset($list['product.lists.type']) || isset($list['product.lists.type']) |
|
| 200 | + && $list['product.lists.type'] === $listItem->getType()) |
|
| 201 | 201 | ) { |
| 202 | 202 | return true; |
| 203 | 203 | } |
@@ -213,22 +213,22 @@ discard block |
||
| 213 | 213 | * @param string $type Attribute type |
| 214 | 214 | * @return \Aimeos\MShop\Attribute\Item\Iface Attribute item object |
| 215 | 215 | */ |
| 216 | - protected function getAttributeItem( $code, $type ) |
|
| 216 | + protected function getAttributeItem($code, $type) |
|
| 217 | 217 | { |
| 218 | - if( ( $item = $this->cache->get( $code, $type ) ) === null ) |
|
| 218 | + if (($item = $this->cache->get($code, $type)) === null) |
|
| 219 | 219 | { |
| 220 | - $manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'attribute' ); |
|
| 220 | + $manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'attribute'); |
|
| 221 | 221 | |
| 222 | 222 | $item = $manager->createItem(); |
| 223 | - $item->setTypeId( $this->getTypeId( 'attribute/type', 'product', $type ) ); |
|
| 224 | - $item->setDomain( 'product' ); |
|
| 225 | - $item->setLabel( $type . ' ' . $code ); |
|
| 226 | - $item->setCode( $code ); |
|
| 227 | - $item->setStatus( 1 ); |
|
| 223 | + $item->setTypeId($this->getTypeId('attribute/type', 'product', $type)); |
|
| 224 | + $item->setDomain('product'); |
|
| 225 | + $item->setLabel($type . ' ' . $code); |
|
| 226 | + $item->setCode($code); |
|
| 227 | + $item->setStatus(1); |
|
| 228 | 228 | |
| 229 | - $manager->saveItem( $item ); |
|
| 229 | + $manager->saveItem($item); |
|
| 230 | 230 | |
| 231 | - $this->cache->set( $item ); |
|
| 231 | + $this->cache->set($item); |
|
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | return $item; |