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 pathoptions.php
200 lines (141 loc) · 5.62 KB
/
options.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
<?php
/**
* Register and Render the WooCommerce Amazon Integration Plugin
* Menu and Settings Pages
*
* @since v0.3.0
* @version 0.5.0
*/
defined( 'ABSPATH' ) or die( 'You do not have sufficient permissions to access this page.' );
class Woo_Amz_Integration_Settings_Page {
/**
* Holds the values to be used in the fields callbacks
*/
private static $woo_amz_int_options;
public function __construct() {
add_action( 'admin_menu', array( $this, 'tfs_add_woo_amz_menu' ) );
add_action( 'admin_init', array( $this, 'tfs_register_woo_amz_settings' ) );
$this->tfs_get_form_values();
}
public static function tfs_get_form_values() {
if ( self::$woo_amz_int_options['enable_feed'] == 1 ) {
//Woo_REST_API::tfs_get_product_data();
}
}
/**
* Get the current options for use with the plugin add on classes
*
* @since 0.3.0
* @return array - options
*/
public static function get_inventory_tools_options() {
return get_option('inventory_tools_settings');
}
/**
* Adds a top level menu page for the plugin to the admin menu
*
* @since 0.3.0
*/
public function tfs_add_woo_amz_menu() {
add_menu_page('AMZ FEED', 'AMZ FEED', 'manage_options', 'tfs-woo-amz-integration', array( $this, 'tfs_render_woo_amz_integration_settings_page' ) );
}
/**
* Renders the settings page
*
* @since 0.3.0
*/
public function tfs_render_woo_amz_integration_settings_page() {
//set the options property
self::$woo_amz_int_options = get_option('woo_amz_int_settings');
$dbman = new TFS_DB_MAN();
$download_status = $dbman->tfs_check_product_feed_download_status();
?>
<h1>WooCommerce Amazon Integration Settings</h1>
<?php if ( Woo_Amz_File_Handler::tfs_check_if_inv_file_exists() ) : ?>
<div class="notice is-dismissable notice-info">
<p>
<strong><?php _e( 'An Inventory File Currently Exists. ' ); ?></strong>
<?php _e( 'You can create a new one below.', 'lightyourhome.com' ); ?>
</p>
</div>
<?php else : ?>
<div class="notice is-dismissable notice-error">
<p><?php _e( 'An Inventory File Does Not Currently Exist. You can create a new one below.', 'lightyourhome.com' ); ?></p>
</div>
<?php endif; ?>
<?php if ( $download_status !== NULL && $download_status->products_processed < $download_status->products_to_process ) : ?>
<div class="notice is-dismissable notice-error">
<p>
<strong>
<?php _e( 'The last feed run did not finish. ' ); ?>
</strong>
<?php _e('Click "Continue Feed" to continue the last feed, or "Restart Feed" to restart it.'); ?>
</p>
</div>
<?php endif; ?>
<div id="feed-progress"></div>
<div id="feed-status"><img id="ajax-loader" src="<?php echo site_url('/wp-content/plugins/woo-amz-integration/assets/images/ajax-loader.gif'); ?>"><div id="feed-status-text"></div></div>
<div id="feed-warning"><strong>The feed is currently running. Please do not close or refresh this page.</strong></div>
<div id="feed-warning-amz" style="display: none;"><strong>The feed is currently being submitted and processed by Amazon. Please do not close or refresh this page.</strong></div>
<br />
<form id="woo-amz-admin-settings-form" action="options.php" method="post">
<?php
settings_fields( 'woo-amz-integration' );
do_settings_sections( 'woo-amz-integration' ); ?>
<input name="submit" class="button button-primary" type="submit" value="<?php esc_attr_e( 'Save Settings' ); ?>" />
<?php if ( $download_status !== NULL && $download_status->products_processed < $download_status->products_to_process ) : ?>
<input id="feed_continue" name="submit" class="button button-primary" type="button" value="<?php esc_attr_e( 'Continue Feed' ); ?>" />
<?php endif; ?>
<input id="feed_submit" name="submit" class="button button-primary" type="button" value="<?php esc_attr_e( 'Create New Feed' ); ?>" />
<a href="<?php echo site_url('/wp-content/uploads/amz_inventory.txt'); ?>" class="button button-primary" download>Download Inventory File</a>
<input id="send_inventory" name="submit" class="button button-primary" type="button" value="<?php esc_attr_e( 'Send Inventory to Amazon' ); ?>" />
</form>
<?php
}
/**
* Adds the plugin settings, sections and fields during admin_init
*
* @since 0.3.0
*/
public function tfs_register_woo_amz_settings() {
register_setting( 'woo-amz-integration', 'woo_amz_int_settings' );
add_settings_section(
'woo_amz_int_settings_section',
'',
array( $this, 'tfs_woo_amz_int_section_description' ),
'woo-amz-integration'
);
add_settings_field(
'enable_feed',
'Enable Amazon Feed',
array( $this, 'tfs_enable_woo_amz_feed' ),
'woo-amz-integration',
'woo_amz_int_settings_section'
);
}
private function tfs_on_option_save( $options ) {
return $options;
}
/**
* Callback function for inventory tools settings section
* adds content to the start of the inventory tools settings section
*
* @since 0.3.0
*/
public function tfs_woo_amz_int_section_description() {
echo '<p><strong>Enable or Disable the Amazon Feed and Click Save</strong></p>';
}
/**
* Callback function for product checker setting
*
* @since 0.3.0
*/
public function tfs_enable_woo_amz_feed() {
?>
<input id="feed_enabled" name="woo_amz_int_settings[enable_feed]" type="checkbox" value="1" <?php checked( isset( self::$woo_amz_int_options['enable_feed'] ), 1 ) ?> />
<?php
}
}
if ( is_admin() ) {
$init_inventory_tools_setting_page = new Woo_Amz_Integration_Settings_Page();
}