API
3 years ago
Admin
2 years ago
Emails
2 years ago
Framework
2 years ago
Gateway
2 years ago
Handlers
2 years ago
Sync
2 years ago
Utilities
2 years ago
AJAX.php
3 years ago
API.php
3 years ago
Admin.php
2 years ago
Functions.php
3 years ago
Gateway.php
2 years ago
Lifecycle.php
3 years ago
Plugin.php
2 years ago
Settings.php
2 years ago
WC_Order_Square.php
2 years ago
Admin.php
264 lines
| 1 | <?php |
| 2 | /** |
| 3 | * WooCommerce Square |
| 4 | * |
| 5 | * This source file is subject to the GNU General Public License v3.0 |
| 6 | * that is bundled with this package in the file license.txt. |
| 7 | * It is also available through the world-wide-web at this URL: |
| 8 | * http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0 or later |
| 9 | * If you did not receive a copy of the license and are unable to |
| 10 | * obtain it through the world-wide-web, please send an email |
| 11 | * to license@woocommerce.com so we can send you a copy immediately. |
| 12 | * |
| 13 | * DISCLAIMER |
| 14 | * |
| 15 | * Do not edit or add to this file if you wish to upgrade WooCommerce Square to newer |
| 16 | * versions in the future. If you wish to customize WooCommerce Square for your |
| 17 | * needs please refer to https://docs.woocommerce.com/document/woocommerce-square/ |
| 18 | * |
| 19 | * @author WooCommerce |
| 20 | * @copyright Copyright: (c) 2019, Automattic, Inc. |
| 21 | * @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0 or later |
| 22 | */ |
| 23 | |
| 24 | namespace WooCommerce\Square; |
| 25 | |
| 26 | defined( 'ABSPATH' ) || exit; |
| 27 | |
| 28 | use WooCommerce\Square\Admin\Analytics\Revenue; |
| 29 | use WooCommerce\Square\Handlers\Product; |
| 30 | |
| 31 | /** |
| 32 | * The base admin handler class. |
| 33 | * |
| 34 | * @since 2.0.0 |
| 35 | */ |
| 36 | class Admin { |
| 37 | |
| 38 | |
| 39 | /** |
| 40 | * Product handler. |
| 41 | * |
| 42 | * @var Handlers\Products |
| 43 | */ |
| 44 | private $products_handler; |
| 45 | |
| 46 | /** |
| 47 | * Privacy handler. |
| 48 | * |
| 49 | * @var Admin\Privacy |
| 50 | */ |
| 51 | private $privacy_handler; |
| 52 | |
| 53 | /** |
| 54 | * Plugin |
| 55 | * |
| 56 | * @var Plugin plugin instance |
| 57 | */ |
| 58 | private $plugin; |
| 59 | |
| 60 | |
| 61 | /** |
| 62 | * Constructs the class. |
| 63 | * |
| 64 | * @since 2.0.0 |
| 65 | * |
| 66 | * @param Plugin $plugin plugin instance. |
| 67 | */ |
| 68 | public function __construct( Plugin $plugin ) { |
| 69 | |
| 70 | $this->plugin = $plugin; |
| 71 | |
| 72 | $this->products_handler = $this->plugin->get_products_handler(); |
| 73 | |
| 74 | // privacy |
| 75 | $this->privacy_handler = new Admin\Privacy(); |
| 76 | |
| 77 | new Revenue(); |
| 78 | |
| 79 | $this->add_hooks(); |
| 80 | } |
| 81 | |
| 82 | |
| 83 | /** |
| 84 | * Adds the action & filter hooks. |
| 85 | * |
| 86 | * @since 2.0.0 |
| 87 | */ |
| 88 | private function add_hooks() { |
| 89 | |
| 90 | // add the settings page. |
| 91 | add_filter( |
| 92 | 'woocommerce_get_settings_pages', |
| 93 | function ( $pages ) { |
| 94 | |
| 95 | $pages[] = new Admin\Settings_Page( $this->get_plugin()->get_settings_handler() ); |
| 96 | |
| 97 | return $pages; |
| 98 | } |
| 99 | ); |
| 100 | |
| 101 | // load admin scripts. |
| 102 | add_action( |
| 103 | 'admin_enqueue_scripts', |
| 104 | function() { |
| 105 | $this->load_scripts_styles(); |
| 106 | } |
| 107 | ); |
| 108 | } |
| 109 | |
| 110 | |
| 111 | /** |
| 112 | * Loads and enqueues admin scripts and styles. |
| 113 | * |
| 114 | * @since 2.0.0 |
| 115 | */ |
| 116 | private function load_scripts_styles() { |
| 117 | global $typenow; |
| 118 | |
| 119 | if ( 'product' === $typenow ) { |
| 120 | |
| 121 | wp_enqueue_script( |
| 122 | 'wc-square-admin-products', |
| 123 | $this->get_plugin()->get_plugin_url() . '/assets/js/admin/wc-square-admin-products.min.js', |
| 124 | array( 'jquery' ), |
| 125 | Plugin::VERSION, |
| 126 | true |
| 127 | ); |
| 128 | |
| 129 | wp_localize_script( |
| 130 | 'wc-square-admin-products', |
| 131 | 'wc_square_admin_products', |
| 132 | array( |
| 133 | 'ajax_url' => admin_url( 'admin-ajax.php' ), |
| 134 | 'settings_url' => esc_url( $this->get_plugin()->get_settings_url() ), |
| 135 | 'variable_product_types' => $this->get_variable_product_types(), |
| 136 | 'synced_with_square_taxonomy' => Product::SYNCED_WITH_SQUARE_TAXONOMY, |
| 137 | 'is_product_sync_enabled' => $this->get_plugin()->get_settings_handler()->is_product_sync_enabled(), |
| 138 | 'is_woocommerce_sor' => $this->get_plugin()->get_settings_handler()->is_system_of_record_woocommerce(), |
| 139 | 'is_square_sor' => $this->get_plugin()->get_settings_handler()->is_system_of_record_square(), |
| 140 | 'is_inventory_sync_enabled' => $this->get_plugin()->get_settings_handler()->is_inventory_sync_enabled(), |
| 141 | 'get_quick_edit_product_details_nonce' => wp_create_nonce( 'get-quick-edit-product-details' ), |
| 142 | 'fetch_product_stock_with_square_nonce' => wp_create_nonce( 'fetch-product-stock-with-square' ), |
| 143 | 'supported_products_for_sync' => array( 'simple', 'variable' ), |
| 144 | 'i18n' => array( |
| 145 | 'inventory_tracking_disabled' => __( 'Inventory tracking is disabled for this product', 'woocommerce-square' ), |
| 146 | 'synced_with_square' => __( 'Synced with Square', 'woocommerce-square' ), |
| 147 | 'managed_by_square' => __( 'Managed by Square', 'woocommerce-square' ), |
| 148 | 'fetch_stock_with_square' => __( 'Fetch stock from Square', 'woocommerce-square' ), |
| 149 | 'sync_inventory' => __( 'Sync inventory', 'woocommerce-square' ), |
| 150 | 'sync_stock_from_square' => __( 'Sync stock from Square', 'woocommerce-square' ), |
| 151 | ), |
| 152 | ) |
| 153 | ); |
| 154 | } elseif ( $this->get_plugin()->is_plugin_settings() ) { |
| 155 | wp_enqueue_style( |
| 156 | 'wc-square-admin', |
| 157 | $this->get_plugin()->get_plugin_url() . '/assets/css/admin/wc-square-admin.min.css', |
| 158 | array(), |
| 159 | Plugin::VERSION |
| 160 | ); |
| 161 | |
| 162 | wp_enqueue_script( |
| 163 | 'wc-square-admin-settings', |
| 164 | $this->get_plugin()->get_plugin_url() . '/assets/js/admin/wc-square-admin-settings.min.js', |
| 165 | array( 'jquery', 'jquery-blockui', 'backbone', 'wc-backbone-modal' ), |
| 166 | Plugin::VERSION, |
| 167 | true |
| 168 | ); |
| 169 | |
| 170 | $sync_job = $this->get_plugin()->get_sync_handler()->get_job_in_progress(); |
| 171 | |
| 172 | if ( $sync_job ) { |
| 173 | $existing_sync_id = $sync_job->id; |
| 174 | } else { |
| 175 | $existing_sync_id = false; |
| 176 | } |
| 177 | |
| 178 | wp_localize_script( |
| 179 | 'wc-square-admin-settings', |
| 180 | 'wc_square_admin_settings', |
| 181 | array( |
| 182 | 'ajax_url' => admin_url( 'admin-ajax.php' ), |
| 183 | 'is_product_sync_enabled' => $this->get_plugin()->get_settings_handler()->is_product_sync_enabled(), |
| 184 | 'is_woocommerce_sor' => $this->get_plugin()->get_settings_handler()->is_system_of_record_woocommerce(), |
| 185 | 'is_square_sor' => $this->get_plugin()->get_settings_handler()->is_system_of_record_square(), |
| 186 | 'is_inventory_sync_enabled' => $this->get_plugin()->get_settings_handler()->is_inventory_sync_enabled(), |
| 187 | 'is_sandbox' => $this->get_plugin()->get_settings_handler()->is_sandbox(), |
| 188 | 'existing_sync_job_id' => $existing_sync_id, |
| 189 | 'import_products_from_square' => wp_create_nonce( 'import-products-from-square' ), |
| 190 | 'sync_products_with_square' => wp_create_nonce( 'sync-products-with-square' ), |
| 191 | 'get_sync_with_square_status_nonce' => wp_create_nonce( 'get-sync-with-square-status' ), |
| 192 | 'handle_sync_with_square_records' => wp_create_nonce( 'handle-sync-with-square-records' ), |
| 193 | 'i18n' => array( |
| 194 | 'resolved' => __( 'Resolved', 'woocommerce-square' ), |
| 195 | 'no_records_found' => __( 'No records found', 'woocommerce-square' ), |
| 196 | 'skipped' => __( 'Skipped', 'woocommerce-square' ), |
| 197 | 'updated' => __( 'Updated', 'woocommerce-square' ), |
| 198 | 'imported' => __( 'Imported', 'woocommerce-square' ), |
| 199 | 'sync_inventory_label' => array( |
| 200 | 'square' => __( 'Enable to fetch inventory changes from Square', 'woocommerce-square' ), |
| 201 | 'woocommerce' => __( 'Enable to push inventory changes to Square', 'woocommerce-square' ), |
| 202 | ), |
| 203 | 'sync_inventory_description' => array( |
| 204 | 'square' => __( 'Inventory is fetched from Square periodically and updated in WooCommerce', 'woocommerce-square' ), |
| 205 | 'woocommerce' => sprintf( |
| 206 | /* translators: Placeholders: %1$s - <strong> tag, %2$s - </strong> tag */ |
| 207 | __( 'Inventory is %1$salways fetched from Square%2$s periodically to account for sales from other channels.', 'woocommerce-square' ), |
| 208 | '<strong>', |
| 209 | '</strong>' |
| 210 | ), |
| 211 | ), |
| 212 | ), |
| 213 | ) |
| 214 | ); |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | |
| 219 | /** |
| 220 | * Gets a list of variable product types. |
| 221 | * |
| 222 | * @since 2.0.0 |
| 223 | * |
| 224 | * @return string[] |
| 225 | */ |
| 226 | private function get_variable_product_types() { |
| 227 | |
| 228 | /** |
| 229 | * Filters the variable product types. |
| 230 | * |
| 231 | * @since 2.0.0 |
| 232 | * |
| 233 | * @param string[] array of product types |
| 234 | */ |
| 235 | return (array) apply_filters( 'wc_square_variable_product_types', array( 'variable', 'variable-subscription' ) ); |
| 236 | } |
| 237 | |
| 238 | |
| 239 | /** |
| 240 | * Gets the products handler. |
| 241 | * |
| 242 | * @since 2.0.0 |
| 243 | * |
| 244 | * @return Admin\Products |
| 245 | */ |
| 246 | public function get_products_handler() { |
| 247 | |
| 248 | return $this->products_handler; |
| 249 | } |
| 250 | |
| 251 | |
| 252 | /** |
| 253 | * Gets the plugin instance. |
| 254 | * |
| 255 | * @since 2.0.0 |
| 256 | * |
| 257 | * @return Plugin |
| 258 | */ |
| 259 | protected function get_plugin() { |
| 260 | |
| 261 | return $this->plugin; |
| 262 | } |
| 263 | } |
| 264 |