| @@ -10,9 +10,8 @@ | ||
| 10 | 10 | use LassoLite\Admin\Constant; |
| 11 | 11 | use LassoLite\Classes\Amazon_Api as Lasso_Amazon_Api; |
| 12 | 12 | use LassoLite\Classes\Affiliate_Link as Lasso_Affiliate_Link; |
| 13 | 13 | use LassoLite\Classes\Cache_Per_Process as Lasso_Cache_Per_Process; |
| 14 | -use LassoLite\Classes\Setting_Enum; | |
| 15 | 14 | use LassoLite\Classes\Helper as Lasso_Helper; |
| 16 | 15 | use LassoLite\Classes\Lasso_DB; |
| 17 | 16 | use LassoLite\Classes\Setting as Lasso_Setting; |
| 18 | 17 | |
| @@ -44,13 +43,8 @@ | ||
| 44 | 43 | if ( '' === $import_id || '' === $import_source ) { |
| 45 | 44 | return false; |
| 46 | 45 | } |
| 47 | 46 | |
| 48 | - // Bulk revert passes plugin slugs from the revert table; UI passes display labels. | |
| 49 | - if ( isset( Setting_Enum::SUPPORT_IMPORT_PLUGINS[ $import_source ] ) ) { | |
| 50 | - $import_source = Setting_Enum::SUPPORT_IMPORT_PLUGINS[ $import_source ]; | |
| 51 | - } | |
| 52 | - | |
| 53 | 47 | if ( 'AAWP' === $import_source && 'aawp_list' === $post_type ) { |
| 54 | 48 | $aawp_list = $lasso_db->get_aawp_list( $import_id ); |
| 55 | 49 | $aawp_amazon_ids = $aawp_list->product_asins ?? ''; |
| 56 | 50 | $aawp_amazon_ids = '' !== $aawp_amazon_ids ? explode( ',', $aawp_amazon_ids ) : array(); |
| @@ -58,30 +52,23 @@ | ||
| 58 | 52 | foreach ( $aawp_amazon_ids as $amazon_id ) { |
| 59 | 53 | $url_detail = $lasso_db->get_url_details_by_product_id( $amazon_id, Amazon_Api::PRODUCT_TYPE ); |
| 60 | 54 | if ( $url_detail ) { |
| 61 | 55 | $import_id = $url_detail->lasso_id; |
| 62 | - wp_update_post( | |
| 63 | - array( | |
| 64 | - 'ID' => $import_id, | |
| 65 | - 'post_status' => 'trash', | |
| 66 | - ) | |
| 67 | - ); | |
| 56 | + wp_delete_post( $import_id ); | |
| 68 | 57 | $status = $lasso_db->process_revert( $import_id, false ); |
| 69 | 58 | } |
| 70 | 59 | } |
| 71 | 60 | } elseif ( isset( $import_source ) && in_array( $import_source, array( 'AAWP', 'AmaLinks Pro', 'EasyAzon' ), true ) ) { |
| 72 | - wp_update_post( | |
| 73 | - array( | |
| 74 | - 'ID' => $import_id, | |
| 75 | - 'post_status' => 'trash', | |
| 76 | - ) | |
| 77 | - ); | |
| 61 | + wp_delete_post( $import_id ); | |
| 78 | 62 | $status = $lasso_db->process_revert( $import_id, false ); |
| 79 | 63 | } else { |
| 64 | + $lasso_db->get_revert_by_id( $import_id ); | |
| 80 | 65 | $status = $lasso_db->process_revert( $import_id ); |
| 81 | 66 | delete_post_meta( $import_id, 'affiliate_link_type' ); |
| 82 | 67 | } |
| 83 | 68 | |
| 69 | + $lasso_db->delete_url_details( $import_id ); | |
| 70 | + | |
| 84 | 71 | // ? clear cache after reverting |
| 85 | 72 | Lasso_Cache_Per_Process::get_instance()->un_set( self::OBJECT_KEY . '_' . $import_id ); |
| 86 | 73 | Lasso_Cache_Per_Process::get_instance()->un_set( 'wp_post_' . $import_id ); |
| 87 | 74 | |
| @@ -114,10 +101,8 @@ | ||
| 114 | 101 | } elseif ( 'amalinkspro' === $post_type ) { |
| 115 | 102 | $import_data = $this->get_amalinkspro_data( $import_id, $post_title, $import_permalink ); |
| 116 | 103 | } elseif ( 'easy_affiliate_link' === $post_type ) { |
| 117 | 104 | $import_data = $this->get_easy_affiliate_link_data( $import_id, $post_title, $import_permalink ); |
| 118 | - } elseif ( Setting_Enum::LASSO_PRO_SLUG === $post_type ) { | |
| 119 | - $import_data = $this->get_lasso_pro_data( $import_id ); | |
| 120 | 105 | } |
| 121 | 106 | $import_data['post_type'] = $post_type; |
| 122 | 107 | |
| 123 | 108 | // ? Make a Lasso Link |
| @@ -128,9 +113,9 @@ | ||
| 128 | 113 | return array( $status, $import_data ); |
| 129 | 114 | } |
| 130 | 115 | |
| 131 | 116 | $lasso_url = Lasso_Affiliate_Link::get_lasso_url( $import_data['post']->ID ); |
| 132 | - $lasso_id = $lasso_url->id ?? 0; | |
| 117 | + $lasso_id = $lasso_url->lasso_id ?? 0; | |
| 133 | 118 | |
| 134 | 119 | // ? Flip all old links to Lasso |
| 135 | 120 | if ( $lasso_id > 0 ) { |
| 136 | 121 | $import_data['new_url'] = $lasso_url->public_link ?? ''; |
| @@ -186,9 +171,9 @@ | ||
| 186 | 171 | 'affiliate_name' => $title, |
| 187 | 172 | 'affiliate_url' => $import_data['redirect_url'] ?? '', |
| 188 | 173 | 'post_name' => $slug, |
| 189 | 174 | 'price' => $import_data['price'] ?? '', |
| 190 | - 'description' => $import_data['description'] ?? '', | |
| 175 | + 'affiliate_desc' => $import_data['description'] ?? '', | |
| 191 | 176 | 'buy_btn_text' => $import_data['button_text'] ?? $default_btn_txt, |
| 192 | 177 | |
| 193 | 178 | 'open_new_tab' => $import_data['open_new_tab'] ?? $lasso_settings['open_new_tab'] ?? 1, |
| 194 | 179 | 'enable_nofollow' => $import_data['enable_nofollow'] ?? $lasso_settings['enable_nofollow'] ?? 1, |
| @@ -194,10 +179,8 @@ | ||
| 194 | 179 | 'enable_nofollow' => $import_data['enable_nofollow'] ?? $lasso_settings['enable_nofollow'] ?? 1, |
| 195 | 180 | 'enable_sponsored' => $import_data['enable_sponsored'] ?? $lasso_settings['enable_sponsored'] ?? 1, |
| 196 | 181 | 'show_disclosure' => $import_data['show_disclosure'] ?? $lasso_settings['show_disclosure'] ?? 1, |
| 197 | 182 | 'is_opportunity' => $import_data['is_opportunity'] ?? 1, |
| 198 | - 'badge_text' => $import_data['badge_text'] ?? '', | |
| 199 | - 'thumbnail' => $import_data['thumbnail'] ?? '', | |
| 200 | 183 | ); |
| 201 | 184 | |
| 202 | 185 | $cat_ids = $import_data['cat_ids'] ?? array(); |
| 203 | 186 | if ( count( $cat_ids ) > 0 ) { |
| @@ -207,12 +190,11 @@ | ||
| 207 | 190 | $data['post_id'] = $post_id; |
| 208 | 191 | $data['settings'] = $affiliate_link; |
| 209 | 192 | $data['thumbnail_id'] = $import_data['thumbnail_id'][0] ?? ''; |
| 210 | 193 | $data['old_uri'] = $import_data['old_uri'] ?? ''; |
| 211 | - $data['is_importing'] = true; | |
| 212 | 194 | |
| 213 | 195 | // ? Use defined "affiliate name" as Lasso Post's name |
| 214 | - if ( in_array( $post_type, array( Setting_Enum::EASY_AFFILIATE_LINK_SLUG, Setting_Enum::LASSO_PRO_SLUG ), true ) ) { | |
| 196 | + if ( 'easy_affiliate_link' === $post_type ) { | |
| 215 | 197 | $data['use_defined_affiliate_name'] = 1; |
| 216 | 198 | } |
| 217 | 199 | |
| 218 | 200 | // ? Flip post type and log import |
| @@ -386,9 +368,9 @@ | ||
| 386 | 368 | $base_url = $lasso_amazon_api->get_amazon_product_url( $product->url, false ); |
| 387 | 369 | $product_data = array( |
| 388 | 370 | 'product_id' => $product->asin, |
| 389 | 371 | 'title' => $product->title, |
| 390 | - 'price' => Lasso_Amazon_Api::format_price( $product->price, $product->currency ), | |
| 372 | + 'price' => $product->price . $product->currency, | |
| 391 | 373 | 'default_url' => $base_url, |
| 392 | 374 | 'url' => $product->url, |
| 393 | 375 | 'image' => $product->image_url, |
| 394 | 376 | 'is_prime' => $product->is_prime, |
| @@ -396,10 +378,8 @@ | ||
| 396 | 378 | 'features' => $product->features, |
| 397 | 379 | 'savings_amount' => $product->savings, |
| 398 | 380 | 'savings_percent' => $product->savings_percentage, |
| 399 | 381 | 'savings_basis' => $product->savings_basis, |
| 400 | - 'rating' => $product->rating, | |
| 401 | - 'reviews' => $product->reviews, | |
| 402 | 382 | 'is_manual' => 1, |
| 403 | 383 | ); |
| 404 | 384 | |
| 405 | 385 | $lasso_amazon_api->update_amazon_product_in_db( $product_data, $product->date_updated ); |
| @@ -444,82 +424,8 @@ | ||
| 444 | 424 | return $data; |
| 445 | 425 | } |
| 446 | 426 | |
| 447 | 427 | /** |
| 448 | - * Get Lasso Pro data to import. | |
| 449 | - * | |
| 450 | - * @param int $import_id Lasso Pro post id. | |
| 451 | - * @return array | |
| 452 | - */ | |
| 453 | - private function get_lasso_pro_data( $import_id ) { | |
| 454 | - $target_url = self::get_lasso_pro_target_url( $import_id ); | |
| 455 | - $amazon_id = Lasso_Amazon_Api::get_product_id_by_url( $target_url ); | |
| 456 | - $terms = get_the_terms( $import_id, 'lasso-cat' ); | |
| 457 | - $cat_ids = $terms && ! is_wp_error( $terms ) ? wp_list_pluck( $terms, 'name' ) : null; | |
| 458 | - | |
| 459 | - $lasso_amazon_api = new Lasso_Amazon_Api(); | |
| 460 | - if ( $amazon_id && ! $lasso_amazon_api->get_amazon_product_from_db( $amazon_id ) ) { | |
| 461 | - $this->import_lasso_pro_amazon_product_into_lasso_lite( $amazon_id ); | |
| 462 | - } | |
| 463 | - | |
| 464 | - $data = array( | |
| 465 | - 'post' => get_post( $import_id ), | |
| 466 | - 'redirect_url' => $target_url, | |
| 467 | - 'cat_ids' => $cat_ids, | |
| 468 | - 'old_uri' => $target_url, | |
| 469 | - 'button_text' => get_post_meta( $import_id, 'buy_btn_text', true ), | |
| 470 | - 'price' => get_post_meta( $import_id, 'price', true ), | |
| 471 | - 'thumbnail_id' => get_post_meta( $import_id, 'lasso_thumbnail_id', true ), | |
| 472 | - 'thumbnail' => get_post_meta( $import_id, 'lasso_custom_thumbnail', true ), | |
| 473 | - 'description' => get_post_meta( $import_id, 'affiliate_desc', true ), | |
| 474 | - 'open_new_tab' => get_post_meta( $import_id, 'open_new_tab', true ), | |
| 475 | - 'enable_nofollow' => get_post_meta( $import_id, 'enable_nofollow', true ), | |
| 476 | - 'enable_sponsored' => get_post_meta( $import_id, 'enable_sponsored', true ), | |
| 477 | - 'show_disclosure' => get_post_meta( $import_id, 'show_disclosure', true ), | |
| 478 | - 'badge_text' => get_post_meta( $import_id, 'badge_text', true ), | |
| 479 | - ); | |
| 480 | - | |
| 481 | - return $data; | |
| 482 | - } | |
| 483 | - | |
| 484 | - /** | |
| 485 | - * Import Lasso Pro amazon product data to Lite | |
| 486 | - * | |
| 487 | - * @param string $amazon_id Amazon Product id. | |
| 488 | - * @return array|bool|mixed|object|void|null | |
| 489 | - */ | |
| 490 | - private function import_lasso_pro_amazon_product_into_lasso_lite( $amazon_id ) { | |
| 491 | - $lasso_db = new Lasso_DB(); | |
| 492 | - $lasso_amazon_api = new Lasso_Amazon_Api(); | |
| 493 | - | |
| 494 | - $product = $lasso_db->get_lasso_pro_amazon_product( $amazon_id ); | |
| 495 | - if ( $product ) { | |
| 496 | - $product_data = array( | |
| 497 | - 'product_id' => $product->amazon_id, | |
| 498 | - 'title' => $product->default_product_name, | |
| 499 | - 'price' => $product->latest_price, | |
| 500 | - 'default_url' => $product->base_url, | |
| 501 | - 'url' => $product->url, | |
| 502 | - 'image' => $product->image_url, | |
| 503 | - 'is_prime' => $product->is_prime, | |
| 504 | - 'currency' => $product->currency, | |
| 505 | - 'features' => $product->features, | |
| 506 | - 'savings_amount' => $product->savings_amount, | |
| 507 | - 'savings_percent' => $product->savings_percent, | |
| 508 | - 'savings_basis' => $product->savings_basis, | |
| 509 | - 'quantity' => $product->quantity, | |
| 510 | - 'rating' => $product->rating, | |
| 511 | - 'reviews' => $product->reviews, | |
| 512 | - 'is_manual' => 1, | |
| 513 | - ); | |
| 514 | - | |
| 515 | - $lasso_amazon_api->update_amazon_product_in_db( $product_data, $product->last_updated ); | |
| 516 | - } | |
| 517 | - | |
| 518 | - return $product; | |
| 519 | - } | |
| 520 | - | |
| 521 | - /** | |
| 522 | 428 | * Get post data of Aawp plugin |
| 523 | 429 | * |
| 524 | 430 | * @param int $import_id Post id. |
| 525 | 431 | */ |
| @@ -579,9 +485,9 @@ | ||
| 579 | 485 | 'price' => $product['attributes']['ListPrice'] ?? $product['lowest_price_n'] ?? '', |
| 580 | 486 | 'default_url' => $product['url'], |
| 581 | 487 | 'url' => $product['url'], |
| 582 | 488 | 'image' => $product['images'][4]['url'] ?? $product['images'][ count( $product['images'] ) - 1 ]['url'], |
| 583 | - 'quantity' => 200, // Deferred: BLS quantity for out-of-stock checks (product decision — see epic #496). | |
| 489 | + 'quantity' => 200, // Manual checks won't show out of stock for now. TODO: Add BLS to out of stock checks. | |
| 584 | 490 | 'is_manual' => 1, |
| 585 | 491 | ); |
| 586 | 492 | $lasso_amazon_api->update_amazon_product_in_db( $store_data ); |
| 587 | 493 | } |
| @@ -832,25 +738,6 @@ | ||
| 832 | 738 | '; |
| 833 | 739 | $prepare = Model::prepare( $sql, $taxonomy_id, $taxonomy_slug ); |
| 834 | 740 | |
| 835 | 741 | return Model::get_row( $prepare ); |
| 836 | - } | |
| 837 | - | |
| 838 | - /** | |
| 839 | - * Get Lasso Pro target url | |
| 840 | - * | |
| 841 | - * @param int $lasso_pro_id Lasso Pro post Id. | |
| 842 | - * @return mixed | |
| 843 | - */ | |
| 844 | - public static function get_lasso_pro_target_url( $lasso_pro_id ) { | |
| 845 | - $sql = ' | |
| 846 | - SELECT redirect_url | |
| 847 | - FROM ' . Model::get_wp_table_name( 'lasso_url_details' ) . ' | |
| 848 | - WHERE lasso_id = %d | |
| 849 | - '; | |
| 850 | - $sql = Model::prepare( $sql, $lasso_pro_id ); | |
| 851 | - | |
| 852 | - $target_url = Model::get_var( $sql ); | |
| 853 | - | |
| 854 | - return $target_url; | |
| 855 | 742 | } |
| 856 | 743 | } |