|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2018 |
|
6
|
|
|
* @package Controller |
|
7
|
|
|
* @subpackage Common |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
namespace Aimeos\Controller\Common\Product\Import\Csv\Processor\Property; |
|
12
|
|
|
|
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Product property processor for CSV imports |
|
16
|
|
|
* |
|
17
|
|
|
* @package Controller |
|
18
|
|
|
* @subpackage Common |
|
19
|
|
|
*/ |
|
20
|
|
|
class Standard |
|
21
|
|
|
extends \Aimeos\Controller\Common\Product\Import\Csv\Processor\Base |
|
22
|
|
|
implements \Aimeos\Controller\Common\Product\Import\Csv\Processor\Iface |
|
23
|
|
|
{ |
|
24
|
|
|
/** controller/common/product/import/csv/processor/property/name |
|
25
|
|
|
* Name of the property processor implementation |
|
26
|
|
|
* |
|
27
|
|
|
* Use "Myname" if your class is named "\Aimeos\Controller\Common\Product\Import\Csv\Processor\Property\Myname". |
|
28
|
|
|
* The name is case-sensitive and you should avoid camel case names like "MyName". |
|
29
|
|
|
* |
|
30
|
|
|
* @param string Last part of the processor class name |
|
31
|
|
|
* @since 2015.10 |
|
32
|
|
|
* @category Developer |
|
33
|
|
|
*/ |
|
34
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Saves the product property related data to the storage |
|
38
|
|
|
* |
|
39
|
|
|
* @param \Aimeos\MShop\Product\Item\Iface $product Product item with associated items |
|
40
|
|
|
* @param array $data List of CSV fields with position as key and data as value |
|
41
|
|
|
* @return array List of data which hasn't been imported |
|
42
|
|
|
*/ |
|
43
|
|
|
public function process( \Aimeos\MShop\Product\Item\Iface $product, array $data ) |
|
44
|
|
|
{ |
|
45
|
|
|
$manager = \Aimeos\MShop::create( $this->getContext(), 'product/property' ); |
|
46
|
|
|
|
|
47
|
|
|
$propMap = []; |
|
48
|
|
|
$items = $product->getPropertyItems( null, false ); |
|
49
|
|
|
$map = $this->getMappedChunk( $data, $this->getMapping() ); |
|
50
|
|
|
|
|
51
|
|
|
foreach( $items as $item ) { |
|
52
|
|
|
$propMap[$item->getValue()][$item->getType()] = $item; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
foreach( $map as $list ) |
|
56
|
|
|
{ |
|
57
|
|
|
if( ( $value = $this->getValue( $list, 'product.property.value' ) ) === null ) { |
|
58
|
|
|
continue; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
$type = $this->getValue( $list, 'product.property.type' ); |
|
62
|
|
|
$this->addType( 'product/property/type', 'product', $type ); |
|
63
|
|
|
|
|
64
|
|
|
if( isset( $propMap[$value][$type] ) ) |
|
65
|
|
|
{ |
|
66
|
|
|
$item = $propMap[$value][$type]; |
|
67
|
|
|
unset( $items[$item->getId()] ); |
|
68
|
|
|
} |
|
69
|
|
|
else |
|
70
|
|
|
{ |
|
71
|
|
|
$item = $manager->createItem()->setType( $type ); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
$product->addPropertyItem( $item->fromArray( $list ) ); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
$product->deletePropertyItems( $items ); |
|
78
|
|
|
|
|
79
|
|
|
return $this->getObject()->process( $product, $data ); |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|