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
|
|
|
public function initialize(array $config) |
44
|
|
|
{ |
45
|
|
|
parent::initialize($config); |
46
|
|
|
|
47
|
|
|
//$this->table('shops'); |
|
|
|
|
48
|
|
|
$this->displayField('myshopify_domain'); |
49
|
|
|
//$this->primaryKey('id'); |
|
|
|
|
50
|
|
|
|
51
|
|
|
$this->hasMany( |
52
|
|
|
'AccessTokens', |
53
|
|
|
[ |
54
|
|
|
'className' => 'Multidimensional/Cakephpify.AccessTokens' |
55
|
|
|
] |
56
|
|
|
); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Default validation rules. |
61
|
|
|
* |
62
|
|
|
* @param \Cake\Validation\Validator $validator Validator instance. |
63
|
|
|
* @return \Cake\Validation\Validator |
64
|
|
|
*/ |
65
|
|
|
public function validationDefault(Validator $validator) |
66
|
|
|
{ |
67
|
|
|
$validator |
68
|
|
|
->integer('id') |
69
|
|
|
->allowEmpty('id', 'create'); |
70
|
|
|
|
71
|
|
|
$validator |
72
|
|
|
->requirePresence('domain', 'create') |
73
|
|
|
->notEmpty('domain'); |
74
|
|
|
|
75
|
|
|
$validator |
76
|
|
|
->requirePresence('name', 'create') |
77
|
|
|
->notEmpty('name'); |
78
|
|
|
|
79
|
|
|
$validator |
80
|
|
|
->email('email') |
81
|
|
|
->requirePresence('email', 'create') |
82
|
|
|
->notEmpty('email'); |
83
|
|
|
|
84
|
|
|
$validator |
85
|
|
|
->requirePresence('shop_owner', 'create') |
86
|
|
|
->notEmpty('shop_owner'); |
87
|
|
|
|
88
|
|
|
$validator |
89
|
|
|
->requirePresence('address1', 'create') |
90
|
|
|
->notEmpty('address1'); |
91
|
|
|
|
92
|
|
|
$validator |
93
|
|
|
->requirePresence('address2', 'create') |
94
|
|
|
->notEmpty('address2'); |
95
|
|
|
|
96
|
|
|
$validator |
97
|
|
|
->requirePresence('city', 'create') |
98
|
|
|
->notEmpty('city'); |
99
|
|
|
|
100
|
|
|
$validator |
101
|
|
|
->requirePresence('province_code', 'create') |
102
|
|
|
->notEmpty('province_code'); |
103
|
|
|
|
104
|
|
|
$validator |
105
|
|
|
->requirePresence('province', 'create') |
106
|
|
|
->notEmpty('province'); |
107
|
|
|
|
108
|
|
|
$validator |
109
|
|
|
->requirePresence('zip', 'create') |
110
|
|
|
->notEmpty('zip'); |
111
|
|
|
|
112
|
|
|
$validator |
113
|
|
|
->requirePresence('country', 'create') |
114
|
|
|
->notEmpty('country'); |
115
|
|
|
|
116
|
|
|
$validator |
117
|
|
|
->requirePresence('country_code', 'create') |
118
|
|
|
->notEmpty('country_code'); |
119
|
|
|
|
120
|
|
|
$validator |
121
|
|
|
->requirePresence('country_name', 'create') |
122
|
|
|
->notEmpty('country_name'); |
123
|
|
|
|
124
|
|
|
$validator |
125
|
|
|
->allowEmpty('source'); |
126
|
|
|
|
127
|
|
|
$validator |
128
|
|
|
->requirePresence('phone', 'create') |
129
|
|
|
->notEmpty('phone'); |
130
|
|
|
|
131
|
|
|
$validator |
132
|
|
|
->dateTime('created_at') |
133
|
|
|
->requirePresence('created_at', 'create') |
134
|
|
|
->notEmpty('created_at'); |
135
|
|
|
|
136
|
|
|
$validator |
137
|
|
|
->dateTime('updated_at') |
138
|
|
|
->requirePresence('updated_at', 'create') |
139
|
|
|
->notEmpty('updated_at'); |
140
|
|
|
|
141
|
|
|
$validator |
142
|
|
|
->requirePresence('customer_email', 'create') |
143
|
|
|
->allowEmpty('customer_email'); |
144
|
|
|
|
145
|
|
|
$validator |
146
|
|
|
->decimal('latitude') |
147
|
|
|
->requirePresence('latitude', 'create') |
148
|
|
|
->notEmpty('latitude'); |
149
|
|
|
|
150
|
|
|
$validator |
151
|
|
|
->decimal('longitude') |
152
|
|
|
->requirePresence('longitude', 'create') |
153
|
|
|
->notEmpty('longitude'); |
154
|
|
|
|
155
|
|
|
$validator |
156
|
|
|
->requirePresence('primary_locale', 'create') |
157
|
|
|
->notEmpty('primary_locale'); |
158
|
|
|
|
159
|
|
|
$validator |
160
|
|
|
->requirePresence('currency', 'create') |
161
|
|
|
->notEmpty('currency'); |
162
|
|
|
|
163
|
|
|
$validator |
164
|
|
|
->requirePresence('iana_timezone', 'create') |
165
|
|
|
->notEmpty('iana_timezone'); |
166
|
|
|
|
167
|
|
|
$validator |
168
|
|
|
->requirePresence('money_format', 'create') |
169
|
|
|
->notEmpty('money_format'); |
170
|
|
|
|
171
|
|
|
$validator |
172
|
|
|
->requirePresence('money_with_currency_format', 'create') |
173
|
|
|
->notEmpty('money_with_currency_format'); |
174
|
|
|
|
175
|
|
|
$validator |
176
|
|
|
->boolean('taxes_included') |
177
|
|
|
->allowEmpty('taxes_included'); |
178
|
|
|
|
179
|
|
|
$validator |
180
|
|
|
->boolean('tax_shipping') |
181
|
|
|
->allowEmpty('tax_shipping'); |
182
|
|
|
|
183
|
|
|
$validator |
184
|
|
|
->boolean('county_taxes') |
185
|
|
|
->allowEmpty('county_taxes'); |
186
|
|
|
|
187
|
|
|
$validator |
188
|
|
|
->requirePresence('plan_display_name', 'create') |
189
|
|
|
->notEmpty('plan_display_name'); |
190
|
|
|
|
191
|
|
|
$validator |
192
|
|
|
->requirePresence('plan_name', 'create') |
193
|
|
|
->notEmpty('plan_name'); |
194
|
|
|
|
195
|
|
|
$validator |
196
|
|
|
->boolean('has_discounts') |
197
|
|
|
->allowEmpty('has_discounts'); |
198
|
|
|
|
199
|
|
|
$validator |
200
|
|
|
->boolean('has_gift_cards') |
201
|
|
|
->allowEmpty('has_gift_cards'); |
202
|
|
|
|
203
|
|
|
$validator |
204
|
|
|
->requirePresence('myshopify_domain', 'create') |
205
|
|
|
->notEmpty('myshopify_domain'); |
206
|
|
|
|
207
|
|
|
$validator |
208
|
|
|
->allowEmpty('google_apps_domain'); |
209
|
|
|
|
210
|
|
|
$validator |
211
|
|
|
->allowEmpty('google_apps_login_enabled'); |
212
|
|
|
|
213
|
|
|
$validator |
214
|
|
|
->requirePresence('money_in_emails_format', 'create') |
215
|
|
|
->notEmpty('money_in_emails_format'); |
216
|
|
|
|
217
|
|
|
$validator |
218
|
|
|
->requirePresence('money_with_currency_in_emails_format', 'create') |
219
|
|
|
->notEmpty('money_with_currency_in_emails_format'); |
220
|
|
|
|
221
|
|
|
$validator |
222
|
|
|
->boolean('eligible_for_payments') |
223
|
|
|
->allowEmpty('eligible_for_payments'); |
224
|
|
|
|
225
|
|
|
$validator |
226
|
|
|
->boolean('requires_extra_payments_agreement') |
227
|
|
|
->allowEmpty('requires_extra_payments_agreement'); |
228
|
|
|
|
229
|
|
|
$validator |
230
|
|
|
->boolean('password_enabled') |
231
|
|
|
->allowEmpty('password_enabled'); |
232
|
|
|
|
233
|
|
|
$validator |
234
|
|
|
->boolean('has_storefront') |
235
|
|
|
->allowEmpty('has_storefront'); |
236
|
|
|
|
237
|
|
|
$validator |
238
|
|
|
->boolean('eligible_for_card_reader_giveaway') |
239
|
|
|
->allowEmpty('eligible_for_card_reader_giveaway'); |
240
|
|
|
|
241
|
|
|
$validator |
242
|
|
|
->boolean('finances') |
243
|
|
|
->allowEmpty('finances'); |
244
|
|
|
|
245
|
|
|
$validator |
246
|
|
|
->boolean('setup_required') |
247
|
|
|
->allowEmpty('setup_required'); |
248
|
|
|
|
249
|
|
|
$validator |
250
|
|
|
->boolean('force_ssl') |
251
|
|
|
->allowEmpty('force_ssl'); |
252
|
|
|
|
253
|
|
|
return $validator; |
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
/** |
257
|
|
|
* Returns a rules checker object that will be used for validating |
258
|
|
|
* application integrity. |
259
|
|
|
* |
260
|
|
|
* @param \Cake\ORM\RulesChecker $rules The rules object to be modified. |
261
|
|
|
* @return \Cake\ORM\RulesChecker |
262
|
|
|
*/ |
263
|
|
|
public function buildRules(RulesChecker $rules) |
264
|
|
|
{ |
265
|
|
|
$rules->add($rules->isUnique(['email'])); |
266
|
|
|
|
267
|
|
|
return $rules; |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
|
271
|
|
|
public function findByShopDomain(Query $query, array $options) |
|
|
|
|
272
|
|
|
{ |
273
|
|
|
$shopDomain = $options['domain']; |
274
|
|
|
|
275
|
|
|
return $query->where(['myshopify_domain' => $shopDomain]); |
276
|
|
|
} |
277
|
|
|
|
278
|
|
|
|
279
|
|
|
} |
280
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.