| @@ -19,9 +19,9 @@ | ||
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | function init() { |
| 22 | 22 | $this->add_actions_and_listeners(); |
| 23 | - add_action('clear_dynsync_config', array($this, 'clearConfig')); | |
| 23 | + add_action('wpr_clear_dynsync_config', array($this, 'clearConfig')); | |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | public function clearConfig() { |
| 27 | 27 | $this->db->dropBVTable(BVWPDynSync::$dynsync_table); |
| @@ -254,22 +254,34 @@ | ||
| 254 | 254 | return !$is_ignored; |
| 255 | 255 | } |
| 256 | 256 | |
| 257 | 257 | /* WOOCOMMERCE SUPPORT FUNCTIONS BEGINS FROM HERE*/ |
| 258 | - | |
| 259 | - function woocommerce_resume_order_handler($order_id) { | |
| 258 | + function handle_order_items($order_id, $type = null) { | |
| 260 | 259 | $this->add_db_event('woocommerce_order_items', array('order_id' => $order_id, 'msg_type' => 'delete')); |
| 261 | - $meta_ids = array(); | |
| 262 | 260 | $itemmeta_table = $this->db->getWPTable('woocommerce_order_itemmeta'); |
| 263 | 261 | $items_table = $this->db->getWPTable('woocommerce_order_items'); |
| 264 | - foreach( $this->db->getResult($this->db->prepare("SELECT {$itemmeta_table}.meta_id FROM {$itemmeta_table} INNER JOIN {$items_table} WHERE {$items_table}.order_item_id = {$itemmeta_table}.order_item_id AND {$items_table}.order_id = %d", $order_id)) as $key => $row) { | |
| 265 | - if (!in_array($row->meta_id, $meta_ids, true)) { | |
| 266 | - $meta_ids[] = $row->meta_id; | |
| 267 | - $this->add_db_event('woocommerce_order_itemmeta', array('meta_id' => $row->meta_id, 'msg_type' => 'delete')); | |
| 262 | + $query = "SELECT {$itemmeta_table}.meta_id FROM {$itemmeta_table} INNER JOIN {$items_table} WHERE {$itemmeta_table}.order_item_id = {$items_table}.order_item_id AND {$items_table}.order_id = {$order_id}"; | |
| 263 | + if (!empty($type)) { | |
| 264 | + $query .= " AND {$items_table}.order_item_type = '{$type}'"; | |
| 265 | + } | |
| 266 | + $meta_ids = array(); | |
| 267 | + foreach ($this->db->getResult($query) as $row) { | |
| 268 | + if (!in_array($row['meta_id'], $meta_ids, true)) { | |
| 269 | + $meta_ids[] = $row['meta_id']; | |
| 270 | + $this->add_db_event('woocommerce_order_itemmeta', array('meta_id' => $row['meta_id'], 'msg_type' => 'delete')); | |
| 268 | 271 | } |
| 269 | 272 | } |
| 270 | 273 | } |
| 271 | 274 | |
| 275 | + function woocommerce_remove_order_items_handler($order, $type = null) { | |
| 276 | + $order_id = $order->get_id(); | |
| 277 | + $this->handle_order_items($order_id, $type); | |
| 278 | + } | |
| 279 | + | |
| 280 | + function woocommerce_resume_order_handler($order_id) { | |
| 281 | + $this->handle_order_items($order_id); | |
| 282 | + } | |
| 283 | + | |
| 272 | 284 | function woocommerce_update_order_handler($order_id, $order = null) { |
| 273 | 285 | $this->add_db_event('wc_orders', array('id' => $order_id)); |
| 274 | 286 | $this->add_db_event('wc_orders_meta', array('order_id' => $order_id)); |
| 275 | 287 | $this->add_db_event('wc_order_addresses', array('order_id' => $order_id)); |
| @@ -327,9 +339,8 @@ | ||
| 327 | 339 | } |
| 328 | 340 | |
| 329 | 341 | function woocommerce_tax_rate_handler($tax_rate_id, $_tax_rate) { |
| 330 | 342 | $this->add_db_event('woocommerce_tax_rates', array('tax_rate_id' => $tax_rate_id)); |
| 331 | - $this->add_db_event('woocommerce_tax_rate_locations', array('tax_rate_id' => $tax_rate_id)); | |
| 332 | 343 | } |
| 333 | 344 | |
| 334 | 345 | function woocommerce_tax_rate_deleted_handler($tax_rate_id) { |
| 335 | 346 | $this->add_db_event('woocommerce_tax_rates', array('tax_rate_id' => $tax_rate_id, 'msg_type' => 'delete')); |
| @@ -493,12 +504,28 @@ | ||
| 493 | 504 | function woocommerce_analytics_tax_delete_handler($tax_rate_id, $order_id) { |
| 494 | 505 | $this->add_db_event('wc_order_tax_lookup', array('order_id' => $order_id, 'msg_type' => 'delete')); |
| 495 | 506 | } |
| 496 | 507 | |
| 497 | - function woocommerce_product_update_handler($product_id) { | |
| 508 | + function woocommerce_product_update_handler($product_id, $meta_key = null) { | |
| 498 | 509 | $this->add_db_event('wc_product_meta_lookup', array('product_id' => $product_id, 'msg_type' => 'edit')); |
| 510 | + if(!empty($meta_key)) { | |
| 511 | + $meta_ids = $this->db->getResult("SELECT meta_id FROM {$this->db->dbprefix()}postmeta WHERE post_id = {$product_id} AND meta_key = '{$meta_key}';"); | |
| 512 | + $this->postmeta_action_handler(array_column($meta_ids, 'meta_id'), null, $meta_key); | |
| 513 | + } | |
| 499 | 514 | } |
| 500 | 515 | |
| 516 | + function woocommerce_product_stock_update_handler($product_id) { | |
| 517 | + $this->woocommerce_product_update_handler($product_id, '_stock'); | |
| 518 | + } | |
| 519 | + | |
| 520 | + function woocommerce_product_sales_update_handler($product_id) { | |
| 521 | + $this->woocommerce_product_update_handler($product_id, 'total_sales'); | |
| 522 | + } | |
| 523 | + | |
| 524 | + function woocommerce_product_price_update_handler($product_id) { | |
| 525 | + $this->woocommerce_product_update_handler($product_id); | |
| 526 | + } | |
| 527 | + | |
| 501 | 528 | function woocommerce_trash_untrash_post_handler($post_id) { |
| 502 | 529 | if (!$post_id) { |
| 503 | 530 | return; |
| 504 | 531 | } |
| @@ -618,8 +645,9 @@ | ||
| 618 | 645 | add_action('add_site_option', array($this, 'sitemeta_handler'), 10, 1); |
| 619 | 646 | add_action('update_site_option', array($this, 'sitemeta_handler'), 10, 1); |
| 620 | 647 | |
| 621 | 648 | /* CAPTURING EVENTS FOR WOOCOMMERCE */ |
| 649 | + add_action('woocommerce_remove_order_items', array($this, 'woocommerce_remove_order_items_handler'), 10, 2); | |
| 622 | 650 | add_action('woocommerce_update_order', array($this, 'woocommerce_update_order_handler'), 10, 2); |
| 623 | 651 | add_action('woocommerce_delete_order', array($this, 'woocommerce_delete_order_handler'), 10, 1); |
| 624 | 652 | add_action('woocommerce_trash_order', array($this, 'woocommerce_trash_order_handler'), 10, 1); |
| 625 | 653 | add_action('woocommerce_resume_order', array($this, 'woocommerce_resume_order_handler'), 10, 1); |
| @@ -648,9 +676,8 @@ | ||
| 648 | 676 | add_action('woocommerce_ajax_revoke_access_to_product_download', array($this, 'woocommerce_revoke_access_to_product_download_handler'), 10, 4); |
| 649 | 677 | add_action('woocommerce_deleted_order_downloadable_permissions', array($this, 'woocommerce_deleted_order_downloadable_permissions_handler'), 10, 1); |
| 650 | 678 | |
| 651 | 679 | add_action('woocommerce_new_payment_token', array($this, 'woocommerce_payment_token_handler'), 10, 1); |
| 652 | - add_action('woocommerce_payment_token_created', array($this, 'woocommerce_payment_token_handler'), 10, 1); | |
| 653 | 680 | add_action('woocommerce_payment_token_updated', array($this, 'woocommerce_payment_token_handler'), 10, 1); |
| 654 | 681 | add_action('woocommerce_payment_token_deleted', array($this, 'woocommerce_payment_token_deleted_handler'), 10, 2); |
| 655 | 682 | add_action('added_payment_token_meta', array($this, 'woocommerce_payment_token_meta_handler' ), 10, 4); |
| 656 | 683 | add_action('updated_payment_token_meta', array($this, 'woocommerce_payment_token_meta_handler'), 10, 4); |
| @@ -685,11 +712,11 @@ | ||
| 685 | 712 | |
| 686 | 713 | add_action('woocommerce_analytics_update_tax', array($this, 'woocommerce_analytics_tax_update_handler'), 10, 2); |
| 687 | 714 | add_action('woocommerce_analytics_delete_tax', array($this, 'woocommerce_analytics_tax_delete_handler'), 10, 2); |
| 688 | 715 | |
| 689 | - add_action('woocommerce_updated_product_stock', array($this, 'woocommerce_product_update_handler'), 10, 1); | |
| 690 | - add_action('woocommerce_updated_product_sales', array($this, 'woocommerce_product_update_handler'), 10, 1); | |
| 691 | - add_action('woocommerce_updated_product_price', array($this, 'woocommerce_product_update_handler'), 10, 1); | |
| 716 | + add_action('woocommerce_updated_product_stock', array($this, 'woocommerce_product_stock_update_handler'), 10, 1); | |
| 717 | + add_action('woocommerce_updated_product_sales', array($this, 'woocommerce_product_sales_update_handler'), 10, 1); | |
| 718 | + add_action('woocommerce_updated_product_price', array($this, 'woocommerce_product_price_update_handler'), 10, 1); | |
| 692 | 719 | |
| 693 | 720 | add_action('wp_trash_post', array($this, 'woocommerce_trash_untrash_post_handler'), 10, 1); |
| 694 | 721 | add_action('untrashed_post', array($this, 'woocommerce_trash_untrash_post_handler'), 10, 1); |
| 695 | 722 | |