@@ -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 = array(); |
89 | - $map = $this->getMappedChunk( $data ); |
|
90 | - $listItems = $product->getListItems( 'price', $this->listTypes ); |
|
89 | + $map = $this->getMappedChunk($data); |
|
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 | - $manager->saveItem( $refItem ); |
|
124 | + $refItem->fromArray($this->addItemDefaults($list)); |
|
125 | + $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 ); |
|
132 | + $listItem->fromArray($this->addListItemDefaults($list, $pos)); |
|
133 | + $listManager->saveItem($listItem); |
|
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 | - $remaining = $this->getObject()->process( $product, $data ); |
|
143 | + $remaining = $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 | } |
@@ -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 = array(); |
95 | - $map = $this->getMappedChunk( $data ); |
|
96 | - $listItems = $product->getListItems( 'attribute', $this->listTypes ); |
|
95 | + $map = $this->getMappedChunk($data); |
|
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 | - $manager->saveItem( $attrItem ); |
|
115 | + $attrItem = $this->getAttributeItem($code, $list['attribute.type']); |
|
116 | + $attrItem->fromArray($list); |
|
117 | + $attrItem->setCode($code); |
|
118 | + $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 ); |
|
136 | + $listItem->fromArray($this->addListItemDefaults($list, $pos)); |
|
137 | + $listManager->saveItem($listItem); |
|
138 | 138 | } |
139 | 139 | } |
140 | 140 | |
141 | - $listManager->deleteItems( array_keys( $listItems ) ); |
|
141 | + $listManager->deleteItems(array_keys($listItems)); |
|
142 | 142 | |
143 | - $remaining = $this->getObject()->process( $product, $data ); |
|
143 | + $remaining = $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 | - $manager->saveItem( $item ); |
|
196 | + $manager->saveItem($item); |
|
197 | 197 | |
198 | - $this->cache->set( $item ); |
|
198 | + $this->cache->set($item); |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | return $item; |
@@ -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 | $propPap = array(); |
51 | - $map = $this->getMappedChunk( $data ); |
|
52 | - $items = $this->getPropertyItems( $product->getId() ); |
|
51 | + $map = $this->getMappedChunk($data); |
|
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 ); |
|
78 | + $item->fromArray($list); |
|
79 | + $manager->saveItem($item); |
|
80 | 80 | } |
81 | 81 | |
82 | - $manager->deleteItems( array_keys( $items ) ); |
|
82 | + $manager->deleteItems(array_keys($items)); |
|
83 | 83 | |
84 | - $remaining = $this->getObject()->process( $product, $data ); |
|
84 | + $remaining = $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 | } |
@@ -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/product/listtypes |
52 | 52 | * Names of the product list types that are updated or removed |
@@ -73,11 +73,11 @@ discard block |
||
73 | 73 | * @see controller/common/product/import/csv/processor/price/listtypes |
74 | 74 | * @see controller/common/product/import/csv/processor/text/listtypes |
75 | 75 | */ |
76 | - $default = array( 'default', 'suggestion' ); |
|
76 | + $default = array('default', 'suggestion'); |
|
77 | 77 | $key = 'controller/common/product/import/csv/processor/product/listtypes'; |
78 | - $this->listTypes = $context->getConfig()->get( $key, $default ); |
|
78 | + $this->listTypes = $context->getConfig()->get($key, $default); |
|
79 | 79 | |
80 | - $this->cache = $this->getCache( 'product' ); |
|
80 | + $this->cache = $this->getCache('product'); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | |
@@ -88,13 +88,13 @@ discard block |
||
88 | 88 | * @param array $data List of CSV fields with position as key and data as value |
89 | 89 | * @return array List of data which hasn't been imported |
90 | 90 | */ |
91 | - public function process( \Aimeos\MShop\Product\Item\Iface $product, array $data ) |
|
91 | + public function process(\Aimeos\MShop\Product\Item\Iface $product, array $data) |
|
92 | 92 | { |
93 | 93 | $context = $this->getContext(); |
94 | - $manager = \Aimeos\MShop\Factory::createManager( $context, 'product' ); |
|
95 | - $separator = $context->getConfig()->get( 'controller/common/product/import/csv/separator', "\n" ); |
|
94 | + $manager = \Aimeos\MShop\Factory::createManager($context, 'product'); |
|
95 | + $separator = $context->getConfig()->get('controller/common/product/import/csv/separator', "\n"); |
|
96 | 96 | |
97 | - $this->cache->set( $product ); |
|
97 | + $this->cache->set($product); |
|
98 | 98 | |
99 | 99 | $manager->begin(); |
100 | 100 | |
@@ -102,37 +102,37 @@ discard block |
||
102 | 102 | { |
103 | 103 | $types = array(); |
104 | 104 | |
105 | - foreach( $this->getMappedChunk( $data ) as $list ) |
|
105 | + foreach ($this->getMappedChunk($data) as $list) |
|
106 | 106 | { |
107 | - if( $this->checkEntry( $list ) === false ) { |
|
107 | + if ($this->checkEntry($list) === false) { |
|
108 | 108 | continue; |
109 | 109 | } |
110 | 110 | |
111 | 111 | $listMap = array(); |
112 | - $type = ( isset( $list['product.lists.type'] ) ? $list['product.lists.type'] : 'default' ); |
|
112 | + $type = (isset($list['product.lists.type']) ? $list['product.lists.type'] : 'default'); |
|
113 | 113 | $types[] = $type; |
114 | 114 | |
115 | - foreach( explode( $separator, $list['product.code'] ) as $code ) |
|
115 | + foreach (explode($separator, $list['product.code']) as $code) |
|
116 | 116 | { |
117 | - if( ( $prodid = $this->cache->get( $code ) ) === null ) |
|
117 | + if (($prodid = $this->cache->get($code)) === null) |
|
118 | 118 | { |
119 | 119 | $msg = 'No product for code "%1$s" available when importing product with code "%2$s"'; |
120 | - throw new \Aimeos\Controller\Jobs\Exception( sprintf( $msg, $code, $product->getCode() ) ); |
|
120 | + throw new \Aimeos\Controller\Jobs\Exception(sprintf($msg, $code, $product->getCode())); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | $listMap[$prodid] = $list; |
124 | 124 | } |
125 | 125 | |
126 | - $manager->updateListItems( $product, $listMap, 'product', $type ); |
|
126 | + $manager->updateListItems($product, $listMap, 'product', $type); |
|
127 | 127 | } |
128 | 128 | |
129 | - $this->deleteListItems( $product->getId(), $types ); |
|
129 | + $this->deleteListItems($product->getId(), $types); |
|
130 | 130 | |
131 | - $remaining = $this->getObject()->process( $product, $data ); |
|
131 | + $remaining = $this->getObject()->process($product, $data); |
|
132 | 132 | |
133 | 133 | $manager->commit(); |
134 | 134 | } |
135 | - catch( \Exception $e ) |
|
135 | + catch (\Exception $e) |
|
136 | 136 | { |
137 | 137 | $manager->rollback(); |
138 | 138 | throw $e; |
@@ -148,10 +148,10 @@ discard block |
||
148 | 148 | * @param array $list Associative list of key/value pairs from the mapping |
149 | 149 | * @return boolean True if valid, false if not |
150 | 150 | */ |
151 | - protected function checkEntry( array $list ) |
|
151 | + protected function checkEntry(array $list) |
|
152 | 152 | { |
153 | - if( !isset( $list['product.code'] ) || $list['product.code'] === '' || isset( $list['product.lists.type'] ) |
|
154 | - && $this->listTypes !== null && !in_array( $list['product.lists.type'], (array) $this->listTypes ) |
|
153 | + if (!isset($list['product.code']) || $list['product.code'] === '' || isset($list['product.lists.type']) |
|
154 | + && $this->listTypes !== null && !in_array($list['product.lists.type'], (array) $this->listTypes) |
|
155 | 155 | ) { |
156 | 156 | return false; |
157 | 157 | } |
@@ -166,19 +166,19 @@ discard block |
||
166 | 166 | * @param string $prodId Unique product ID |
167 | 167 | * @param array $types List of types that have been updated |
168 | 168 | */ |
169 | - protected function deleteListItems( $prodId, array $types ) |
|
169 | + protected function deleteListItems($prodId, array $types) |
|
170 | 170 | { |
171 | - $codes = array_diff( $this->listTypes, $types ); |
|
172 | - $manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'product/lists' ); |
|
171 | + $codes = array_diff($this->listTypes, $types); |
|
172 | + $manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'product/lists'); |
|
173 | 173 | |
174 | 174 | $search = $manager->createSearch(); |
175 | 175 | $expr = array( |
176 | - $search->compare( '==', 'product.lists.parentid', $prodId ), |
|
177 | - $search->compare( '==', 'product.lists.domain', 'product' ), |
|
178 | - $search->compare( '==', 'product.lists.type.code', $codes ), |
|
176 | + $search->compare('==', 'product.lists.parentid', $prodId), |
|
177 | + $search->compare('==', 'product.lists.domain', 'product'), |
|
178 | + $search->compare('==', 'product.lists.type.code', $codes), |
|
179 | 179 | ); |
180 | - $search->setConditions( $search->combine( '&&', $expr ) ); |
|
180 | + $search->setConditions($search->combine('&&', $expr)); |
|
181 | 181 | |
182 | - $manager->deleteItems( array_keys( $manager->searchItems( $search ) ) ); |
|
182 | + $manager->deleteItems(array_keys($manager->searchItems($search))); |
|
183 | 183 | } |
184 | 184 | } |