@@ -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( 'warehouse' ); |
|
| 50 | + $this->cache = $this->getCache('warehouse'); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | |
@@ -58,55 +58,55 @@ 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(), 'product/stock' ); |
|
| 63 | + $manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'product/stock'); |
|
| 64 | 64 | $manager->begin(); |
| 65 | 65 | |
| 66 | 66 | try |
| 67 | 67 | { |
| 68 | 68 | $pos = 0; |
| 69 | 69 | $delete = array(); |
| 70 | - $map = $this->getMappedChunk( $data ); |
|
| 71 | - $items = $this->getStockItems( $product->getId() ); |
|
| 70 | + $map = $this->getMappedChunk($data); |
|
| 71 | + $items = $this->getStockItems($product->getId()); |
|
| 72 | 72 | |
| 73 | - foreach( $map as $pos => $list ) |
|
| 73 | + foreach ($map as $pos => $list) |
|
| 74 | 74 | { |
| 75 | - if( !array_key_exists( 'product.stock.stocklevel', $list ) ) { |
|
| 75 | + if (!array_key_exists('product.stock.stocklevel', $list)) { |
|
| 76 | 76 | continue; |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - $whcode = ( isset( $list['product.stock.warehouse'] ) ? $list['product.stock.warehouse'] : 'default' ); |
|
| 79 | + $whcode = (isset($list['product.stock.warehouse']) ? $list['product.stock.warehouse'] : 'default'); |
|
| 80 | 80 | |
| 81 | - if( !isset( $list['product.stock.warehouseid'] ) ) { |
|
| 82 | - $list['product.stock.warehouseid'] = $this->cache->get( $whcode ); |
|
| 81 | + if (!isset($list['product.stock.warehouseid'])) { |
|
| 82 | + $list['product.stock.warehouseid'] = $this->cache->get($whcode); |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | - if( isset( $list['product.stock.dateback'] ) && $list['product.stock.dateback'] === '' ) { |
|
| 85 | + if (isset($list['product.stock.dateback']) && $list['product.stock.dateback'] === '') { |
|
| 86 | 86 | $list['product.stock.dateback'] = null; |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | - if( $list['product.stock.stocklevel'] === '' ) { |
|
| 89 | + if ($list['product.stock.stocklevel'] === '') { |
|
| 90 | 90 | $list['product.stock.stocklevel'] = null; |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | $list['product.stock.parentid'] = $product->getId(); |
| 94 | 94 | |
| 95 | - if( ( $item = array_pop( $items ) ) === null ) { |
|
| 95 | + if (($item = array_pop($items)) === null) { |
|
| 96 | 96 | $item = $manager->createItem(); |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | - $item->fromArray( $list ); |
|
| 100 | - $manager->saveItem( $item ); |
|
| 99 | + $item->fromArray($list); |
|
| 100 | + $manager->saveItem($item); |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | - $manager->deleteItems( array_keys( $items ) ); |
|
| 103 | + $manager->deleteItems(array_keys($items)); |
|
| 104 | 104 | |
| 105 | - $remaining = $this->getObject()->process( $product, $data ); |
|
| 105 | + $remaining = $this->getObject()->process($product, $data); |
|
| 106 | 106 | |
| 107 | 107 | $manager->commit(); |
| 108 | 108 | } |
| 109 | - catch( \Exception $e ) |
|
| 109 | + catch (\Exception $e) |
|
| 110 | 110 | { |
| 111 | 111 | $manager->rollback(); |
| 112 | 112 | throw $e; |
@@ -122,13 +122,13 @@ discard block |
||
| 122 | 122 | * @param string $prodid Unique product ID |
| 123 | 123 | * @return array Associative list of product stock items |
| 124 | 124 | */ |
| 125 | - protected function getStockItems( $prodid ) |
|
| 125 | + protected function getStockItems($prodid) |
|
| 126 | 126 | { |
| 127 | - $manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'product/stock' ); |
|
| 127 | + $manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'product/stock'); |
|
| 128 | 128 | |
| 129 | 129 | $search = $manager->createSearch(); |
| 130 | - $search->setConditions( $search->compare( '==', 'product.stock.parentid', $prodid ) ); |
|
| 130 | + $search->setConditions($search->compare('==', 'product.stock.parentid', $prodid)); |
|
| 131 | 131 | |
| 132 | - return $manager->searchItems( $search ); |
|
| 132 | + return $manager->searchItems($search); |
|
| 133 | 133 | } |
| 134 | 134 | } |
@@ -129,8 +129,7 @@ |
||
| 129 | 129 | $remaining = $this->getObject()->process( $product, $data ); |
| 130 | 130 | |
| 131 | 131 | $manager->commit(); |
| 132 | - } |
|
| 133 | - catch( \Exception $e ) |
|
| 132 | + } catch( \Exception $e ) |
|
| 134 | 133 | { |
| 135 | 134 | $manager->rollback(); |
| 136 | 135 | throw $e; |
@@ -27,8 +27,8 @@ discard block |
||
| 27 | 27 | * @param array $mapping Associative list of field position in CSV as key and domain item key as value |
| 28 | 28 | * @param \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $processor Decorated processor |
| 29 | 29 | */ |
| 30 | - public function __construct( \Aimeos\MShop\Context\Item\Iface $context, array $mapping, |
|
| 31 | - \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $processor = null ) |
|
| 30 | + public function __construct(\Aimeos\MShop\Context\Item\Iface $context, array $mapping, |
|
| 31 | + \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $processor = null) |
|
| 32 | 32 | { |
| 33 | 33 | } |
| 34 | 34 | |
@@ -40,7 +40,7 @@ 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 | 45 | return $data; |
| 46 | 46 | } |
@@ -26,8 +26,8 @@ discard block |
||
| 26 | 26 | * @param array $mapping Associative list of field position in CSV as key and domain item key as value |
| 27 | 27 | * @param \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $processor Decorated processor |
| 28 | 28 | */ |
| 29 | - public function __construct( \Aimeos\MShop\Context\Item\Iface $context, array $mapping, |
|
| 30 | - \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $processor = null ); |
|
| 29 | + public function __construct(\Aimeos\MShop\Context\Item\Iface $context, array $mapping, |
|
| 30 | + \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface $processor = null); |
|
| 31 | 31 | |
| 32 | 32 | |
| 33 | 33 | /** |
@@ -37,5 +37,5 @@ discard block |
||
| 37 | 37 | * @param array $data List of CSV fields with position as key and data as value |
| 38 | 38 | * @return array List of data which hasn't been imported |
| 39 | 39 | */ |
| 40 | - public function process( \Aimeos\MShop\Product\Item\Iface $product, array $data ); |
|
| 40 | + public function process(\Aimeos\MShop\Product\Item\Iface $product, array $data); |
|
| 41 | 41 | } |
| 42 | 42 | \ 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/catalog/listtypes |
| 52 | 52 | * Names of the catalog list types that are updated or removed |
@@ -67,9 +67,9 @@ discard block |
||
| 67 | 67 | * @see controller/common/product/import/csv/processor/product/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/catalog/listtypes' ); |
|
| 70 | + $this->listTypes = $context->getConfig()->get('controller/common/product/import/csv/processor/catalog/listtypes'); |
|
| 71 | 71 | |
| 72 | - $this->cache = $this->getCache( 'catalog' ); |
|
| 72 | + $this->cache = $this->getCache('catalog'); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | |
@@ -80,11 +80,11 @@ 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, 'catalog' ); |
|
| 87 | - $listManager = \Aimeos\MShop\Factory::createManager( $context, 'catalog/lists' ); |
|
| 86 | + $manager = \Aimeos\MShop\Factory::createManager($context, 'catalog'); |
|
| 87 | + $listManager = \Aimeos\MShop\Factory::createManager($context, 'catalog/lists'); |
|
| 88 | 88 | |
| 89 | 89 | /** controller/common/product/import/csv/separator |
| 90 | 90 | * Single separator character for multiple entries in one field of the import file |
@@ -104,54 +104,54 @@ discard block |
||
| 104 | 104 | * @category Developer |
| 105 | 105 | * @see controller/common/product/import/csv/domains |
| 106 | 106 | */ |
| 107 | - $separator = $context->getConfig()->get( 'controller/common/product/import/csv/separator', "\n" ); |
|
| 107 | + $separator = $context->getConfig()->get('controller/common/product/import/csv/separator', "\n"); |
|
| 108 | 108 | |
| 109 | 109 | $manager->begin(); |
| 110 | 110 | |
| 111 | 111 | try |
| 112 | 112 | { |
| 113 | 113 | $prodid = $product->getId(); |
| 114 | - $map = $this->getMappedChunk( $data ); |
|
| 115 | - $listItems = $this->getListItemPool( $product, $map ); |
|
| 114 | + $map = $this->getMappedChunk($data); |
|
| 115 | + $listItems = $this->getListItemPool($product, $map); |
|
| 116 | 116 | |
| 117 | - foreach( $map as $pos => $list ) |
|
| 117 | + foreach ($map as $pos => $list) |
|
| 118 | 118 | { |
| 119 | - if( !isset( $list['catalog.code'] ) || $list['catalog.code'] === '' || isset( $list['catalog.lists.type'] ) |
|
| 120 | - && $this->listTypes !== null && !in_array( $list['catalog.lists.type'], (array) $this->listTypes ) |
|
| 119 | + if (!isset($list['catalog.code']) || $list['catalog.code'] === '' || isset($list['catalog.lists.type']) |
|
| 120 | + && $this->listTypes !== null && !in_array($list['catalog.lists.type'], (array) $this->listTypes) |
|
| 121 | 121 | ) { |
| 122 | 122 | continue; |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | - $codes = explode( $separator, $list['catalog.code'] ); |
|
| 126 | - $type = ( isset( $list['catalog.lists.type'] ) ? $list['catalog.lists.type'] : 'default' ); |
|
| 125 | + $codes = explode($separator, $list['catalog.code']); |
|
| 126 | + $type = (isset($list['catalog.lists.type']) ? $list['catalog.lists.type'] : 'default'); |
|
| 127 | 127 | |
| 128 | - foreach( $codes as $code ) |
|
| 128 | + foreach ($codes as $code) |
|
| 129 | 129 | { |
| 130 | - if( ( $catid = $this->cache->get( $code ) ) === null ) |
|
| 130 | + if (($catid = $this->cache->get($code)) === null) |
|
| 131 | 131 | { |
| 132 | 132 | $msg = 'No category for code "%1$s" available when importing product with code "%2$s"'; |
| 133 | - throw new \Aimeos\Controller\Jobs\Exception( sprintf( $msg, $code, $product->getCode() ) ); |
|
| 133 | + throw new \Aimeos\Controller\Jobs\Exception(sprintf($msg, $code, $product->getCode())); |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | - if( ( $listItem = array_shift( $listItems ) ) === null ) { |
|
| 136 | + if (($listItem = array_shift($listItems)) === null) { |
|
| 137 | 137 | $listItem = $listManager->createItem(); |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | - $list['catalog.lists.typeid'] = $this->getTypeId( 'catalog/lists/type', 'product', $type ); |
|
| 140 | + $list['catalog.lists.typeid'] = $this->getTypeId('catalog/lists/type', 'product', $type); |
|
| 141 | 141 | $list['catalog.lists.parentid'] = $catid; |
| 142 | 142 | $list['catalog.lists.refid'] = $prodid; |
| 143 | 143 | $list['catalog.lists.domain'] = 'product'; |
| 144 | 144 | |
| 145 | - $listItem->fromArray( $this->addListItemDefaults( $list, $pos++ ) ); |
|
| 146 | - $listManager->saveItem( $listItem ); |
|
| 145 | + $listItem->fromArray($this->addListItemDefaults($list, $pos++)); |
|
| 146 | + $listManager->saveItem($listItem); |
|
| 147 | 147 | } |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | - $remaining = $this->getObject()->process( $product, $data ); |
|
| 150 | + $remaining = $this->getObject()->process($product, $data); |
|
| 151 | 151 | |
| 152 | 152 | $manager->commit(); |
| 153 | 153 | } |
| 154 | - catch( \Exception $e ) |
|
| 154 | + catch (\Exception $e) |
|
| 155 | 155 | { |
| 156 | 156 | $manager->rollback(); |
| 157 | 157 | throw $e; |
@@ -168,13 +168,13 @@ discard block |
||
| 168 | 168 | * @param integer $pos Computed position of the list item in the associated list of items |
| 169 | 169 | * @return array Given associative list enriched by default values if they were not already set |
| 170 | 170 | */ |
| 171 | - protected function addListItemDefaults( array $list, $pos ) |
|
| 171 | + protected function addListItemDefaults(array $list, $pos) |
|
| 172 | 172 | { |
| 173 | - if( !isset( $list['catalog.lists.position'] ) ) { |
|
| 173 | + if (!isset($list['catalog.lists.position'])) { |
|
| 174 | 174 | $list['catalog.lists.position'] = $pos; |
| 175 | 175 | } |
| 176 | 176 | |
| 177 | - if( !isset( $list['catalog.lists.status'] ) ) { |
|
| 177 | + if (!isset($list['catalog.lists.status'])) { |
|
| 178 | 178 | $list['catalog.lists.status'] = 1; |
| 179 | 179 | } |
| 180 | 180 | |
@@ -189,25 +189,25 @@ discard block |
||
| 189 | 189 | * @param array|null $types List of catalog list types |
| 190 | 190 | * @return array List of catalog list items |
| 191 | 191 | */ |
| 192 | - protected function getListItems( $prodid, $types ) |
|
| 192 | + protected function getListItems($prodid, $types) |
|
| 193 | 193 | { |
| 194 | - $manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'catalog/lists' ); |
|
| 194 | + $manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'catalog/lists'); |
|
| 195 | 195 | $search = $manager->createSearch(); |
| 196 | 196 | |
| 197 | 197 | $expr = array( |
| 198 | - $search->compare( '==', 'catalog.lists.domain', 'product' ), |
|
| 199 | - $search->compare( '==', 'catalog.lists.refid', $prodid ), |
|
| 198 | + $search->compare('==', 'catalog.lists.domain', 'product'), |
|
| 199 | + $search->compare('==', 'catalog.lists.refid', $prodid), |
|
| 200 | 200 | ); |
| 201 | 201 | |
| 202 | - if( $types !== null ) { |
|
| 203 | - $expr[] = $search->compare( '==', 'catalog.lists.type.code', $types ); |
|
| 202 | + if ($types !== null) { |
|
| 203 | + $expr[] = $search->compare('==', 'catalog.lists.type.code', $types); |
|
| 204 | 204 | } |
| 205 | 205 | |
| 206 | - $search->setConditions( $search->combine( '&&', $expr ) ); |
|
| 207 | - $search->setSortations( array( $search->sort( '+', 'catalog.lists.position' ) ) ); |
|
| 208 | - $search->setSlice( 0, 0x7FFFFFFF ); |
|
| 206 | + $search->setConditions($search->combine('&&', $expr)); |
|
| 207 | + $search->setSortations(array($search->sort('+', 'catalog.lists.position'))); |
|
| 208 | + $search->setSlice(0, 0x7FFFFFFF); |
|
| 209 | 209 | |
| 210 | - return $manager->searchItems( $search ); |
|
| 210 | + return $manager->searchItems($search); |
|
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | |
@@ -218,16 +218,16 @@ discard block |
||
| 218 | 218 | * @param array $map List of associative arrays containing the chunked properties |
| 219 | 219 | * @return array List of list items implementing \Aimeos\MShop\Common\Item\Lists\Iface |
| 220 | 220 | */ |
| 221 | - protected function getListItemPool( \Aimeos\MShop\Product\Item\Iface $product, array $map ) |
|
| 221 | + protected function getListItemPool(\Aimeos\MShop\Product\Item\Iface $product, array $map) |
|
| 222 | 222 | { |
| 223 | 223 | $pos = 0; |
| 224 | 224 | $delete = array(); |
| 225 | - $listItems = $this->getListItems( $product->getId(), $this->listTypes ); |
|
| 225 | + $listItems = $this->getListItems($product->getId(), $this->listTypes); |
|
| 226 | 226 | |
| 227 | - foreach( $listItems as $listId => $listItem ) |
|
| 227 | + foreach ($listItems as $listId => $listItem) |
|
| 228 | 228 | { |
| 229 | - if( isset( $map[$pos] ) && ( !isset( $map[$pos]['catalog.code'] ) |
|
| 230 | - || $this->cache->get( $map[$pos]['catalog.code'] ) == $listItem->getParentId() ) |
|
| 229 | + if (isset($map[$pos]) && (!isset($map[$pos]['catalog.code']) |
|
| 230 | + || $this->cache->get($map[$pos]['catalog.code']) == $listItem->getParentId()) |
|
| 231 | 231 | ) { |
| 232 | 232 | $pos++; |
| 233 | 233 | continue; |
@@ -238,8 +238,8 @@ discard block |
||
| 238 | 238 | $pos++; |
| 239 | 239 | } |
| 240 | 240 | |
| 241 | - $listManager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'catalog/lists' ); |
|
| 242 | - $listManager->deleteItems( $delete ); |
|
| 241 | + $listManager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'catalog/lists'); |
|
| 242 | + $listManager->deleteItems($delete); |
|
| 243 | 243 | |
| 244 | 244 | return $listItems; |
| 245 | 245 | } |
@@ -129,8 +129,7 @@ |
||
| 129 | 129 | $remaining = $this->getObject()->process( $product, $data ); |
| 130 | 130 | |
| 131 | 131 | $manager->commit(); |
| 132 | - } |
|
| 133 | - catch( \Exception $e ) |
|
| 132 | + } catch( \Exception $e ) |
|
| 134 | 133 | { |
| 135 | 134 | $manager->rollback(); |
| 136 | 135 | throw $e; |
@@ -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,60 +77,60 @@ 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 | - $listItems = $product->getListItems( 'price' ); |
|
| 89 | - $map = $this->getMappedChunk( $data ); |
|
| 88 | + $listItems = $product->getListItems('price'); |
|
| 89 | + $map = $this->getMappedChunk($data); |
|
| 90 | 90 | |
| 91 | - foreach( $map as $pos => $list ) |
|
| 91 | + foreach ($map as $pos => $list) |
|
| 92 | 92 | { |
| 93 | - if( !isset( $list['price.value'] ) || $list['price.value'] === '' || isset( $list['product.lists.type'] ) |
|
| 94 | - && $this->listTypes !== null && !in_array( $list['product.lists.type'], (array) $this->listTypes ) |
|
| 93 | + if (!isset($list['price.value']) || $list['price.value'] === '' || isset($list['product.lists.type']) |
|
| 94 | + && $this->listTypes !== null && !in_array($list['product.lists.type'], (array) $this->listTypes) |
|
| 95 | 95 | ) { |
| 96 | 96 | continue; |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | - if( ( $listItem = array_shift( $listItems ) ) !== null ) { |
|
| 99 | + if (($listItem = array_shift($listItems)) !== null) { |
|
| 100 | 100 | $refItem = $listItem->getRefItem(); |
| 101 | 101 | } else { |
| 102 | 102 | $listItem = $listManager->createItem(); |
| 103 | 103 | $refItem = $manager->createItem(); |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | - $typecode = ( isset( $list['price.type'] ) ? $list['price.type'] : 'default' ); |
|
| 107 | - $list['price.typeid'] = $this->getTypeId( 'price/type', 'product', $typecode ); |
|
| 106 | + $typecode = (isset($list['price.type']) ? $list['price.type'] : 'default'); |
|
| 107 | + $list['price.typeid'] = $this->getTypeId('price/type', 'product', $typecode); |
|
| 108 | 108 | $list['price.domain'] = 'product'; |
| 109 | 109 | |
| 110 | - $refItem->fromArray( $this->addItemDefaults( $list ) ); |
|
| 111 | - $manager->saveItem( $refItem ); |
|
| 110 | + $refItem->fromArray($this->addItemDefaults($list)); |
|
| 111 | + $manager->saveItem($refItem); |
|
| 112 | 112 | |
| 113 | - $typecode = ( isset( $list['product.lists.type'] ) ? $list['product.lists.type'] : 'default' ); |
|
| 114 | - $list['product.lists.typeid'] = $this->getTypeId( 'product/lists/type', 'price', $typecode ); |
|
| 113 | + $typecode = (isset($list['product.lists.type']) ? $list['product.lists.type'] : 'default'); |
|
| 114 | + $list['product.lists.typeid'] = $this->getTypeId('product/lists/type', 'price', $typecode); |
|
| 115 | 115 | $list['product.lists.parentid'] = $product->getId(); |
| 116 | 116 | $list['product.lists.refid'] = $refItem->getId(); |
| 117 | 117 | $list['product.lists.domain'] = 'price'; |
| 118 | 118 | |
| 119 | - $listItem->fromArray( $this->addListItemDefaults( $list, $pos ) ); |
|
| 120 | - $listManager->saveItem( $listItem ); |
|
| 119 | + $listItem->fromArray($this->addListItemDefaults($list, $pos)); |
|
| 120 | + $listManager->saveItem($listItem); |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | - foreach( $listItems as $listItem ) |
|
| 123 | + foreach ($listItems as $listItem) |
|
| 124 | 124 | { |
| 125 | - $manager->deleteItem( $listItem->getRefItem()->getId() ); |
|
| 126 | - $listManager->deleteItem( $listItem->getId() ); |
|
| 125 | + $manager->deleteItem($listItem->getRefItem()->getId()); |
|
| 126 | + $listManager->deleteItem($listItem->getId()); |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | - $remaining = $this->getObject()->process( $product, $data ); |
|
| 129 | + $remaining = $this->getObject()->process($product, $data); |
|
| 130 | 130 | |
| 131 | 131 | $manager->commit(); |
| 132 | 132 | } |
| 133 | - catch( \Exception $e ) |
|
| 133 | + catch (\Exception $e) |
|
| 134 | 134 | { |
| 135 | 135 | $manager->rollback(); |
| 136 | 136 | throw $e; |
@@ -146,17 +146,17 @@ discard block |
||
| 146 | 146 | * @param array $list Associative list of domain item keys and their values, e.g. "price.status" => 1 |
| 147 | 147 | * @return array Given associative list enriched by default values if they were not already set |
| 148 | 148 | */ |
| 149 | - protected function addItemDefaults( array $list ) |
|
| 149 | + protected function addItemDefaults(array $list) |
|
| 150 | 150 | { |
| 151 | - if( !isset( $list['price.currencyid'] ) ) { |
|
| 151 | + if (!isset($list['price.currencyid'])) { |
|
| 152 | 152 | $list['price.currencyid'] = $this->getContext()->getLocale()->getCurrencyId(); |
| 153 | 153 | } |
| 154 | 154 | |
| 155 | - if( !isset( $list['price.label'] ) ) { |
|
| 155 | + if (!isset($list['price.label'])) { |
|
| 156 | 156 | $list['price.label'] = $list['price.currencyid'] . ' ' . $list['price.value']; |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | - if( !isset( $list['price.status'] ) ) { |
|
| 159 | + if (!isset($list['price.status'])) { |
|
| 160 | 160 | $list['price.status'] = 1; |
| 161 | 161 | } |
| 162 | 162 | |
@@ -129,8 +129,7 @@ |
||
| 129 | 129 | $remaining = $this->getObject()->process( $product, $data ); |
| 130 | 130 | |
| 131 | 131 | $manager->commit(); |
| 132 | - } |
|
| 133 | - catch( \Exception $e ) |
|
| 132 | + } catch( \Exception $e ) |
|
| 134 | 133 | { |
| 135 | 134 | $manager->rollback(); |
| 136 | 135 | throw $e; |
@@ -40,32 +40,32 @@ 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 | $pos = 0; |
| 51 | 51 | $delete = array(); |
| 52 | - $map = $this->getMappedChunk( $data ); |
|
| 53 | - $items = $this->getPropertyItems( $product->getId() ); |
|
| 52 | + $map = $this->getMappedChunk($data); |
|
| 53 | + $items = $this->getPropertyItems($product->getId()); |
|
| 54 | 54 | |
| 55 | - foreach( $items as $id => $item ) |
|
| 55 | + foreach ($items as $id => $item) |
|
| 56 | 56 | { |
| 57 | - if( isset( $map[$pos] ) ) |
|
| 57 | + if (isset($map[$pos])) |
|
| 58 | 58 | { |
| 59 | - if( !isset( $map[$pos]['product.property.type'] ) || !isset( $map[$pos]['product.property.value'] ) ) |
|
| 59 | + if (!isset($map[$pos]['product.property.type']) || !isset($map[$pos]['product.property.value'])) |
|
| 60 | 60 | { |
| 61 | - unset( $map[$pos] ); |
|
| 61 | + unset($map[$pos]); |
|
| 62 | 62 | continue; |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | - if( $map[$pos]['product.property.type'] === $item->getType() |
|
| 65 | + if ($map[$pos]['product.property.type'] === $item->getType() |
|
| 66 | 66 | && $map[$pos]['product.property.value'] === $item->getValue() |
| 67 | - && ( !isset( $map[$pos]['product.property.languageid'] ) |
|
| 68 | - || isset( $map[$pos]['product.property.languageid'] ) |
|
| 67 | + && (!isset($map[$pos]['product.property.languageid']) |
|
| 68 | + || isset($map[$pos]['product.property.languageid']) |
|
| 69 | 69 | && $map[$pos]['product.property.languageid'] === $item->getLanguageId() |
| 70 | 70 | ) |
| 71 | 71 | ) { |
@@ -79,31 +79,31 @@ discard block |
||
| 79 | 79 | $pos++; |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | - $manager->deleteItems( $delete ); |
|
| 82 | + $manager->deleteItems($delete); |
|
| 83 | 83 | |
| 84 | - foreach( $map as $pos => $list ) |
|
| 84 | + foreach ($map as $pos => $list) |
|
| 85 | 85 | { |
| 86 | - if( $list['product.property.type'] == '' || $list['product.property.value'] == '' ) { |
|
| 86 | + if ($list['product.property.type'] == '' || $list['product.property.value'] == '') { |
|
| 87 | 87 | continue; |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | $typecode = $list['product.property.type']; |
| 91 | - $list['product.property.typeid'] = $this->getTypeId( 'product/property/type', 'product', $typecode ); |
|
| 91 | + $list['product.property.typeid'] = $this->getTypeId('product/property/type', 'product', $typecode); |
|
| 92 | 92 | $list['product.property.parentid'] = $product->getId(); |
| 93 | 93 | |
| 94 | - if( ( $item = array_shift( $items ) ) === null ) { |
|
| 94 | + if (($item = array_shift($items)) === null) { |
|
| 95 | 95 | $item = $manager->createItem(); |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - $item->fromArray( $list ); |
|
| 99 | - $manager->saveItem( $item ); |
|
| 98 | + $item->fromArray($list); |
|
| 99 | + $manager->saveItem($item); |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | - $remaining = $this->getObject()->process( $product, $data ); |
|
| 102 | + $remaining = $this->getObject()->process($product, $data); |
|
| 103 | 103 | |
| 104 | 104 | $manager->commit(); |
| 105 | 105 | } |
| 106 | - catch( \Exception $e ) |
|
| 106 | + catch (\Exception $e) |
|
| 107 | 107 | { |
| 108 | 108 | $manager->rollback(); |
| 109 | 109 | throw $e; |
@@ -119,13 +119,13 @@ discard block |
||
| 119 | 119 | * @param string $prodid Unique product ID |
| 120 | 120 | * @return array Associative list of product property items |
| 121 | 121 | */ |
| 122 | - protected function getPropertyItems( $prodid ) |
|
| 122 | + protected function getPropertyItems($prodid) |
|
| 123 | 123 | { |
| 124 | - $manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'product/property' ); |
|
| 124 | + $manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'product/property'); |
|
| 125 | 125 | |
| 126 | 126 | $search = $manager->createSearch(); |
| 127 | - $search->setConditions( $search->compare( '==', 'product.property.parentid', $prodid ) ); |
|
| 127 | + $search->setConditions($search->compare('==', 'product.property.parentid', $prodid)); |
|
| 128 | 128 | |
| 129 | - return $manager->searchItems( $search ); |
|
| 129 | + return $manager->searchItems($search); |
|
| 130 | 130 | } |
| 131 | 131 | } |
@@ -129,8 +129,7 @@ |
||
| 129 | 129 | $remaining = $this->getObject()->process( $product, $data ); |
| 130 | 130 | |
| 131 | 131 | $manager->commit(); |
| 132 | - } |
|
| 133 | - catch( \Exception $e ) |
|
| 132 | + } catch( \Exception $e ) |
|
| 134 | 133 | { |
| 135 | 134 | $manager->rollback(); |
| 136 | 135 | throw $e; |
@@ -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,39 +102,39 @@ 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( !isset( $list['product.code'] ) || $list['product.code'] === '' || isset( $list['product.lists.type'] ) |
|
| 108 | - && $this->listTypes !== null && !in_array( $list['product.lists.type'], (array) $this->listTypes ) |
|
| 107 | + if (!isset($list['product.code']) || $list['product.code'] === '' || isset($list['product.lists.type']) |
|
| 108 | + && $this->listTypes !== null && !in_array($list['product.lists.type'], (array) $this->listTypes) |
|
| 109 | 109 | ) { |
| 110 | 110 | continue; |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | $listMap = array(); |
| 114 | - $type = ( isset( $list['product.lists.type'] ) ? $list['product.lists.type'] : 'default' ); |
|
| 114 | + $type = (isset($list['product.lists.type']) ? $list['product.lists.type'] : 'default'); |
|
| 115 | 115 | $types[] = $type; |
| 116 | 116 | |
| 117 | - foreach( explode( $separator, $list['product.code'] ) as $code ) |
|
| 117 | + foreach (explode($separator, $list['product.code']) as $code) |
|
| 118 | 118 | { |
| 119 | - if( ( $prodid = $this->cache->get( $code ) ) === null ) |
|
| 119 | + if (($prodid = $this->cache->get($code)) === null) |
|
| 120 | 120 | { |
| 121 | 121 | $msg = 'No product for code "%1$s" available when importing product with code "%2$s"'; |
| 122 | - throw new \Aimeos\Controller\Jobs\Exception( sprintf( $msg, $code, $product->getCode() ) ); |
|
| 122 | + throw new \Aimeos\Controller\Jobs\Exception(sprintf($msg, $code, $product->getCode())); |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | $listMap[$prodid] = $list; |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | - $manager->updateListItems( $product, $listMap, 'product', $type ); |
|
| 128 | + $manager->updateListItems($product, $listMap, 'product', $type); |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | - $this->deleteListItems( $product->getId(), $types ); |
|
| 131 | + $this->deleteListItems($product->getId(), $types); |
|
| 132 | 132 | |
| 133 | - $remaining = $this->getObject()->process( $product, $data ); |
|
| 133 | + $remaining = $this->getObject()->process($product, $data); |
|
| 134 | 134 | |
| 135 | 135 | $manager->commit(); |
| 136 | 136 | } |
| 137 | - catch( \Exception $e ) |
|
| 137 | + catch (\Exception $e) |
|
| 138 | 138 | { |
| 139 | 139 | $manager->rollback(); |
| 140 | 140 | throw $e; |
@@ -150,19 +150,19 @@ discard block |
||
| 150 | 150 | * @param string $prodId Unique product ID |
| 151 | 151 | * @param array $types List of types that have been updated |
| 152 | 152 | */ |
| 153 | - protected function deleteListItems( $prodId, array $types ) |
|
| 153 | + protected function deleteListItems($prodId, array $types) |
|
| 154 | 154 | { |
| 155 | - $codes = array_diff( $this->listTypes, $types ); |
|
| 156 | - $manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'product/lists' ); |
|
| 155 | + $codes = array_diff($this->listTypes, $types); |
|
| 156 | + $manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'product/lists'); |
|
| 157 | 157 | |
| 158 | 158 | $search = $manager->createSearch(); |
| 159 | 159 | $expr = array( |
| 160 | - $search->compare( '==', 'product.lists.parentid', $prodId ), |
|
| 161 | - $search->compare( '==', 'product.lists.domain', 'product' ), |
|
| 162 | - $search->compare( '==', 'product.lists.type.code', $codes ), |
|
| 160 | + $search->compare('==', 'product.lists.parentid', $prodId), |
|
| 161 | + $search->compare('==', 'product.lists.domain', 'product'), |
|
| 162 | + $search->compare('==', 'product.lists.type.code', $codes), |
|
| 163 | 163 | ); |
| 164 | - $search->setConditions( $search->combine( '&&', $expr ) ); |
|
| 164 | + $search->setConditions($search->combine('&&', $expr)); |
|
| 165 | 165 | |
| 166 | - $manager->deleteItems( array_keys( $manager->searchItems( $search ) ) ); |
|
| 166 | + $manager->deleteItems(array_keys($manager->searchItems($search))); |
|
| 167 | 167 | } |
| 168 | 168 | } |
@@ -129,8 +129,7 @@ |
||
| 129 | 129 | $remaining = $this->getObject()->process( $product, $data ); |
| 130 | 130 | |
| 131 | 131 | $manager->commit(); |
| 132 | - } |
|
| 133 | - catch( \Exception $e ) |
|
| 132 | + } catch( \Exception $e ) |
|
| 134 | 133 | { |
| 135 | 134 | $manager->rollback(); |
| 136 | 135 | throw $e; |
@@ -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/text/listtypes |
| 51 | 51 | * Names of the product list types for texts 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/product/listtypes |
| 68 | 68 | */ |
| 69 | - $this->listTypes = $context->getConfig()->get( 'controller/common/product/import/csv/processor/text/listtypes' ); |
|
| 69 | + $this->listTypes = $context->getConfig()->get('controller/common/product/import/csv/processor/text/listtypes'); |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | |
@@ -77,60 +77,60 @@ 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(), 'text' ); |
|
| 82 | + $listManager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'product/lists'); |
|
| 83 | + $manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'text'); |
|
| 84 | 84 | $manager->begin(); |
| 85 | 85 | |
| 86 | 86 | try |
| 87 | 87 | { |
| 88 | - $listItems = $product->getListItems( 'text' ); |
|
| 89 | - $map = $this->getMappedChunk( $data ); |
|
| 88 | + $listItems = $product->getListItems('text'); |
|
| 89 | + $map = $this->getMappedChunk($data); |
|
| 90 | 90 | |
| 91 | - foreach( $map as $pos => $list ) |
|
| 91 | + foreach ($map as $pos => $list) |
|
| 92 | 92 | { |
| 93 | - if( !isset( $list['text.content'] ) || $list['text.content'] === '' || isset( $list['product.lists.type'] ) |
|
| 94 | - && $this->listTypes !== null && !in_array( $list['product.lists.type'], (array) $this->listTypes ) |
|
| 93 | + if (!isset($list['text.content']) || $list['text.content'] === '' || isset($list['product.lists.type']) |
|
| 94 | + && $this->listTypes !== null && !in_array($list['product.lists.type'], (array) $this->listTypes) |
|
| 95 | 95 | ) { |
| 96 | 96 | continue; |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | - if( ( $listItem = array_shift( $listItems ) ) !== null ) { |
|
| 99 | + if (($listItem = array_shift($listItems)) !== null) { |
|
| 100 | 100 | $refItem = $listItem->getRefItem(); |
| 101 | 101 | } else { |
| 102 | 102 | $listItem = $listManager->createItem(); |
| 103 | 103 | $refItem = $manager->createItem(); |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | - $typecode = ( isset( $list['text.type'] ) ? $list['text.type'] : 'name' ); |
|
| 107 | - $list['text.typeid'] = $this->getTypeId( 'text/type', 'product', $typecode ); |
|
| 106 | + $typecode = (isset($list['text.type']) ? $list['text.type'] : 'name'); |
|
| 107 | + $list['text.typeid'] = $this->getTypeId('text/type', 'product', $typecode); |
|
| 108 | 108 | $list['text.domain'] = 'product'; |
| 109 | 109 | |
| 110 | - $refItem->fromArray( $this->addItemDefaults( $list ) ); |
|
| 111 | - $manager->saveItem( $refItem ); |
|
| 110 | + $refItem->fromArray($this->addItemDefaults($list)); |
|
| 111 | + $manager->saveItem($refItem); |
|
| 112 | 112 | |
| 113 | - $typecode = ( isset( $list['product.lists.type'] ) ? $list['product.lists.type'] : 'default' ); |
|
| 114 | - $list['product.lists.typeid'] = $this->getTypeId( 'product/lists/type', 'text', $typecode ); |
|
| 113 | + $typecode = (isset($list['product.lists.type']) ? $list['product.lists.type'] : 'default'); |
|
| 114 | + $list['product.lists.typeid'] = $this->getTypeId('product/lists/type', 'text', $typecode); |
|
| 115 | 115 | $list['product.lists.parentid'] = $product->getId(); |
| 116 | 116 | $list['product.lists.refid'] = $refItem->getId(); |
| 117 | 117 | $list['product.lists.domain'] = 'text'; |
| 118 | 118 | |
| 119 | - $listItem->fromArray( $this->addListItemDefaults( $list, $pos ) ); |
|
| 120 | - $listManager->saveItem( $listItem ); |
|
| 119 | + $listItem->fromArray($this->addListItemDefaults($list, $pos)); |
|
| 120 | + $listManager->saveItem($listItem); |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | - foreach( $listItems as $listItem ) |
|
| 123 | + foreach ($listItems as $listItem) |
|
| 124 | 124 | { |
| 125 | - $manager->deleteItem( $listItem->getRefItem()->getId() ); |
|
| 126 | - $listManager->deleteItem( $listItem->getId() ); |
|
| 125 | + $manager->deleteItem($listItem->getRefItem()->getId()); |
|
| 126 | + $listManager->deleteItem($listItem->getId()); |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | - $remaining = $this->getObject()->process( $product, $data ); |
|
| 129 | + $remaining = $this->getObject()->process($product, $data); |
|
| 130 | 130 | |
| 131 | 131 | $manager->commit(); |
| 132 | 132 | } |
| 133 | - catch( \Exception $e ) |
|
| 133 | + catch (\Exception $e) |
|
| 134 | 134 | { |
| 135 | 135 | $manager->rollback(); |
| 136 | 136 | throw $e; |
@@ -146,17 +146,17 @@ discard block |
||
| 146 | 146 | * @param array $list Associative list of domain item keys and their values, e.g. "text.status" => 1 |
| 147 | 147 | * @return array Given associative list enriched by default values if they were not already set |
| 148 | 148 | */ |
| 149 | - protected function addItemDefaults( array $list ) |
|
| 149 | + protected function addItemDefaults(array $list) |
|
| 150 | 150 | { |
| 151 | - if( !isset( $list['text.label'] ) ) { |
|
| 152 | - $list['text.label'] = mb_strcut( $list['text.content'], 0, 255 ); |
|
| 151 | + if (!isset($list['text.label'])) { |
|
| 152 | + $list['text.label'] = mb_strcut($list['text.content'], 0, 255); |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | - if( !isset( $list['text.languageid'] ) ) { |
|
| 155 | + if (!isset($list['text.languageid'])) { |
|
| 156 | 156 | $list['text.languageid'] = $this->getContext()->getLocale()->getLanguageId(); |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | - if( !isset( $list['text.status'] ) ) { |
|
| 159 | + if (!isset($list['text.status'])) { |
|
| 160 | 160 | $list['text.status'] = 1; |
| 161 | 161 | } |
| 162 | 162 | |
@@ -129,8 +129,7 @@ |
||
| 129 | 129 | $remaining = $this->getObject()->process( $product, $data ); |
| 130 | 130 | |
| 131 | 131 | $manager->commit(); |
| 132 | - } |
|
| 133 | - catch( \Exception $e ) |
|
| 132 | + } catch( \Exception $e ) |
|
| 134 | 133 | { |
| 135 | 134 | $manager->rollback(); |
| 136 | 135 | throw $e; |
@@ -40,15 +40,15 @@ discard block |
||
| 40 | 40 | * |
| 41 | 41 | * @param \Aimeos\MShop\Context\Item\Iface $context Context object |
| 42 | 42 | */ |
| 43 | - public function __construct( \Aimeos\MShop\Context\Item\Iface $context ) |
|
| 43 | + public function __construct(\Aimeos\MShop\Context\Item\Iface $context) |
|
| 44 | 44 | { |
| 45 | - parent::__construct( $context ); |
|
| 45 | + parent::__construct($context); |
|
| 46 | 46 | |
| 47 | - $manager = \Aimeos\MShop\Factory::createManager( $context, 'attribute' ); |
|
| 48 | - $result = $manager->searchItems( $manager->createSearch() ); |
|
| 47 | + $manager = \Aimeos\MShop\Factory::createManager($context, 'attribute'); |
|
| 48 | + $result = $manager->searchItems($manager->createSearch()); |
|
| 49 | 49 | |
| 50 | - foreach( $result as $id => $item ) { |
|
| 51 | - $this->attributes[ $item->getCode() ][ $item->getType() ] = $item; |
|
| 50 | + foreach ($result as $id => $item) { |
|
| 51 | + $this->attributes[$item->getCode()][$item->getType()] = $item; |
|
| 52 | 52 | } |
| 53 | 53 | } |
| 54 | 54 | |
@@ -60,24 +60,24 @@ discard block |
||
| 60 | 60 | * @param string|null $type Attribute type |
| 61 | 61 | * @return \Aimeos\MShop\Attribute\Item\Iface|null Attribute object or null if not found |
| 62 | 62 | */ |
| 63 | - public function get( $code, $type = null ) |
|
| 63 | + public function get($code, $type = null) |
|
| 64 | 64 | { |
| 65 | - if( isset( $this->attributes[$code] ) && isset( $this->attributes[$code][$type] ) ) { |
|
| 65 | + if (isset($this->attributes[$code]) && isset($this->attributes[$code][$type])) { |
|
| 66 | 66 | return $this->attributes[$code][$type]; |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - $manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'attribute' ); |
|
| 69 | + $manager = \Aimeos\MShop\Factory::createManager($this->getContext(), 'attribute'); |
|
| 70 | 70 | |
| 71 | 71 | $search = $manager->createSearch(); |
| 72 | 72 | $expr = array( |
| 73 | - $search->compare( '==', 'attribute.code', $code ), |
|
| 74 | - $search->compare( '==', 'attribute.type.code', $type ), |
|
| 73 | + $search->compare('==', 'attribute.code', $code), |
|
| 74 | + $search->compare('==', 'attribute.type.code', $type), |
|
| 75 | 75 | ); |
| 76 | - $search->setConditions( $search->combine( '&&', $expr ) ); |
|
| 76 | + $search->setConditions($search->combine('&&', $expr)); |
|
| 77 | 77 | |
| 78 | - $result = $manager->searchItems( $search ); |
|
| 78 | + $result = $manager->searchItems($search); |
|
| 79 | 79 | |
| 80 | - if( ( $item = reset( $result ) ) !== false ) |
|
| 80 | + if (($item = reset($result)) !== false) |
|
| 81 | 81 | { |
| 82 | 82 | $this->attributes[$code][$type] = $item; |
| 83 | 83 | return $item; |
@@ -90,14 +90,14 @@ discard block |
||
| 90 | 90 | * |
| 91 | 91 | * @param \Aimeos\MShop\Common\Item\Iface $item Attribute object |
| 92 | 92 | */ |
| 93 | - public function set( \Aimeos\MShop\Common\Item\Iface $item ) |
|
| 93 | + public function set(\Aimeos\MShop\Common\Item\Iface $item) |
|
| 94 | 94 | { |
| 95 | 95 | $code = $item->getCode(); |
| 96 | 96 | |
| 97 | - if( !isset( $this->attributes[$code] ) || !is_array( $this->attributes[$code] ) ) { |
|
| 97 | + if (!isset($this->attributes[$code]) || !is_array($this->attributes[$code])) { |
|
| 98 | 98 | $this->attributes[$code] = array(); |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | - $this->attributes[$code][ $item->getType() ] = $item; |
|
| 101 | + $this->attributes[$code][$item->getType()] = $item; |
|
| 102 | 102 | } |
| 103 | 103 | } |
| 104 | 104 | \ No newline at end of file |