1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2019-2025 |
6
|
|
|
* @package Controller |
7
|
|
|
* @subpackage Common |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
namespace Aimeos\Controller\Jobs\Common\Import\Xml\Processor\Lists\Product; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Product list processor for XML imports |
16
|
|
|
* |
17
|
|
|
* @package Controller |
18
|
|
|
* @subpackage Common |
19
|
|
|
*/ |
20
|
|
|
class Standard |
21
|
|
|
extends \Aimeos\Controller\Jobs\Common\Import\Xml\Processor\Base |
22
|
|
|
implements \Aimeos\Controller\Jobs\Common\Import\Xml\Processor\Iface |
23
|
|
|
{ |
24
|
|
|
use \Aimeos\Controller\Jobs\Common\Import\Xml\Traits; |
25
|
|
|
|
26
|
|
|
|
27
|
|
|
/** controller/jobs/common/import/xml/processor/lists/product/name |
28
|
|
|
* Name of the lists processor implementation |
29
|
|
|
* |
30
|
|
|
* Use "Myname" if your class is named "\Aimeos\Controller\Jobs\Common\Import\Xml\Processor\Lists\Product\Myname". |
31
|
|
|
* The name is case-sensitive and you should avoid camel case names like "MyName". |
32
|
|
|
* |
33
|
|
|
* @param string Last part of the processor class name |
34
|
|
|
* @since 2019.04 |
35
|
|
|
*/ |
36
|
|
|
|
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Updates the given item using the data from the DOM node |
40
|
|
|
* |
41
|
|
|
* @param \Aimeos\MShop\Common\Item\Iface $item Item which should be updated |
42
|
|
|
* @param \DOMNode $node XML document node containing a list of nodes to process |
43
|
|
|
* @return \Aimeos\MShop\Common\Item\Iface Updated item |
44
|
|
|
*/ |
45
|
|
|
public function process( \Aimeos\MShop\Common\Item\Iface $item, \DOMNode $node ) : \Aimeos\MShop\Common\Item\Iface |
46
|
|
|
{ |
47
|
|
|
\Aimeos\Utils::implements( $item, \Aimeos\MShop\Common\Item\ListsRef\Iface::class ); |
48
|
|
|
|
49
|
|
|
$context = $this->context(); |
50
|
|
|
$resource = $item->getResourceType(); |
51
|
|
|
$listItems = $item->getListItems( 'product', null, null, false ); |
52
|
|
|
$manager = \Aimeos\MShop::create( $context, $resource ); |
53
|
|
|
$map = $this->getItems( $node->childNodes ); |
54
|
|
|
|
55
|
|
|
foreach( $node->childNodes as $node ) |
56
|
|
|
{ |
57
|
|
|
$attributes = $node->attributes; |
58
|
|
|
|
59
|
|
|
if( $node->nodeName !== 'productitem' ) { |
60
|
|
|
continue; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
if( ( $attr = $attributes->getNamedItem( 'ref' ) ) === null ) { |
64
|
|
|
continue; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
$attrValue = \Aimeos\Base\Str::decode( $attr->nodeValue ); |
68
|
|
|
|
69
|
|
|
if( !isset( $map[$attrValue] ) ) { |
70
|
|
|
continue; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
$list = []; |
74
|
|
|
$refItem = $map[$attrValue]; |
75
|
|
|
$type = ( $attr = $attributes->getNamedItem( 'lists.type' ) ) !== null ? $attr->nodeValue : 'default'; |
76
|
|
|
|
77
|
|
|
if( ( $listItem = $item->getListItem( 'product', $type, $refItem->getId() ) ) === null ) { |
78
|
|
|
$listItem = $manager->createListItem(); |
|
|
|
|
79
|
|
|
} else { |
80
|
|
|
unset( $listItems[$listItem->getId()] ); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
foreach( $attributes as $attrName => $attrNode ) { |
84
|
|
|
$list[$resource . '.' . $attrName] = \Aimeos\Base\Str::decode( $attrNode->nodeValue ); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
$name = $resource . '.lists.config'; |
88
|
|
|
$list[$name] = ( isset( $list[$name] ) ? (array) json_decode( $list[$name] ) : [] ); |
89
|
|
|
$list[$resource . '.lists.type'] = $type; |
90
|
|
|
|
91
|
|
|
$this->addType( $resource . '/lists/type', 'product', $type ); |
92
|
|
|
|
93
|
|
|
$listItem = $listItem->fromArray( $list ); |
94
|
|
|
$item = $item->addListItem( 'product', $listItem, $refItem ); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
return $item->deleteListItems( $listItems->toArray() ); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Returns the product items for the given nodes |
103
|
|
|
* |
104
|
|
|
* @param \DomNodeList $nodes List of XML product item nodes |
105
|
|
|
* @return \Aimeos\MShop\Product\Item\Iface[] Associative list of product items with codes as keys |
106
|
|
|
*/ |
107
|
|
|
protected function getItems( \DomNodeList $nodes ) : array |
108
|
|
|
{ |
109
|
|
|
$codes = $map = []; |
110
|
|
|
$manager = \Aimeos\MShop::create( $this->context(), 'product' ); |
111
|
|
|
|
112
|
|
|
foreach( $nodes as $node ) |
113
|
|
|
{ |
114
|
|
|
if( $node->nodeName === 'productitem' && ( $attr = $node->attributes->getNamedItem( 'ref' ) ) !== null ) { |
115
|
|
|
$codes[\Aimeos\Base\Str::decode( $attr->nodeValue )] = null; |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
$search = $manager->filter()->slice( 0, count( $codes ) ); |
120
|
|
|
$search->setConditions( $search->compare( '==', 'product.code', array_keys( $codes ) ) ); |
121
|
|
|
|
122
|
|
|
foreach( $manager->search( $search, [] ) as $item ) { |
123
|
|
|
$map[$item->getCode()] = $item; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
return $map; |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.