-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplugin.php
More file actions
127 lines (99 loc) · 3.48 KB
/
Copy pathplugin.php
File metadata and controls
127 lines (99 loc) · 3.48 KB
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
<?php
/**
* @package Fhb Kika API
* @author Fhb
*
* @wordpress-plugin
* Plugin Name: Kika API
* Plugin URI: http://www.fhb.sk/
* Description: Woocommerce integrácia na fullfilment systém KIKA
* Version: 2.28
* Text Domain: woocommerce-fhb-api
* Domain Path: /languages
*/
// If this file is called directly, abort.
if (!function_exists('add_action')) {
echo 'Hi there! I\'m just a plugin, not much I can do when called directly.';
exit;
}
define('KIKA_PLUGIN_URL', plugin_dir_url( __FILE__));
register_activation_hook(__FILE__, function() {
update_option('kika_method_cod', true);
update_option('kika_status_delete', ['wc-cancelled', 'wc-failed']);
if (!wp_next_scheduled('wp_job_fhb_kika_export_order')) {
wp_schedule_event(time() + 3600, 'hourly', 'wp_job_fhb_kika_export_order');
}
});
register_deactivation_hook(__FILE__, function() {
if (wp_next_scheduled('wp_job_fhb_kika_export_order')) {
wp_clear_scheduled_hook('wp_job_fhb_kika_export_order');
}
});
add_action('admin_enqueue_scripts', function() {
wp_enqueue_script('fhb-kika-api-js', plugins_url('assets/fhb-kika.js', __FILE__), array('jquery'));
wp_enqueue_style('fhb-kika-api-css', plugins_url('assets/fhb-kika.css', __FILE__));
});
require_once('api/RestApi.php');
require_once('api/OrderApi.php');
require_once('api/ProductApi.php');
require_once('api/InfoApi.php');
require_once('repositories/ProductRepo.php');
require_once('repositories/OrderRepo.php');
require_once('repositories/ParcelServiceRepo.php');
require_once('SettingPanel.php');
require_once('Orders.php');
require_once('Products.php');
require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
use Kika\Api\RestApi;
use Kika\Api\OrderApi;
use Kika\Api\ProductApi;
use Kika\Api\InfoApi;
use Kika\SettingPanel;
use Kika\Products;
use Kika\Orders;
use Kika\Repositories\ProductRepo;
use Kika\Repositories\OrderRepo;
use Kika\Repositories\ParcelServiceRepo;
$apiId = get_option('kika_appid');
$secret = get_option('kika_secret');
$restApi = new RestApi($apiId, $secret);
if (get_option('kika_sandbox')) {
$restApi->setEndpoint('https://system-dev.fhb.sk/api/v2');
}
$productApi = new ProductApi($restApi);
$orderApi = new OrderApi($restApi);
$infoApi = new InfoApi($restApi);
$productRepo = new ProductRepo();
$parcelServiceRepo = new ParcelServiceRepo($infoApi);
$orderRepo = new OrderRepo($parcelServiceRepo);
$orders = new Orders($orderApi, $orderRepo, $parcelServiceRepo);
new Products($productApi, $productRepo);
new SettingPanel($parcelServiceRepo);
add_filter( 'manage_edit-shop_order_columns', function($columns) {
$new_columns = array();
foreach ( $columns as $column_name => $column_info ) {
$new_columns[ $column_name ] = $column_info;
if ( 'order_total' === $column_name ) {
$new_columns[OrderRepo::STATUS_KEY] = 'Kika API';
}
}
return $new_columns;
}, 20);
add_filter('bulk_actions-edit-shop_order', function($actions) {
$actions['fhb-bulk-export'] = "FHB Bulk export";
return $actions;
}, 20, 1);
add_filter('handle_bulk_actions-edit-shop_order', function($redirect_to, $action, $post_ids) use ($orders) {
if($action != 'fhb-bulk-export') {
return $redirect_to;
}
$orders->bulkExport($post_ids);
return $redirect_to;
}, 20, 3);
add_action('manage_shop_order_posts_custom_column', function($column, $post_id) {
echo get_post_meta($post_id, $column, true);
}, 10, 2);
add_action( 'plugins_loaded', function() {
load_plugin_textdomain( 'woocommerce-fhb-api', FALSE, basename( dirname( __FILE__ ) ) . '/languages/' );
}
);