forked from darkrain/woo-export-yml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
woo-export-yml.php
executable file
·143 lines (103 loc) · 4.32 KB
/
woo-export-yml.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
<?php
/*
Plugin Name: YML API Export for Woocommerce
Plugin URI: http://progerlab.ru
Description: Апи для экспорта товаров с Woocommerce в YML
Version: 3.1
Author: Ivantsov Mikhail
Author URI: mailto:[email protected]
*/
if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ){
class WooExportYmlInit
{
function __construct()
{
$this->id = 'export_yml';
$this->sourcesExportApis = array();
require_once( dirname(__FILE__). '/unittests.php' );
require_once( dirname(__FILE__). '/WooExportYmlFunctions.php' );
require_once( dirname(__FILE__). '/api.php' );
require_once( dirname(__FILE__). '/source-manager.php' );
add_filter( 'woocommerce_get_settings_pages', array( $this, 'add_settings' ) );
add_action( 'wp_ajax_yml_send_log', array( $this, 'send_log' ) );
add_action( 'woocommerce_product_options_general_product_data', array( $this, 'add_vendor_field' ) );
add_action( 'woocommerce_process_product_meta', array( $this, 'add_vendor_field_save' ) );
$this->sources = new WooExportYmlSourceManager( $this->id );
$this->init_sources_apis();
}
public function init_sources_apis(){
foreach( $this->sources->get_sources() as $key => $name ){
$bid = get_option($key.'_bid');
$vendors = get_option($key.'_vendors');
$settings = array(
'isdeliver' => ( get_option($key.'_isdeliver') == 'yes' ) ? true : false,
'isexportattr' => ( get_option($key.'_isexportattr') == 'yes' ) ? true : false,
'isexporpictures' => ( get_option($key.'_isexportpictures') == 'yes' ) ? true : false,
'ispickup' => ( get_option($key.'_ispickup') == 'yes' ) ? 'true' : 'false',
'isstore' => ( get_option($key.'_isstore') == 'yes' ) ? 'true' : 'false',
'cpa' => ( get_option($key.'_cpa') == 'yes' ) ? true : false,
'isgroupidattr' => ( get_option($key.'_isgroupidattr') == 'yes' ) ? true : false,
'bid' => ( !empty( $bid ) ) ? $bid : false,
'isbid' => ( get_option($key.'_isbid') == 'yes' ) ? true : false,
'vendors' => ( !empty( $vendors ) ) ? ( $vendors == 'false' ) ? false : $vendors : false,
'salesNote' => get_option($key.'_sales_note')
);
$this->sourcesExportApis[ $key ] = new WooExportYmlApi( $key, $settings );
}
}
public function send_log(){
$logs = glob( dirname(__FILE__) . '/*.log' );
$logLinks = array();
foreach ($logs as $file) {
$logLinks[] = str_replace(dirname(__FILE__), plugins_url('', __FILE__), $file);
}
wp_mail(
'Problem with plugin WooExportYml',
'Domain: '.home_url()."\n\nLogs:\n".implode("\n",$logLinks),
'From: Problem with plugin WooExportYml <info@'.str_replace('http://', '', home_url() ).'>' . "\r\n"
);
die("ok");
}
public function add_settings( $settings ){
$settings[] = include( dirname(__FILE__). '/settings.php' );
new WC_Settings_Export_YML( $this->id , $this->sources );
return $settings;
}
static function activate(){
wp_mail(
'Install plugin WooExportYml',
'Domain: '.home_url(),
'From: Activation Plugin WooExportYml <info@'.str_replace('http://', '', home_url() ).'>' . "\r\n"
);
}
/*
Создает дополнительное поле Бренд, для товара. Обязателен для выгрузки
*/
public function add_vendor_field(){
global $woocommerce, $post;
echo '<div class="options_group">';
woocommerce_wp_text_input(
array(
'id' => '_vendor',
'label' => 'Производитель',
'placeholder' => '',
'description' => 'Если не заполенено, то не учавствует в выгрузке маркета',
'type' => 'text',
)
);
echo '</div>';
}
/*
Сохраняет дополнительное поле Бренд, для товара.
*/
public function add_vendor_field_save( $post_id )
{
$field_name = '_vendor';
$vendor = $_POST[ $field_name ];
update_post_meta( $post_id, $field_name, $vendor );
}
} $WooExportYmlInit = new WooExportYmlInit();
register_activation_hook( __FILE__, array( $WooExportYmlInit, 'activate' ) );
}