167 lines
3.4 KiB
PHP
167 lines
3.4 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Plugin Name: WP Product Importer
|
|
* Description: Import WooCommerce products from API or CSV (Cron supported)
|
|
* Version: 1.0.0
|
|
* Author: You
|
|
*/
|
|
|
|
if (!defined('ABSPATH')) exit;
|
|
|
|
/**
|
|
* Constants
|
|
*/
|
|
define('WPI_PATH', plugin_dir_path(__FILE__));
|
|
define('WPI_URL', plugin_dir_url(__FILE__));
|
|
|
|
/**
|
|
* =========================
|
|
* Require core files
|
|
* =========================
|
|
*/
|
|
|
|
// Migrations
|
|
require_once WPI_PATH . 'includes/migrations/create-config-table.php';
|
|
|
|
// Models
|
|
require_once WPI_PATH . 'includes/models/class-wpi-config-model.php';
|
|
|
|
// Helper
|
|
require_once WPI_PATH . 'includes/helpers/class-product-helper.php';
|
|
require_once WPI_PATH . 'includes/helpers/class-category-helper.php';
|
|
|
|
|
|
// Core classes
|
|
require_once WPI_PATH . 'includes/class-api-importer.php';
|
|
require_once WPI_PATH . 'includes/class-cron.php';
|
|
require_once WPI_PATH . 'includes/class-logger.php';
|
|
require_once WPI_PATH . 'includes/class-product-map.php';
|
|
require_once WPI_PATH . 'includes/class-product-validator.php';
|
|
|
|
|
|
/**
|
|
* =========================
|
|
* Init plugin
|
|
* =========================
|
|
*/
|
|
add_action('plugins_loaded', function () {
|
|
|
|
// Admin UI
|
|
// if (is_admin()) {
|
|
// new WPI_Admin_Page();
|
|
// }
|
|
|
|
// Init cron only if WooCommerce active
|
|
if (class_exists('WooCommerce')) {
|
|
WPI_Cron::init();
|
|
}
|
|
});
|
|
|
|
/**
|
|
* =========================
|
|
* Plugin activation
|
|
* =========================
|
|
*/
|
|
register_activation_hook(__FILE__, function () {
|
|
|
|
if (!class_exists('WooCommerce')) {
|
|
deactivate_plugins(plugin_basename(__FILE__));
|
|
wp_die('WooCommerce is required for WP Product Importer');
|
|
}
|
|
|
|
// Create DB tables
|
|
wpi_create_config_table();
|
|
|
|
// Default configs
|
|
WPI_Config_Model::set_config(
|
|
'base_api',
|
|
'https://distidata.nswteam.net/api/ecom',
|
|
'Api path to get data import'
|
|
);
|
|
|
|
WPI_Config_Model::set_config(
|
|
'import_api',
|
|
'/scraping-product',
|
|
'Api path to get data import'
|
|
);
|
|
|
|
// Default configs
|
|
WPI_Config_Model::set_config(
|
|
'categories_api',
|
|
'/category',
|
|
'Api path to get categories'
|
|
);
|
|
|
|
WPI_Config_Model::set_config(
|
|
'authen_key',
|
|
'abc',
|
|
'Authentication key'
|
|
);
|
|
|
|
WPI_Config_Model::set_config(
|
|
'limit_per_time',
|
|
30,
|
|
'Item sync per time'
|
|
);
|
|
|
|
WPI_Config_Model::set_config(
|
|
'current_page',
|
|
0,
|
|
'Current page sync'
|
|
);
|
|
|
|
WPI_Config_Model::set_config(
|
|
'sync_status',
|
|
0,
|
|
'Status sync process'
|
|
);
|
|
|
|
WPI_Config_Model::set_config(
|
|
'status_cron',
|
|
1,
|
|
'Status cron sync'
|
|
);
|
|
|
|
WPI_Config_Model::set_config(
|
|
'status_workers',
|
|
0,
|
|
'Status workers'
|
|
);
|
|
|
|
WPI_Config_Model::set_config(
|
|
'import_workers',
|
|
5,
|
|
'Workers process per time'
|
|
);
|
|
|
|
WPI_Config_Model::set_config(
|
|
'categories_sync_status',
|
|
0,
|
|
'Status sync categories process'
|
|
);
|
|
|
|
WPI_Config_Model::set_config(
|
|
'categories_status_cron',
|
|
1,
|
|
'Categoroies status cron'
|
|
);
|
|
|
|
// Activate cron
|
|
WPI_Cron::activate();
|
|
|
|
error_log('[WPI] Plugin activated');
|
|
});
|
|
|
|
/**
|
|
* =========================
|
|
* Plugin deactivation
|
|
* =========================
|
|
*/
|
|
register_deactivation_hook(__FILE__, function () {
|
|
|
|
WPI_Cron::deactivate();
|
|
|
|
error_log('[WPI] Plugin deactivated');
|
|
});
|