1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2016 |
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\Factory::createManager( $this->getContext(), 'product/property' ); |
46
|
|
|
$manager->begin(); |
47
|
|
|
|
48
|
|
|
try |
49
|
|
|
{ |
50
|
|
|
$propPap = array(); |
|
|
|
|
51
|
|
|
$map = $this->getMappedChunk( $data ); |
52
|
|
|
$items = $this->getPropertyItems( $product->getId() ); |
53
|
|
|
|
54
|
|
|
foreach( $items as $item ) { |
55
|
|
|
$propMap[ $item->getValue() ][ $item->getType() ] = $item; |
|
|
|
|
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
foreach( $map as $list ) |
59
|
|
|
{ |
60
|
|
|
if( $list['product.property.type'] == '' || $list['product.property.value'] == '' ) { |
61
|
|
|
continue; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
$typecode = $list['product.property.type']; |
65
|
|
|
$list['product.property.typeid'] = $this->getTypeId( 'product/property/type', 'product', $typecode ); |
66
|
|
|
$list['product.property.parentid'] = $product->getId(); |
67
|
|
|
|
68
|
|
|
if( isset( $propMap[ $list['product.property.value'] ][$typecode] ) ) |
69
|
|
|
{ |
70
|
|
|
$item = $propMap[ $list['product.property.value'] ][$typecode]; |
71
|
|
|
unset( $items[ $item->getId() ] ); |
72
|
|
|
} |
73
|
|
|
else |
74
|
|
|
{ |
75
|
|
|
$item = $manager->createItem(); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
$item->fromArray( $list ); |
79
|
|
|
$manager->saveItem( $item ); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
$manager->deleteItems( array_keys( $items ) ); |
83
|
|
|
|
84
|
|
|
$remaining = $this->getObject()->process( $product, $data ); |
85
|
|
|
|
86
|
|
|
$manager->commit(); |
87
|
|
|
} |
88
|
|
|
catch( \Exception $e ) |
89
|
|
|
{ |
90
|
|
|
$manager->rollback(); |
91
|
|
|
throw $e; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
return $remaining; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Returns the product properties for the given product ID |
100
|
|
|
* |
101
|
|
|
* @param string $prodid Unique product ID |
102
|
|
|
* @return array Associative list of product property items |
103
|
|
|
*/ |
104
|
|
|
protected function getPropertyItems( $prodid ) |
105
|
|
|
{ |
106
|
|
|
$manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'product/property' ); |
107
|
|
|
|
108
|
|
|
$search = $manager->createSearch(); |
109
|
|
|
$search->setConditions( $search->compare( '==', 'product.property.parentid', $prodid ) ); |
110
|
|
|
|
111
|
|
|
return $manager->searchItems( $search ); |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|