This repository was archived by the owner on Jun 1, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwoo-amz-integration.php
349 lines (266 loc) · 9.65 KB
/
woo-amz-integration.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
<?php
/**
* The plugin bootstrap file
*
* This file is read by WordPress to generate the plugin information in the plugin
* admin area. This file also includes all of the dependencies used by the plugin,
* registers the activation and deactivation functions, and defines a function
* that starts the plugin.
*
* @link https://lightyourhome.com
* @since 0.1.0
* @package Woo_Amz_Integration
*
* @wordpress-plugin
* Plugin Name: WooCommerce Amazon Integration
* Plugin URI: https://lightyourhome.com
* Description: This is a short description of what the plugin does. It's displayed in the WordPress admin area.
* Version: 0.11.0
* Author: Jim Merk
* Author URI: https://lightyourhome.com
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Text Domain: woo-amz-integration
* Domain Path: /languages
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
/**
* Currently plugin version.
* Start at version 1.0.0 and use SemVer - https://semver.org
* Rename this for your plugin and update it as you release new versions.
*/
define( 'WOO_AMZ_INTEGRATION_VERSION', '0.11.0' );
define('WOO_AMZ_PLUGIN_DIR', ABSPATH . 'wp-content/plugins/woo-amz-integration/');
define('WOO_AMZ_INV_FILE_PATH', ABSPATH . 'wp-content/uploads/amz_inventory.txt');
define('WOO_AMZ_RESPONSE_LOG', ABSPATH . 'wp-content/uploads/amz_response_log');
define('WOO_AMZ_ERROR_LOG', ABSPATH . 'wp-content/uploads/amz_error_log.txt');
define('MWS_CONFIG', plugin_dir_path( __FILE__ ) . 'includes/Config/.config.inc.php');
/**
* The code that runs during plugin activation.
* This action is documented in includes/class-woo-amz-integration-activator.php
*/
function activate_woo_amz_integration() {
require_once plugin_dir_path( __FILE__ ) . 'includes/class-woo-amz-integration-activator.php';
Woo_Amz_Integration_Activator::activate();
}
/**
* The code that runs during plugin deactivation.
* This action is documented in includes/class-woo-amz-integration-deactivator.php
*/
function deactivate_woo_amz_integration() {
require_once plugin_dir_path( __FILE__ ) . 'includes/class-woo-amz-integration-deactivator.php';
Woo_Amz_Integration_Deactivator::deactivate();
}
function tfs_create_custom_table() {
global $wpdb;
$charset_collate = $wpdb->get_charset_collate();
$tbl_name = $wpdb->prefix . 'tfs_amz_int_data';
$sql = "CREATE TABLE IF NOT EXISTS $tbl_name (
id mediumint(9) NOT NULL,
products_to_process mediumint(9) NOT NULL,
current_page VARCHAR(100) NOT NULL,
products_processed mediumint(9) NOT NULL,
completed BOOLEAN,
UNIQUE KEY id (id)
) $charset_collate;";
if ( ! function_exists('dbDelta') ) {
require_once( ABSPATH . 'wp-admin/includes/upgrade,php' );
}
add_option( $wpdb->prefix . 'tfs_amz_int_data_version', '0.1.0' );
dbDelta( $sql );
}
/**
* Activation Hooks
*/
register_activation_hook( __FILE__, 'activate_woo_amz_integration' );
register_activation_hook( __FILE__, 'tfs_create_custom_table' );
/**
* Deactivation Hooks
*/
register_deactivation_hook( __FILE__, 'deactivate_woo_amz_integration' );
/**
* The core plugin class that is used to define internationalization,
* admin-specific hooks, and public-facing site hooks.
*/
require plugin_dir_path( __FILE__ ) . 'includes/core/class-tfs-dbman.php';
/**
* The core plugin class that is used to define internationalization,
* admin-specific hooks, and public-facing site hooks.
*/
require plugin_dir_path( __FILE__ ) . 'includes/class-woo-amz-integration.php';
/**
* The class responsible for communicating with the woocommerce rest api
*/
require plugin_dir_path( __FILE__ ) . 'woo-rest-api.php';
/**
* The class responsible for interacting with the Wordpress REST API
*/
require plugin_dir_path( __FILE__ ) . 'wp-rest-api.php';
/**
* The class responsible for interacting with the Wordpress REST API
*/
require plugin_dir_path( __FILE__ ) . 'options.php';
/**
* The class responsible for handling file creation
*/
require plugin_dir_path( __FILE__ ) . 'includes/class-woo-amz-file-handler.php';
/**
* MarketplaceWebService Class responsible for exception handling
*
* @since 0.6.0
*/
require plugin_dir_path( __FILE__ ) . 'includes/MarketplaceWebService/Exception.php';
/**
* MarketplaceWebService interface
*
* @since 0.6.0
*/
require plugin_dir_path( __FILE__ ) . 'includes/MarketplaceWebService/Interface.php';
/**
* Creates mock up xml files for MarketplaceWebService responses
*
* @since 0.6.0
*/
require plugin_dir_path( __FILE__ ) . 'includes/MarketplaceWebService/Mock.php';
/**
* Model class
*
* @since 0.6.0
*/
require plugin_dir_path( __FILE__ ) . 'includes/MarketplaceWebService/Model.php';
/**
* Class that handles the type of request being sent to MarketplaceWebService
*
* @since 0.6.0
*/
require plugin_dir_path( __FILE__ ) . 'includes/MarketplaceWebService/RequestType.php';
/** TODO: DOCUMENT MODEL FILES */
/**
* Class responsible for submitting inventory feed response from MWS
*
* @since 0.6.0
*/
require plugin_dir_path( __FILE__ ) . 'includes/MarketplaceWebService/Model/SubmitFeedResponse.php';
require plugin_dir_path( __FILE__ ) . 'includes/MarketplaceWebService/Model/SubmitFeedRequest.php';
require plugin_dir_path( __FILE__ ) . 'includes/MarketplaceWebService/Model/SubmitFeedResult.php';
//require plugin_dir_path( __FILE__ ) . 'includes/MarketplaceWebService/Model/ContentType.php';
require plugin_dir_path( __FILE__ ) . 'includes/MarketplaceWebService/Model/GetFeedSubmissionListRequest.php';
require plugin_dir_path( __FILE__ ) . 'includes/MarketplaceWebService/Model/GetFeedSubmissionListResponse.php';
require plugin_dir_path( __FILE__ ) . 'includes/MarketplaceWebService/Model/GetFeedSubmissionListResult.php';
require plugin_dir_path( __FILE__ ) . 'includes/MarketplaceWebService/Model/GetFeedSubmissionResultRequest.php';
require plugin_dir_path( __FILE__ ) . 'includes/MarketplaceWebService/Model/GetFeedSubmissionResultResponse.php';
require plugin_dir_path( __FILE__ ) . 'includes/MarketplaceWebService/Model/GetFeedSubmissionResultResult.php';
/**
* MarketplaceWebService Client configuration file
*
* @since 0.6.0
*/
//require plugin_dir_path( __FILE__ ) . 'includes/MarketplaceWebService/Feed/.config.inc.php';
/** TODO: Remove old sample files when no longer needed */
/**
* Class responsible for submitting inventory feed to MarketplaceWebService
*
* @since 0.6.0
*/
//require plugin_dir_path( __FILE__ ) . 'includes/MarketplaceWebService/Feed/SubmitFeedphp';
/**
* Class responsible for submitting inventory feed to MarketplaceWebService
*
* @since 0.6.0
*/
//require plugin_dir_path( __FILE__ ) . 'includes/MarketplaceWebService/Feed/GetFeedSubmissionList.php';
/**
* Class responsible for submitting inventory feed to MarketplaceWebService
*
* @since 0.6.0
*/
//require plugin_dir_path( __FILE__ ) . 'includes/MarketplaceWebService/Feed/GetFeedSubmissionResult.php';
/**
* Class responsible for submitting inventory feed to MarketplaceWebService
*
* @since 0.6.0
*/
require plugin_dir_path( __FILE__ ) . 'includes/MarketplaceWebService/Feed/tfs-class-mws-feed.php';
/**
* Class responsible for registering and deregistering destinations for the MWS Subscription service
*
* @since 0.11.0
*/
require plugin_dir_path( __FILE__ ) . 'includes/MWSSubscriptionsService/Destination/class-mws-destination.php';
/**
* Class responsible for creating and updating MWS notification subscriptions
*
* @since 0.11.0
*/
require plugin_dir_path( __FILE__ ) . 'includes/MWSSubscriptionsService/Subscriptions/class-mws-subscriptions.php';
/**
* Class responsible for creating and updating MWS notification subscriptions
*
* @since 0.11.0
*/
require plugin_dir_path( __FILE__ ) . 'includes/MWSSubscriptionsService/Notifications/class-test-notifications.php';
/**
* Enqueue admin scripts
*
* @since 0.3.0
*/
function tfs_enqueue_scripts() {
wp_register_script('tfs_woo_amz_int', site_url('/wp-content/plugins/woo-amz-integration/admin/js/woo-amz-integration-admin.js?07032020'), true);
wp_enqueue_script( 'tfs_woo_amz_int' );
}
add_action( 'admin_enqueue_scripts', 'tfs_enqueue_scripts');
/**
* Adds processing query string for use with CRON
*
* @since 0.3.0
* @return boolean - whether or not the query string has been hit
*/
function tfs_processing_script_query_string() {
$query_string = $_SERVER['QUERY_STRING'];
if ( $query_string === '0800fc577294c34e0b28ad2839435945' ) {
return true;
} else {
return;
}
}
/**
* Adds trigger query string to start feed execution with CRON
*
* @since 0.3.0
* @return boolean - whether or not the query string has been hit
*/
function tfs_trigger_script_query_string() {
$query_string = $_SERVER['QUERY_STRING'];
if ( $query_string === '962e52217134c1f7556fefeb1bfa1e35' ) {
return true;
} else {
return;
}
}
/**
* Begins execution of the plugin.
*
* Since everything within the plugin is registered via hooks,
* then kicking off the plugin from this point in the file does
* not affect the page life cycle.
*
* @since 0.1.0
*/
function run_woo_amz_integration() {
if ( tfs_trigger_script_query_string() == true ) {
$plugin = new Woo_Amz_Integration();
$plugin->run();
// $init_woo_api = new Woo_REST_API();
//$init_reg_destination = new MWS_Destination( 'RegisterDestination' );
//$init = new MWS_Subscriptions( 'CreateSubscription' );
//$init = new MWS_Subscriptions( 'UpdateSubscription' );
$init = new MWS_Test_Notifications( 'TestInventoryNotification' );
}
if ( tfs_processing_script_query_string() == true ) {
Woo_REST_API::tfs_restart_product_data_feed();
}
}
run_woo_amz_integration();