@@ -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,73 +80,73 @@ 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, trim( $list['attribute.code'] ) ); |
|
111 | + $codes = explode($separator, trim($list['attribute.code'])); |
|
112 | 112 | |
113 | - foreach( $codes as $code ) |
|
113 | + foreach ($codes as $code) |
|
114 | 114 | { |
115 | - $code = trim( $code ); |
|
115 | + $code = trim($code); |
|
116 | 116 | |
117 | - $attrItem = $this->getAttributeItem( $code, trim( $list['attribute.type'] ) ); |
|
118 | - $attrItem->fromArray( $list ); |
|
119 | - $attrItem->setCode( $code ); |
|
120 | - $attrItem = $manager->saveItem( $attrItem ); |
|
117 | + $attrItem = $this->getAttributeItem($code, trim($list['attribute.type'])); |
|
118 | + $attrItem->fromArray($list); |
|
119 | + $attrItem->setCode($code); |
|
120 | + $attrItem = $manager->saveItem($attrItem); |
|
121 | 121 | |
122 | - $typecode = trim( $this->getValue( $list, 'product.lists.type', 'default' ) ); |
|
123 | - $list['product.lists.typeid'] = $this->getTypeId( 'product/lists/type', 'attribute', $typecode ); |
|
122 | + $typecode = trim($this->getValue($list, 'product.lists.type', 'default')); |
|
123 | + $list['product.lists.typeid'] = $this->getTypeId('product/lists/type', 'attribute', $typecode); |
|
124 | 124 | $list['product.lists.refid'] = $attrItem->getId(); |
125 | 125 | $list['product.lists.parentid'] = $product->getId(); |
126 | 126 | $list['product.lists.domain'] = 'attribute'; |
127 | 127 | |
128 | - if( isset( $listMap[$code][$typecode] ) ) |
|
128 | + if (isset($listMap[$code][$typecode])) |
|
129 | 129 | { |
130 | 130 | $listItem = $listMap[$code][$typecode]; |
131 | - unset( $listItems[ $listItem->getId() ] ); |
|
131 | + unset($listItems[$listItem->getId()]); |
|
132 | 132 | } |
133 | 133 | else |
134 | 134 | { |
135 | 135 | $listItem = $listManager->createItem(); |
136 | 136 | } |
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 | - $listManager->deleteItems( array_keys( $listItems ) ); |
|
143 | + $listManager->deleteItems(array_keys($listItems)); |
|
144 | 144 | |
145 | - $data = $this->getObject()->process( $product, $data ); |
|
145 | + $data = $this->getObject()->process($product, $data); |
|
146 | 146 | |
147 | 147 | $manager->commit(); |
148 | 148 | } |
149 | - catch( \Exception $e ) |
|
149 | + catch (\Exception $e) |
|
150 | 150 | { |
151 | 151 | $manager->rollback(); |
152 | 152 | throw $e; |
@@ -162,11 +162,11 @@ discard block |
||
162 | 162 | * @param array $list Associative list of key/value pairs from the mapped data |
163 | 163 | * @return boolean True if the entry is valid, false if not |
164 | 164 | */ |
165 | - protected function checkEntry( array $list ) |
|
165 | + protected function checkEntry(array $list) |
|
166 | 166 | { |
167 | - if( !isset( $list['attribute.code'] ) || trim( $list['attribute.code'] ) === '' |
|
168 | - || trim( $list['attribute.type'] ) === '' || isset( $list['product.lists.type'] ) |
|
169 | - && $this->listTypes !== null && !in_array( trim( $list['product.lists.type'] ), (array) $this->listTypes ) |
|
167 | + if (!isset($list['attribute.code']) || trim($list['attribute.code']) === '' |
|
168 | + || trim($list['attribute.type']) === '' || isset($list['product.lists.type']) |
|
169 | + && $this->listTypes !== null && !in_array(trim($list['product.lists.type']), (array) $this->listTypes) |
|
170 | 170 | ) { |
171 | 171 | return false; |
172 | 172 | } |
@@ -182,22 +182,22 @@ discard block |
||
182 | 182 | * @param string $type Attribute type |
183 | 183 | * @return \Aimeos\MShop\Attribute\Item\Iface Attribute item object |
184 | 184 | */ |
185 | - protected function getAttributeItem( $code, $type ) |
|
185 | + protected function getAttributeItem($code, $type) |
|
186 | 186 | { |
187 | - if( ( $item = $this->cache->get( $code, $type ) ) === null ) |
|
187 | + if (($item = $this->cache->get($code, $type)) === null) |
|
188 | 188 | { |
189 | - $manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'attribute' ); |
|
189 | + $manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'attribute'); |
|
190 | 190 | |
191 | 191 | $item = $manager->createItem(); |
192 | - $item->setTypeId( $this->getTypeId( 'attribute/type', 'product', $type ) ); |
|
193 | - $item->setDomain( 'product' ); |
|
194 | - $item->setLabel( $type . ' ' . $code ); |
|
195 | - $item->setCode( $code ); |
|
196 | - $item->setStatus( 1 ); |
|
192 | + $item->setTypeId($this->getTypeId('attribute/type', 'product', $type)); |
|
193 | + $item->setDomain('product'); |
|
194 | + $item->setLabel($type . ' ' . $code); |
|
195 | + $item->setCode($code); |
|
196 | + $item->setStatus(1); |
|
197 | 197 | |
198 | - $item = $manager->saveItem( $item ); |
|
198 | + $item = $manager->saveItem($item); |
|
199 | 199 | |
200 | - $this->cache->set( $item ); |
|
200 | + $this->cache->set($item); |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | return $item; |
@@ -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,47 +77,47 @@ 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, trim( $list['media.url'] ) ); |
|
109 | - $type = trim( $this->getValue( $list, 'media.type', 'default' ) ); |
|
110 | - $typecode = trim( $this->getValue( $list, 'product.lists.type', 'default' ) ); |
|
108 | + $urls = explode($separator, trim($list['media.url'])); |
|
109 | + $type = trim($this->getValue($list, 'media.type', 'default')); |
|
110 | + $typecode = trim($this->getValue($list, 'product.lists.type', 'default')); |
|
111 | 111 | |
112 | - foreach( $urls as $url ) |
|
112 | + foreach ($urls as $url) |
|
113 | 113 | { |
114 | - $url = trim( $url ); |
|
114 | + $url = trim($url); |
|
115 | 115 | |
116 | - if( isset( $listMap[$url][$type][$typecode] ) ) |
|
116 | + if (isset($listMap[$url][$type][$typecode])) |
|
117 | 117 | { |
118 | 118 | $listItem = $listMap[$url][$type][$typecode]; |
119 | 119 | $refItem = $listItem->getRefItem(); |
120 | - unset( $listItems[ $listItem->getId() ] ); |
|
120 | + unset($listItems[$listItem->getId()]); |
|
121 | 121 | } |
122 | 122 | else |
123 | 123 | { |
@@ -125,35 +125,35 @@ discard block |
||
125 | 125 | $refItem = $manager->createItem(); |
126 | 126 | } |
127 | 127 | |
128 | - $list['media.typeid'] = $this->getTypeId( 'media/type', 'product', $type ); |
|
128 | + $list['media.typeid'] = $this->getTypeId('media/type', 'product', $type); |
|
129 | 129 | $list['media.domain'] = 'product'; |
130 | 130 | $list['media.url'] = $url; |
131 | 131 | |
132 | - $refItem->fromArray( $this->addItemDefaults( $list ) ); |
|
133 | - $refItem = $manager->saveItem( $refItem ); |
|
132 | + $refItem->fromArray($this->addItemDefaults($list)); |
|
133 | + $refItem = $manager->saveItem($refItem); |
|
134 | 134 | |
135 | - $list['product.lists.typeid'] = $this->getTypeId( 'product/lists/type', 'media', $typecode ); |
|
135 | + $list['product.lists.typeid'] = $this->getTypeId('product/lists/type', 'media', $typecode); |
|
136 | 136 | $list['product.lists.parentid'] = $product->getId(); |
137 | 137 | $list['product.lists.refid'] = $refItem->getId(); |
138 | 138 | $list['product.lists.domain'] = 'media'; |
139 | 139 | |
140 | - $listItem->fromArray( $this->addListItemDefaults( $list, $pos++ ) ); |
|
141 | - $listManager->saveItem( $listItem, false ); |
|
140 | + $listItem->fromArray($this->addListItemDefaults($list, $pos++)); |
|
141 | + $listManager->saveItem($listItem, false); |
|
142 | 142 | } |
143 | 143 | } |
144 | 144 | |
145 | - foreach( $listItems as $listItem ) { |
|
145 | + foreach ($listItems as $listItem) { |
|
146 | 146 | $delete[] = $listItem->getRefId(); |
147 | 147 | } |
148 | 148 | |
149 | - $manager->deleteItems( $delete ); |
|
150 | - $listManager->deleteItems( array_keys( $listItems ) ); |
|
149 | + $manager->deleteItems($delete); |
|
150 | + $listManager->deleteItems(array_keys($listItems)); |
|
151 | 151 | |
152 | - $data = $this->getObject()->process( $product, $data ); |
|
152 | + $data = $this->getObject()->process($product, $data); |
|
153 | 153 | |
154 | 154 | $manager->commit(); |
155 | 155 | } |
156 | - catch( \Exception $e ) |
|
156 | + catch (\Exception $e) |
|
157 | 157 | { |
158 | 158 | $manager->rollback(); |
159 | 159 | throw $e; |
@@ -169,17 +169,17 @@ discard block |
||
169 | 169 | * @param array $list Associative list of domain item keys and their values, e.g. "media.status" => 1 |
170 | 170 | * @return array Given associative list enriched by default values if they were not already set |
171 | 171 | */ |
172 | - protected function addItemDefaults( array $list ) |
|
172 | + protected function addItemDefaults(array $list) |
|
173 | 173 | { |
174 | - if( !isset( $list['media.label'] ) ) { |
|
174 | + if (!isset($list['media.label'])) { |
|
175 | 175 | $list['media.label'] = $list['media.url']; |
176 | 176 | } |
177 | 177 | |
178 | - if( !isset( $list['media.preview'] ) ) { |
|
178 | + if (!isset($list['media.preview'])) { |
|
179 | 179 | $list['media.preview'] = $list['media.url']; |
180 | 180 | } |
181 | 181 | |
182 | - if( !isset( $list['media.status'] ) ) { |
|
182 | + if (!isset($list['media.status'])) { |
|
183 | 183 | $list['media.status'] = 1; |
184 | 184 | } |
185 | 185 | |
@@ -193,10 +193,10 @@ discard block |
||
193 | 193 | * @param array $list Associative list of key/value pairs from the mapping |
194 | 194 | * @return boolean True if valid, false if not |
195 | 195 | */ |
196 | - protected function checkEntry( array $list ) |
|
196 | + protected function checkEntry(array $list) |
|
197 | 197 | { |
198 | - if( !isset( $list['media.url'] ) || trim( $list['media.url'] ) === '' || isset( $list['product.lists.type'] ) |
|
199 | - && $this->listTypes !== null && !in_array( trim( $list['product.lists.type'] ), (array) $this->listTypes ) |
|
198 | + if (!isset($list['media.url']) || trim($list['media.url']) === '' || isset($list['product.lists.type']) |
|
199 | + && $this->listTypes !== null && !in_array(trim($list['product.lists.type']), (array) $this->listTypes) |
|
200 | 200 | ) { |
201 | 201 | return false; |
202 | 202 | } |
@@ -40,21 +40,21 @@ |
||
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\Coupon\Item\Code\Iface $item, array $data ) |
|
43 | + public function process(\Aimeos\MShop\Coupon\Item\Code\Iface $item, array $data) |
|
44 | 44 | { |
45 | - $manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'coupon/code' ); |
|
46 | - $map = $this->getMappedChunk( $data, $this->getMapping() ); |
|
45 | + $manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'coupon/code'); |
|
46 | + $map = $this->getMappedChunk($data, $this->getMapping()); |
|
47 | 47 | |
48 | - foreach( $map as $list ) |
|
48 | + foreach ($map as $list) |
|
49 | 49 | { |
50 | - if( trim( $list['coupon.code.code'] ) == '' ) { |
|
50 | + if (trim($list['coupon.code.code']) == '') { |
|
51 | 51 | continue; |
52 | 52 | } |
53 | 53 | |
54 | - $item->fromArray( $list ); |
|
55 | - $manager->saveItem( $item ); |
|
54 | + $item->fromArray($list); |
|
55 | + $manager->saveItem($item); |
|
56 | 56 | } |
57 | 57 | |
58 | - return $this->getObject()->process( $item, $data ); |
|
58 | + return $this->getObject()->process($item, $data); |
|
59 | 59 | } |
60 | 60 | } |