1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Metaways Infosystems GmbH, 2014 |
6
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2018 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
namespace Aimeos\MW\Setup\Task; |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Adds demo records to customer tables. |
15
|
|
|
*/ |
16
|
|
|
class DemoAddCustomerData extends \Aimeos\MW\Setup\Task\MShopAddDataAbstract |
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 array( 'MShopAddTypeDataDefault', 'MShopAddCodeDataDefault' ); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Returns the list of task names which depends on this task. |
31
|
|
|
* |
32
|
|
|
* @return array List of task names |
33
|
|
|
*/ |
34
|
|
|
public function getPostDependencies() |
35
|
|
|
{ |
36
|
|
|
return []; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Insert service data. |
42
|
|
|
*/ |
43
|
|
|
public function migrate() |
44
|
|
|
{ |
45
|
|
|
$this->msg( 'Processing customer demo data', 0 ); |
46
|
|
|
|
47
|
|
|
$context = $this->getContext(); |
48
|
|
|
$value = $context->getConfig()->get( 'setup/default/demo', '' ); |
49
|
|
|
|
50
|
|
|
if( $value === '' ) |
51
|
|
|
{ |
52
|
|
|
$this->status( 'OK' ); |
53
|
|
|
return; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
|
57
|
|
|
$manager = \Aimeos\MShop::create( $context, 'customer' ); |
58
|
|
|
|
59
|
|
|
$search = $manager->createSearch(); |
60
|
|
|
$search->setConditions( $search->compare( '=~', 'customer.code', 'demo-' ) ); |
61
|
|
|
$services = $manager->searchItems( $search ); |
62
|
|
|
|
63
|
|
|
$manager->deleteItems( array_keys( $services ) ); |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
if( $value === '1' ) |
67
|
|
|
{ |
68
|
|
|
$ds = DIRECTORY_SEPARATOR; |
69
|
|
|
$path = __DIR__ . $ds . 'data' . $ds . 'demo-customer.php'; |
70
|
|
|
|
71
|
|
|
if( ( $data = include( $path ) ) == false ) { |
72
|
|
|
throw new \Aimeos\MShop\Exception( sprintf( 'No file "%1$s" found for customer domain', $path ) ); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
$this->saveCustomerItems( $data ); |
76
|
|
|
|
77
|
|
|
$this->status( 'added' ); |
78
|
|
|
} |
79
|
|
|
else |
80
|
|
|
{ |
81
|
|
|
$this->status( 'removed' ); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Stores the customer items |
88
|
|
|
* |
89
|
|
|
* @param array $data List of arrays containing the customer properties |
90
|
|
|
*/ |
91
|
|
|
protected function saveCustomerItems( array $data ) |
92
|
|
|
{ |
93
|
|
|
$manager = \Aimeos\MShop::create( $this->getContext(), 'customer' ); |
94
|
|
|
|
95
|
|
|
foreach( $data as $entry ) |
96
|
|
|
{ |
97
|
|
|
$item = $manager->createItem(); |
98
|
|
|
$item->setCode( $entry['code'] ); |
99
|
|
|
$item->setLabel( $entry['label'] ); |
100
|
|
|
$item->setBirthday( $entry['birthday'] ); |
|
|
|
|
101
|
|
|
$item->setPassword( $entry['password'] ); |
|
|
|
|
102
|
|
|
$item->setStatus( $entry['status'] ); |
103
|
|
|
$item->setDateVerified( $entry['vtime'] ); |
|
|
|
|
104
|
|
|
|
105
|
|
|
$addr = $item->getPaymentAddress(); |
|
|
|
|
106
|
|
|
$addr->setTitle( $entry['title'] ); |
107
|
|
|
$addr->setSalutation( $entry['salutation'] ); |
108
|
|
|
$addr->setCompany( $entry['company'] ); |
109
|
|
|
$addr->setVatID( $entry['vatid'] ); |
110
|
|
|
$addr->setFirstname( $entry['firstname'] ); |
111
|
|
|
$addr->setLastname( $entry['lastname'] ); |
112
|
|
|
$addr->setAddress1( $entry['address1'] ); |
113
|
|
|
$addr->setAddress2( $entry['address2'] ); |
114
|
|
|
$addr->setAddress3( $entry['address3'] ); |
115
|
|
|
$addr->setPostal( $entry['postal'] ); |
116
|
|
|
$addr->setCity( $entry['city'] ); |
117
|
|
|
$addr->setState( $entry['state'] ); |
118
|
|
|
$addr->setLanguageId( $entry['langid'] ); |
119
|
|
|
$addr->setCountryId( $entry['countryid'] ); |
120
|
|
|
$addr->setTelephone( $entry['telephone'] ); |
121
|
|
|
$addr->setEmail( $entry['email'] ); |
122
|
|
|
$addr->setTelefax( $entry['telefax'] ); |
123
|
|
|
$addr->setWebsite( $entry['website'] ); |
124
|
|
|
|
125
|
|
|
$manager->saveItem( $item ); |
126
|
|
|
|
127
|
|
|
if( isset( $entry['delivery'] ) ) { |
128
|
|
|
$this->saveAddressItems( $entry['delivery'], $item->getId() ); |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* Stores the customer items |
136
|
|
|
* |
137
|
|
|
* @param array $data List of arrays containing the customer properties |
138
|
|
|
* @param string $id Unique ID of the customer item |
139
|
|
|
*/ |
140
|
|
|
protected function saveAddressItems( array $data, $id ) |
141
|
|
|
{ |
142
|
|
|
$manager = \Aimeos\MShop::create( $this->getContext(), 'customer/address' ); |
143
|
|
|
|
144
|
|
|
foreach( $data as $entry ) |
145
|
|
|
{ |
146
|
|
|
$addr = $manager->createItem(); |
147
|
|
|
$addr->setParentId( $id ); |
|
|
|
|
148
|
|
|
$addr->setTitle( $entry['title'] ); |
|
|
|
|
149
|
|
|
$addr->setSalutation( $entry['salutation'] ); |
|
|
|
|
150
|
|
|
$addr->setCompany( $entry['company'] ); |
|
|
|
|
151
|
|
|
$addr->setVatID( $entry['vatid'] ); |
|
|
|
|
152
|
|
|
$addr->setFirstname( $entry['firstname'] ); |
|
|
|
|
153
|
|
|
$addr->setLastname( $entry['lastname'] ); |
|
|
|
|
154
|
|
|
$addr->setAddress1( $entry['address1'] ); |
|
|
|
|
155
|
|
|
$addr->setAddress2( $entry['address2'] ); |
|
|
|
|
156
|
|
|
$addr->setAddress3( $entry['address3'] ); |
|
|
|
|
157
|
|
|
$addr->setPostal( $entry['postal'] ); |
|
|
|
|
158
|
|
|
$addr->setCity( $entry['city'] ); |
|
|
|
|
159
|
|
|
$addr->setState( $entry['state'] ); |
|
|
|
|
160
|
|
|
$addr->setLanguageId( $entry['langid'] ); |
|
|
|
|
161
|
|
|
$addr->setCountryId( $entry['countryid'] ); |
|
|
|
|
162
|
|
|
$addr->setTelephone( $entry['telephone'] ); |
|
|
|
|
163
|
|
|
$addr->setEmail( $entry['email'] ); |
|
|
|
|
164
|
|
|
$addr->setTelefax( $entry['telefax'] ); |
|
|
|
|
165
|
|
|
$addr->setWebsite( $entry['website'] ); |
|
|
|
|
166
|
|
|
|
167
|
|
|
$manager->saveItem( $addr ); |
168
|
|
|
} |
169
|
|
|
} |
170
|
|
|
} |
171
|
|
|
|
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.