PluginProbe
Lasso Lite – Affiliate Link Manager & Product Displays / 156
Lasso Lite – Affiliate Link Manager & Product Displays v156
158 157 155 156 154 153 152 151 150 149 148 trunk 0.9.9 104 105 106 107 108 109 110 111 112 113 114 115 All 57 releases
← All changes | classes/class-import.php +123 -10 112156 View file →
@@ -10,8 +10,9 @@
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;
14 15 use LassoLite\Classes\Helper as Lasso_Helper;
15 16 use LassoLite\Classes\Lasso_DB;
16 17 use LassoLite\Classes\Setting as Lasso_Setting;
17 18
@@ -43,8 +44,13 @@
43 44 if ( '' === $import_id || '' === $import_source ) {
44 45 return false;
45 46 }
46 47
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 +
47 53 if ( 'AAWP' === $import_source && 'aawp_list' === $post_type ) {
48 54 $aawp_list = $lasso_db->get_aawp_list( $import_id );
49 55 $aawp_amazon_ids = $aawp_list->product_asins ?? '';
50 56 $aawp_amazon_ids = '' !== $aawp_amazon_ids ? explode( ',', $aawp_amazon_ids ) : array();
@@ -52,23 +58,30 @@
52 58 foreach ( $aawp_amazon_ids as $amazon_id ) {
53 59 $url_detail = $lasso_db->get_url_details_by_product_id( $amazon_id, Amazon_Api::PRODUCT_TYPE );
54 60 if ( $url_detail ) {
55 61 $import_id = $url_detail->lasso_id;
56 - wp_delete_post( $import_id );
62 + wp_update_post(
63 + array(
64 + 'ID' => $import_id,
65 + 'post_status' => 'trash',
66 + )
67 + );
57 68 $status = $lasso_db->process_revert( $import_id, false );
58 69 }
59 70 }
60 71 } elseif ( isset( $import_source ) && in_array( $import_source, array( 'AAWP', 'AmaLinks Pro', 'EasyAzon' ), true ) ) {
61 - wp_delete_post( $import_id );
72 + wp_update_post(
73 + array(
74 + 'ID' => $import_id,
75 + 'post_status' => 'trash',
76 + )
77 + );
62 78 $status = $lasso_db->process_revert( $import_id, false );
63 79 } else {
64 - $lasso_db->get_revert_by_id( $import_id );
65 80 $status = $lasso_db->process_revert( $import_id );
66 81 delete_post_meta( $import_id, 'affiliate_link_type' );
67 82 }
68 83
69 - $lasso_db->delete_url_details( $import_id );
70 -
71 84 // ? clear cache after reverting
72 85 Lasso_Cache_Per_Process::get_instance()->un_set( self::OBJECT_KEY . '_' . $import_id );
73 86 Lasso_Cache_Per_Process::get_instance()->un_set( 'wp_post_' . $import_id );
74 87
@@ -101,8 +114,10 @@
101 114 } elseif ( 'amalinkspro' === $post_type ) {
102 115 $import_data = $this->get_amalinkspro_data( $import_id, $post_title, $import_permalink );
103 116 } elseif ( 'easy_affiliate_link' === $post_type ) {
104 117 $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 );
105 120 }
106 121 $import_data['post_type'] = $post_type;
107 122
108 123 // ? Make a Lasso Link
@@ -113,9 +128,9 @@
113 128 return array( $status, $import_data );
114 129 }
115 130
116 131 $lasso_url = Lasso_Affiliate_Link::get_lasso_url( $import_data['post']->ID );
117 - $lasso_id = $lasso_url->lasso_id ?? 0;
132 + $lasso_id = $lasso_url->id ?? 0;
118 133
119 134 // ? Flip all old links to Lasso
120 135 if ( $lasso_id > 0 ) {
121 136 $import_data['new_url'] = $lasso_url->public_link ?? '';
@@ -171,9 +186,9 @@
171 186 'affiliate_name' => $title,
172 187 'affiliate_url' => $import_data['redirect_url'] ?? '',
173 188 'post_name' => $slug,
174 189 'price' => $import_data['price'] ?? '',
175 - 'affiliate_desc' => $import_data['description'] ?? '',
190 + 'description' => $import_data['description'] ?? '',
176 191 'buy_btn_text' => $import_data['button_text'] ?? $default_btn_txt,
177 192
178 193 'open_new_tab' => $import_data['open_new_tab'] ?? $lasso_settings['open_new_tab'] ?? 1,
179 194 'enable_nofollow' => $import_data['enable_nofollow'] ?? $lasso_settings['enable_nofollow'] ?? 1,
@@ -179,8 +194,10 @@
179 194 'enable_nofollow' => $import_data['enable_nofollow'] ?? $lasso_settings['enable_nofollow'] ?? 1,
180 195 'enable_sponsored' => $import_data['enable_sponsored'] ?? $lasso_settings['enable_sponsored'] ?? 1,
181 196 'show_disclosure' => $import_data['show_disclosure'] ?? $lasso_settings['show_disclosure'] ?? 1,
182 197 'is_opportunity' => $import_data['is_opportunity'] ?? 1,
198 + 'badge_text' => $import_data['badge_text'] ?? '',
199 + 'thumbnail' => $import_data['thumbnail'] ?? '',
183 200 );
184 201
185 202 $cat_ids = $import_data['cat_ids'] ?? array();
186 203 if ( count( $cat_ids ) > 0 ) {
@@ -190,11 +207,12 @@
190 207 $data['post_id'] = $post_id;
191 208 $data['settings'] = $affiliate_link;
192 209 $data['thumbnail_id'] = $import_data['thumbnail_id'][0] ?? '';
193 210 $data['old_uri'] = $import_data['old_uri'] ?? '';
211 + $data['is_importing'] = true;
194 212
195 213 // ? Use defined "affiliate name" as Lasso Post's name
196 - if ( 'easy_affiliate_link' === $post_type ) {
214 + if ( in_array( $post_type, array( Setting_Enum::EASY_AFFILIATE_LINK_SLUG, Setting_Enum::LASSO_PRO_SLUG ), true ) ) {
197 215 $data['use_defined_affiliate_name'] = 1;
198 216 }
199 217
200 218 // ? Flip post type and log import
@@ -368,9 +386,9 @@
368 386 $base_url = $lasso_amazon_api->get_amazon_product_url( $product->url, false );
369 387 $product_data = array(
370 388 'product_id' => $product->asin,
371 389 'title' => $product->title,
372 - 'price' => $product->price . $product->currency,
390 + 'price' => Lasso_Amazon_Api::format_price( $product->price, $product->currency ),
373 391 'default_url' => $base_url,
374 392 'url' => $product->url,
375 393 'image' => $product->image_url,
376 394 'is_prime' => $product->is_prime,
@@ -378,8 +396,10 @@
378 396 'features' => $product->features,
379 397 'savings_amount' => $product->savings,
380 398 'savings_percent' => $product->savings_percentage,
381 399 'savings_basis' => $product->savings_basis,
400 + 'rating' => $product->rating,
401 + 'reviews' => $product->reviews,
382 402 'is_manual' => 1,
383 403 );
384 404
385 405 $lasso_amazon_api->update_amazon_product_in_db( $product_data, $product->date_updated );
@@ -424,8 +444,82 @@
424 444 return $data;
425 445 }
426 446
427 447 /**
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 + /**
428 522 * Get post data of Aawp plugin
429 523 *
430 524 * @param int $import_id Post id.
431 525 */
@@ -485,9 +579,9 @@
485 579 'price' => $product['attributes']['ListPrice'] ?? $product['lowest_price_n'] ?? '',
486 580 'default_url' => $product['url'],
487 581 'url' => $product['url'],
488 582 'image' => $product['images'][4]['url'] ?? $product['images'][ count( $product['images'] ) - 1 ]['url'],
489 - 'quantity' => 200, // Manual checks won't show out of stock for now. TODO: Add BLS to out of stock checks.
583 + 'quantity' => 200, // Deferred: BLS quantity for out-of-stock checks (product decision — see epic #496).
490 584 'is_manual' => 1,
491 585 );
492 586 $lasso_amazon_api->update_amazon_product_in_db( $store_data );
493 587 }
@@ -738,6 +832,25 @@
738 832 ';
739 833 $prepare = Model::prepare( $sql, $taxonomy_id, $taxonomy_slug );
740 834
741 835 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;
742 855 }
743 856 }