Passed
Push — master ( f4114c...63f97d )
by Aimeos
02:47
created

Ezpublish::__construct()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 20
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 11
nc 4
nop 1
dl 0
loc 20
rs 9.9
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2016-2018
6
 * @package MShop
7
 * @subpackage Customer
8
 */
9
10
11
namespace Aimeos\MShop\Customer\Manager;
12
13
14
/**
15
 * Customer class implementation for ezPublish
16
 *
17
 * @package MShop
18
 * @subpackage Customer
19
 */
20
class Ezpublish
21
	extends \Aimeos\MShop\Customer\Manager\Standard
22
{
23
	private $searchConfig = array(
24
		'customer.id' => array(
25
			'label' => 'Customer ID',
26
			'code' => 'customer.id',
27
			'internalcode' => 'ezu."contentobject_id"',
28
			'type' => 'integer',
29
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_INT
30
		),
31
		// customer.siteid is not available
32
		'customer.label' => array(
33
			'label' => 'Customer label',
34
			'code' => 'customer.label',
35
			'internalcode' => 'ezu."login"',
36
			'type' => 'string',
37
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR
38
		),
39
		'customer.code' => array(
40
			'label' => 'Customer username',
41
			'code' => 'customer.code',
42
			'internalcode' => 'ezu."login_normalized"',
43
			'type' => 'string',
44
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR
45
		),
46
		'customer.salutation' => array(
47
			'label' => 'Customer salutation',
48
			'code' => 'customer.salutation',
49
			'internalcode' => 'ezu."salutation"',
50
			'type' => 'string',
51
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
52
		),
53
		'customer.company'=> array(
54
			'label' => 'Customer company',
55
			'code' => 'customer.company',
56
			'internalcode' => 'ezu."company"',
57
			'type' => 'string',
58
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
59
		),
60
		'customer.vatid'=> array(
61
			'label' => 'Customer VAT ID',
62
			'code' => 'customer.vatid',
63
			'internalcode' => 'ezu."vatid"',
64
			'type' => 'string',
65
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
66
		),
67
		'customer.title' => array(
68
			'label' => 'Customer title',
69
			'code' => 'customer.title',
70
			'internalcode' => 'ezu."title"',
71
			'type' => 'string',
72
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
73
		),
74
		'customer.firstname' => array(
75
			'label' => 'Customer firstname',
76
			'code' => 'customer.firstname',
77
			'internalcode' => 'ezu."firstname"',
78
			'type' => 'string',
79
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
80
		),
81
		'customer.lastname' => array(
82
			'label' => 'Customer lastname',
83
			'code' => 'customer.lastname',
84
			'internalcode' => 'ezu."lastname"',
85
			'type' => 'string',
86
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
87
		),
88
		'customer.address1' => array(
89
			'label' => 'Customer address part one',
90
			'code' => 'customer.address1',
91
			'internalcode' => 'ezu."address1"',
92
			'type' => 'string',
93
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
94
		),
95
		'customer.address2' => array(
96
			'label' => 'Customer address part two',
97
			'code' => 'customer.address2',
98
			'internalcode' => 'ezu."address2"',
99
			'type' => 'string',
100
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
101
		),
102
		'customer.address3' => array(
103
			'label' => 'Customer address part three',
104
			'code' => 'customer.address3',
105
			'internalcode' => 'ezu."address3"',
106
			'type' => 'string',
107
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
108
		),
109
		'customer.postal' => array(
110
			'label' => 'Customer postal',
111
			'code' => 'customer.postal',
112
			'internalcode' => 'ezu."postal"',
113
			'type' => 'string',
114
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
115
		),
116
		'customer.city' => array(
117
			'label' => 'Customer city',
118
			'code' => 'customer.city',
119
			'internalcode' => 'ezu."city"',
120
			'type' => 'string',
121
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
122
		),
123
		'customer.state' => array(
124
			'label' => 'Customer state',
125
			'code' => 'customer.state',
126
			'internalcode' => 'ezu."state"',
127
			'type' => 'string',
128
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
129
		),
130
		'customer.languageid' => array(
131
			'label' => 'Customer language',
132
			'code' => 'customer.languageid',
133
			'internalcode' => 'ezu."langid"',
134
			'type' => 'string',
135
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
136
		),
137
		'customer.countryid' => array(
138
			'label' => 'Customer country',
139
			'code' => 'customer.countryid',
140
			'internalcode' => 'ezu."countryid"',
141
			'type' => 'string',
142
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
143
		),
144
		'customer.telephone' => array(
145
			'label' => 'Customer telephone',
146
			'code' => 'customer.telephone',
147
			'internalcode' => 'ezu."telephone"',
148
			'type' => 'string',
149
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
150
		),
151
		'customer.email' => array(
152
			'label' => 'Customer email',
153
			'code' => 'customer.email',
154
			'internalcode' => 'ezu."email"',
155
			'type' => 'string',
156
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
157
		),
158
		'customer.telefax' => array(
159
			'label' => 'Customer telefax',
160
			'code' => 'customer.telefax',
161
			'internalcode' => 'ezu."telefax"',
162
			'type' => 'string',
163
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
164
		),
165
		'customer.website' => array(
166
			'label' => 'Customer website',
167
			'code' => 'customer.website',
168
			'internalcode' => 'ezu."website"',
169
			'type' => 'string',
170
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
171
		),
172
		'customer.birthday' => array(
173
			'label' => 'Customer birthday',
174
			'code' => 'customer.birthday',
175
			'internalcode' => 'ezu."birthday"',
176
			'type' => 'string',
177
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
178
		),
179
		'customer.password'=> array(
180
			'label' => 'Customer password',
181
			'code' => 'customer.password',
182
			'internalcode' => 'ezu."password_hash"',
183
			'type' => 'string',
184
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
185
		),
186
		'customer.status'=> array(
187
			'label' => 'Customer status',
188
			'code' => 'customer.status',
189
			'internalcode' => 'ezs."is_enabled"',
190
			'type' => 'integer',
191
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_INT
192
		),
193
		'customer.dateverified'=> array(
194
			'label' => 'Customer verification date',
195
			'code' => 'customer.dateverified',
196
			'internalcode' => 'ezu."vdate"',
197
			'type' => 'date',
198
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
199
		),
200
		'customer.ctime'=> array(
201
			'label' => 'Customer creation time',
202
			'code' => 'customer.ctime',
203
			'internalcode' => 'ezu."ctime"',
204
			'type' => 'datetime',
205
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
206
		),
207
		'customer.mtime'=> array(
208
			'label' => 'Customer modification time',
209
			'code' => 'customer.mtime',
210
			'internalcode' => 'ezu."mtime"',
211
			'type' => 'datetime',
212
			'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
213
		),
214
		'customer.editor'=> array(
215
			'label'=>'Customer editor',
216
			'code'=>'customer.editor',
217
			'internalcode' => 'ezu."editor"',
218
			'type'=> 'string',
219
			'internaltype'=> \Aimeos\MW\DB\Statement\Base::PARAM_STR,
220
		),
221
		'customer:has' => array(
222
			'code' => 'customer:has()',
223
			'internalcode' => '(
224
				SELECT ezuli_has."id" FROM ezuser_list AS ezuli_has
225
				WHERE ezu."id" = ezuli_has."parentid" AND :site
226
					AND ezuli_has."domain" = $1 AND ezuli_has."type" = $2 AND ezuli_has."refid" = $3
227
			)',
228
			'label' => 'Customer has list item, parameter(<domain>,<list type>,<reference ID>)',
229
			'type' => 'null',
230
			'internaltype' => 'null',
231
			'public' => false,
232
		),
233
		'customer:prop' => array(
234
			'code' => 'customer:prop()',
235
			'internalcode' => '(
236
				SELECT ezupr_prop."id" FROM ezuser_property AS ezupr_prop
237
				WHERE ezu."id" = ezupr_prop."parentid" AND :site
238
					AND ezupr_prop."type" = $1 AND ezupr_prop."value" = $3
239
					AND ( ezupr_prop."langid" = $2 OR ezupr_prop."langid" IS NULL )
240
			)',
241
			'label' => 'Customer has property item, parameter(<property type>,<language code>,<property value>)',
242
			'type' => 'null',
243
			'internaltype' => 'null',
244
			'public' => false,
245
		),
246
	);
247
248
249
	/**
250
	 * Initializes the object.
251
	 *
252
	 * @param \Aimeos\MShop\Context\Item\Iface $context Context object
253
	 */
254
	public function __construct( \Aimeos\MShop\Context\Item\Iface $context )
255
	{
256
		parent::__construct( $context );
257
258
		$locale = $context->getLocale();
259
		$level = \Aimeos\MShop\Locale\Manager\Base::SITE_ALL;
260
		$level = $context->getConfig()->get( 'mshop/customer/manager/sitemode', $level );
261
262
		$siteIds = [$locale->getSiteId()];
263
264
		if( $level & \Aimeos\MShop\Locale\Manager\Base::SITE_PATH ) {
265
			$siteIds = array_merge( $siteIds, $locale->getSitePath() );
266
		}
267
268
		if( $level & \Aimeos\MShop\Locale\Manager\Base::SITE_SUBTREE ) {
269
			$siteIds = array_merge( $siteIds, $locale->getSiteSubTree() );
270
		}
271
272
		$this->replaceSiteMarker( $this->searchConfig['customer:has'], 'ezuli_has."siteid"', $siteIds, ':site' );
273
		$this->replaceSiteMarker( $this->searchConfig['customer:prop'], 'ezupr_prop."siteid"', $siteIds, ':site' );
274
	}
275
276
277
	/**
278
	 * Removes old entries from the storage.
279
	 *
280
	 * @param array $siteids List of IDs for sites whose entries should be deleted
281
	 */
282
	public function cleanup( array $siteids )
283
	{
284
		$path = 'mshop/customer/manager/submanagers';
285
		foreach( $this->getContext()->getConfig()->get( $path, ['address', 'group', 'lists', 'property'] ) as $domain ) {
286
			$this->getObject()->getSubManager( $domain )->cleanup( $siteids );
287
		}
288
	}
289
290
291
	/**
292
	 * Removes multiple items specified by ids in the array.
293
	 *
294
	 * @param array $ids List of IDs
295
	 */
296
	public function deleteItems( array $ids )
297
	{
298
		$service = $this->getContext()->getEzUserService();
0 ignored issues
show
Bug introduced by
The method getEzUserService() does not exist on Aimeos\MShop\Context\Item\Iface. It seems like you code against a sub-type of Aimeos\MShop\Context\Item\Iface such as Aimeos\MShop\Context\Item\Ezpublish. ( Ignorable by Annotation )

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

298
		$service = $this->getContext()->/** @scrutinizer ignore-call */ getEzUserService();
Loading history...
299
300
		foreach( $ids as $id ) {
301
			$service->deleteUser( $service->loadUser( $id ) );
302
		}
303
	}
304
305
306
	/**
307
	 * Returns the list attributes that can be used for searching.
308
	 *
309
	 * @param boolean $withsub Return also attributes of sub-managers if true
310
	 * @return array List of attribute items implementing \Aimeos\MW\Criteria\Attribute\Iface
311
	 */
312
	public function getSearchAttributes( $withsub = true )
313
	{
314
		$path = 'mshop/customer/manager/submanagers';
315
316
		return $this->getSearchAttributesBase( $this->searchConfig, $path, ['address', 'group', 'lists', 'property'], $withsub );
317
	}
318
319
320
	/**
321
	 * Returns a new manager for customer extensions
322
	 *
323
	 * @param string $manager Name of the sub manager type in lower case
324
	 * @param string|null $name Name of the implementation, will be from configuration (or Default) if null
325
	 * @return mixed Manager for different extensions, e.g stock, tags, locations, etc.
326
	 */
327
	public function getSubManager( $manager, $name = null )
328
	{
329
		return $this->getSubManagerBase( 'customer', $manager, ( $name === null ? 'Ezpublish' : $name ) );
330
	}
331
332
333
	/**
334
	 * Saves a customer item object.
335
	 *
336
	 * @param \Aimeos\MShop\Customer\Item\Iface $item Customer item object
337
	 * @param boolean $fetch True if the new ID should be returned in the item
338
	 * @return \Aimeos\MShop\Common\Item\Iface $item Updated item including the generated ID
339
	 */
340
	public function saveItem( \Aimeos\MShop\Common\Item\Iface $item, $fetch = true )
341
	{
342
		self::checkClass( '\\Aimeos\\MShop\\Customer\\Item\\Iface', $item );
343
344
		if( !$item->isModified() )
345
		{
346
			$item = $this->savePropertyItems( $item, 'customer' );
347
			$item = $this->saveAddressItems( $item, 'customer' );
0 ignored issues
show
Bug introduced by
$item of type Aimeos\MShop\Common\Item\PropertyRef\Iface is incompatible with the type Aimeos\MShop\Common\Item\AddressRef\Iface expected by parameter $item of Aimeos\MShop\Customer\Ma...ard::saveAddressItems(). ( Ignorable by Annotation )

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

347
			$item = $this->saveAddressItems( /** @scrutinizer ignore-type */ $item, 'customer' );
Loading history...
348
			return $this->saveListItems( $item, 'customer' );
349
		}
350
351
		$context = $this->getContext();
352
353
		$class = '\Aimeos\MShop\Context\Item\Ezpublish';
354
		if( !is_a( $context, $class ) ) {
355
			throw new \Aimeos\MShop\Customer\Exception( sprintf( 'Object is not of required type "%1$s"', $class ) );
356
		}
357
358
		$service = $context->getEzUserService();
359
		$email = $item->getPaymentAddress()->getEmail();
0 ignored issues
show
Bug introduced by
The method getPaymentAddress() does not exist on Aimeos\MShop\Common\Item\Iface. It seems like you code against a sub-type of Aimeos\MShop\Common\Item\Iface such as Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Customer\Item\Base or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Customer\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

359
		$email = $item->/** @scrutinizer ignore-call */ getPaymentAddress()->getEmail();
Loading history...
360
361
		if( $item->getId() !== null )
362
		{
363
			$struct = $service->newUserUpdateStruct();
364
			$struct->password = $item->getPassword();
0 ignored issues
show
Bug introduced by
The method getPassword() does not exist on Aimeos\MShop\Common\Item\Iface. It seems like you code against a sub-type of Aimeos\MShop\Common\Item\Iface such as Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Customer\Item\Base or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Customer\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

364
			/** @scrutinizer ignore-call */ 
365
   $struct->password = $item->getPassword();
Loading history...
365
			$struct->enabled = $item->getStatus();
0 ignored issues
show
Bug introduced by
The method getStatus() does not exist on Aimeos\MShop\Common\Item\Iface. It seems like you code against a sub-type of Aimeos\MShop\Common\Item\Iface such as Aimeos\MShop\Product\Item\Iface or Aimeos\MShop\Service\Item\Iface or Aimeos\MShop\Order\Item\Base\Product\Iface or Aimeos\MShop\Locale\Item\Site\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Text\Item\Iface or Aimeos\MShop\Common\Item\Status\Iface or Aimeos\MShop\Media\Item\Iface or Aimeos\MShop\Subscription\Item\Iface or Aimeos\MShop\Coupon\Item\Iface or Aimeos\MAdmin\Job\Item\Iface or Aimeos\MShop\Common\Item\Lists\Iface or Aimeos\MShop\Price\Item\Iface or Aimeos\MShop\Locale\Item\Iface or Aimeos\MShop\Common\Item\Type\Iface or Aimeos\MShop\Attribute\Item\Iface or Aimeos\MShop\Order\Item\Base\Iface or Aimeos\MShop\Locale\Item\Language\Iface or Aimeos\MShop\Catalog\Item\Iface or Aimeos\MShop\Plugin\Item\Iface or Aimeos\MShop\Supplier\Item\Iface or Aimeos\MShop\Locale\Item\Currency\Iface or Aimeos\MShop\Attribute\Item\Standard or Aimeos\MShop\Catalog\Item\Standard or Aimeos\MShop\Customer\Item\Base or Aimeos\MShop\Plugin\Item\Standard or Aimeos\MShop\Media\Item\Standard or Aimeos\MAdmin\Job\Item\Standard or Aimeos\MShop\Common\Item\Type\Standard or Aimeos\MShop\Subscription\Item\Standard or Aimeos\MShop\Locale\Item\Site\Standard or Aimeos\MShop\Locale\Item\Currency\Standard or Aimeos\MShop\Text\Item\Standard or Aimeos\MShop\Locale\Item\Language\Standard or Aimeos\MShop\Locale\Item\Standard or Aimeos\MShop\Common\Item\Lists\Standard or Aimeos\MShop\Service\Item\Standard or Aimeos\MShop\Price\Item\Base or Aimeos\MShop\Supplier\Item\Standard or Aimeos\MShop\Coupon\Item\Standard or Aimeos\MShop\Product\Item\Standard or Aimeos\MShop\Order\Item\Base\Product\Standard or Aimeos\MShop\Product\Item\Iface or Aimeos\MShop\Service\Item\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Text\Item\Iface or Aimeos\MShop\Media\Item\Iface or Aimeos\MShop\Price\Item\Iface or Aimeos\MShop\Attribute\Item\Iface or Aimeos\MShop\Catalog\Item\Iface or Aimeos\MShop\Supplier\Item\Iface or Aimeos\MShop\Product\Item\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Media\Item\Iface or Aimeos\MShop\Attribute\Item\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Supplier\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

365
			/** @scrutinizer ignore-call */ 
366
   $struct->enabled = $item->getStatus();
Loading history...
366
			$struct->email = $email;
367
368
			$user = $service->loadUser( $item->getId() );
369
			$service->updateUser( $user, $struct );
370
		}
371
		else
372
		{
373
			$struct = $service->newUserCreateStruct( $item->getCode(), $email, $item->getPassword(), 'eng-GB' );
0 ignored issues
show
Bug introduced by
The method getCode() does not exist on Aimeos\MShop\Common\Item\Iface. It seems like you code against a sub-type of Aimeos\MShop\Common\Item\Iface such as Aimeos\MShop\Product\Item\Iface or Aimeos\MShop\Service\Item\Iface or Aimeos\MShop\Locale\Item\Site\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Order\Item\Base\Service\Iface or Aimeos\MShop\Customer\Item\Group\Iface or Aimeos\MShop\Order\Item\Base\Coupon\Iface or Aimeos\MShop\Common\Item\Type\Iface or Aimeos\MShop\Attribute\Item\Iface or Aimeos\MShop\Locale\Item\Language\Iface or Aimeos\MShop\Order\Item\...Service\Attribute\Iface or Aimeos\MShop\Catalog\Item\Iface or Aimeos\MShop\Order\Item\...Product\Attribute\Iface or Aimeos\MShop\Coupon\Item\Code\Iface or Aimeos\MShop\Supplier\Item\Iface or Aimeos\MShop\Locale\Item\Currency\Iface or Aimeos\MShop\Attribute\Item\Standard or Aimeos\MShop\Catalog\Item\Standard or Aimeos\MShop\Customer\Item\Base or Aimeos\MShop\Customer\Item\Group\Standard or Aimeos\MShop\Common\Item\Type\Standard or Aimeos\MShop\Locale\Item\Site\Standard or Aimeos\MShop\Locale\Item\Currency\Standard or Aimeos\MShop\Locale\Item\Language\Standard or Aimeos\MShop\Order\Item\Base\Service\Base or Aimeos\MShop\Service\Item\Standard or Aimeos\MShop\Order\Item\Base\Coupon\Standard or Aimeos\MShop\Coupon\Item\Code\Standard or Aimeos\MShop\Order\Item\...vice\Attribute\Standard or Aimeos\MShop\Supplier\Item\Standard or Aimeos\MShop\Product\Item\Standard or Aimeos\MShop\Order\Item\...duct\Attribute\Standard or Aimeos\MShop\Product\Item\Iface or Aimeos\MShop\Service\Item\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Common\Item\Type\Iface or Aimeos\MShop\Attribute\Item\Iface or Aimeos\MShop\Locale\Item\Language\Iface or Aimeos\MShop\Common\Item\Tree\Iface or Aimeos\MShop\Supplier\Item\Iface or Aimeos\MShop\Locale\Item\Currency\Iface or Aimeos\MShop\Product\Item\Iface or Aimeos\MShop\Service\Item\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Attribute\Item\Iface or Aimeos\MShop\Catalog\Item\Iface or Aimeos\MShop\Supplier\Item\Iface or Aimeos\MShop\Product\Item\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Attribute\Item\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Supplier\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

373
			$struct = $service->newUserCreateStruct( $item->/** @scrutinizer ignore-call */ getCode(), $email, $item->getPassword(), 'eng-GB' );
Loading history...
374
			$struct->enabled = $item->getStatus();
375
376
			$user = $service->createUser( $struct, [] );
377
			$item->setId( $user->getUserId() );
378
		}
379
380
		$dbm = $context->getDatabaseManager();
381
		$dbname = $this->getResourceName();
382
		$conn = $dbm->acquire( $dbname );
383
384
		try
385
		{
386
			$date = date( 'Y-m-d H:i:s' );
387
			$ctime = ( $item->getTimeCreated() ? $item->getTimeCreated() : $date );
388
			$billingAddress = $item->getPaymentAddress();
389
390
			$path = 'mshop/customer/manager/ezpublish/update';
391
			$stmt = $this->getCachedStatement( $conn, $path );
392
393
			$stmt->bind( 1, $billingAddress->getCompany() );
394
			$stmt->bind( 2, $billingAddress->getVatID() );
395
			$stmt->bind( 3, $billingAddress->getSalutation() );
396
			$stmt->bind( 4, $billingAddress->getTitle() );
397
			$stmt->bind( 5, $billingAddress->getFirstname() );
398
			$stmt->bind( 6, $billingAddress->getLastname() );
399
			$stmt->bind( 7, $billingAddress->getAddress1() );
400
			$stmt->bind( 8, $billingAddress->getAddress2() );
401
			$stmt->bind( 9, $billingAddress->getAddress3() );
402
			$stmt->bind( 10, $billingAddress->getPostal() );
403
			$stmt->bind( 11, $billingAddress->getCity() );
404
			$stmt->bind( 12, $billingAddress->getState() );
405
			$stmt->bind( 13, $billingAddress->getCountryId() );
406
			$stmt->bind( 14, $billingAddress->getLanguageId() );
407
			$stmt->bind( 15, $billingAddress->getTelephone() );
408
			$stmt->bind( 16, $billingAddress->getTelefax() );
409
			$stmt->bind( 17, $billingAddress->getWebsite() );
410
			$stmt->bind( 18, $item->getBirthday() );
0 ignored issues
show
Bug introduced by
The method getBirthday() does not exist on Aimeos\MShop\Common\Item\Iface. It seems like you code against a sub-type of Aimeos\MShop\Common\Item\Iface such as Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Customer\Item\Base or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Customer\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

410
			$stmt->bind( 18, $item->/** @scrutinizer ignore-call */ getBirthday() );
Loading history...
411
			$stmt->bind( 19, $item->getDateVerified() );
0 ignored issues
show
Bug introduced by
The method getDateVerified() does not exist on Aimeos\MShop\Common\Item\Iface. It seems like you code against a sub-type of Aimeos\MShop\Common\Item\Iface such as Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Customer\Item\Base or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Customer\Item\Iface or Aimeos\MShop\Customer\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

411
			$stmt->bind( 19, $item->/** @scrutinizer ignore-call */ getDateVerified() );
Loading history...
412
			$stmt->bind( 20, $date ); // Modification time
413
			$stmt->bind( 21, $context->getEditor() );
414
			$stmt->bind( 22, $ctime ); // Creation time
415
			$stmt->bind( 23, $item->getId(), \Aimeos\MW\DB\Statement\Base::PARAM_INT );
416
417
			$stmt->execute()->finish();
418
419
			$dbm->release( $conn, $dbname );
420
		}
421
		catch( \Exception $e )
422
		{
423
			$dbm->release( $conn, $dbname );
424
			throw $e;
425
		}
426
427
		$item = $this->savePropertyItems( $item, 'customer' );
428
		$item = $this->saveAddressItems( $item, 'customer' );
429
		return $this->saveListItems( $item, 'customer' );
430
	}
431
432
433
	/**
434
	 * Returns the item objects matched by the given search criteria.
435
	 *
436
	 * @param \Aimeos\MW\Criteria\Iface $search Search criteria object
437
	 * @param integer &$total Number of items that are available in total
438
	 * @return array List of items implementing \Aimeos\MShop\Customer\Item\Iface
439
	 * @throws \Aimeos\MShop\Customer\Exception If creating items failed
440
	 */
441
	public function searchItems( \Aimeos\MW\Criteria\Iface $search, array $ref = [], &$total = null )
442
	{
443
		$dbm = $this->getContext()->getDatabaseManager();
444
		$dbname = $this->getResourceName();
445
		$conn = $dbm->acquire( $dbname );
446
		$map = [];
447
448
		try
449
		{
450
			$level = \Aimeos\MShop\Locale\Manager\Base::SITE_ALL;
451
			$cfgPathSearch = 'mshop/customer/manager/ezpublish/search';
452
			$cfgPathCount = 'mshop/customer/manager/ezpublish/count';
453
			$required = array( 'customer' );
454
455
			$results = $this->searchItemsBase( $conn, $search, $cfgPathSearch, $cfgPathCount, $required, $total, $level );
456
457
			while( ( $row = $results->fetch() ) !== false )
458
			{
459
				$map[ $row['customer.id'] ] = $row;
460
				$map[ $row['customer.id'] ]['groups'] = [];
461
			}
462
463
464
			$path = 'mshop/customer/manager/ezpublish/groups';
465
			$stmt = $conn->create( $this->getGroupSql( array_keys( $map ), $path ) );
466
			$results = $stmt->execute();
467
468
			while( ( $row = $results->fetch() ) !== false ) {
469
				$map[ $row['contentobject_id'] ]['groups'][] = $row['role_id'];
470
			}
471
472
			$dbm->release( $conn, $dbname );
473
		}
474
		catch( \Exception $e )
475
		{
476
			$dbm->release( $conn, $dbname  );
477
			throw $e;
478
		}
479
480
		return $this->buildItems( $map, $ref, 'customer' );
481
	}
482
483
484
	/**
485
	 * Creates a new customer item.
486
	 *
487
	 * @param array $values List of attributes for customer item
488
	 * @param \Aimeos\MShop\Common\Lists\Item\Iface[] $listItems List of list items
489
	 * @param \Aimeos\MShop\Common\Item\Iface[] $refItems List of referenced items
490
	 * @param \Aimeos\MShop\Common\Item\Address\Iface[] $addrItems List of referenced address items
491
	 * @param \Aimeos\MShop\Common\Item\Property\Iface[] $propItems List of property items
492
	 * @return \Aimeos\MShop\Customer\Item\Iface New customer item
493
	 */
494
	protected function createItemBase( array $values = [], array $listItems = [], array $refItems = [],
495
		array $addrItems = [], array $propItems = [] )
496
	{
497
		$address = new \Aimeos\MShop\Common\Item\Address\Simple( 'customer.', $values );
498
499
		return new \Aimeos\MShop\Customer\Item\Ezpublish(
500
			$address, $values, $listItems, $refItems, $addrItems, $propItems
501
		);
502
	}
503
504
505
	/**
506
	 * Returns the SQL statement for retrieving the customer group IDs
507
	 *
508
	 * @param array $ids List of customer IDs
509
	 * @param string $cfgpath Configuration path to the SQL statement
510
	 * @return string SQL statement ready for execution
511
	 */
512
	protected function getGroupSql( array $ids, $cfgpath )
513
	{
514
		if( empty( $ids ) ) { return '1=1'; }
515
516
		$search = $this->getObject()->createSearch();
517
		$search->setConditions( $search->compare( '==', 'id', $ids ) );
518
519
		$types = array( 'id' => \Aimeos\MW\DB\Statement\Base::PARAM_INT );
520
		$translations = array( 'id' => '"contentobject_id"' );
521
522
		$cond = $search->getConditionSource( $types, $translations );
523
524
		return str_replace( ':cond', $cond, $this->getSqlConfig( $cfgpath ) );
525
	}
526
}
527