Completed
Push — master ( adcfe9...7ac821 )
by Aimeos
07:11
created
src/Controller/Common/Product/Import/Csv/Processor/Attribute/Standard.php 1 patch
Spacing   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -43,10 +43,10 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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( $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($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;
Please login to merge, or discard this patch.