Enhanced Ecommerce Google Analytics Plugin for WooCommerce - Version 3.0.5

Version Description

  • 12/04/2021 =
    • Add auto product sync feature enhancement - In the background, every month runs a process to sync the product, Run only those products who are completed the manual product sync.
Download this release

Release Info

Developer Tatvic
Plugin Icon 128x128 Enhanced Ecommerce Google Analytics Plugin for WooCommerce
Version 3.0.5
Comparing to
See all releases

Code changes from version 3.0.4 to 3.0.5

admin/class-tvc-admin-auto-product-sync-helper.php ADDED
@@ -0,0 +1,545 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) {
3
+ exit;
4
+ }
5
+ if ( ! class_exists( 'TVC_Admin_Auto_Product_sync_Helper' ) ) {
6
+ Class TVC_Admin_Auto_Product_sync_Helper{
7
+ protected $TVC_Admin_Helper;
8
+ protected $TVC_Admin_DB_Helper;
9
+ protected $time_space;
10
+ private $apiDomain;
11
+ protected $batch_size;
12
+ public function __construct() {
13
+ $this->TVC_Admin_Helper = new TVC_Admin_Helper();
14
+ $this->TVC_Admin_DB_Helper = new TVC_Admin_DB_Helper();
15
+ $this->apiDomain = TVC_API_CALL_URL;
16
+ $this->includes();
17
+ add_action('admin_init', array($this,'add_table_in_db'));
18
+ $this->customApiObj = new CustomApi();
19
+ $this->time_space = $this->TVC_Admin_Helper->get_auto_sync_time_space();
20
+ $this->batch_size = $this->TVC_Admin_Helper->get_auto_sync_batch_size();
21
+ //add_action('admin_init',array($this,'add_woo_req'));
22
+
23
+ add_action('admin_init',array($this,'add_schedule_event'));
24
+ add_action( 'ee_auto_product_sync_check', array($this, 'call_auto_sync_product' ), 10, 1 );
25
+
26
+ //add_action('admin_init',array($this,'call_auto_sync_product_tttt'));
27
+ }
28
+
29
+ public function includes() {
30
+ require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
31
+ if (!class_exists('CustomApi')) {
32
+ require_once(ENHANCAD_PLUGIN_DIR . 'includes/setup/CustomApi.php');
33
+ }
34
+ }
35
+
36
+ public function add_woo_req(){
37
+ // include_once WC_ABSPATH . 'packages/action-scheduler/action-scheduler.php';
38
+ }
39
+
40
+ public function add_table_in_db(){
41
+ //add_filter( 'cron_schedules', array($this,'tvc_add_cron_interval') );
42
+ global $wpdb;
43
+ $tablename = $wpdb->prefix ."ee_product_sync_data";
44
+ $query = $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $tablename ) );
45
+ if ( $wpdb->get_var( $query ) === $tablename ) {
46
+
47
+ }else{
48
+ $sql_create = "CREATE TABLE ".$tablename." ( `id` BIGINT(20) NOT NULL AUTO_INCREMENT , `w_product_id` BIGINT(20) NOT NULL , `w_cat_id` INT(10) NOT NULL , `g_cat_id` INT(10) NOT NULL , `g_attribute_mapping` LONGTEXT NOT NULL , `update_date` DATE NOT NULL , `status` INT(1) NOT NULL DEFAULT '1', PRIMARY KEY (`id`) );";
49
+ if(maybe_create_table( $tablename, $sql_create )){
50
+ $this->import_last_sync_in_db();
51
+ }
52
+ }
53
+
54
+ $tablename = $wpdb->prefix ."ee_product_sync_call";
55
+ $sql_create = "CREATE TABLE ".$tablename." ( `id` BIGINT(20) NOT NULL AUTO_INCREMENT, `sync_product_ids` LONGTEXT NULL, `w_total_product` INT(10) NOT NULL , `total_sync_product` INT(10) NOT NULL ,last_sync DATETIME NOT NULL, create_sync DATETIME NOT NULL, next_sync DATETIME NOT NULL, `last_sync_product_id` BIGINT(20) NOT NULL, `action_scheduler_id` INT(10) NOT NULL, `status` INT(1) NOT NULL COMMENT '0 failed, 1 completed', PRIMARY KEY (`id`) );";
56
+ if(!maybe_create_table( $tablename, $sql_create )){ }
57
+ }
58
+
59
+ public function import_last_sync_in_db(){
60
+ $ee_prod_mapped_cats = unserialize(get_option('ee_prod_mapped_cats'));
61
+ $ee_prod_mapped_attrs = unserialize(get_option('ee_prod_mapped_attrs'));
62
+ if($ee_prod_mapped_cats != "" && $ee_prod_mapped_attrs != ""){
63
+ global $wpdb;
64
+ //$table, $field_name = "*"
65
+ $row_count = $this->TVC_Admin_DB_Helper->tvc_row_count('ee_product_sync_data');
66
+ if($row_count == 0){
67
+ if(!empty($ee_prod_mapped_cats)){
68
+ foreach($ee_prod_mapped_cats as $mc_key => $mappedCat){
69
+ $args= array(
70
+ 'post_type' => 'product',
71
+ 'numberposts' => -1,
72
+ 'post_status' => 'publish',
73
+ 'tax_query' => array( array(
74
+ 'taxonomy' => 'product_cat',
75
+ 'field' => 'term_id',
76
+ 'terms' =>$mc_key,
77
+ 'operator' => 'IN'
78
+ )
79
+ )
80
+ );
81
+ $all_products = get_posts($args);
82
+ if(!empty($all_products)){
83
+ foreach($all_products as $postkey => $postvalue){
84
+ $t_data = array(
85
+ 'w_product_id'=>$postvalue->ID,
86
+ 'w_cat_id'=>$mc_key,
87
+ 'g_cat_id'=>$mappedCat['id'],
88
+ 'g_attribute_mapping'=> json_encode($ee_prod_mapped_attrs),
89
+ 'update_date'=>date('Y-m-d')
90
+ );
91
+
92
+ $this->TVC_Admin_DB_Helper->tvc_add_row('ee_product_sync_data', $t_data);
93
+ }
94
+ wp_reset_postdata();
95
+ }
96
+ }
97
+ }
98
+ }
99
+ }
100
+ }
101
+
102
+ public function update_last_sync_in_db(){
103
+ $ee_prod_mapped_cats = unserialize(get_option('ee_prod_mapped_cats'));
104
+ $ee_prod_mapped_attrs = unserialize(get_option('ee_prod_mapped_attrs'));
105
+ if($ee_prod_mapped_cats != "" && $ee_prod_mapped_attrs != "" &&!empty($ee_prod_mapped_cats)){
106
+ global $wpdb;
107
+ foreach($ee_prod_mapped_cats as $mc_key => $mappedCat){
108
+ $args= array(
109
+ 'post_type' => 'product',
110
+ 'numberposts' => -1,
111
+ 'post_status' => 'publish',
112
+ 'tax_query' => array( array(
113
+ 'taxonomy' => 'product_cat',
114
+ 'field' => 'term_id',
115
+ 'terms' =>$mc_key,
116
+ 'operator' => 'IN'
117
+ )
118
+ )
119
+ );
120
+ $all_products = get_posts($args);
121
+ $where ="w_cat_id = ".$mc_key;
122
+ $p_c_ids = $this->TVC_Admin_DB_Helper->tvc_get_results_in_array('ee_product_sync_data', $where, array('w_product_id','w_cat_id'), true);
123
+ if(!empty($all_products)){
124
+ foreach($all_products as $postkey => $postvalue){
125
+ $t_data = array(
126
+ 'w_product_id'=>$postvalue->ID,
127
+ 'w_cat_id'=>$mc_key,
128
+ 'g_cat_id'=>$mappedCat['id'],
129
+ 'g_attribute_mapping'=> json_encode($ee_prod_mapped_attrs),
130
+ 'update_date'=>date('Y-m-d')
131
+ );
132
+ //$table, $where, $field_name = "*"
133
+ $p_c_id = $postvalue->ID."_".$mc_key;
134
+ if(!in_array($p_c_id, $p_c_ids)){
135
+ $this->TVC_Admin_DB_Helper->tvc_add_row('ee_product_sync_data', $t_data);
136
+ }else{
137
+ $this->TVC_Admin_DB_Helper->tvc_update_row('ee_product_sync_data', $t_data, array('w_product_id'=>$postvalue->ID, 'w_cat_id'=> $mc_key));
138
+ }
139
+ }
140
+ wp_reset_postdata();
141
+ }
142
+ }
143
+ }
144
+ }
145
+
146
+ public function tvc_get_post_meta($post_id){
147
+ $where ="post_id = ".$post_id;
148
+ $rows = $this->TVC_Admin_DB_Helper->tvc_get_results_in_array('postmeta', $where, array('meta_key','meta_value'));
149
+ $metas = array();
150
+ if(!empty($rows)){
151
+ foreach($rows as $val){
152
+ $metas[$val['meta_key']] = $val['meta_value'];
153
+ }
154
+ }
155
+ return $metas;
156
+ }
157
+
158
+ public function tvc_get_map_product_attribute($products, $tvc_currency, $merchantId){
159
+ if(!empty($products)){
160
+ $items = [];
161
+ $skipProducts = [];
162
+ $product_ids = [];
163
+ $batchId = time();
164
+ foreach ($products as $postkey => $postvalue) {
165
+ $product_ids[] = $postvalue->w_product_id;
166
+ $postmeta = [];
167
+ $postmeta = $this->tvc_get_post_meta($postvalue->w_product_id);
168
+ $prd = wc_get_product($postvalue->w_product_id);
169
+ $postObj = (object) array_merge((array) get_post($postvalue->w_product_id), (array) $postmeta);
170
+
171
+ $product = array(
172
+ 'offer_id'=>$postvalue->w_product_id,
173
+ 'channel'=>'online',
174
+ 'link'=>get_permalink($postvalue->w_product_id),
175
+ 'google_product_category'=>$postvalue->g_cat_id
176
+ );
177
+
178
+ $temp_product=array();
179
+ $fixed_att_select_list = array("gender", "age_group", "shipping", "tax", "content_language", "target_country", "condition");
180
+ $formArray = json_decode($postvalue->g_attribute_mapping, true);
181
+ foreach ($fixed_att_select_list as $fixed_key) {
182
+ if(isset($formArray[$fixed_key]) && $formArray[$fixed_key] != "" ){
183
+ if($fixed_key == "shipping" && $formArray[$fixed_key] != ""){
184
+ $temp_product[$fixed_key]['price']['value'] = $formArray[$fixed_key];
185
+ $temp_product[$fixed_key]['price']['currency'] = $tvc_currency;
186
+ $temp_product[$fixed_key]['country'] = $formArray['target_country'];
187
+ }else if($fixed_key == "tax" && $formArray[$fixed_key] != ""){
188
+ $temp_product['taxes']['rate'] = $formArray[$fixed_key];
189
+ $temp_product['taxes']['country'] = $formArray['target_country'];
190
+ }else if( $formArray[$fixed_key] != ""){
191
+ $temp_product[$fixed_key] = $formArray[$fixed_key];
192
+ }
193
+ }
194
+ unset($formArray[$fixed_key]);
195
+ }
196
+
197
+ $product = array_merge($temp_product,$product);
198
+
199
+ if($prd->get_type() == "variable"){
200
+ $variation_attributes = $prd->get_variation_attributes();
201
+ $can_add_item_group_id = false;
202
+ $is_color_size = false;
203
+ if(!empty($variation_attributes)){
204
+ foreach($variation_attributes as $va_key => $va_value ){
205
+ $va_key = str_replace("_", " ", $va_key);
206
+ if (strpos($va_key, 'color') !== false) {
207
+ $can_add_item_group_id = true;
208
+ $is_color_size = true;
209
+ break;
210
+ }else if (strpos($va_key, 'size') !== false) {
211
+ $can_add_item_group_id = true;
212
+ $is_color_size = true;
213
+ break;
214
+ }
215
+ }
216
+ }
217
+ if(isset($formArray['gender']) && $formArray['gender']!= ""){
218
+ $can_add_item_group_id = true;
219
+ }else if(isset($formArray['age_group']) && $formArray['age_group']!= ""){
220
+ $can_add_item_group_id = true;
221
+ }
222
+ if($can_add_item_group_id == true){
223
+ $p_variations = $prd->get_available_variations();
224
+ if(!empty($p_variations)){
225
+ foreach ($p_variations as $v_key => $v_value) {
226
+ $postmeta_var = (object)$this->tvc_get_post_meta($v_value['variation_id']);
227
+ $formArray_val = $formArray['title'];
228
+ $product['title'] = (isset($postObj->$formArray_val))?$postObj->$formArray_val:get_the_title($postvalue->w_product_id);
229
+ $tvc_temp_desc_key = $formArray['description'];
230
+ $product['description'] = (isset($v_value['variation_description']) && $v_value['variation_description'] != "")?$v_value['variation_description']:$postObj->$tvc_temp_desc_key;
231
+ $product['offer_id'] = $v_value['variation_id'];
232
+ $product['id'] = $v_value['variation_id'];
233
+ $product['item_group_id'] = $postvalue->w_product_id;
234
+ $image_id = $v_value['image_id'];
235
+ $product['image_link'] = wp_get_attachment_image_url($image_id, 'full');
236
+ if($is_color_size == true){
237
+ if(isset($v_value['attributes']) && !empty($v_value['attributes']) ){
238
+ foreach($v_value['attributes'] as $va_key => $va_value ){
239
+ $va_key = str_replace("_", " ", $va_key);
240
+ if (strpos($va_key, 'color') !== false) {
241
+ $product['color'] = $va_value;
242
+ }else if (strpos($va_key, 'size') !== false) {
243
+ $product['sizes'] = $va_value;
244
+ }
245
+ }
246
+ }
247
+ }
248
+ foreach($formArray as $key => $value){
249
+ if($key == 'price'){
250
+ if(isset($postmeta_var->$value) && $postmeta_var->$value > 0){
251
+ $product[$key]['value'] = $postmeta_var->$value;
252
+ }else if(isset($postmeta_var->_regular_price) && $postmeta_var->_regular_price && $postmeta_var->_regular_price >0 ){
253
+ $product[$key]['value'] = $postmeta_var->_regular_price;
254
+ }else if(isset($postmeta_var->_price) && $postmeta_var->_price && $postmeta_var->_price >0 ){
255
+ $product[$key]['value'] = $postmeta_var->_price;
256
+ }else if(isset($postmeta_var->_sale_price) && $postmeta_var->_sale_price && $postmeta_var->_sale_price >0 ){
257
+ $product[$key]['value'] = $postmeta_var->_sale_price;
258
+ }
259
+ if(isset($product[$key]['value']) && $product[$key]['value'] >0){
260
+ $product[$key]['currency'] = $tvc_currency;
261
+ }else{
262
+ $skipProducts[$postmeta_var->ID] = $postmeta_var;
263
+ }
264
+ }else if($key == 'sale_price'){
265
+ if(isset($postmeta_var->$value) && $postmeta_var->$value > 0){
266
+ $product[$key]['value'] = $postmeta_var->$value;
267
+ }else if(isset($postmeta_var->_sale_price) && $postmeta_var->_sale_price && $postmeta_var->_sale_price >0 ){
268
+ $product[$key]['value'] = $postmeta_var->_sale_price;
269
+ }
270
+ if(isset($product[$key]['value']) && $product[$key]['value'] >0){
271
+ $product[$key]['currency'] = $tvc_currency;
272
+ }
273
+ }else if($key == 'availability'){
274
+ $tvc_find = array("instock","outofstock","onbackorder");
275
+ $tvc_replace = array("in stock","out of stock","preorder");
276
+ if(isset($postmeta_var->$value) && $postmeta_var->$value != ""){
277
+ $stock_status = $postmeta_var->$value;
278
+ $stock_status = str_replace($tvc_find,$tvc_replace,$stock_status);
279
+ $product[$key] = $stock_status;
280
+ }else{
281
+ $stock_status = $postmeta_var->_stock_status;
282
+ $stock_status = str_replace($tvc_find,$tvc_replace,$stock_status);
283
+ $product[$key] = $stock_status;
284
+ }
285
+ }else if(isset($postmeta_var->$value) && $postmeta_var->$value != ""){$product[$key] = $postmeta_var->$value;
286
+ }
287
+ }
288
+ $item = [
289
+ 'merchant_id' => $merchantId,
290
+ 'batch_id' => ++$batchId,
291
+ 'method' => 'insert',
292
+ 'product' => $product
293
+ ];
294
+ $items[] = $item;
295
+ }
296
+ }
297
+ }else{
298
+ goto simpleproduct;
299
+ }
300
+ }else{
301
+ simpleproduct:
302
+ $image_id = $prd->get_image_id();
303
+ $product['image_link'] = wp_get_attachment_image_url($image_id, 'full');
304
+ foreach($formArray as $key => $value){
305
+ if($key == 'price'){
306
+ if(isset($postObj->$value) && $postObj->$value > 0){
307
+ $product[$key]['value'] = $postObj->$value;
308
+ }else if(isset($postObj->_regular_price) && $postObj->_regular_price && $postObj->_regular_price >0 ){
309
+ $product[$key]['value'] = $postObj->_regular_price;
310
+ }else if(isset($postObj->_price) && $postObj->_price && $postObj->_price >0 ){
311
+ $product[$key]['value'] = $postObj->_price;
312
+ }else if(isset($postObj->_sale_price) && $postObj->_sale_price && $postObj->_sale_price >0 ){
313
+ $product[$key]['value'] = $postObj->_sale_price;
314
+ }
315
+ if(isset($product[$key]['value']) && $product[$key]['value'] >0){
316
+ $product[$key]['currency'] = $tvc_currency;
317
+ }else{
318
+ $skipProducts[$postObj->ID] = $postObj;
319
+ }
320
+ }else if($key == 'sale_price'){
321
+ if(isset($postObj->$value) && $postObj->$value > 0){
322
+ $product[$key]['value'] = $postObj->$value;
323
+ }else if(isset($postObj->_sale_price) && $postObj->_sale_price && $postObj->_sale_price >0 ){
324
+ $product[$key]['value'] = $postObj->_sale_price;
325
+ }
326
+ if(isset($product[$key]['value']) && $product[$key]['value'] >0){
327
+ $product[$key]['currency'] = $tvc_currency;
328
+ }
329
+ }else if($key == 'availability'){
330
+ $tvc_find = array("instock","outofstock","onbackorder");
331
+ $tvc_replace = array("in stock","out of stock","preorder");
332
+ if(isset($postObj->$value) && $postObj->$value != ""){
333
+ $stock_status = $postObj->$value;
334
+ $stock_status = str_replace($tvc_find,$tvc_replace,$stock_status);
335
+ $product[$key] = $stock_status;
336
+ }else{
337
+ $stock_status = $postObj->_stock_status;
338
+ $stock_status = str_replace($tvc_find,$tvc_replace,$stock_status);
339
+ $product[$key] = $stock_status;
340
+ }
341
+ }else if(isset($postObj->$value) && $postObj->$value != ""){
342
+ //echo $key."==".$postObj->$value."<br>";
343
+ $product[$key] = $postObj->$value;
344
+ }
345
+ }
346
+ $item = [
347
+ 'merchant_id' => $merchantId,
348
+ 'batch_id' => ++$batchId,
349
+ 'method' => 'insert',
350
+ 'product' => $product
351
+ ];
352
+ $items[] = $item;
353
+ }
354
+ }
355
+ return array('items' => $items, 'skipProducts'=> $skipProducts, 'product_ids'=>$product_ids);
356
+ }
357
+ }
358
+ public function call_auto_sync_product($last_sync_product_id = array()){
359
+ $product_count = $this->TVC_Admin_DB_Helper->tvc_row_count('ee_product_sync_data');
360
+ //$count = 0;
361
+ $pre_last_sync_product_id = $last_sync_product_id;
362
+ if( $product_count > 0 ){
363
+ $tvc_currency = $this->TVC_Admin_Helper->get_woo_currency();
364
+ $merchantId = $this->TVC_Admin_Helper->get_merchantId();
365
+ $customerId = $this->TVC_Admin_Helper->get_currentCustomerId();
366
+ $accountId = $this->TVC_Admin_Helper->get_main_merchantId();
367
+ $subscriptionId = $this->TVC_Admin_Helper->get_subscriptionId();
368
+ $last_sync_product_id =( $last_sync_product_id > 0)?$last_sync_product_id:0;
369
+ global $wpdb;
370
+ $tablename = $wpdb->prefix .'ee_product_sync_data';
371
+ $sql = "select * from ".$tablename." where id > ".$last_sync_product_id." LIMIT ".$this->batch_size;
372
+ $products = $wpdb->get_results($sql, OBJECT);
373
+ $entries = [];
374
+ if(!empty($products)){
375
+ $p_map_attribute = $this->tvc_get_map_product_attribute($products, $tvc_currency, $merchantId);
376
+ if(!empty($p_map_attribute) && isset($p_map_attribute['items']) && !empty($p_map_attribute['items'])){
377
+ // call product sync API
378
+ $data = [
379
+ 'merchant_id' => $accountId,
380
+ 'account_id' => $merchantId,
381
+ 'subscription_id' => $subscriptionId,
382
+ 'entries' => $p_map_attribute['items']
383
+ ];
384
+ $url = $this->apiDomain.'/products/batch';
385
+ $args = array(
386
+ 'timeout' => 10000,
387
+ 'headers' => array(
388
+ 'Authorization' => "Bearer MTIzNA==",
389
+ 'Content-Type' => 'application/json',
390
+ 'AccessToken' => $this->generateAccessToken($this->get_tvc_access_token(), $this->get_tvc_refresh_token())
391
+ ),
392
+ 'body' => wp_json_encode($data)
393
+ );
394
+ $request = wp_remote_post($url, $args);
395
+
396
+ // Retrieve information
397
+ $response_code = wp_remote_retrieve_response_code($request);
398
+ $response_message = wp_remote_retrieve_response_message($request);
399
+ $response_body = json_decode(wp_remote_retrieve_body($request));
400
+ $sync_status = 0;
401
+ if((isset($response_body->error) && $response_body->error == '')){
402
+ $sync_status = 1;
403
+ }
404
+ // End call product sync API
405
+ $sync_product_ids = (isset($p_map_attribute['product_ids']))?$p_map_attribute['product_ids']:"";
406
+ $last_sync_product_id =end($products)->id;
407
+ $total_sync_product = 0;
408
+ $action_scheduler_id ="";
409
+ $last_sync = date( 'Y-m-d H:i:s', current_time( 'timestamp') );
410
+ $next_sync = date( 'Y-m-d H:i:s', current_time( 'timestamp')+$this->time_space);
411
+ if($pre_last_sync_product_id == 0){
412
+ $last_sync_row = $this->TVC_Admin_DB_Helper->tvc_get_last_row('ee_product_sync_call');
413
+ $total_sync_product = count($sync_product_ids);
414
+ if(!empty($last_sync_row)){
415
+ $action_scheduler_id = $last_sync_row['id']+1;
416
+ $last_sync = $last_sync_row['create_sync'];
417
+ $next_sync = date( 'Y-m-d H:i:s', current_time( 'timestamp')+ $this->time_space);
418
+ }else{
419
+ $action_scheduler_id = 1;
420
+ }
421
+ }else{
422
+ $last_sync_row = $this->TVC_Admin_DB_Helper->tvc_get_last_row('ee_product_sync_call');
423
+ if(!empty($last_sync_row)){
424
+ $total_sync_product = count($sync_product_ids) + $last_sync_row['total_sync_product'];
425
+ $action_scheduler_id = $last_sync_row['action_scheduler_id'];
426
+ $next_sync = $last_sync_row['next_sync'];
427
+ $last_sync = $last_sync_row['last_sync'];
428
+ }
429
+ }
430
+ $t_data = array(
431
+ 'sync_product_ids'=>json_encode($sync_product_ids),
432
+ 'w_total_product'=>$product_count,
433
+ 'total_sync_product'=>$total_sync_product,
434
+ 'last_sync'=>$last_sync,
435
+ 'create_sync'=>date( 'Y-m-d H:i:s', current_time( 'timestamp') ),
436
+ 'next_sync'=>$next_sync,
437
+ 'last_sync_product_id'=>$last_sync_product_id,
438
+ 'action_scheduler_id'=> $action_scheduler_id,
439
+ 'status'=>$sync_status
440
+ );
441
+ $this->TVC_Admin_DB_Helper->tvc_add_row('ee_product_sync_call', $t_data);
442
+ as_enqueue_async_action('ee_auto_product_sync_check', array('last_sync_product_id' => $last_sync_product_id));
443
+ }
444
+ }
445
+ }
446
+ }
447
+ public function add_schedule_event(){
448
+ $row_count = $this->TVC_Admin_DB_Helper->tvc_row_count('ee_product_sync_data');
449
+ if($row_count >0){
450
+ if ( function_exists( 'as_next_scheduled_action' ) && false === as_next_scheduled_action( 'ee_auto_product_sync_check' ) ) {
451
+ //strtotime( 'midnight tonight' )
452
+ as_schedule_recurring_action( strtotime( "+2 minutes" ), $this->time_space, 'ee_auto_product_sync_check',array("last_sync_product_id"=>0),"product_sync");
453
+ }
454
+ }
455
+ }
456
+
457
+ /*protected function maybe_remove_cronjobs() {
458
+ if ( function_exists( 'as_next_scheduled_action' ) && as_next_scheduled_action( 'ee_auto_product_sync_check' ) ) {
459
+ as_unschedule_all_actions( 'ee_auto_product_sync_check' );
460
+ }
461
+ if ( function_exists( 'as_next_scheduled_action' ) && as_next_scheduled_action( 'ee_auto_product_sync_recheck' ) ) {
462
+ as_unschedule_all_actions( 'ee_auto_product_sync_recheck' );
463
+ }
464
+ }*/
465
+
466
+ public function generateAccessToken($access_token, $refresh_token) {
467
+ $request = "https://www.googleapis.com/oauth2/v1/tokeninfo?"
468
+ . "access_token=" . $access_token;
469
+
470
+ $ch = curl_init();
471
+ curl_setopt($ch, CURLOPT_URL, $request);
472
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
473
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
474
+ $response = curl_exec($ch);
475
+ $result = json_decode($response);
476
+
477
+ if (isset($result->error) && $result->error) {
478
+ $credentials_file = ENHANCAD_PLUGIN_DIR . 'includes/setup/json/client-secrets.json';
479
+ $str = file_get_contents($credentials_file);
480
+ $credentials = $str ? json_decode($str, true) : [];
481
+ $url = 'https://www.googleapis.com/oauth2/v4/token';
482
+ $header = array("content-type: application/json");
483
+ $clientId = $credentials['web']['client_id'];
484
+ $clientSecret = $credentials['web']['client_secret'];
485
+ $refreshToken = $refresh_token;
486
+ $data = [
487
+ "grant_type" => 'refresh_token',
488
+ "client_id" => $clientId,
489
+ 'client_secret' => $clientSecret,
490
+ 'refresh_token' => $refreshToken,
491
+ ];
492
+
493
+ $postData = json_encode($data);
494
+ $ch = curl_init();
495
+ curl_setopt_array($ch, array(
496
+ CURLOPT_URL => $url, //esc_url($this->curl_url),
497
+ CURLOPT_RETURNTRANSFER => true,
498
+ CURLOPT_TIMEOUT => 0,
499
+ CURLOPT_HTTPHEADER => $header,
500
+ CURLOPT_POSTFIELDS => $postData
501
+ ));
502
+ $response = curl_exec($ch);
503
+ $response = json_decode($response);
504
+ return $response->access_token;
505
+ } else {
506
+ return $access_token;
507
+ }
508
+ }
509
+ public function get_tvc_access_token(){
510
+ if(!empty($this->access_token)){
511
+ return $this->access_token;
512
+ }else if(isset($_SESSION['access_token']) && $_SESSION['access_token']){
513
+ $this->access_token = $_SESSION['access_token'];
514
+ return $this->access_token;
515
+ }else{
516
+ $google_detail = $this->TVC_Admin_Helper->get_ee_options_data();
517
+ $this->access_token = $google_detail['setting']->access_token;
518
+ return $this->access_token;
519
+ }
520
+ }
521
+
522
+ public function get_tvc_refresh_token(){
523
+ if(!empty($this->refresh_token)){
524
+ return $this->refresh_token;
525
+ }else if(isset($_SESSION['refresh_token']) && $_SESSION['refresh_token']){
526
+ $this->refresh_token = $_SESSION['refresh_token'];
527
+ return $this->refresh_token;
528
+ }else{
529
+ $google_detail = $this->TVC_Admin_Helper->get_ee_options_data();
530
+ $this->refresh_token = $google_detail['setting']->refresh_token;
531
+ return $this->refresh_token;
532
+ }
533
+ }
534
+ /*
535
+ function tvc_add_cron_interval( $schedules ) {
536
+ $schedules['five_seconds'] = array(
537
+ 'interval' => 5,
538
+ 'display' => esc_html__( 'Every Five Seconds' ) );
539
+ return $schedules;
540
+ }
541
+ */
542
+ }// end Class
543
+ }
544
+ new TVC_Admin_Auto_Product_sync_Helper();
545
+ ?>
admin/class-tvc-admin-db-helper.php ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if ( ! defined( 'ABSPATH' ) ) {
3
+ exit;
4
+ }
5
+ if ( ! class_exists( 'TVC_Admin_DB_Helper' ) ) {
6
+ Class TVC_Admin_DB_Helper{
7
+ public function __construct() {
8
+ $this->includes();
9
+ }
10
+ public function includes() {
11
+ //require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
12
+ }
13
+
14
+ public function tvc_row_count($table, $field_name = "*"){
15
+ if($table ==""){
16
+ return;
17
+ }else{
18
+ global $wpdb;
19
+ $tablename = $wpdb->prefix .$table;
20
+ $sql = "select count(".$field_name.") from ".$tablename;
21
+ return $wpdb->get_var($sql);
22
+ }
23
+ }
24
+
25
+ public function tvc_add_row($table, $t_data){
26
+ if($table =="" || $t_data == ""){
27
+ return;
28
+ }else{
29
+ global $wpdb;
30
+ $tablename = $wpdb->prefix .$table;
31
+ return $wpdb->insert($tablename, $t_data);
32
+ }
33
+ }
34
+
35
+ public function tvc_update_row($table, $t_data, $where){
36
+ if($table =="" || $t_data == "" || $where == ""){
37
+ return;
38
+ }else{
39
+ global $wpdb;
40
+ $tablename = $wpdb->prefix .$table;
41
+ return $wpdb->update($tablename, $t_data, $where);
42
+ }
43
+ }
44
+
45
+ public function tvc_check_row_with_num_where($table, $where, $field_name = "*"){
46
+ if($table =="" || $where == ""){
47
+ return;
48
+ }else if(is_array($where)){
49
+ global $wpdb;
50
+ $tablename = $wpdb->prefix .$table;
51
+ $key = "";
52
+ foreach ($where as $key => $value) {
53
+ $key=($key!="")?$key."=%d":", ".$key."=%d";
54
+ }
55
+ $sql = $wpdb->prepare("select count(".$field_name.") from ".$tablename. "where ".$key,$where);
56
+ return $wpdb->get_var($sql);
57
+ }
58
+ return ;
59
+ }
60
+
61
+ public function tvc_get_results_in_array($table, $where, $fields, $concat = false){
62
+ global $wpdb;
63
+ $tablename = $wpdb->prefix .$table;
64
+ if($table =="" || $where == "" || $fields == ""){
65
+ return;
66
+ }else{
67
+ if($concat == true){
68
+ $fields = implode(',\'_\',', $fields);
69
+ $sql = "select CONCAT(".$fields.") as p_c_id from ".$tablename." where ".$where;
70
+ return $wpdb->get_col($sql);
71
+ }else{
72
+ $fields = implode(',', $fields);
73
+ $sql = "select ".$fields." from ".$tablename." where ".$where;
74
+ return $wpdb->get_results($sql, ARRAY_A);
75
+ }
76
+ }
77
+ }
78
+
79
+ public function tvc_get_last_row($table, $fields=null){
80
+ if($table ==""){
81
+ return;
82
+ }else{
83
+ global $wpdb;
84
+ $tablename = $wpdb->prefix .$table;
85
+ $sql = "select * from ".$tablename." ORDER BY id DESC LIMIT 1";
86
+ if($fields){
87
+ $fields = implode(',', $fields);
88
+ $sql = "select ".$fields." from ".$tablename." ORDER BY id DESC LIMIT 1";
89
+ }
90
+
91
+ return $wpdb->get_row($sql,ARRAY_A);
92
+ }
93
+ }
94
+
95
+
96
+
97
+
98
+ }
99
+ }
100
+
101
+ ?>
admin/class-tvc-admin-helper.php CHANGED
@@ -15,9 +15,11 @@ Class TVC_Admin_Helper{
15
  protected $user_currency_symbol = "";
16
  protected $setting_status = "";
17
  protected $ee_additional_data = "";
 
18
  public function __construct() {
19
  $this->includes();
20
  $this->customApiObj = new CustomApi();
 
21
  }
22
 
23
  public function includes() {
@@ -730,4 +732,17 @@ Class TVC_Admin_Helper{
730
  </div>';
731
  }
732
 
 
 
 
 
 
 
 
 
 
 
 
 
 
733
  }?>
15
  protected $user_currency_symbol = "";
16
  protected $setting_status = "";
17
  protected $ee_additional_data = "";
18
+ protected $TVC_Admin_DB_Helper;
19
  public function __construct() {
20
  $this->includes();
21
  $this->customApiObj = new CustomApi();
22
+ $this->TVC_Admin_DB_Helper = new TVC_Admin_DB_Helper();
23
  }
24
 
25
  public function includes() {
732
  </div>';
733
  }
734
 
735
+ public function get_auto_sync_time_space(){
736
+ $time_space = strtotime("25 days",0); //day
737
+ return $time_space;
738
+ }
739
+
740
+ public function get_auto_sync_batch_size(){
741
+ return "200";
742
+ }
743
+
744
+ public function get_last_auto_sync_product_info(){
745
+ return $this->TVC_Admin_DB_Helper->tvc_get_last_row('ee_product_sync_call', array("total_sync_product","create_sync","next_sync","status"));
746
+ }
747
+
748
  }?>
admin/css/enhanced-ecommerce-google-analytics-admin.css CHANGED
@@ -302,7 +302,8 @@ img.config-success, .nav-tabs li img.config-success, .nav-tabs li img.config-fai
302
  cursor: auto;
303
  }
304
  .tvc-tooltip .tvc-tooltiptext a{
305
- color: #2D73C5;
 
306
  }
307
  .tvc-tooltip-top {
308
  bottom: 115%;
@@ -642,4 +643,36 @@ button.tvc_animate_btn:hover::after, button.tvc_animate_btn:focus::after {
642
  .tvc-notice-error{position: relative;}
643
  .tvc-notice-error .call_both_verification-spinner{
644
  right: 5px;top: 10px;margin-left: 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
645
  }
302
  cursor: auto;
303
  }
304
  .tvc-tooltip .tvc-tooltiptext a{
305
+ color: #fff;
306
+ opacity: 0.8;
307
  }
308
  .tvc-tooltip-top {
309
  bottom: 115%;
643
  .tvc-notice-error{position: relative;}
644
  .tvc-notice-error .call_both_verification-spinner{
645
  right: 5px;top: 10px;margin-left: 0;
646
+ }
647
+ .product-auto-sync-details table { border-collapse: collapse;
648
+ border-spacing: 0;
649
+ width: 100%; border-color: grey; margin-top: 5px;}
650
+
651
+ .product-auto-sync-details table tr {
652
+ display: table-row;
653
+ vertical-align: inherit;
654
+ border-color: inherit;
655
+ }
656
+ .product-auto-sync-details table tr th {
657
+ padding-top: 11px;
658
+ padding-bottom: 11px;
659
+ background-color: #28a745;
660
+ color: white;
661
+ border: 1px solid #ddd;
662
+ text-align: left;
663
+ padding: 8px;
664
+ display: table-cell;
665
+ vertical-align: inherit;
666
+ font-weight: bold;
667
+ text-align: center;
668
+ font-size: 15px;
669
+ }
670
+ .product-auto-sync-details table tr td {
671
+ display: table-cell;
672
+ vertical-align: inherit;
673
+ border: 1px solid #ddd;
674
+ text-align: left;
675
+ padding: 8px 3px;
676
+ text-align: center;
677
+ font-size: 15px;
678
  }
enhanced-ecommerce-google-analytics.php CHANGED
@@ -16,7 +16,7 @@
16
  * Plugin Name: Enhanced E-commerce for Woocommerce store
17
  * Plugin URI: https://www.tatvic.com/tatvic-labs/woocommerce-extension/
18
  * Description: Automates eCommerce tracking in Google Analytics, dynamic remarkting in Google Ads, and provides complete Google Shopping features.
19
- * Version: 3.0.4
20
  * Author: Tatvic
21
  * Author URI: www.tatvic.com
22
  * License: GPL-2.0+
@@ -38,7 +38,7 @@ if ( ! defined( 'WPINC' ) ) {
38
  * Start at version 1.0.0 and use SemVer - https://semver.org
39
  * Rename this for your plugin and update it as you release new versions.
40
  */
41
- define( 'PLUGIN_NAME_VERSION', '3.0.4' );
42
  $fullName = plugin_basename( __FILE__ );
43
  $dir = str_replace('/enhanced-ecommerce-google-analytics.php','',$fullName);
44
  if ( ! defined( 'ENHANCAD_PLUGIN_NAME' ) ) {
16
  * Plugin Name: Enhanced E-commerce for Woocommerce store
17
  * Plugin URI: https://www.tatvic.com/tatvic-labs/woocommerce-extension/
18
  * Description: Automates eCommerce tracking in Google Analytics, dynamic remarkting in Google Ads, and provides complete Google Shopping features.
19
+ * Version: 3.0.5
20
  * Author: Tatvic
21
  * Author URI: www.tatvic.com
22
  * License: GPL-2.0+
38
  * Start at version 1.0.0 and use SemVer - https://semver.org
39
  * Rename this for your plugin and update it as you release new versions.
40
  */
41
+ define( 'PLUGIN_NAME_VERSION', '3.0.5' );
42
  $fullName = plugin_basename( __FILE__ );
43
  $dir = str_replace('/enhanced-ecommerce-google-analytics.php','',$fullName);
44
  if ( ! defined( 'ENHANCAD_PLUGIN_NAME' ) ) {
includes/class-enhanced-ecommerce-google-analytics.php CHANGED
@@ -109,7 +109,8 @@ class Enhanced_Ecommerce_Google_Analytics {
109
  * The class responsible for defining internationalization functionality
110
  * of the plugin.
111
  */
112
- require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-enhanced-ecommerce-google-analytics-i18n.php';
 
113
  // Feed Manager Files
114
  require_once plugin_dir_path(dirname(__FILE__)) . 'includes/data/class-tvc-queries.php';
115
  require_once plugin_dir_path(dirname(__FILE__)) . 'includes/data/class-tvc-file.php';
@@ -130,6 +131,9 @@ class Enhanced_Ecommerce_Google_Analytics {
130
 
131
  require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-enhanced-ecommerce-google-analytics-settings.php';
132
 
 
 
 
133
  /**
134
  * The class responsible for defining all actions that occur in the public-facing
135
  * side of the site.
109
  * The class responsible for defining internationalization functionality
110
  * of the plugin.
111
  */
112
+ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-enhanced-ecommerce-google-analytics-i18n.php';
113
+ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-tvc-admin-db-helper.php';
114
  // Feed Manager Files
115
  require_once plugin_dir_path(dirname(__FILE__)) . 'includes/data/class-tvc-queries.php';
116
  require_once plugin_dir_path(dirname(__FILE__)) . 'includes/data/class-tvc-file.php';
131
 
132
  require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-enhanced-ecommerce-google-analytics-settings.php';
133
 
134
+ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-tvc-admin-auto-product-sync-helper.php';
135
+
136
+
137
  /**
138
  * The class responsible for defining all actions that occur in the public-facing
139
  * side of the site.
includes/data/class-tvc-ajax-file.php CHANGED
@@ -48,8 +48,7 @@ class TVC_Ajax_File extends TVC_Ajax_Calls {
48
  add_action('wp_ajax_tvc_call_notice_dismiss', array($this, 'tvc_call_notice_dismiss'));
49
  }
50
  public function tvc_call_notice_dismiss(){
51
- if($this->safe_ajax_call(filter_input(INPUT_POST, 'apiNoticDismissNonce'), 'tvc_call_notice_dismiss-nonce')){
52
-
53
  $ee_notice_dismiss_id = $_POST['data']['ee_notice_dismiss_id'];
54
  if($ee_notice_dismiss_id != ""){
55
  $TVC_Admin_Helper = new TVC_Admin_Helper();
@@ -672,7 +671,7 @@ class TVC_Ajax_File extends TVC_Ajax_Calls {
672
  */
673
  public function tvcajax_product_syncup(){
674
  // make sure this call is legal
675
- ini_set('max_execution_time', '0');
676
  ini_set('memory_limit','-1');
677
  if($this->safe_ajax_call(filter_input(INPUT_POST, 'productSyncupNonce'), 'tvcajax-product-syncup-nonce')){
678
 
@@ -686,7 +685,7 @@ class TVC_Ajax_File extends TVC_Ajax_Calls {
686
  $customerId = filter_input(INPUT_POST, 'customerId');
687
  $accountId = filter_input(INPUT_POST, 'accountId');
688
  $subscriptionId = filter_input(INPUT_POST, 'subscriptionId');
689
- $platformCustomerId = filter_input(INPUT_POST, 'platformCustomerId');
690
  $data = filter_input(INPUT_POST, 'data');
691
  parse_str($data, $formArray);
692
  $mappedCatsDB = [];
@@ -954,7 +953,6 @@ class TVC_Ajax_File extends TVC_Ajax_Calls {
954
  }
955
  wp_reset_query();
956
  }
957
- //print_r($entries);
958
  $data = [
959
  'merchant_id' => $accountId,
960
  'account_id' => $merchantId,
@@ -982,6 +980,8 @@ class TVC_Ajax_File extends TVC_Ajax_Calls {
982
  //print_r($response_body);
983
  //die;
984
  if((isset($response_body->error) && $response_body->error == '')){
 
 
985
  $customObj->setGmcCategoryMapping($catMapRequest);
986
  $customObj->setGmcAttributeMapping($attrMapRequest);
987
  echo json_encode(['status' => 'success', 'skipProducts' => count($skipProducts)]);
48
  add_action('wp_ajax_tvc_call_notice_dismiss', array($this, 'tvc_call_notice_dismiss'));
49
  }
50
  public function tvc_call_notice_dismiss(){
51
+ if($this->safe_ajax_call(filter_input(INPUT_POST, 'apiNoticDismissNonce'), 'tvc_call_notice_dismiss-nonce')){
 
52
  $ee_notice_dismiss_id = $_POST['data']['ee_notice_dismiss_id'];
53
  if($ee_notice_dismiss_id != ""){
54
  $TVC_Admin_Helper = new TVC_Admin_Helper();
671
  */
672
  public function tvcajax_product_syncup(){
673
  // make sure this call is legal
674
+ ini_set('max_execution_time', '0');
675
  ini_set('memory_limit','-1');
676
  if($this->safe_ajax_call(filter_input(INPUT_POST, 'productSyncupNonce'), 'tvcajax-product-syncup-nonce')){
677
 
685
  $customerId = filter_input(INPUT_POST, 'customerId');
686
  $accountId = filter_input(INPUT_POST, 'accountId');
687
  $subscriptionId = filter_input(INPUT_POST, 'subscriptionId');
688
+ //$platformCustomerId = filter_input(INPUT_POST, 'platformCustomerId');
689
  $data = filter_input(INPUT_POST, 'data');
690
  parse_str($data, $formArray);
691
  $mappedCatsDB = [];
953
  }
954
  wp_reset_query();
955
  }
 
956
  $data = [
957
  'merchant_id' => $accountId,
958
  'account_id' => $merchantId,
980
  //print_r($response_body);
981
  //die;
982
  if((isset($response_body->error) && $response_body->error == '')){
983
+ $TVC_Admin_Auto_Product_sync_Helper = new TVC_Admin_Auto_Product_sync_Helper();
984
+ $TVC_Admin_Auto_Product_sync_Helper->update_last_sync_in_db();
985
  $customObj->setGmcCategoryMapping($catMapRequest);
986
  $customObj->setGmcAttributeMapping($attrMapRequest);
987
  echo json_encode(['status' => 'success', 'skipProducts' => count($skipProducts)]);
includes/setup/google-shopping-feed-gaa-config.php CHANGED
@@ -329,8 +329,7 @@ function submitProductSyncUp() {
329
  var merchantId = '<?php echo $this->merchantId; ?>';
330
  var accountId = '<?php echo $this->accountId; ?>';
331
  var customerId = '<?php echo $this->currentCustomerId; ?>';
332
- var subscriptionId = '<?php echo $this->subscriptionId; ?>';
333
- var platformCustomerId = jQuery("#platform_customer_id").val();
334
  var formData = jQuery("#productSync").serialize();
335
  //console.log(formData);
336
  jQuery("#feed-spinner").css("display", "block");
@@ -342,7 +341,6 @@ function submitProductSyncUp() {
342
  customerId: customerId,
343
  accountId: accountId,
344
  subscriptionId: subscriptionId,
345
- platformCustomerId: platformCustomerId,
346
  data: formData,
347
  productSyncupNonce: myAjaxNonces.productSyncupNonce
348
  },
329
  var merchantId = '<?php echo $this->merchantId; ?>';
330
  var accountId = '<?php echo $this->accountId; ?>';
331
  var customerId = '<?php echo $this->currentCustomerId; ?>';
332
+ var subscriptionId = '<?php echo $this->subscriptionId; ?>';
 
333
  var formData = jQuery("#productSync").serialize();
334
  //console.log(formData);
335
  jQuery("#feed-spinner").css("display", "block");
341
  customerId: customerId,
342
  accountId: accountId,
343
  subscriptionId: subscriptionId,
 
344
  data: formData,
345
  productSyncupNonce: myAjaxNonces.productSyncupNonce
346
  },
includes/setup/google-shopping-feed-sync-product.php CHANGED
@@ -401,8 +401,7 @@ function submitProductSyncUp() {
401
  var merchantId = '<?php echo $this->merchantId; ?>';
402
  var accountId = '<?php echo $this->accountId; ?>';
403
  var customerId = '<?php echo $this->currentCustomerId; ?>';
404
- var subscriptionId = '<?php echo $this->subscriptionId; ?>';
405
- var platformCustomerId = jQuery("#platform_customer_id").val();
406
  var formData = jQuery("#productSync").serialize();
407
  //console.log(formData);
408
  jQuery("#feed-spinner").css("display", "block");
@@ -414,7 +413,6 @@ function submitProductSyncUp() {
414
  customerId: customerId,
415
  accountId: accountId,
416
  subscriptionId: subscriptionId,
417
- platformCustomerId: platformCustomerId,
418
  data: formData,
419
  productSyncupNonce: myAjaxNonces.productSyncupNonce
420
  },
401
  var merchantId = '<?php echo $this->merchantId; ?>';
402
  var accountId = '<?php echo $this->accountId; ?>';
403
  var customerId = '<?php echo $this->currentCustomerId; ?>';
404
+ var subscriptionId = '<?php echo $this->subscriptionId; ?>';
 
405
  var formData = jQuery("#productSync").serialize();
406
  //console.log(formData);
407
  jQuery("#feed-spinner").css("display", "block");
413
  customerId: customerId,
414
  accountId: accountId,
415
  subscriptionId: subscriptionId,
 
416
  data: formData,
417
  productSyncupNonce: myAjaxNonces.productSyncupNonce
418
  },
includes/setup/google-shopping-feed.php CHANGED
@@ -137,6 +137,31 @@ class GoogleShoppingFeed {
137
  }?></span><img id="refresh_api" onclick="call_tvc_api_sync_up();" src="<?php echo ENHANCAD_PLUGIN_URL.'/admin/images/refresh.png'; ?>">
138
  </div>
139
  <?php } ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140
  <div class="configuration-section" id="config-pt1">
141
  <div class="row confg-card gsf-sec">
142
  <div class="col-md-12 col-lg-4 mb-3 mb-lg-0">
137
  }?></span><img id="refresh_api" onclick="call_tvc_api_sync_up();" src="<?php echo ENHANCAD_PLUGIN_URL.'/admin/images/refresh.png'; ?>">
138
  </div>
139
  <?php } ?>
140
+ <?php
141
+ $last_auto_sync = $this->TVC_Admin_Helper->get_last_auto_sync_product_info();
142
+ if(!empty($last_auto_sync)){
143
+ $status = isset($last_auto_sync['status'])?$last_auto_sync['status']:0;
144
+ $status_text = array("0"=>"Failed","1"=>"Completed");
145
+ $create_sync = (isset($last_auto_sync['create_sync']))?$last_auto_sync['create_sync']:"";
146
+ $create_sync = date($date_formate,strtotime($create_sync));
147
+ $next_sync = (isset($last_auto_sync['next_sync']))?$last_auto_sync['next_sync']:"";
148
+ $next_sync = date($date_formate,strtotime($next_sync));
149
+ ?>
150
+ <div class="product-auto-sync-details">
151
+ <strong>Last auto product sync details</strong>
152
+ <table>
153
+ <tr><th>Last sync</th><th width="10">Sync product</th><th width="10px">Status</th><th>Upcoming sync</th></tr>
154
+ <tr>
155
+ <td><?php echo $create_sync;?></td>
156
+ <td width="10"><?php echo (isset($last_auto_sync['total_sync_product']))?$last_auto_sync['total_sync_product']:"";?></td>
157
+ <td><?php echo $status_text[$status]; ?></td>
158
+ <td><?php echo $next_sync;?></td>
159
+ </tr>
160
+ </table>
161
+ </div>
162
+ <?php
163
+ }
164
+ ?>
165
  <div class="configuration-section" id="config-pt1">
166
  <div class="row confg-card gsf-sec">
167
  <div class="col-md-12 col-lg-4 mb-3 mb-lg-0">
readme.txt CHANGED
@@ -8,8 +8,8 @@ Author: Tatvic
8
  Requires at least: 1.4.1
9
  Tested up to: 5.7
10
  Requires PHP: 5.6 or Higher
11
- Stable tag: 3.0.4
12
- Version: 3.0.4
13
  License: GPLv3
14
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
15
 
@@ -356,6 +356,9 @@ You can resolve the duplication of data by removing the manually implemented GA
356
 
357
  == Changelog ==
358
 
 
 
 
359
  = 3.0.4 - 31/03/2021 =
360
  * UI bug issue solved
361
  * Fix to dismiss the admin notices permanentaly
8
  Requires at least: 1.4.1
9
  Tested up to: 5.7
10
  Requires PHP: 5.6 or Higher
11
+ Stable tag: 3.0.5
12
+ Version: 3.0.5
13
  License: GPLv3
14
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
15
 
356
 
357
  == Changelog ==
358
 
359
+ = 3.0.5 - 12/04/2021 =
360
+ * Add auto product sync feature enhancement - In the background, every month runs a process to sync the product, Run only those products who are completed the manual product sync.
361
+
362
  = 3.0.4 - 31/03/2021 =
363
  * UI bug issue solved
364
  * Fix to dismiss the admin notices permanentaly