1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* CakePHPify : CakePHP Plugin for Shopify API Authentication |
4
|
|
|
* Copyright (c) Multidimension.al (http://multidimension.al) |
5
|
|
|
* Github : https://github.com/multidimension-al/cakephpify |
6
|
|
|
* |
7
|
|
|
* Licensed under The MIT License |
8
|
|
|
* For full copyright and license information, please see the LICENSE file |
9
|
|
|
* Redistributions of files must retain the above copyright notice. |
10
|
|
|
* |
11
|
|
|
* @copyright (c) Multidimension.al (http://multidimension.al) |
12
|
|
|
* @link https://github.com/multidimension-al/cakephpify CakePHPify Github |
13
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT License |
14
|
|
|
*/ |
15
|
|
|
|
16
|
|
|
namespace Multidimensional\Cakephpify\Model\Table; |
17
|
|
|
|
18
|
|
|
use Cake\ORM\Query; |
19
|
|
|
use Cake\ORM\RulesChecker; |
20
|
|
|
use Cake\ORM\Table; |
21
|
|
|
use Cake\Validation\Validator; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Shops Model |
25
|
|
|
* |
26
|
|
|
* @method \App\Model\Entity\Shop get($primaryKey, $options = []) |
27
|
|
|
* @method \App\Model\Entity\Shop newEntity($data = null, array $options = []) |
28
|
|
|
* @method \App\Model\Entity\Shop[] newEntities(array $data, array $options = []) |
29
|
|
|
* @method \App\Model\Entity\Shop|bool save(\Cake\Datasource\EntityInterface $entity, $options = []) |
30
|
|
|
* @method \App\Model\Entity\Shop patchEntity(\Cake\Datasource\EntityInterface $entity, array $data, array $options = []) |
31
|
|
|
* @method \App\Model\Entity\Shop[] patchEntities($entities, array $data, array $options = []) |
32
|
|
|
* @method \App\Model\Entity\Shop findOrCreate($search, callable $callback = null) |
33
|
|
|
*/ |
34
|
|
|
class ShopsTable extends Table |
35
|
|
|
{ |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Initialize method |
39
|
|
|
* |
40
|
|
|
* @param array $config The configuration for the Table. |
41
|
|
|
* @return void |
42
|
|
|
*/ |
43
|
18 |
|
public function initialize(array $config) |
44
|
|
|
{ |
45
|
18 |
|
parent::initialize($config); |
46
|
|
|
|
47
|
18 |
|
$this->displayField('myshopify_domain'); |
48
|
18 |
|
$this->hasMany( |
49
|
18 |
|
'AccessTokens', |
50
|
|
|
[ |
51
|
|
|
'className' => 'Multidimensional/Cakephpify.AccessTokens' |
52
|
18 |
|
] |
53
|
18 |
|
); |
54
|
18 |
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Default validation rules. |
58
|
|
|
* |
59
|
|
|
* @param \Cake\Validation\Validator $validator Validator instance. |
60
|
|
|
* @return \Cake\Validation\Validator |
61
|
|
|
*/ |
62
|
|
|
public function validationDefault(Validator $validator) |
63
|
|
|
{ |
64
|
|
|
$validator |
65
|
|
|
->integer('id') |
66
|
|
|
->allowEmpty('id', 'create'); |
67
|
|
|
|
68
|
|
|
$validator |
69
|
|
|
->requirePresence('domain', 'create') |
70
|
|
|
->notEmpty('domain'); |
71
|
|
|
|
72
|
|
|
$validator |
73
|
|
|
->requirePresence('name', 'create') |
74
|
|
|
->notEmpty('name'); |
75
|
|
|
|
76
|
|
|
$validator |
77
|
|
|
->email('email') |
78
|
|
|
->requirePresence('email', 'create') |
79
|
|
|
->notEmpty('email'); |
80
|
|
|
|
81
|
|
|
$validator |
82
|
|
|
->requirePresence('shop_owner', 'create') |
83
|
|
|
->notEmpty('shop_owner'); |
84
|
|
|
|
85
|
|
|
$validator |
86
|
|
|
->requirePresence('address1', 'create') |
87
|
|
|
->notEmpty('address1'); |
88
|
|
|
|
89
|
|
|
$validator |
90
|
|
|
->requirePresence('address2', 'create') |
91
|
|
|
->notEmpty('address2'); |
92
|
|
|
|
93
|
|
|
$validator |
94
|
|
|
->requirePresence('city', 'create') |
95
|
|
|
->notEmpty('city'); |
96
|
|
|
|
97
|
|
|
$validator |
98
|
|
|
->requirePresence('province_code', 'create') |
99
|
|
|
->notEmpty('province_code'); |
100
|
|
|
|
101
|
|
|
$validator |
102
|
|
|
->requirePresence('province', 'create') |
103
|
|
|
->notEmpty('province'); |
104
|
|
|
|
105
|
|
|
$validator |
106
|
|
|
->requirePresence('zip', 'create') |
107
|
|
|
->notEmpty('zip'); |
108
|
|
|
|
109
|
|
|
$validator |
110
|
|
|
->requirePresence('country', 'create') |
111
|
|
|
->notEmpty('country'); |
112
|
|
|
|
113
|
|
|
$validator |
114
|
|
|
->requirePresence('country_code', 'create') |
115
|
|
|
->notEmpty('country_code'); |
116
|
|
|
|
117
|
|
|
$validator |
118
|
|
|
->requirePresence('country_name', 'create') |
119
|
|
|
->notEmpty('country_name'); |
120
|
|
|
|
121
|
|
|
$validator |
122
|
|
|
->allowEmpty('source'); |
123
|
|
|
|
124
|
|
|
$validator |
125
|
|
|
->requirePresence('phone', 'create') |
126
|
|
|
->notEmpty('phone'); |
127
|
|
|
|
128
|
|
|
$validator |
129
|
|
|
->dateTime('created_at') |
130
|
|
|
->requirePresence('created_at', 'create') |
131
|
|
|
->notEmpty('created_at'); |
132
|
|
|
|
133
|
|
|
$validator |
134
|
|
|
->dateTime('updated_at') |
135
|
|
|
->requirePresence('updated_at', 'create') |
136
|
|
|
->notEmpty('updated_at'); |
137
|
|
|
|
138
|
|
|
$validator |
139
|
|
|
->requirePresence('customer_email', 'create') |
140
|
|
|
->allowEmpty('customer_email'); |
141
|
|
|
|
142
|
|
|
$validator |
143
|
|
|
->decimal('latitude') |
144
|
|
|
->requirePresence('latitude', 'create') |
145
|
|
|
->notEmpty('latitude'); |
146
|
|
|
|
147
|
|
|
$validator |
148
|
|
|
->decimal('longitude') |
149
|
|
|
->requirePresence('longitude', 'create') |
150
|
|
|
->notEmpty('longitude'); |
151
|
|
|
|
152
|
|
|
$validator |
153
|
|
|
->requirePresence('primary_locale', 'create') |
154
|
|
|
->notEmpty('primary_locale'); |
155
|
|
|
|
156
|
|
|
$validator |
157
|
|
|
->requirePresence('currency', 'create') |
158
|
|
|
->notEmpty('currency'); |
159
|
|
|
|
160
|
|
|
$validator |
161
|
|
|
->requirePresence('iana_timezone', 'create') |
162
|
|
|
->notEmpty('iana_timezone'); |
163
|
|
|
|
164
|
|
|
$validator |
165
|
|
|
->requirePresence('money_format', 'create') |
166
|
|
|
->notEmpty('money_format'); |
167
|
|
|
|
168
|
|
|
$validator |
169
|
|
|
->requirePresence('money_with_currency_format', 'create') |
170
|
|
|
->notEmpty('money_with_currency_format'); |
171
|
|
|
|
172
|
|
|
$validator |
173
|
|
|
->boolean('taxes_included') |
174
|
|
|
->allowEmpty('taxes_included'); |
175
|
|
|
|
176
|
|
|
$validator |
177
|
|
|
->boolean('tax_shipping') |
178
|
|
|
->allowEmpty('tax_shipping'); |
179
|
|
|
|
180
|
|
|
$validator |
181
|
|
|
->boolean('county_taxes') |
182
|
|
|
->allowEmpty('county_taxes'); |
183
|
|
|
|
184
|
|
|
$validator |
185
|
|
|
->requirePresence('plan_display_name', 'create') |
186
|
|
|
->notEmpty('plan_display_name'); |
187
|
|
|
|
188
|
|
|
$validator |
189
|
|
|
->requirePresence('plan_name', 'create') |
190
|
|
|
->notEmpty('plan_name'); |
191
|
|
|
|
192
|
|
|
$validator |
193
|
|
|
->boolean('has_discounts') |
194
|
|
|
->allowEmpty('has_discounts'); |
195
|
|
|
|
196
|
|
|
$validator |
197
|
|
|
->boolean('has_gift_cards') |
198
|
|
|
->allowEmpty('has_gift_cards'); |
199
|
|
|
|
200
|
|
|
$validator |
201
|
|
|
->requirePresence('myshopify_domain', 'create') |
202
|
|
|
->notEmpty('myshopify_domain'); |
203
|
|
|
|
204
|
|
|
$validator |
205
|
|
|
->allowEmpty('google_apps_domain'); |
206
|
|
|
|
207
|
|
|
$validator |
208
|
|
|
->allowEmpty('google_apps_login_enabled'); |
209
|
|
|
|
210
|
|
|
$validator |
211
|
|
|
->requirePresence('money_in_emails_format', 'create') |
212
|
|
|
->notEmpty('money_in_emails_format'); |
213
|
|
|
|
214
|
|
|
$validator |
215
|
|
|
->requirePresence('money_with_currency_in_emails_format', 'create') |
216
|
|
|
->notEmpty('money_with_currency_in_emails_format'); |
217
|
|
|
|
218
|
|
|
$validator |
219
|
|
|
->boolean('eligible_for_payments') |
220
|
|
|
->allowEmpty('eligible_for_payments'); |
221
|
|
|
|
222
|
|
|
$validator |
223
|
|
|
->boolean('requires_extra_payments_agreement') |
224
|
|
|
->allowEmpty('requires_extra_payments_agreement'); |
225
|
|
|
|
226
|
|
|
$validator |
227
|
|
|
->boolean('password_enabled') |
228
|
|
|
->allowEmpty('password_enabled'); |
229
|
|
|
|
230
|
|
|
$validator |
231
|
|
|
->boolean('has_storefront') |
232
|
|
|
->allowEmpty('has_storefront'); |
233
|
|
|
|
234
|
|
|
$validator |
235
|
|
|
->boolean('eligible_for_card_reader_giveaway') |
236
|
|
|
->allowEmpty('eligible_for_card_reader_giveaway'); |
237
|
|
|
|
238
|
|
|
$validator |
239
|
|
|
->boolean('finances') |
240
|
|
|
->allowEmpty('finances'); |
241
|
|
|
|
242
|
|
|
$validator |
243
|
|
|
->boolean('setup_required') |
244
|
|
|
->allowEmpty('setup_required'); |
245
|
|
|
|
246
|
|
|
$validator |
247
|
|
|
->boolean('force_ssl') |
248
|
|
|
->allowEmpty('force_ssl'); |
249
|
|
|
|
250
|
|
|
return $validator; |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
/** |
254
|
|
|
* Returns a rules checker object that will be used for validating |
255
|
|
|
* application integrity. |
256
|
|
|
* |
257
|
|
|
* @param \Cake\ORM\RulesChecker $rules The rules object to be modified. |
258
|
|
|
* @return \Cake\ORM\RulesChecker |
259
|
|
|
*/ |
260
|
|
|
public function buildRules(RulesChecker $rules) |
261
|
|
|
{ |
262
|
|
|
$rules->add($rules->isUnique(['email'])); |
263
|
|
|
|
264
|
|
|
return $rules; |
265
|
|
|
} |
266
|
|
|
|
267
|
|
|
/** |
268
|
|
|
* @param Query $query |
|
|
|
|
269
|
|
|
* @param array $options |
|
|
|
|
270
|
|
|
* @return Query |
|
|
|
|
271
|
|
|
*/ |
|
|
|
|
272
|
6 |
|
public function findShopDomain(Query $query, array $options) |
273
|
|
|
{ |
274
|
6 |
|
$shopDomain = $options['domain']; |
275
|
|
|
|
276
|
6 |
|
return $query->where(['myshopify_domain' => $shopDomain]); |
277
|
|
|
} |
278
|
|
|
} |
279
|
|
|
|