@@ -17,16 +17,16 @@ discard block |
||
| 17 | 17 | |
| 18 | 18 | protected function setUp() |
| 19 | 19 | { |
| 20 | - \Aimeos\MShop\Factory::setCache( true ); |
|
| 20 | + \Aimeos\MShop\Factory::setCache(true); |
|
| 21 | 21 | |
| 22 | 22 | $this->context = \TestHelperCntl::getContext(); |
| 23 | - $this->endpoint = new \Aimeos\Controller\Common\Product\Import\Csv\Processor\Done( $this->context, array() ); |
|
| 23 | + $this->endpoint = new \Aimeos\Controller\Common\Product\Import\Csv\Processor\Done($this->context, array()); |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | |
| 27 | 27 | protected function tearDown() |
| 28 | 28 | { |
| 29 | - \Aimeos\MShop\Factory::setCache( false ); |
|
| 29 | + \Aimeos\MShop\Factory::setCache(false); |
|
| 30 | 30 | \Aimeos\MShop\Factory::clear(); |
| 31 | 31 | } |
| 32 | 32 | |
@@ -43,21 +43,21 @@ discard block |
||
| 43 | 43 | 1 => '2000-01-01 00:00:00', |
| 44 | 44 | ); |
| 45 | 45 | |
| 46 | - $product = $this->create( 'job_csv_test' ); |
|
| 46 | + $product = $this->create('job_csv_test'); |
|
| 47 | 47 | |
| 48 | - $object = new \Aimeos\Controller\Common\Product\Import\Csv\Processor\Stock\Standard( $this->context, $mapping, $this->endpoint ); |
|
| 49 | - $object->process( $product, $data ); |
|
| 48 | + $object = new \Aimeos\Controller\Common\Product\Import\Csv\Processor\Stock\Standard($this->context, $mapping, $this->endpoint); |
|
| 49 | + $object->process($product, $data); |
|
| 50 | 50 | |
| 51 | - $items = $this->getStockItems( $product->getCode() ); |
|
| 52 | - $this->delete( $product ); |
|
| 51 | + $items = $this->getStockItems($product->getCode()); |
|
| 52 | + $this->delete($product); |
|
| 53 | 53 | |
| 54 | 54 | |
| 55 | - $this->assertEquals( 1, count( $items ) ); |
|
| 55 | + $this->assertEquals(1, count($items)); |
|
| 56 | 56 | |
| 57 | - foreach( $items as $item ) |
|
| 57 | + foreach ($items as $item) |
|
| 58 | 58 | { |
| 59 | - $this->assertEquals( 100, $item->getStocklevel() ); |
|
| 60 | - $this->assertEquals( '2000-01-01 00:00:00', $item->getDateBack() ); |
|
| 59 | + $this->assertEquals(100, $item->getStocklevel()); |
|
| 60 | + $this->assertEquals('2000-01-01 00:00:00', $item->getDateBack()); |
|
| 61 | 61 | } |
| 62 | 62 | } |
| 63 | 63 | |
@@ -78,19 +78,19 @@ discard block |
||
| 78 | 78 | 3 => '200', |
| 79 | 79 | ); |
| 80 | 80 | |
| 81 | - $product = $this->create( 'job_csv_test' ); |
|
| 81 | + $product = $this->create('job_csv_test'); |
|
| 82 | 82 | |
| 83 | - $object = new \Aimeos\Controller\Common\Product\Import\Csv\Processor\Stock\Standard( $this->context, $mapping, $this->endpoint ); |
|
| 84 | - $object->process( $product, $data ); |
|
| 83 | + $object = new \Aimeos\Controller\Common\Product\Import\Csv\Processor\Stock\Standard($this->context, $mapping, $this->endpoint); |
|
| 84 | + $object->process($product, $data); |
|
| 85 | 85 | |
| 86 | - $items = $this->getStockItems( $product->getCode() ); |
|
| 87 | - $this->delete( $product ); |
|
| 86 | + $items = $this->getStockItems($product->getCode()); |
|
| 87 | + $this->delete($product); |
|
| 88 | 88 | |
| 89 | 89 | |
| 90 | - $this->assertEquals( 2, count( $items ) ); |
|
| 90 | + $this->assertEquals(2, count($items)); |
|
| 91 | 91 | |
| 92 | - foreach( $items as $item ) { |
|
| 93 | - $this->assertEquals( 200, $item->getStocklevel() ); |
|
| 92 | + foreach ($items as $item) { |
|
| 93 | + $this->assertEquals(200, $item->getStocklevel()); |
|
| 94 | 94 | } |
| 95 | 95 | } |
| 96 | 96 | |
@@ -109,21 +109,21 @@ discard block |
||
| 109 | 109 | 0 => '20', |
| 110 | 110 | ); |
| 111 | 111 | |
| 112 | - $product = $this->create( 'job_csv_test' ); |
|
| 112 | + $product = $this->create('job_csv_test'); |
|
| 113 | 113 | |
| 114 | - $object = new \Aimeos\Controller\Common\Product\Import\Csv\Processor\Stock\Standard( $this->context, $mapping, $this->endpoint ); |
|
| 114 | + $object = new \Aimeos\Controller\Common\Product\Import\Csv\Processor\Stock\Standard($this->context, $mapping, $this->endpoint); |
|
| 115 | 115 | |
| 116 | - $object->process( $product, $data ); |
|
| 117 | - $object->process( $product, $dataUpdate ); |
|
| 116 | + $object->process($product, $data); |
|
| 117 | + $object->process($product, $dataUpdate); |
|
| 118 | 118 | |
| 119 | - $items = $this->getStockItems( $product->getCode() ); |
|
| 120 | - $this->delete( $product ); |
|
| 119 | + $items = $this->getStockItems($product->getCode()); |
|
| 120 | + $this->delete($product); |
|
| 121 | 121 | |
| 122 | 122 | |
| 123 | - $item = reset( $items ); |
|
| 123 | + $item = reset($items); |
|
| 124 | 124 | |
| 125 | - $this->assertEquals( 1, count( $items ) ); |
|
| 126 | - $this->assertEquals( 20, $item->getStocklevel() ); |
|
| 125 | + $this->assertEquals(1, count($items)); |
|
| 126 | + $this->assertEquals(20, $item->getStocklevel()); |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | |
@@ -137,19 +137,19 @@ discard block |
||
| 137 | 137 | 0 => 50, |
| 138 | 138 | ); |
| 139 | 139 | |
| 140 | - $product = $this->create( 'job_csv_test' ); |
|
| 140 | + $product = $this->create('job_csv_test'); |
|
| 141 | 141 | |
| 142 | - $object = new \Aimeos\Controller\Common\Product\Import\Csv\Processor\Stock\Standard( $this->context, $mapping, $this->endpoint ); |
|
| 143 | - $object->process( $product, $data ); |
|
| 142 | + $object = new \Aimeos\Controller\Common\Product\Import\Csv\Processor\Stock\Standard($this->context, $mapping, $this->endpoint); |
|
| 143 | + $object->process($product, $data); |
|
| 144 | 144 | |
| 145 | - $object = new \Aimeos\Controller\Common\Product\Import\Csv\Processor\Stock\Standard( $this->context, array(), $this->endpoint ); |
|
| 146 | - $object->process( $product, array() ); |
|
| 145 | + $object = new \Aimeos\Controller\Common\Product\Import\Csv\Processor\Stock\Standard($this->context, array(), $this->endpoint); |
|
| 146 | + $object->process($product, array()); |
|
| 147 | 147 | |
| 148 | - $items = $this->getStockItems( $product->getCode() ); |
|
| 149 | - $this->delete( $product ); |
|
| 148 | + $items = $this->getStockItems($product->getCode()); |
|
| 149 | + $this->delete($product); |
|
| 150 | 150 | |
| 151 | 151 | |
| 152 | - $this->assertEquals( 0, count( $items ) ); |
|
| 152 | + $this->assertEquals(0, count($items)); |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | |
@@ -167,20 +167,20 @@ discard block |
||
| 167 | 167 | 2 => '', |
| 168 | 168 | ); |
| 169 | 169 | |
| 170 | - $product = $this->create( 'job_csv_test' ); |
|
| 170 | + $product = $this->create('job_csv_test'); |
|
| 171 | 171 | |
| 172 | - $object = new \Aimeos\Controller\Common\Product\Import\Csv\Processor\Stock\Standard( $this->context, $mapping, $this->endpoint ); |
|
| 173 | - $object->process( $product, $data ); |
|
| 172 | + $object = new \Aimeos\Controller\Common\Product\Import\Csv\Processor\Stock\Standard($this->context, $mapping, $this->endpoint); |
|
| 173 | + $object->process($product, $data); |
|
| 174 | 174 | |
| 175 | - $items = $this->getStockItems( $product->getCode() ); |
|
| 176 | - $this->delete( $product ); |
|
| 175 | + $items = $this->getStockItems($product->getCode()); |
|
| 176 | + $this->delete($product); |
|
| 177 | 177 | |
| 178 | - $this->assertEquals( 1, count( $items ) ); |
|
| 178 | + $this->assertEquals(1, count($items)); |
|
| 179 | 179 | |
| 180 | - foreach( $items as $item ) |
|
| 180 | + foreach ($items as $item) |
|
| 181 | 181 | { |
| 182 | - $this->assertEquals( null, $item->getStocklevel() ); |
|
| 183 | - $this->assertEquals( null, $item->getDateBack() ); |
|
| 182 | + $this->assertEquals(null, $item->getStocklevel()); |
|
| 183 | + $this->assertEquals(null, $item->getDateBack()); |
|
| 184 | 184 | } |
| 185 | 185 | } |
| 186 | 186 | |
@@ -188,43 +188,43 @@ discard block |
||
| 188 | 188 | /** |
| 189 | 189 | * @param string $code |
| 190 | 190 | */ |
| 191 | - protected function create( $code ) |
|
| 191 | + protected function create($code) |
|
| 192 | 192 | { |
| 193 | - $manager = \Aimeos\MShop\Product\Manager\Factory::createManager( $this->context ); |
|
| 194 | - $typeManager = $manager->getSubManager( 'type' ); |
|
| 193 | + $manager = \Aimeos\MShop\Product\Manager\Factory::createManager($this->context); |
|
| 194 | + $typeManager = $manager->getSubManager('type'); |
|
| 195 | 195 | |
| 196 | 196 | $typeSearch = $typeManager->createSearch(); |
| 197 | - $typeSearch->setConditions( $typeSearch->compare( '==', 'product.type.code', 'default' ) ); |
|
| 198 | - $typeResult = $typeManager->searchItems( $typeSearch ); |
|
| 197 | + $typeSearch->setConditions($typeSearch->compare('==', 'product.type.code', 'default')); |
|
| 198 | + $typeResult = $typeManager->searchItems($typeSearch); |
|
| 199 | 199 | |
| 200 | - if( ( $typeItem = reset( $typeResult ) ) === false ) { |
|
| 201 | - throw new \RuntimeException( 'No product type "default" found' ); |
|
| 200 | + if (($typeItem = reset($typeResult)) === false) { |
|
| 201 | + throw new \RuntimeException('No product type "default" found'); |
|
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | $item = $manager->createItem(); |
| 205 | - $item->setTypeid( $typeItem->getId() ); |
|
| 206 | - $item->setCode( $code ); |
|
| 205 | + $item->setTypeid($typeItem->getId()); |
|
| 206 | + $item->setCode($code); |
|
| 207 | 207 | |
| 208 | - $manager->saveItem( $item ); |
|
| 208 | + $manager->saveItem($item); |
|
| 209 | 209 | |
| 210 | 210 | return $item; |
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | |
| 214 | - protected function delete( \Aimeos\MShop\Product\Item\Iface $product ) |
|
| 214 | + protected function delete(\Aimeos\MShop\Product\Item\Iface $product) |
|
| 215 | 215 | { |
| 216 | - $manager = \Aimeos\MShop\Product\Manager\Factory::createManager( $this->context ); |
|
| 217 | - $manager->deleteItem( $product->getId() ); |
|
| 216 | + $manager = \Aimeos\MShop\Product\Manager\Factory::createManager($this->context); |
|
| 217 | + $manager->deleteItem($product->getId()); |
|
| 218 | 218 | } |
| 219 | 219 | |
| 220 | 220 | |
| 221 | - protected function getStockItems( $code ) |
|
| 221 | + protected function getStockItems($code) |
|
| 222 | 222 | { |
| 223 | - $manager = \Aimeos\MShop\Factory::createManager( $this->context, 'stock' ); |
|
| 223 | + $manager = \Aimeos\MShop\Factory::createManager($this->context, 'stock'); |
|
| 224 | 224 | |
| 225 | 225 | $search = $manager->createSearch(); |
| 226 | - $search->setConditions( $search->compare( '==', 'stock.productcode', $code ) ); |
|
| 226 | + $search->setConditions($search->compare('==', 'stock.productcode', $code)); |
|
| 227 | 227 | |
| 228 | - return $manager->searchItems( $search ); |
|
| 228 | + return $manager->searchItems($search); |
|
| 229 | 229 | } |
| 230 | 230 | } |
| 231 | 231 | \ No newline at end of file |
@@ -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,70 +80,70 @@ 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() ][ $refItem->getType() ] = $listItem; |
|
| 100 | + if (($refItem = $listItem->getRefItem()) !== null) { |
|
| 101 | + $listMap[$refItem->getCode()][$refItem->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][ $list['attribute.type'] ] ) ) |
|
| 126 | + if (isset($listMap[$code][$list['attribute.type']])) |
|
| 127 | 127 | { |
| 128 | - $listItem = $listMap[$code][ $list['attribute.type'] ]; |
|
| 129 | - unset( $listItems[ $listItem->getId() ] ); |
|
| 128 | + $listItem = $listMap[$code][$list['attribute.type']]; |
|
| 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 ) ); |
|
| 142 | - $remaining = $this->getObject()->process( $product, $data ); |
|
| 141 | + $listManager->deleteItems(array_keys($listItems)); |
|
| 142 | + $remaining = $this->getObject()->process($product, $data); |
|
| 143 | 143 | |
| 144 | 144 | $manager->commit(); |
| 145 | 145 | } |
| 146 | - catch( \Exception $e ) |
|
| 146 | + catch (\Exception $e) |
|
| 147 | 147 | { |
| 148 | 148 | $manager->rollback(); |
| 149 | 149 | throw $e; |
@@ -159,11 +159,11 @@ discard block |
||
| 159 | 159 | * @param array $list Associative list of key/value pairs from the mapped data |
| 160 | 160 | * @return boolean True if the entry is valid, false if not |
| 161 | 161 | */ |
| 162 | - protected function checkEntry( array $list ) |
|
| 162 | + protected function checkEntry(array $list) |
|
| 163 | 163 | { |
| 164 | - if( !isset( $list['attribute.code'] ) || $list['attribute.code'] === '' || $list['attribute.type'] === '' |
|
| 165 | - || isset( $list['product.lists.type'] ) && $this->listTypes !== null |
|
| 166 | - && !in_array( $list['product.lists.type'], (array) $this->listTypes ) |
|
| 164 | + if (!isset($list['attribute.code']) || $list['attribute.code'] === '' || $list['attribute.type'] === '' |
|
| 165 | + || isset($list['product.lists.type']) && $this->listTypes !== null |
|
| 166 | + && !in_array($list['product.lists.type'], (array) $this->listTypes) |
|
| 167 | 167 | ) { |
| 168 | 168 | return false; |
| 169 | 169 | } |
@@ -179,22 +179,22 @@ discard block |
||
| 179 | 179 | * @param string $type Attribute type |
| 180 | 180 | * @return \Aimeos\MShop\Attribute\Item\Iface Attribute item object |
| 181 | 181 | */ |
| 182 | - protected function getAttributeItem( $code, $type ) |
|
| 182 | + protected function getAttributeItem($code, $type) |
|
| 183 | 183 | { |
| 184 | - if( ( $item = $this->cache->get( $code, $type ) ) === null ) |
|
| 184 | + if (($item = $this->cache->get($code, $type)) === null) |
|
| 185 | 185 | { |
| 186 | - $manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'attribute' ); |
|
| 186 | + $manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'attribute'); |
|
| 187 | 187 | |
| 188 | 188 | $item = $manager->createItem(); |
| 189 | - $item->setTypeId( $this->getTypeId( 'attribute/type', 'product', $type ) ); |
|
| 190 | - $item->setDomain( 'product' ); |
|
| 191 | - $item->setLabel( $type . ' ' . $code ); |
|
| 192 | - $item->setCode( $code ); |
|
| 193 | - $item->setStatus( 1 ); |
|
| 189 | + $item->setTypeId($this->getTypeId('attribute/type', 'product', $type)); |
|
| 190 | + $item->setDomain('product'); |
|
| 191 | + $item->setLabel($type . ' ' . $code); |
|
| 192 | + $item->setCode($code); |
|
| 193 | + $item->setStatus(1); |
|
| 194 | 194 | |
| 195 | - $manager->saveItem( $item ); |
|
| 195 | + $manager->saveItem($item); |
|
| 196 | 196 | |
| 197 | - $this->cache->set( $item ); |
|
| 197 | + $this->cache->set($item); |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | return $item; |
@@ -127,8 +127,7 @@ discard block |
||
| 127 | 127 | { |
| 128 | 128 | $listItem = $listMap[$code][ $list['attribute.type'] ]; |
| 129 | 129 | unset( $listItems[ $listItem->getId() ] ); |
| 130 | - } |
|
| 131 | - else |
|
| 130 | + } else |
|
| 132 | 131 | { |
| 133 | 132 | $listItem = $listManager->createItem(); |
| 134 | 133 | } |
@@ -142,8 +141,7 @@ discard block |
||
| 142 | 141 | $remaining = $this->getObject()->process( $product, $data ); |
| 143 | 142 | |
| 144 | 143 | $manager->commit(); |
| 145 | - } |
|
| 146 | - catch( \Exception $e ) |
|
| 144 | + } catch( \Exception $e ) |
|
| 147 | 145 | { |
| 148 | 146 | $manager->rollback(); |
| 149 | 147 | throw $e; |
@@ -42,12 +42,12 @@ 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 | - $this->cache = $this->getCache( 'stocktype' ); |
|
| 50 | + $this->cache = $this->getCache('stocktype'); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | |
@@ -58,53 +58,53 @@ discard block |
||
| 58 | 58 | * @param array $data List of CSV fields with position as key and data as value |
| 59 | 59 | * @return array List of data which hasn't been imported |
| 60 | 60 | */ |
| 61 | - public function process( \Aimeos\MShop\Product\Item\Iface $product, array $data ) |
|
| 61 | + public function process(\Aimeos\MShop\Product\Item\Iface $product, array $data) |
|
| 62 | 62 | { |
| 63 | - $manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'stock' ); |
|
| 63 | + $manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'stock'); |
|
| 64 | 64 | $manager->begin(); |
| 65 | 65 | |
| 66 | 66 | try |
| 67 | 67 | { |
| 68 | - $map = $this->getMappedChunk( $data ); |
|
| 69 | - $items = $this->getStockItems( $product->getCode() ); |
|
| 68 | + $map = $this->getMappedChunk($data); |
|
| 69 | + $items = $this->getStockItems($product->getCode()); |
|
| 70 | 70 | |
| 71 | - foreach( $map as $pos => $list ) |
|
| 71 | + foreach ($map as $pos => $list) |
|
| 72 | 72 | { |
| 73 | - if( !array_key_exists( 'stock.stocklevel', $list ) ) { |
|
| 73 | + if (!array_key_exists('stock.stocklevel', $list)) { |
|
| 74 | 74 | continue; |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - $stockType = ( isset( $list['stock.type'] ) ? $list['stock.type'] : 'default' ); |
|
| 77 | + $stockType = (isset($list['stock.type']) ? $list['stock.type'] : 'default'); |
|
| 78 | 78 | |
| 79 | - if( !isset( $list['stock.typeid'] ) ) { |
|
| 80 | - $list['stock.typeid'] = $this->cache->get( $stockType ); |
|
| 79 | + if (!isset($list['stock.typeid'])) { |
|
| 80 | + $list['stock.typeid'] = $this->cache->get($stockType); |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | - if( isset( $list['stock.dateback'] ) && $list['stock.dateback'] === '' ) { |
|
| 83 | + if (isset($list['stock.dateback']) && $list['stock.dateback'] === '') { |
|
| 84 | 84 | $list['stock.dateback'] = null; |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | - if( $list['stock.stocklevel'] === '' ) { |
|
| 87 | + if ($list['stock.stocklevel'] === '') { |
|
| 88 | 88 | $list['stock.stocklevel'] = null; |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | $list['stock.productcode'] = $product->getCode(); |
| 92 | 92 | |
| 93 | - if( ( $item = array_pop( $items ) ) === null ) { |
|
| 93 | + if (($item = array_pop($items)) === null) { |
|
| 94 | 94 | $item = $manager->createItem(); |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | - $item->fromArray( $list ); |
|
| 98 | - $manager->saveItem( $item ); |
|
| 97 | + $item->fromArray($list); |
|
| 98 | + $manager->saveItem($item); |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | - $manager->deleteItems( array_keys( $items ) ); |
|
| 101 | + $manager->deleteItems(array_keys($items)); |
|
| 102 | 102 | |
| 103 | - $remaining = $this->getObject()->process( $product, $data ); |
|
| 103 | + $remaining = $this->getObject()->process($product, $data); |
|
| 104 | 104 | |
| 105 | 105 | $manager->commit(); |
| 106 | 106 | } |
| 107 | - catch( \Exception $e ) |
|
| 107 | + catch (\Exception $e) |
|
| 108 | 108 | { |
| 109 | 109 | $manager->rollback(); |
| 110 | 110 | throw $e; |
@@ -120,13 +120,13 @@ discard block |
||
| 120 | 120 | * @param string $code Unique product code |
| 121 | 121 | * @return \Aimeos\MShop\Stock\Item\Iface[] Associative list of stock items |
| 122 | 122 | */ |
| 123 | - protected function getStockItems( $code ) |
|
| 123 | + protected function getStockItems($code) |
|
| 124 | 124 | { |
| 125 | - $manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'stock' ); |
|
| 125 | + $manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'stock'); |
|
| 126 | 126 | |
| 127 | 127 | $search = $manager->createSearch(); |
| 128 | - $search->setConditions( $search->compare( '==', 'stock.productcode', $code ) ); |
|
| 128 | + $search->setConditions($search->compare('==', 'stock.productcode', $code)); |
|
| 129 | 129 | |
| 130 | - return $manager->searchItems( $search ); |
|
| 130 | + return $manager->searchItems($search); |
|
| 131 | 131 | } |
| 132 | 132 | } |