Passed
Push — master ( 3311dc...3c99d6 )
by Aimeos
05:26
created

lib/mshoplib/setup/unittest/OrderAddTestData.php (33 issues)

1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Metaways Infosystems GmbH, 2012
6
 * @copyright Aimeos (aimeos.org), 2015-2018
7
 */
8
9
10
namespace Aimeos\MW\Setup\Task;
11
12
13
/**
14
 * Adds order test data.
15
 */
16
class OrderAddTestData extends \Aimeos\MW\Setup\Task\Base
17
{
18
	/**
19
	 * Returns the list of task names which this task depends on.
20
	 *
21
	 * @return string[] List of task names
22
	 */
23
	public function getPreDependencies()
24
	{
25
		return ['CustomerAddTestData', 'ProductAddTestData', 'PluginAddTestData', 'ServiceAddTestData'];
26
	}
27
28
29
	/**
30
	 * Adds order test data.
31
	 */
32
	public function migrate()
33
	{
34
		\Aimeos\MW\Common\Base::checkClass( \Aimeos\MShop\Context\Item\Iface::class, $this->additional );
35
36
		$this->msg( 'Adding order test data', 0 );
37
		$this->additional->setEditor( 'core:lib/mshoplib' );
38
39
		$localeManager = \Aimeos\MShop\Locale\Manager\Factory::create( $this->additional, 'Standard' );
40
		$orderManager = \Aimeos\MShop\Order\Manager\Factory::create( $this->additional, 'Standard' );
41
		$orderBaseManager = $orderManager->getSubManager( 'base' );
42
43
		$search = $orderBaseManager->createSearch();
44
		$search->setConditions( $search->compare( '==', 'order.base.sitecode', array( 'unittest', 'unit' ) ) );
45
46
		foreach( $orderBaseManager->searchItems( $search ) as $order ) {
47
			$orderBaseManager->deleteItem( $order->getId() );
48
		}
49
50
51
		$ds = DIRECTORY_SEPARATOR;
52
		$path = __DIR__ . $ds . 'data' . $ds . 'order.php';
53
54
		if( ( $testdata = include( $path ) ) == false ) {
55
			throw new \Aimeos\MShop\Exception( sprintf( 'No file "%1$s" found for order domain', $path ) );
56
		}
57
58
		$this->additional->setLocale( $this->additional->getLocale()->setCurrencyId( 'EUR' ) );
59
60
		$bases = $this->addOrderBaseData( $localeManager, $orderBaseManager, $testdata );
61
		$bases['items'] = $this->addOrderBaseProductData( $orderBaseManager, $bases, $testdata );
62
		$bases['items'] = $this->addOrderBaseServiceData( $orderBaseManager, $bases, $testdata );
63
64
		//update order bases (getPrice)
65
		foreach( $bases['items'] as $baseItem ) {
66
			$orderBaseManager->saveItem( $baseItem, false );
67
		}
68
69
		$this->additional->setLocale( $this->additional->getLocale()->setCurrencyId( null ) );
70
71
		$this->addOrderData( $orderManager, $bases['ids'], $testdata );
72
73
		$this->status( 'done' );
74
	}
75
76
77
	/**
78
	 * Adds the required order base data.
79
	 *
80
	 * @param \Aimeos\MShop\Common\Manager\Iface $localeManager Locale manager
81
	 * @param \Aimeos\MShop\Common\Manager\Iface $orderBaseManager Order base manager
82
	 * @param array $testdata Associative list of key/list pairs
83
	 * @throws \Aimeos\MW\Setup\Exception If no type ID is found
84
	 */
85
	protected function addOrderBaseData( \Aimeos\MShop\Common\Manager\Iface $localeManager,
86
		\Aimeos\MShop\Common\Manager\Iface $orderBaseManager, array $testdata )
87
	{
88
		$bases = [];
89
		$locale = $localeManager->createItem();
90
		$customerIds = $this->getCustomerIds( $testdata );
91
		$orderBaseAddressManager = $orderBaseManager->getSubManager( 'address', 'Standard' );
92
93
		$orderBaseManager->begin();
94
95
		foreach( $testdata['order/base'] as $key => $dataset )
96
		{
97
			$bases['items'][$key] = $orderBaseManager->createItem();
98
			$bases['items'][$key]->setId( null );
99
			$bases['items'][$key]->setComment( $dataset['comment'] );
100
			$bases['items'][$key]->setCustomerId( $customerIds[$dataset['customerid']] );
101
102
			$locale->setId( null );
103
			$locale->setSiteId( $this->additional->getLocale()->getSiteId() );
104
			$locale->setLanguageId( $dataset['langid'] );
0 ignored issues
show
The method setLanguageId() does not exist on Aimeos\MShop\Attribute\Item\Iface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

104
			$locale->/** @scrutinizer ignore-call */ 
105
            setLanguageId( $dataset['langid'] );

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.

Loading history...
105
			$locale->setCurrencyId( $dataset['currencyid'] );
0 ignored issues
show
The method setCurrencyId() does not exist on Aimeos\MShop\Attribute\Item\Iface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

105
			$locale->/** @scrutinizer ignore-call */ 
106
            setCurrencyId( $dataset['currencyid'] );

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.

Loading history...
106
			$bases['items'][$key]->setLocale( $locale );
107
108
			$orderBaseManager->saveItem( $bases['items'][$key] );
109
			$bases['ids'][$key] = $bases['items'][$key]->getId();
110
		}
111
112
		$this->addOrderBaseAddressData( $orderBaseAddressManager, $bases, $testdata );
113
114
		$orderBaseManager->commit();
115
116
		return $bases;
117
	}
118
119
120
	/**
121
	 * Adds the order address data.
122
	 *
123
	 * @param \Aimeos\MShop\Common\Manager\Iface $manager
124
	 * @param array $testdata
125
	 */
126
	protected function addOrderBaseAddressData( \Aimeos\MShop\Common\Manager\Iface $manager,
127
		array $bases, array $testdata )
128
	{
129
		$orderAddr = $manager->createItem();
130
131
		foreach( $testdata['order/base/address'] as $dataset )
132
		{
133
			if( !isset( $bases['ids'][$dataset['baseid']] ) ) {
134
				throw new \Aimeos\MW\Setup\Exception( sprintf( 'No base ID found for "%1$s"', $dataset['baseid'] ) );
135
			}
136
137
			$orderAddr->setId( null );
138
			$orderAddr->setBaseId( $bases['ids'][$dataset['baseid']] );
0 ignored issues
show
The method setBaseId() does not exist on Aimeos\MShop\Attribute\Item\Iface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

138
			$orderAddr->/** @scrutinizer ignore-call */ 
139
               setBaseId( $bases['ids'][$dataset['baseid']] );

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.

Loading history...
139
			$orderAddr->setAddressId( ( isset( $dataset['addrid'] ) ? $dataset['addrid'] : '' ) );
140
			$orderAddr->setType( $dataset['type'] );
141
			$orderAddr->setCompany( $dataset['company'] );
0 ignored issues
show
The method setCompany() does not exist on Aimeos\MShop\Attribute\Item\Iface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

141
			$orderAddr->/** @scrutinizer ignore-call */ 
142
               setCompany( $dataset['company'] );

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.

Loading history...
142
			$orderAddr->setVatID( ( isset( $dataset['vatid'] ) ? $dataset['vatid'] : '' ) );
143
			$orderAddr->setSalutation( $dataset['salutation'] );
0 ignored issues
show
The method setSalutation() does not exist on Aimeos\MShop\Attribute\Item\Iface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

143
			$orderAddr->/** @scrutinizer ignore-call */ 
144
               setSalutation( $dataset['salutation'] );

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.

Loading history...
144
			$orderAddr->setTitle( $dataset['title'] );
0 ignored issues
show
The method setTitle() does not exist on Aimeos\MShop\Attribute\Item\Iface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

144
			$orderAddr->/** @scrutinizer ignore-call */ 
145
               setTitle( $dataset['title'] );

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.

Loading history...
145
			$orderAddr->setFirstname( $dataset['firstname'] );
0 ignored issues
show
The method setFirstname() does not exist on Aimeos\MShop\Attribute\Item\Iface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

145
			$orderAddr->/** @scrutinizer ignore-call */ 
146
               setFirstname( $dataset['firstname'] );

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.

Loading history...
146
			$orderAddr->setLastname( $dataset['lastname'] );
0 ignored issues
show
The method setLastname() does not exist on Aimeos\MShop\Attribute\Item\Iface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

146
			$orderAddr->/** @scrutinizer ignore-call */ 
147
               setLastname( $dataset['lastname'] );

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.

Loading history...
147
			$orderAddr->setAddress1( $dataset['address1'] );
0 ignored issues
show
The method setAddress1() does not exist on Aimeos\MShop\Attribute\Item\Iface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

147
			$orderAddr->/** @scrutinizer ignore-call */ 
148
               setAddress1( $dataset['address1'] );

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.

Loading history...
148
			$orderAddr->setAddress2( $dataset['address2'] );
0 ignored issues
show
The method setAddress2() does not exist on Aimeos\MShop\Attribute\Item\Iface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

148
			$orderAddr->/** @scrutinizer ignore-call */ 
149
               setAddress2( $dataset['address2'] );

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.

Loading history...
149
			$orderAddr->setAddress3( $dataset['address3'] );
0 ignored issues
show
The method setAddress3() does not exist on Aimeos\MShop\Attribute\Item\Iface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

149
			$orderAddr->/** @scrutinizer ignore-call */ 
150
               setAddress3( $dataset['address3'] );

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.

Loading history...
150
			$orderAddr->setPostal( $dataset['postal'] );
0 ignored issues
show
The method setPostal() does not exist on Aimeos\MShop\Attribute\Item\Iface. Did you maybe mean setPosition()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

150
			$orderAddr->/** @scrutinizer ignore-call */ 
151
               setPostal( $dataset['postal'] );

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.

Loading history...
151
			$orderAddr->setCity( $dataset['city'] );
0 ignored issues
show
The method setCity() does not exist on Aimeos\MShop\Attribute\Item\Iface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

151
			$orderAddr->/** @scrutinizer ignore-call */ 
152
               setCity( $dataset['city'] );

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.

Loading history...
152
			$orderAddr->setState( $dataset['state'] );
0 ignored issues
show
The method setState() does not exist on Aimeos\MShop\Attribute\Item\Iface. Did you maybe mean setStatus()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

152
			$orderAddr->/** @scrutinizer ignore-call */ 
153
               setState( $dataset['state'] );

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.

Loading history...
153
			$orderAddr->setCountryId( $dataset['countryid'] );
0 ignored issues
show
The method setCountryId() does not exist on Aimeos\MShop\Attribute\Item\Iface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

153
			$orderAddr->/** @scrutinizer ignore-call */ 
154
               setCountryId( $dataset['countryid'] );

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.

Loading history...
154
			$orderAddr->setTelephone( $dataset['telephone'] );
0 ignored issues
show
The method setTelephone() does not exist on Aimeos\MShop\Attribute\Item\Iface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

154
			$orderAddr->/** @scrutinizer ignore-call */ 
155
               setTelephone( $dataset['telephone'] );

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.

Loading history...
155
			$orderAddr->setEmail( $dataset['email'] );
0 ignored issues
show
The method setEmail() does not exist on Aimeos\MShop\Attribute\Item\Iface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

155
			$orderAddr->/** @scrutinizer ignore-call */ 
156
               setEmail( $dataset['email'] );

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.

Loading history...
156
			$orderAddr->setTelefax( $dataset['telefax'] );
0 ignored issues
show
The method setTelefax() does not exist on Aimeos\MShop\Attribute\Item\Iface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

156
			$orderAddr->/** @scrutinizer ignore-call */ 
157
               setTelefax( $dataset['telefax'] );

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.

Loading history...
157
			$orderAddr->setWebsite( $dataset['website'] );
0 ignored issues
show
The method setWebsite() does not exist on Aimeos\MShop\Attribute\Item\Iface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

157
			$orderAddr->/** @scrutinizer ignore-call */ 
158
               setWebsite( $dataset['website'] );

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.

Loading history...
158
			$orderAddr->setLanguageId( $dataset['langid'] );
159
			$orderAddr->setLatitude( $dataset['latitude'] );
160
			$orderAddr->setLongitude( $dataset['longitude'] );
161
162
			$manager->saveItem( $orderAddr, false );
163
		}
164
	}
165
166
167
	/**
168
	 * Adds the required order base service data.
169
	 *
170
	 * @param \Aimeos\MShop\Common\Manager\Iface $orderBaseManager Order base manager
171
	 * @param array $bases Associative list of key/list pairs
172
	 * @param array $testdata Associative list of key/list pairs
173
	 * @return array Associative list of enhanced order base items
174
	 * @throws \Aimeos\MW\Setup\Exception If no type ID is found
175
	 */
176
	protected function addOrderBaseServiceData( \Aimeos\MShop\Common\Manager\Iface $orderBaseManager,
177
		array $bases, array $testdata )
178
	{
179
		$ordServices = [];
180
		$servIds = $this->getServiceIds( $testdata );
181
		$orderBaseServiceManager = $orderBaseManager->getSubManager( 'service', 'Standard' );
182
		$orderBaseServiceAttrManager = $orderBaseServiceManager->getSubManager( 'attribute', 'Standard' );
183
		$priceManager = \Aimeos\MShop::create( $this->additional, 'price' );
184
		$ordServ = $orderBaseServiceManager->createItem();
185
186
		$orderBaseManager->begin();
187
188
		foreach( $testdata['order/base/service'] as $key => $dataset )
189
		{
190
			if( !isset( $bases['ids'][$dataset['baseid']] ) ) {
191
				throw new \Aimeos\MW\Setup\Exception( sprintf( 'No base ID found for "%1$s" in order base serive data', $dataset['baseid'] ) );
192
			}
193
194
			if( !isset( $bases['items'][$dataset['baseid']] ) ) {
195
				throw new \Aimeos\MW\Setup\Exception( sprintf( 'No base Item found for "%1$s" in order base service data', $dataset['baseid'] ) );
196
			}
197
198
			$ordServ->setId( null );
199
			$ordServ->setBaseId( $bases['ids'][$dataset['baseid']] );
200
			$ordServ->setType( $dataset['type'] );
201
			$ordServ->setCode( $dataset['code'] );
202
			$ordServ->setName( $dataset['name'] );
0 ignored issues
show
The method setName() does not exist on Aimeos\MShop\Attribute\Item\Iface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

202
			$ordServ->/** @scrutinizer ignore-call */ 
203
             setName( $dataset['name'] );

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.

Loading history...
203
			$ordServ->setMediaUrl( $dataset['mediaurl'] );
0 ignored issues
show
The method setMediaUrl() does not exist on Aimeos\MShop\Attribute\Item\Iface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

203
			$ordServ->/** @scrutinizer ignore-call */ 
204
             setMediaUrl( $dataset['mediaurl'] );

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.

Loading history...
204
205
			if( isset( $dataset['servid'] ) ) {
206
				$ordServ->setServiceId( $servIds[$dataset['servid']] );
207
			}
208
209
			$priceItem = $priceManager->createItem();
210
			$priceItem->setCurrencyId( $dataset['currencyid'] );
211
			$priceItem->setValue( $dataset['price'] );
0 ignored issues
show
The method setValue() does not exist on Aimeos\MShop\Attribute\Item\Iface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

211
			$priceItem->/** @scrutinizer ignore-call */ 
212
               setValue( $dataset['price'] );

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.

Loading history...
212
			$priceItem->setCosts( $dataset['shipping'] );
213
			$priceItem->setRebate( $dataset['rebate'] );
0 ignored issues
show
The method setRebate() does not exist on Aimeos\MShop\Attribute\Item\Iface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

213
			$priceItem->/** @scrutinizer ignore-call */ 
214
               setRebate( $dataset['rebate'] );

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.

Loading history...
214
			$priceItem->setTaxRate( $dataset['taxrate'] );
0 ignored issues
show
The method setTaxRate() does not exist on Aimeos\MShop\Attribute\Item\Iface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

214
			$priceItem->/** @scrutinizer ignore-call */ 
215
               setTaxRate( $dataset['taxrate'] );

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.

Loading history...
215
			$ordServ->setPrice( $priceItem );
0 ignored issues
show
The method setPrice() does not exist on Aimeos\MShop\Attribute\Item\Iface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

215
			$ordServ->/** @scrutinizer ignore-call */ 
216
             setPrice( $priceItem );

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.

Loading history...
216
217
			$orderBaseServiceManager->saveItem( $ordServ );
218
219
			$ordServices[$key] = $ordServ->getId();
220
			$bases['items'][$dataset['baseid']]->addService( $ordServ, $dataset['type'] ); //adds Services to orderbase
221
		}
222
223
		$this->addOrderBaseServiceAttributeData( $orderBaseServiceAttrManager, $testdata, $ordServices );
224
225
		$orderBaseManager->commit();
226
227
		return $bases['items'];
228
	}
229
230
231
	/**
232
	 * Adds the required order base product data.
233
	 *
234
	 * @param \Aimeos\MShop\Common\Manager\Iface $orderBaseManager Order Base Manager
235
	 * @param array $bases Associative list of key/list pairs
236
	 * @param array $testdata Associative list of key/list pairs
237
	 * @return array Enhanced list of order base items
238
	 * @throws \Aimeos\MW\Setup\Exception If no type ID is found
239
	 */
240
	protected function addOrderBaseProductData( \Aimeos\MShop\Common\Manager\Iface $orderBaseManager,
241
		array $bases, array $testdata )
242
	{
243
		$ordProds = [];
244
		$products = $this->getProductItems( $testdata );
245
		$orderBaseProductManager = $orderBaseManager->getSubManager( 'product', 'Standard' );
246
		$orderBaseProductAttrManager = $orderBaseProductManager->getSubManager( 'attribute', 'Standard' );
247
		$priceManager = \Aimeos\MShop::create( $this->additional, 'price' );
248
249
		$orderBaseManager->begin();
250
251
		foreach( $testdata['order/base/product'] as $key => $dataset )
252
		{
253
			if( !isset( $bases['ids'][$dataset['baseid']] ) ) {
254
				throw new \Aimeos\MW\Setup\Exception( sprintf( 'No base ID found for "%1$s" in order base product data', $dataset['baseid'] ) );
255
			}
256
257
			if( !isset( $bases['items'][$dataset['baseid']] ) ) {
258
				throw new \Aimeos\MW\Setup\Exception( sprintf( 'No base Item found for "%1$s" in order base product data', $dataset['baseid'] ) );
259
			}
260
261
			$ordProdItem = $orderBaseProductManager->createItem();
262
263
			$ordProdItem->setId( null );
264
			$ordProdItem->setBaseId( $bases['ids'][$dataset['baseid']] );
265
			$ordProdItem->setType( $dataset['type'] );
266
			$ordProdItem->setSupplierCode( $dataset['suppliercode'] );
0 ignored issues
show
The method setSupplierCode() does not exist on Aimeos\MShop\Attribute\Item\Iface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

266
			$ordProdItem->/** @scrutinizer ignore-call */ 
267
                 setSupplierCode( $dataset['suppliercode'] );

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.

Loading history...
267
			$ordProdItem->setProductCode( $dataset['prodcode'] );
0 ignored issues
show
The method setProductCode() does not exist on Aimeos\MShop\Attribute\Item\Iface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

267
			$ordProdItem->/** @scrutinizer ignore-call */ 
268
                 setProductCode( $dataset['prodcode'] );

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.

Loading history...
268
			$ordProdItem->setName( $dataset['name'] );
269
			$ordProdItem->setMediaUrl( $dataset['mediaurl'] );
270
			$ordProdItem->setQuantity( $dataset['amount'] );
0 ignored issues
show
The method setQuantity() does not exist on Aimeos\MShop\Attribute\Item\Iface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

270
			$ordProdItem->/** @scrutinizer ignore-call */ 
271
                 setQuantity( $dataset['amount'] );

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.

Loading history...
271
			$ordProdItem->setFlags( $dataset['flags'] );
0 ignored issues
show
The method setFlags() does not exist on Aimeos\MShop\Attribute\Item\Iface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

271
			$ordProdItem->/** @scrutinizer ignore-call */ 
272
                 setFlags( $dataset['flags'] );

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.

Loading history...
272
			$ordProdItem->setStatus( $dataset['status'] );
273
			$ordProdItem->setPosition( $dataset['pos'] );
274
275
			if( isset( $dataset['stocktype'] ) ) {
276
				$ordProdItem->setStockType( $dataset['stocktype'] );
277
			}
278
279
			if( isset( $dataset['prodid'] ) ) {
280
				$ordProdItem->setProductId( $products[$dataset['prodid']]->getId() );
281
			}
282
283
			// product bundle related fields
284
			if( isset( $dataset['ordprodid'] ) ) {
285
				$ordProdItem->setOrderProductId( $ordProds[$dataset['ordprodid']] );
0 ignored issues
show
The method setOrderProductId() does not exist on Aimeos\MShop\Attribute\Item\Iface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

285
				$ordProdItem->/** @scrutinizer ignore-call */ 
286
                  setOrderProductId( $ordProds[$dataset['ordprodid']] );

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.

Loading history...
286
			}
287
288
			$priceItem = $priceManager->createItem();
289
			$priceItem->setCurrencyId( $dataset['currencyid'] );
290
			$priceItem->setValue( $dataset['price'] );
291
			$priceItem->setCosts( $dataset['shipping'] );
292
			$priceItem->setRebate( $dataset['rebate'] );
293
			$priceItem->setTaxRate( $dataset['taxrate'] );
294
			$ordProdItem->setPrice( $priceItem );
295
296
			$bases['items'][$dataset['baseid']]->addProduct( $ordProdItem, $dataset['pos'] ); //adds Products to orderbase
297
			$ordProds[$key] = $orderBaseProductManager->saveItem( $ordProdItem )->getId();
298
		}
299
300
		$this->addOrderBaseProductAttributeData( $orderBaseProductAttrManager, $testdata, $ordProds, $products );
301
302
		$orderBaseManager->commit();
303
304
		return $bases['items'];
305
	}
306
307
308
	/**
309
	 * Adds the order product attribute test data.
310
	 *
311
	 * @param \Aimeos\MShop\Common\Manager\Iface $manager
312
	 * @param array $testdata
313
	 * @param array $ordProds
314
	 * @param \Aimeos\MShop\Product\Item\Iface[] $products
315
	 * @throws \Aimeos\MW\Setup\Exception
316
	 */
317
	protected function addOrderBaseProductAttributeData( \Aimeos\MShop\Common\Manager\Iface $manager,
318
		array $testdata, array $ordProds, array $products )
319
	{
320
		$attrCodes = [];
321
		$attributeManager = \Aimeos\MShop::create( $this->additional, 'attribute' );
322
		$attributes = $attributeManager->searchItems( $attributeManager->createSearch() );
323
324
		foreach( $attributes as $attrItem ) {
325
			$attrCodes[$attrItem->getType()][] = $attrItem;
326
		}
327
328
		$ordProdAttr = $manager->createItem();
329
330
		foreach( $testdata['order/base/product/attr'] as $dataset )
331
		{
332
			if( !isset( $ordProds[$dataset['ordprodid']] ) ) {
333
				throw new \Aimeos\MW\Setup\Exception( sprintf( 'No order product ID found for "%1$s"', $dataset['ordprodid'] ) );
334
			}
335
336
			$ordProdAttr->setId( null );
337
			$ordProdAttr->setParentId( $ordProds[$dataset['ordprodid']] );
338
			$ordProdAttr->setCode( $dataset['code'] );
339
			$ordProdAttr->setValue( $dataset['value'] );
340
			$ordProdAttr->setName( $dataset['name'] );
341
			$ordProdAttr->setQuantity( $dataset['quantity'] );
342
343
			if( isset( $attrCodes[$dataset['code']] ) )
344
			{
345
				foreach( (array) $attrCodes[$dataset['code']] as $attrItem )
346
				{
347
					if( $attrItem->getCode() == $dataset['value'] ) {
348
						$ordProdAttr->setAttributeId( $attrItem->getId() );
349
					}
350
				}
351
			}
352
353
			if( isset( $dataset['type'] ) ) {
354
				$ordProdAttr->setType( $dataset['type'] );
355
			}
356
357
			$manager->saveItem( $ordProdAttr, false );
358
		}
359
	}
360
361
362
	/**
363
	 * Adds the order service attributes.
364
	 *
365
	 * @param \Aimeos\MShop\Common\Manager\Iface $manager
366
	 * @param array $testdata
367
	 * @param array $ordServices
368
	 * @throws \Aimeos\MW\Setup\Exception
369
	 */
370
	protected function addOrderBaseServiceAttributeData( \Aimeos\MShop\Common\Manager\Iface $manager,
371
		array $testdata, array $ordServices )
372
	{
373
		$ordServAttr = $manager->createItem();
374
375
		foreach( $testdata['order/base/service/attr'] as $dataset )
376
		{
377
			if( !isset( $ordServices[$dataset['ordservid']] ) ) {
378
				throw new \Aimeos\MW\Setup\Exception( sprintf( 'No order service ID found for "%1$s"', $dataset['ordservid'] ) );
379
			}
380
381
			$ordServAttr->setId( null );
382
			$ordServAttr->setParentId( $ordServices[$dataset['ordservid']] );
383
			$ordServAttr->setCode( $dataset['code'] );
384
			$ordServAttr->setValue( $dataset['value'] );
385
			$ordServAttr->setName( $dataset['name'] );
386
			$ordServAttr->setType( $dataset['type'] );
387
			$ordServAttr->setQuantity( $dataset['quantity'] );
388
389
			if( isset( $dataset['attrid'] ) ) {
390
				$ordServAttr->setAttributeId( $dataset['attrid'] );
391
			}
392
393
			$manager->saveItem( $ordServAttr, false );
394
		}
395
	}
396
397
398
	/**
399
	 * Adds the order test data.
400
	 *
401
	 * @param \Aimeos\MShop\Common\Manager\Iface $orderManager Order manager
402
	 * @param array $baseIds List of ids
403
	 * @param array $testdata Associative list of key/list pairs
404
	 * @throws \Aimeos\MW\Setup\Exception If no type ID is found
405
	 */
406
	protected function addOrderData( \Aimeos\MShop\Common\Manager\Iface $orderManager, array $baseIds, array $testdata )
407
	{
408
		$orderStatusManager = $orderManager->getSubManager( 'status', 'Standard' );
409
410
		$ords = [];
411
		$ordItem = $orderManager->createItem();
412
413
		$orderManager->begin();
414
415
		foreach( $testdata['order'] as $key => $dataset )
416
		{
417
			if( !isset( $baseIds[$dataset['baseid']] ) ) {
418
				throw new \Aimeos\MW\Setup\Exception( sprintf( 'No base ID found for "%1$s"', $dataset['baseid'] ) );
419
			}
420
421
			$ordItem->setId( null );
422
			$ordItem->setType( $dataset['type'] );
423
			$ordItem->setBaseId( $baseIds[$dataset['baseid']] );
424
			$ordItem->setDeliveryStatus( $dataset['statusdelivery'] );
0 ignored issues
show
The method setDeliveryStatus() does not exist on Aimeos\MShop\Attribute\Item\Iface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

424
			$ordItem->/** @scrutinizer ignore-call */ 
425
             setDeliveryStatus( $dataset['statusdelivery'] );

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.

Loading history...
425
			$ordItem->setPaymentStatus( $dataset['statuspayment'] );
0 ignored issues
show
The method setPaymentStatus() does not exist on Aimeos\MShop\Attribute\Item\Iface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

425
			$ordItem->/** @scrutinizer ignore-call */ 
426
             setPaymentStatus( $dataset['statuspayment'] );

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.

Loading history...
426
			$ordItem->setDateDelivery( $dataset['datedelivery'] );
427
			$ordItem->setDatePayment( $dataset['datepayment'] );
428
			$ordItem->setRelatedId( $dataset['relatedid'] );
0 ignored issues
show
The method setRelatedId() does not exist on Aimeos\MShop\Attribute\Item\Iface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

428
			$ordItem->/** @scrutinizer ignore-call */ 
429
             setRelatedId( $dataset['relatedid'] );

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.

Loading history...
429
430
			$orderManager->saveItem( $ordItem );
431
			$ords[$key] = $ordItem->getId();
432
		}
433
434
		$ordStat = $orderStatusManager->createItem();
435
		foreach( $testdata['order/status'] as $dataset )
436
		{
437
			if( !isset( $ords[$dataset['parentid']] ) ) {
438
				throw new \Aimeos\MW\Setup\Exception( sprintf( 'No order ID found for "%1$s"', $dataset['parentid'] ) );
439
			}
440
441
			$ordStat->setId( null );
442
			$ordStat->setParentId( $ords[$dataset['parentid']] );
443
			$ordStat->setType( $dataset['type'] );
444
			$ordStat->setValue( $dataset['value'] );
445
446
			$orderStatusManager->saveItem( $ordStat, false );
447
		}
448
449
		$orderManager->commit();
450
	}
451
452
453
	/**
454
	 * Returns the customer IDs for the given test data.
455
	 *
456
	 * @param array $testdata Test data
457
	 * @return array Customer Ids
458
	 */
459
	protected function getCustomerIds( array $testdata )
460
	{
461
		$customercodes = $customerIds = [];
462
463
		foreach( $testdata['order/base'] as $key => $dataset ) {
464
			$customercodes[] = $dataset['customerid'];
465
		}
466
467
		$customerManager = \Aimeos\MShop::create( $this->additional, 'customer' );
468
		$search = $customerManager->createSearch();
469
		$search->setConditions( $search->compare( '==', 'customer.code', $customercodes ) );
470
471
		foreach( $customerManager->searchItems( $search ) as $id => $customerItem ) {
472
			$customerIds[$customerItem->getCode()] = $id;
473
		}
474
475
		return $customerIds;
476
	}
477
478
479
	/**
480
	 * Returns the product items for the given test data.
481
	 *
482
	 * @param array $testdata Test data
483
	 * @return \Aimeos\MShop\Product\Item\Iface[] Product Items
484
	 */
485
	protected function getProductItems( array $testdata )
486
	{
487
		$codes = $items = [];
488
		$productManager = \Aimeos\MShop::create( $this->additional, 'product' );
489
490
		foreach( $testdata['order/base/product'] as $key => $dataset )
491
		{
492
			if( isset( $dataset['prodid'] ) ) {
493
				$codes[$key] = $dataset['prodid'];
494
			}
495
		}
496
497
		$search = $productManager->createSearch();
498
		$search->setConditions( $search->compare( '==', 'product.code', $codes ) );
499
		$result = $productManager->searchItems( $search );
500
501
		foreach( $result as $item ) {
502
			$items[$item->getCode()] = $item;
503
		}
504
505
		return $items;
506
	}
507
508
509
	/**
510
	 * Returns the service item IDs for the given test data.
511
	 *
512
	 * @param array $testdata Test data
513
	 * @return array List of service IDs
514
	 */
515
	protected function getServiceIds( array $testdata )
516
	{
517
		$services = $servIds = [];
518
		$serviceManager = \Aimeos\MShop::create( $this->additional, 'service' );
519
520
		foreach( $testdata['order/base/service'] as $key => $dataset )
521
		{
522
			if( isset( $dataset['servid'] ) ) {
523
				$services[$key] = $dataset['servid'];
524
			}
525
		}
526
527
		$search = $serviceManager->createSearch();
528
		$search->setConditions( $search->compare( '==', 'service.code', $services ) );
529
		$servicesResult = $serviceManager->searchItems( $search );
530
531
		foreach( $servicesResult as $id => $service ) {
532
			$servIds[$service->getCode()] = $id;
533
		}
534
535
		return $servIds;
536
	}
537
}
538