81 lines
2.8 KiB
PHP
81 lines
2.8 KiB
PHP
<?php
|
|
/**
|
|
* Plugin Name: WooZoho Fulfillment
|
|
* Description: WooCommerce ↔ Zoho Inventory: auto-create Sales Orders. Stable build with contact address auto-sync before SO.
|
|
* Version: 0.5.6o
|
|
* Author: Aleksandr Kapustian
|
|
* Requires Plugins: woocommerce
|
|
* Text Domain: woozoho-fulfillment
|
|
*/
|
|
if (!defined('ABSPATH')) exit;
|
|
|
|
define('WZHF_VER','0.5.6o');
|
|
define('WZHF_SLUG','woozoho-fulfillment');
|
|
define('WZHF_OPT','wzhf_options');
|
|
define('WZHF_NS','wzhf/v1');
|
|
define('WZHF_DIR', plugin_dir_path(__FILE__));
|
|
define('WZHF_URL', plugin_dir_url(__FILE__));
|
|
|
|
register_activation_hook(__FILE__, function () {
|
|
if ( !class_exists('WooCommerce') ) {
|
|
update_option('wzhf_missing_wc_on_activation', '1', false);
|
|
}
|
|
// Ensure mapping table exists
|
|
global $wpdb;
|
|
$table = $wpdb->prefix . 'wzhf_orders';
|
|
$charset = $wpdb->get_charset_collate();
|
|
$sql = "CREATE TABLE {$table} (
|
|
wc_order_id BIGINT UNSIGNED NOT NULL,
|
|
zoho_salesorder_id VARCHAR(64) NOT NULL,
|
|
PRIMARY KEY (wc_order_id),
|
|
KEY zoho_salesorder_id (zoho_salesorder_id)
|
|
) $charset;";
|
|
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
|
|
dbDelta($sql);
|
|
});
|
|
|
|
add_action('admin_init', function(){
|
|
if ( get_option('wzhf_missing_wc_on_activation') === '1' ) {
|
|
delete_option('wzhf_missing_wc_on_activation');
|
|
if ( function_exists('is_plugin_active') && is_plugin_active(plugin_basename(__FILE__)) ) {
|
|
deactivate_plugins(plugin_basename(__FILE__));
|
|
}
|
|
add_action('admin_notices', function(){
|
|
echo '<div class="notice notice-error"><p>WooZoho Fulfillment: WooCommerce не активирован. Плагин отключён.</p></div>';
|
|
});
|
|
}
|
|
});
|
|
|
|
// Includes
|
|
require_once __DIR__.'/inc/helpers.php';
|
|
require_once __DIR__.'/inc/class-logger.php';
|
|
require_once __DIR__.'/inc/class-zoho.php';
|
|
require_once __DIR__.'/inc/class-orders-sync.php';
|
|
require_once __DIR__.'/inc/class-webhooks.php';
|
|
require_once __DIR__.'/inc/class-inventory-sync.php';
|
|
require_once __DIR__.'/inc/class-tracking-sync.php';
|
|
require_once __DIR__.'/inc/class-inbound-email.php';
|
|
require_once __DIR__.'/inc/class-tools.php';
|
|
require_once __DIR__.'/inc/class-admin.php';
|
|
|
|
add_action('init', function (){
|
|
add_action('rest_api_init', function(){
|
|
register_rest_route(WZHF_NS, '/oauth/callback', array(
|
|
'methods'=>'GET','callback'=>array('WZHF_Zoho','oauth_callback'),'permission_callback'=>'__return_true'
|
|
));
|
|
register_rest_route(WZHF_NS, '/webhook', array(
|
|
'methods'=>'POST','callback'=>array('WZHF_Webhooks','handle'),'permission_callback'=>'__return_true'
|
|
));
|
|
});
|
|
});
|
|
|
|
add_action('plugins_loaded', function(){
|
|
new WZHF_Admin();
|
|
WZHF_Orders_Sync::bootstrap();
|
|
WZHF_Inventory_Sync::bootstrap();
|
|
WZHF_Webhooks::bootstrap();
|
|
WZHF_Tracking_Sync::bootstrap();
|
|
WZHF_Inbound_Email::bootstrap();
|
|
WZHF_Tools::bootstrap();
|
|
});
|