Changeset 3007104
- Timestamp:
- 12/08/2023 05:02:46 AM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
wp-amazon-shop/trunk/includes/import/wp-amazon-shop-import.php
r2981645 r3007104 3 3 exit; // Exit if accessed directly 4 4 } 5 require_once( 'wp-amazon-shop-ikits.php');5 require_once('wp-amazon-shop-ikits.php'); 6 6 //use html parser 7 7 //use simplehtmldom\HtmlWeb; … … 9 9 { 10 10 11 public function initiate_hooks() { 12 add_action( 'admin_menu' , array(&$this, 'hook_import_submenu')); 11 public function initiate_hooks() 12 { 13 add_action('admin_menu', array(&$this, 'hook_import_submenu')); 13 14 add_action('wp_ajax_wpas_products_import_search', array($this, 'wpas_products_import_search')); 14 15 add_action('wp_ajax_wpas_import_product_from_amazon', array($this, 'wpas_import_product_from_amazon')); 15 16 // Check if WooCommerce is active, and is required WooCommerce version. 16 if( isset($_GET['page']) && sanitize_text_field($_GET['page'])=='wp-amazon-shop-basic-import'){17 if (!class_exists('WooCommerce') || version_compare(get_option('woocommerce_db_version'), 2.2, '<')) {18 add_action('admin_notices', array($this, 'woocommerce_required_notice'));19 return;20 }21 }17 if (isset($_GET['page']) && sanitize_text_field($_GET['page']) == 'wp-amazon-shop-basic-import') { 18 if (!class_exists('WooCommerce') || version_compare(get_option('woocommerce_db_version'), 2.2, '<')) { 19 add_action('admin_notices', array($this, 'woocommerce_required_notice')); 20 return; 21 } 22 } 22 23 } 23 function hook_import_submenu(){ 24 function hook_import_submenu() 25 { 24 26 add_submenu_page( 25 27 'wp-amazon-shop', … … 31 33 ); 32 34 } 33 public static function woocommerce_required_notice(){ 35 public static function woocommerce_required_notice() 36 { 34 37 if (current_user_can('activate_plugins')) : 35 38 if (!class_exists('WooCommerce')) : 36 ?>39 ?> 37 40 <div id="message" class="error"> 38 41 <p> … … 42 45 '<strong>', 43 46 '</strong><br>', 44 '<a href="' .esc_url_raw('https://wordpress.org/plugins/woocommerce/').'" target="_blank" >',47 '<a href="' . esc_url_raw('https://wordpress.org/plugins/woocommerce/') . '" target="_blank" >', 45 48 '</a>' 46 49 ); … … 50 53 <?php 51 54 elseif (version_compare(get_option('woocommerce_db_version'), 2.2, '<')) : 52 ?>55 ?> 53 56 <div id="message" class="error"> 54 57 <p> … … 64 67 <div style="clear:both;"></div> 65 68 </div> 66 <?php69 <?php 67 70 endif; 68 71 endif; 69 72 } 70 public function products_basic_import(){ 73 public function products_basic_import() 74 { 71 75 ?> 72 76 <div class="wrap" id="acl_wpas_products_import"> 73 <h2><?php _e('WP Amazon Shop Products Import', 'wp-amazon-shop');?></h2>77 <h2><?php _e('WP Amazon Shop Products Import', 'wp-amazon-shop'); ?></h2> 74 78 <div class="wpas-import-search-container" style="padding: 10px"> 75 <table class="widefat" style="border:none;">76 <thead>77 </thead>78 <tbody>79 80 <tr>81 <td style="width:30%;text-align:right ">82 <?php83 $categories = $this->product_categories_by_country_domain(get_option('acl_wpas_amazon_country'));84 85 ?>86 <select name="wpas_import_search_category" id="wpas_import_search_category" class="wpas_import_search_category">87 <?php88 if(!empty($categories)){89 foreach ( $categories['categories'] as $index => $category) {90 echo '<option value="' . esc_attr($index) . '">' . esc_html($category) . '</option>';91 }92 }93 ?>94 </select>95 </td>96 <td style="width:30%">97 <input type="text" id="wpas_import_search_keywords" name="wpas_import_search_keywords" class="wpas_import_search_keywords" size="100" style="width:100%;" placeholder="Search Keyword to Import Products" /><br />98 </td>99 <td style="width:40%;text-align:left ">100 <input type="button" class="button button-primary" id="wpas_import_search_btn" value="<?php _e('Search Products','wp-amazon-shop');?>">101 </td>102 </tr>103 <tr id="wpas-woo-categories-container">104 <td style="width:40%;text-align:right "><?php _e('Select a Category where to Import Product','wp-amazon-shop');?></td>105 <td>106 <?php107 $taxonomy = 'product_cat';108 $orderby = 'name';109 $show_count = 0; // 1 for yes, 0 for no110 $pad_counts = 0; // 1 for yes, 0 for no111 $hierarchical = 1; // 1 for yes, 0 for no112 $empty = 0;113 114 $args = array(115 'taxonomy' => $taxonomy,116 'orderby' => $orderby,117 'show_count' => $show_count,118 'pad_counts' => $pad_counts,119 'hierarchical' => $hierarchical,120 'hide_empty' => $empty121 );122 $wpas_woo_categories = get_categories( $args);123 ?>124 <select name="wpas_woo_category" id="wpas_woo_category" class="wpas_woo_category">125 <?php126 if(!empty($wpas_woo_categories)){127 foreach ( $wpas_woo_categories as $category) {128 echo '<option value="'.esc_attr($category->name).'">'.esc_html($category->name).'</option>';129 }130 }131 ?>132 </select>133 </td>134 135 <td></td>136 </tr>137 138 </tbody>139 </table>140 <p style="display:none;color:red;font-weight: 600;text-align: center" id="wpas-import-validation-msg"><?php _e('Entry Keyword and hit ENTER key or click on button ', 'wp-amazon-shop') ?></p>79 <table class="widefat" style="border:none;"> 80 <thead> 81 </thead> 82 <tbody> 83 84 <tr> 85 <td style="width:30%;text-align:right "> 86 <?php 87 $categories = $this->product_categories_by_country_domain(get_option('acl_wpas_amazon_country')); 88 89 ?> 90 <select name="wpas_import_search_category" id="wpas_import_search_category" class="wpas_import_search_category"> 91 <?php 92 if (!empty($categories)) { 93 foreach ($categories['categories'] as $index => $category) { 94 echo '<option value="' . esc_attr($index) . '">' . esc_html($category) . '</option>'; 95 } 96 } 97 ?> 98 </select> 99 </td> 100 <td style="width:30%"> 101 <input type="text" id="wpas_import_search_keywords" name="wpas_import_search_keywords" class="wpas_import_search_keywords" size="100" style="width:100%;" placeholder="Search Keyword to Import Products" /><br /> 102 </td> 103 <td style="width:40%;text-align:left "> 104 <input type="button" class="button button-primary" id="wpas_import_search_btn" value="<?php _e('Search Products', 'wp-amazon-shop'); ?>"> 105 </td> 106 </tr> 107 <tr id="wpas-woo-categories-container"> 108 <td style="width:40%;text-align:right "><?php _e('Select a Category where to Import Product', 'wp-amazon-shop'); ?></td> 109 <td> 110 <?php 111 $taxonomy = 'product_cat'; 112 $orderby = 'name'; 113 $show_count = 0; // 1 for yes, 0 for no 114 $pad_counts = 0; // 1 for yes, 0 for no 115 $hierarchical = 1; // 1 for yes, 0 for no 116 $empty = 0; 117 118 $args = array( 119 'taxonomy' => $taxonomy, 120 'orderby' => $orderby, 121 'show_count' => $show_count, 122 'pad_counts' => $pad_counts, 123 'hierarchical' => $hierarchical, 124 'hide_empty' => $empty 125 ); 126 $wpas_woo_categories = get_categories($args); 127 ?> 128 <select name="wpas_woo_category" id="wpas_woo_category" class="wpas_woo_category"> 129 <?php 130 if (!empty($wpas_woo_categories)) { 131 foreach ($wpas_woo_categories as $category) { 132 echo '<option value="' . esc_attr($category->name) . '">' . esc_html($category->name) . '</option>'; 133 } 134 } 135 ?> 136 </select> 137 </td> 138 139 <td></td> 140 </tr> 141 142 </tbody> 143 </table> 144 <p style="display:none;color:red;font-weight: 600;text-align: center" id="wpas-import-validation-msg"><?php _e('Entry Keyword and hit ENTER key or click on button ', 'wp-amazon-shop') ?></p> 141 145 </div> 142 146 <div class="clear" style="padding: 10px"></div> … … 144 148 <table class="wp-list-table widefat fixed striped "> 145 149 <thead> 146 <tr>147 <th scope="col" id="wpas-import-thumb" class="manage-column column-primary"><?php _e('Thumbnail', 'wp-amazon-shop') ?></th>148 <th scope="col" id="wpas-import-title" class="manage-column"><?php _e('Title', 'wp-amazon-shop') ?></th>149 <th scope="col" id="wpas-import-asin" class="manage-column "><?php _e('ASIN', 'wp-amazon-shop') ?></th>150 <th scope="col" id="wpas-import-price" class="manage-column"><?php _e('Price', 'wp-amazon-shop') ?></th>151 <th scope="col" id="wpas-import-review-rating" class="manage-column"><?php _e('Rating & Review', 'wp-amazon-shop') ?></th>152 <th scope="col" id="wpas-import-action" class="manage-column"><?php _e('Action', 'wp-amazon-shop') ?></th>153 </tr>150 <tr> 151 <th scope="col" id="wpas-import-thumb" class="manage-column column-primary"><?php _e('Thumbnail', 'wp-amazon-shop') ?></th> 152 <th scope="col" id="wpas-import-title" class="manage-column"><?php _e('Title', 'wp-amazon-shop') ?></th> 153 <th scope="col" id="wpas-import-asin" class="manage-column "><?php _e('ASIN', 'wp-amazon-shop') ?></th> 154 <th scope="col" id="wpas-import-price" class="manage-column"><?php _e('Price', 'wp-amazon-shop') ?></th> 155 <th scope="col" id="wpas-import-review-rating" class="manage-column"><?php _e('Rating & Review', 'wp-amazon-shop') ?></th> 156 <th scope="col" id="wpas-import-action" class="manage-column"><?php _e('Action', 'wp-amazon-shop') ?></th> 157 </tr> 154 158 </thead> 155 159 <tbody id="the-list" class="wpas-import-products-list"> … … 173 177 * @return array 174 178 */ 175 private function product_categories_by_country_domain( $country_domain = null ) { 179 private function product_categories_by_country_domain($country_domain = null) 180 { 176 181 $categories_by_country_domain = array(); 177 switch ( $country_domain) {182 switch ($country_domain) { 178 183 case 'com.br': 179 $categories_by_country_domain['categories'] = array( 'All' => 'Todos os departmentos', 184 $categories_by_country_domain['categories'] = array( 185 'All' => 'Todos os departmentos', 180 186 'Books' => 'Livros', 181 187 'KindleStore' => 'Loja Kindle', … … 187 193 case 'ca': 188 194 189 $categories_by_country_domain['categories'] = array( 'All' => 'All Departments', 195 $categories_by_country_domain['categories'] = array( 196 'All' => 'All Departments', 190 197 'Apparel' => 'Clothing & Accessories', 191 'Automotive' => 'Automotive', 'Baby' => 'Baby',198 'Automotive' => 'Automotive', 'Baby' => 'Baby', 192 199 193 200 'Beauty' => 'Beauty', … … 228 235 229 236 case 'cn': 230 $categories_by_country_domain['categories'] = array( 'All' => '全部分类', 237 $categories_by_country_domain['categories'] = array( 238 'All' => '全部分类', 231 239 'Apparel' => '服饰箱包', 232 240 'Appliances' => '大家电', 233 'Automotive' => '汽车用品', 'Baby' => '母婴用品',241 'Automotive' => '汽车用品', 'Baby' => '母婴用品', 234 242 235 243 'Beauty' => '美容化妆', … … 271 279 272 280 case 'fr': 273 $categories_by_country_domain['categories'] = array( 'All' => 'Toutes nos boutiques', 281 $categories_by_country_domain['categories'] = array( 282 'All' => 'Toutes nos boutiques', 274 283 'Apparel' => 'Vêtements et accessoires', 275 284 'Appliances' => 'Gros électroménager', … … 325 334 326 335 case 'de': 327 $categories_by_country_domain['categories'] = array( 'All' => 'Alle Kategorien', 336 $categories_by_country_domain['categories'] = array( 337 'All' => 'Alle Kategorien', 328 338 'Apparel' => 'Bekleidung', 329 339 'Appliances' => 'Elektro-Großgeräte', 330 'Automotive' => 'Auto & Motorrad', 'Baby' => 'Baby',340 'Automotive' => 'Auto & Motorrad', 'Baby' => 'Baby', 331 341 332 342 'Beauty' => 'Beauty', … … 382 392 383 393 case 'in': 384 $categories_by_country_domain['categories'] = array( 'All' => 'All Departments', 394 $categories_by_country_domain['categories'] = array( 395 'All' => 'All Departments', 385 396 'Apparel' => 'Clothing & Accessories', 386 397 'Appliances' => 'Appliances', … … 428 439 429 440 case 'it': 430 $categories_by_country_domain['categories'] = array( 'All' => 'Tutte le categorie', 441 $categories_by_country_domain['categories'] = array( 442 'All' => 'Tutte le categorie', 431 443 'Apparel' => 'Abbigliamento', 432 444 'Automotive' => 'Auto e Moto', … … 479 491 480 492 case 'co.jp': 481 $categories_by_country_domain['categories'] = array( 'All' => 'すべてのカテゴリー', 493 $categories_by_country_domain['categories'] = array( 494 'All' => 'すべてのカテゴリー', 482 495 'Apparel' => '服&ファッション小物', 483 496 'Appliances' => '大型家電', … … 533 546 534 547 case 'com.mx': 535 $categories_by_country_domain['categories'] = array( 'All' => 'Todos los departamentos', 548 $categories_by_country_domain['categories'] = array( 549 'All' => 'Todos los departamentos', 536 550 'Baby' => 'Bebé', 537 551 'Books' => 'Libros', … … 561 575 562 576 case 'es': 563 $categories_by_country_domain['categories'] = array( 'All' => 'Todos los departamentos', 577 $categories_by_country_domain['categories'] = array( 578 'All' => 'Todos los departamentos', 564 579 'Apparel' => 'Ropa y accesorios', 565 580 'Automotive' => 'Coche y moto', … … 610 625 611 626 case 'co.uk': 612 $categories_by_country_domain['categories'] = array( 'All' => 'All Departments', 627 $categories_by_country_domain['categories'] = array( 628 'All' => 'All Departments', 613 629 'Apparel' => 'Clothing', 614 630 'Appliances' => 'Large Appliances', … … 667 683 668 684 case 'com': 669 $categories_by_country_domain['categories'] = array( 'All' => 'All Departments', 685 $categories_by_country_domain['categories'] = array( 686 'All' => 'All Departments', 670 687 'Appliances' => 'Appliances', 671 688 'ArtsAndCrafts' => 'Arts, Crafts & Sewing', … … 733 750 return $categories_by_country_domain; 734 751 } 735 public function wpas_products_import_search(){ 752 public function wpas_products_import_search() 753 { 736 754 if (isset($_POST['page_num'])) { 737 755 $page_num = intval($_POST['page_num']); … … 740 758 } 741 759 $processed_products = $this->process_response(wpas_clean($_POST['data'])); 742 if (count($processed_products)>0){760 if (count($processed_products) > 0) { 743 761 $html = $this->import_products_display($processed_products); 744 } else{745 $html = "<p style=>" .__('No Products Found!','wp-amazon-shop')."</p>";762 } else { 763 $html = "<p style=>" . __('No Products Found!', 'wp-amazon-shop') . "</p>"; 746 764 } 747 765 … … 750 768 } 751 769 752 private function process_response($items = null) { 770 private function process_response($items = null) 771 { 753 772 $item_index = 0; 754 773 $products = array(); … … 771 790 private function import_products_display($products) 772 791 { 773 $affiliate_tag =get_option('acl_wpas_amazon_associate_tag');792 $affiliate_tag = get_option('acl_wpas_amazon_associate_tag'); 774 793 ob_start(); 775 794 foreach ($products as $product) { 776 $import_data =base64_encode(json_encode($product));777 ?>795 $import_data = base64_encode(json_encode($product)); 796 ?> 778 797 <tr> 779 798 <td class="wpas-import-thumb"> 780 799 <div class="amazon-product-thumb"> 781 <?php if (isset($product['IsPrimeEligible']) && $product['IsPrimeEligible']=='1'){?>800 <?php if (isset($product['IsPrimeEligible']) && $product['IsPrimeEligible'] == '1') { ?> 782 801 <span class="amazon-product-prime"></span> 783 802 <?php } ?> … … 787 806 <td class="wpas-import-title"> 788 807 <p class="field_text"><?php echo esc_html(str_replace("\'", "", $product['Title'])); ?></p> 789 <p class="field_text"><a href="<?php echo esc_url($product['DetailPageURL'] . '?tag=' . esc_attr($affiliate_tag)); ?>" target="_blank" class="link_to_source product_url"><?php _e('Amazon Product page', 'wp-amazon-shop'); ?></a></p></td> 808 <p class="field_text"><a href="<?php echo esc_url($product['DetailPageURL'] . '?tag=' . esc_attr($affiliate_tag)); ?>" target="_blank" class="link_to_source product_url"><?php _e('Amazon Product page', 'wp-amazon-shop'); ?></a></p> 809 </td> 790 810 <td class="wpas-import-asin"><strong><?php echo esc_html($product['ASIN']); ?></strong></td> 791 811 <td class="wpas-import-price"> 792 812 <p class="field_text"><?php echo esc_html($product['Price']); ?></p> 793 813 </td> 794 <td class="wpas-import-rating-review" >795 <?php if (isset($product['Rating']) && $product['Rating']!=""){796 if ( strpos( $product['Rating'], '.0') !== false) {797 $formatted_rating =str_replace(".0","",$product['Rating']);798 } else{799 $formatted_rating =str_replace(".","-",$product['Rating']);814 <td class="wpas-import-rating-review"> 815 <?php if (isset($product['Rating']) && $product['Rating'] != "") { 816 if (strpos($product['Rating'], '.0') !== false) { 817 $formatted_rating = str_replace(".0", "", $product['Rating']); 818 } else { 819 $formatted_rating = str_replace(".", "-", $product['Rating']); 800 820 } 801 821 802 $rating_class ="a-star-".$formatted_rating;803 ?>822 $rating_class = "a-star-" . $formatted_rating; 823 ?> 804 824 <div class="amazon-product-rating" data-product-asin="<?php echo esc_attr($product['ASIN']); ?>"> 805 825 <i class="a-icon a-icon-star <?php echo esc_attr($rating_class); ?>"><span class="a-icon-alt"><?php echo esc_html($product['Rating']); ?> <?php _e('out of 5 stars', 'wp-amazon-shop'); ?></span></i> … … 809 829 </td> 810 830 <td class="wpas-import-action"> 811 <button type="button" wpas-import-data="<?php echo esc_attr($import_data); ?>" class="button button-primary button-small wpas-item-import-btn"><?php _e('Import to WooCommerce', 'wp-amazon-shop') ?></button>831 <button type="button" wpas-import-data="<?php echo esc_attr($import_data); ?>" class="button button-primary button-small wpas-item-import-btn"><?php _e('Import to WooCommerce', 'wp-amazon-shop') ?></button> 812 832 <p class="wpas-import-success-action"></p> 813 833 </td> 814 834 </tr> 815 <?php835 <?php 816 836 } 817 837 $content = ob_get_clean(); … … 822 842 * Import as basic 823 843 */ 824 public function wpas_import_product_from_amazon() { 844 public function wpas_import_product_from_amazon() 845 { 825 846 global $wp_error; 826 847 $response = array(); … … 831 852 $image_url = esc_url_raw(isset($_POST['image']) ? $_POST['image'] : ''); 832 853 $product_id = wc_get_product_id_by_sku($sku); 833 if ($product_id) { 834 $response['status'] = 200; 835 $response['success_action'] ='<a href="'.get_admin_url().'/post.php?post='.$product_id.'&action=edit" target="_blank">'.__('Edit','wp-amazon-shop').'</a> | <a href="'.get_permalink( $product_id ).'" target="_blank">'.__('View','wp-amazon-shop').'</a>'; 836 $response['message'] = __('Already Imported','wp-amazon-shop'); 837 } else { 838 if($this->wpas_capabitlity()){ 839 //inserting functionality 840 $post_content = $title . '<br><img src="' . esc_url($image_url) . '" alt="' . esc_attr($title) . '"><br><br><a href="' . esc_url($product_url) . '" target="_blank">Product Link</a>'; 841 $post = array( 842 'post_author' => 1, 843 'post_content' =>$post_content, 844 'post_status' => "publish", 845 'post_title' => $title, 846 'post_parent' => '', 847 'post_type' => "product", 848 ); 849 850 //Create post 851 $post_id = wp_insert_post($post, $wp_error); 852 //Update term & meta. 853 wp_set_object_terms($post_id, wpas_clean($_POST['importing_category']), 'product_cat'); 854 // wp_set_object_terms($post_id, get_option('acl_wpas_category_name'), 'product_cat'); 855 wp_set_object_terms($post_id, 'simple', 'product_type'); 856 857 update_post_meta($post_id, '_visibility', 'visible'); 858 update_post_meta($post_id, '_stock_status', 'instock'); 859 update_post_meta($post_id, 'total_sales', '0'); 860 update_post_meta($post_id, '_virtual', 'yes'); 861 update_post_meta($post_id, '_purchase_note', ""); 862 update_post_meta($post_id, '_featured', "no"); 863 update_post_meta($post_id, '_weight', ""); 864 update_post_meta($post_id, '_length', ""); 865 update_post_meta($post_id, '_width', ""); 866 update_post_meta($post_id, '_height', ""); 867 update_post_meta($post_id, '_sku', $sku); 868 update_post_meta($post_id, '_product_attributes', array()); 869 update_post_meta($post_id, '_sale_price_dates_from', ""); 870 update_post_meta($post_id, '_sale_price_dates_to', ""); 871 update_post_meta($post_id, '_price', $price); 872 update_post_meta($post_id, '_sold_individually', ""); 873 update_post_meta($post_id, '_manage_stock', "no"); 874 update_post_meta($post_id, '_backorders', "no"); 875 update_post_meta($post_id, '_stock', ""); 854 855 if ($this->wpas_is_upload_authorizatied()) { 856 if ($product_id) { 857 $response['status'] = 200; 858 $response['success_action'] = '<a href="' . get_admin_url() . '/post.php?post=' . $product_id . '&action=edit" target="_blank">' . __('Edit', 'wp-amazon-shop') . '</a> | <a href="' . get_permalink($product_id) . '" target="_blank">' . __('View', 'wp-amazon-shop') . '</a>'; 859 $response['message'] = __('Already Imported', 'wp-amazon-shop'); 860 } else { 861 if ($this->wpas_capabitlity()) { 862 //inserting functionality 863 $post_content = $title . '<br><img src="' . esc_url($image_url) . '" alt="' . esc_attr($title) . '"><br><br><a href="' . esc_url($product_url) . '" target="_blank">Product Link</a>'; 864 $post = array( 865 'post_author' => 1, 866 'post_content' => $post_content, 867 'post_status' => "publish", 868 'post_title' => $title, 869 'post_parent' => '', 870 'post_type' => "product", 871 ); 872 873 //Create post 874 $post_id = wp_insert_post($post, $wp_error); 875 //Update term & meta. 876 wp_set_object_terms($post_id, wpas_clean($_POST['importing_category']), 'product_cat'); 877 // wp_set_object_terms($post_id, get_option('acl_wpas_category_name'), 'product_cat'); 878 wp_set_object_terms($post_id, 'simple', 'product_type'); 879 880 update_post_meta($post_id, '_visibility', 'visible'); 881 update_post_meta($post_id, '_stock_status', 'instock'); 882 update_post_meta($post_id, 'total_sales', '0'); 883 update_post_meta($post_id, '_virtual', 'yes'); 884 update_post_meta($post_id, '_purchase_note', ""); 885 update_post_meta($post_id, '_featured', "no"); 886 update_post_meta($post_id, '_weight', ""); 887 update_post_meta($post_id, '_length', ""); 888 update_post_meta($post_id, '_width', ""); 889 update_post_meta($post_id, '_height', ""); 890 update_post_meta($post_id, '_sku', $sku); 891 update_post_meta($post_id, '_product_attributes', array()); 892 update_post_meta($post_id, '_sale_price_dates_from', ""); 893 update_post_meta($post_id, '_sale_price_dates_to', ""); 894 update_post_meta($post_id, '_price', $price); 895 update_post_meta($post_id, '_sold_individually', ""); 896 update_post_meta($post_id, '_manage_stock', "no"); 897 update_post_meta($post_id, '_backorders', "no"); 898 update_post_meta($post_id, '_stock', ""); 876 899 if ($post_id) { 877 900 // Add Featured Image to Post … … 885 908 $filename = basename($unique_file_name); // Create image file name 886 909 //Allow following images type only to upload but other file type. 887 $allowed_file_types = array( 'image/jpeg', 'image/png', 'image/gif'); // Define allowed image types910 $allowed_file_types = array('image/jpeg', 'image/png', 'image/gif'); // Define allowed image types 888 911 $file_info = new finfo(FILEINFO_MIME_TYPE); 889 912 $file_type = $file_info->buffer($image_data); … … 925 948 $set_thumb = set_post_thumbnail($post_id, $attach_id); 926 949 // if ($set_thumb != false) { 927 $response['status'] = 200;928 $response['success_action'] = '<a href="' . get_admin_url() . '/post.php?post=' . $post_id . '&action=edit" target="_blank">' . __('Edit', 'wp-amazon-shop') . '</a> | <a href="' . get_permalink($post_id) . '" target="_blank">' . __('View', 'wp-amazon-shop') . '</a>';929 $response['message'] = __('Imported successfully', 'wp-amazon-shop');950 $response['status'] = 200; 951 $response['success_action'] = '<a href="' . get_admin_url() . '/post.php?post=' . $post_id . '&action=edit" target="_blank">' . __('Edit', 'wp-amazon-shop') . '</a> | <a href="' . get_permalink($post_id) . '" target="_blank">' . __('View', 'wp-amazon-shop') . '</a>'; 952 $response['message'] = __('Imported successfully', 'wp-amazon-shop'); 930 953 } else { 931 954 $response['status'] = 200; … … 933 956 $response['message'] = __('Imported content but image successfully', 'wp-amazon-shop'); 934 957 } 935 if(get_option('acl_wpas_namano_koto')!=""){ 936 $koto=get_option('acl_wpas_namano_koto');$koto++; 937 update_option('acl_wpas_namano_koto',$koto); 958 if (get_option('acl_wpas_namano_koto') != "") { 959 $koto = get_option('acl_wpas_namano_koto'); 960 $koto++; 961 update_option('acl_wpas_namano_koto', $koto); 938 962 } 939 940 }else{ 963 } else { 964 $response['status'] = 300; 965 $response['success_action'] = ''; 966 $response['message'] = __('Sorry Try again', 'wp-amazon-shop'); 967 } 968 } else { 941 969 $response['status'] = 300; 942 $response['success_action'] = '';943 $response['message'] = __('Sorry Try again','wp-amazon-shop');970 $response['success_action'] = '<a style="color: orangered" href="' . esc_url_raw('https://www.wpamazonshop.com/') . '" target="_blank">' . __('Upgrade to Pro for more', 'wp-amazon-shop') . '</a> '; 971 $response['message'] = __('20 Products imported per day!', 'wp-amazon-shop'); 944 972 } 945 } else {946 $response['status'] = 300;947 $response['success_action'] = '<a style="color: orangered" href="'.esc_url_raw('https://www.wpamazonshop.com/').'" target="_blank">'.__('Upgrade to Pro for more', 'wp-amazon-shop').'</a> ';948 $response['message'] = __('20 Products imported per day!', 'wp-amazon-shop');949 950 973 } 974 } else { 975 $response['status'] = 300; 976 $response['success_action'] = ''; 977 $response['message'] = __('You are not authenticated to import, login now!', 'wp-amazon-shop'); 951 978 } 952 979 echo wp_send_json($response); 953 980 wp_die(); 954 981 } 955 956 /*** 957 * 958 * Extended Import 959 */ 960 private function import_operation($product){ 961 $response = array(); 962 $has_variation=false; 963 global $wp_error; 964 $product_id = wc_get_product_id_by_sku($product['ASIN']); 965 if ($product_id) { 966 $edit_post = array( 967 'ID' => $product_id, 968 'post_title' => $product['Title'], 969 'post_content' =>wp_kses_post(base64_decode($product['Description'])), 970 ); 971 // Update the post into the database 972 wp_update_post($edit_post); 973 $response['status'] = 200; 974 $response['sku'] = $product['ASIN']; 975 $response['has_variation'] = false; 976 $response['message'] = __('Product was imported and updated now', 'wp-amazon-shop').'<a href="' . get_admin_url() . '/post.php?post=' . $product_id . '&action=edit" target="_blank">' . __('Edit', 'wp-amazon-shop') . '</a> | <a href="' . get_permalink($product_id) . '" target="_blank">' . __('View', 'wp-amazon-shop') . '</a>'; 977 } else { 978 if($this->wpas_capabitlity()) { 979 //inserting functionality 980 $post = array( 981 'post_author' => 1, 982 'post_content' => wp_kses_post($product['Description']), 983 'post_status' => 'publish', 984 'ping_status' => 'closed', 985 'post_title' => $product['Title'], 986 'post_parent' => '', 987 'post_type' => "product", 988 ); 989 990 //Create post 991 $post_id = wp_insert_post($post, $wp_error); 992 //Update term & meta. 993 //get_option('acl_wpas_category_name') 994 if (is_array($product['category']) && !empty($product['category'])) { 995 wp_set_object_terms($post_id, end($product['category']), 'product_cat'); 996 } else if ($product['category'] != "") { 997 wp_set_object_terms($post_id, $product['category'], 'product_cat'); 998 } else { 999 wp_set_object_terms($post_id, 'Uncategorized', 'product_cat'); 1000 } 1001 //setup meta 1002 wp_set_object_terms($post_id, 'simple', 'product_type'); 1003 update_post_meta($post_id, '_visibility', 'visible'); 1004 update_post_meta($post_id, '_stock_status', 'instock'); 1005 update_post_meta($post_id, 'total_sales', '0'); 1006 update_post_meta($post_id, '_purchase_note', ""); 1007 update_post_meta($post_id, '_featured', "no"); 1008 update_post_meta($post_id, '_virtual', 'no'); 1009 update_post_meta($post_id, '_length', ""); 1010 update_post_meta($post_id, '_width', ""); 1011 update_post_meta($post_id, '_height', ""); 1012 update_post_meta($post_id, '_sku', $product['ASIN']); 1013 update_post_meta($post_id, '_sale_price_dates_from', ""); 1014 update_post_meta($post_id, '_sale_price_dates_to', ""); 1015 update_post_meta($post_id, '_price', $product['price']); 1016 update_post_meta($post_id, '_regular_price', $product['price']); 1017 update_post_meta($post_id, '_sold_individually', ""); 1018 update_post_meta($post_id, '_manage_stock', "no"); 1019 update_post_meta($post_id, '_backorders', "no"); 1020 update_post_meta($post_id, 'wpas_import', 'import'); 1021 if ($post_id) { 1022 $raw_gallery = unserialize(base64_decode($product['gallery'])); 1023 $gallery_images = $raw_gallery['large']; 1024 //setting high resolution thumb 1025 if (isset($gallery_images[0]) && $gallery_images[0] != "") { 1026 $product['thumb'] = $gallery_images[0]; 1027 } 1028 // And finally assign featured image to post 1029 if (!empty($product['thumb'])) { 1030 if (strlen($product['Title']) > 15) { 1031 $image_name = substr($product['Title'], 0, 15) . '.jpg'; 1032 } else { 1033 $image_name = $product['Title'] . '.jpg'; 1034 } 1035 1036 if (isset($product['thumb']) && !empty($product['thumb'])) { 1037 $thumb_id = ACL_WPAS_iKits::insert_single_image($product['thumb'], $image_name, $post_id); 1038 $set_thumb = set_post_thumbnail($post_id, $thumb_id); 1039 } 1040 1041 } 1042 if (!empty($product['gallery'])) { 1043 $gallery_ids = ACL_WPAS_iKits::import_image_gallery($product['gallery'], $product['Title'], $post_id); 1044 if ($gallery_ids != "") { 1045 update_post_meta($post_id, '_product_image_gallery', $gallery_ids); 1046 } 1047 } 1048 if (isset($set_thumb) && $set_thumb != false) { 1049 $response['status'] = 200; 1050 $response['sku'] = $product['ASIN']; 1051 $response['has_variation'] = $has_variation; 1052 $response['message'] = __('Imported Successfully', 'wp-amazon-shop') . '<a href="' . get_admin_url() . '/post.php?post=' . $post_id . '&action=edit" target="_blank">' . __('Edit', 'wp-amazon-shop') . '</a> | <a href="' . get_permalink($post_id) . '" target="_blank">' . __('View', 'wp-amazon-shop') . '</a>'; 1053 } else { 1054 $response['status'] = 200; 1055 $response['sku'] = $product['ASIN']; 1056 $response['has_variation'] = $has_variation; 1057 $response['message'] = __('Imported content but image successfully', 'wp-amazon-shop') . '<a href="' . get_admin_url() . '/post.php?post=' . $post_id . '&action=edit" target="_blank">' . __('Edit', 'wp-amazon-shop') . '</a> | <a href="' . get_permalink($post_id) . '" target="_blank">' . __('View', 'wp-amazon-shop') . '</a>'; 1058 } 1059 if(get_option('acl_wpas_namano_koto')!=""){ 1060 $koto=get_option('acl_wpas_namano_koto');$koto++; 1061 update_option('acl_wpas_namano_koto',$koto); 1062 } 1063 } else { 1064 $response['status'] = 300; 1065 $response['sku'] = $product['ASIN']; 1066 $response['message'] = __('Error occurred! Try again', 'wp-amazon-shop'); 1067 } 1068 }else{ 1069 $response['status'] = 300; 1070 $response['sku'] = $product['ASIN']; 1071 $response['message'] = __('20 Products can be imported per day, <br>Need to import UNLIMITED,VARIATIONS,GALLERY etc <a href="'.esc_url_raw('https://www.wpamazonshop.com/').'" target="_blank">Upgrade to Pro</a> ', 'wp-amazon-shop'); 982 private function wpas_is_upload_authorizatied() 983 { 984 if (is_user_logged_in()) { 985 // Check if the user has the 'import' capability 986 if (current_user_can('upload_files')) { 987 return true; 1072 988 } 1073 989 } 1074 return $response;990 return false; 1075 991 } 1076 private function price_by_asin($asin){ 1077 //$products=array(); 1078 $product=array(); 1079 //Basic info url 1080 $basic_url="http://ws-eu.amazon-adsystem.com/widgets/q?ServiceVersion=20070822&OneJS=1&Operation=GetAdHtml&MarketPlace=GB&ad_type=product_link&marketplace=amazon®ion=GB&tracking_id=".get_option('acl_wpas_amazon_associate_tag')."&asins="; 1081 if(get_option('acl_wpas_amazon_country')=='com'){ 1082 $basic_url="http://ws-na.amazon-adsystem.com/widgets/q?ServiceVersion=20070822&OneJS=1&Operation=GetAdHtml&MarketPlace=US&ad_type=product_link&marketplace=amazon®ion=US&tracking_id=".get_option('acl_wpas_amazon_associate_tag')."&asins="; 1083 }else if(get_option('acl_wpas_amazon_country')=='co.uk'){ 1084 $basic_url="http://ws-eu.amazon-adsystem.com/widgets/q?ServiceVersion=20070822&OneJS=1&Operation=GetAdHtml&MarketPlace=GB&ad_type=product_link&marketplace=amazon®ion=GB&tracking_id=".get_option('acl_wpas_amazon_associate_tag')."&asins="; 1085 }else if(get_option('acl_wpas_amazon_country')=='de'){ 1086 $basic_url="http://ws-eu.amazon-adsystem.com/widgets/q?ServiceVersion=20070822&OneJS=1&Operation=GetAdHtml&MarketPlace=DE&ad_type=product_link&marketplace=amazon®ion=DE&tracking_id=".get_option('acl_wpas_amazon_associate_tag')."&asins="; 1087 }else if(get_option('acl_wpas_amazon_country')=='fr'){ 1088 $basic_url="http://ws-eu.amazon-adsystem.com/widgets/q?ServiceVersion=20070822&OneJS=1&Operation=GetAdHtml&MarketPlace=FR&ad_type=product_link&marketplace=amazon®ion=FR&tracking_id=".get_option('acl_wpas_amazon_associate_tag')."&asins="; 1089 }else if(get_option('acl_wpas_amazon_country')=='co.jp'){ 1090 $basic_url="http://ws-fe.amazon-adsystem.com/widgets/q?ServiceVersion=20070822&OneJS=1&Operation=GetAdHtml&MarketPlace=JP&ad_type=product_link&marketplace=amazon®ion=JP&tracking_id=".get_option('acl_wpas_amazon_associate_tag')."&asins="; 1091 }else if(get_option('acl_wpas_amazon_country')=='ca'){ 1092 $basic_url="http://ws-na.amazon-adsystem.com/widgets/q?ServiceVersion=20070822&OneJS=1&Operation=GetAdHtml&MarketPlace=CA&ad_type=product_link&marketplace=amazon®ion=CA&tracking_id=".get_option('acl_wpas_amazon_associate_tag')."&asins="; 1093 } 1094 //Not working... 1095 else if(get_option('acl_wpas_amazon_country')=='com.mx'){ 1096 $basic_url="http://ws-na.amazon-adsystem.com/widgets/q?ServiceVersion=20070822&OneJS=1&Operation=GetAdHtml&MarketPlace=MX&ad_type=product_link&marketplace=amazon®ion=MX&tracking_id=".get_option('acl_wpas_amazon_associate_tag')."&asins="; 1097 } 1098 //Not working... 1099 else if(get_option('acl_wpas_amazon_country')=='com.br'){ 1100 $basic_url="http://ws-na.amazon-adsystem.com/widgets/q?ServiceVersion=20070822&OneJS=1&Operation=GetAdHtml&MarketPlace=BR&ad_type=product_link&marketplace=amazon®ion=BR&tracking_id=".get_option('acl_wpas_amazon_associate_tag')."&asins="; 1101 }else if(get_option('acl_wpas_amazon_country')=='it'){ 1102 $basic_url="http://ws-eu.amazon-adsystem.com/widgets/q?ServiceVersion=20070822&OneJS=1&Operation=GetAdHtml&MarketPlace=IT&ad_type=product_link&marketplace=amazon®ion=IT&tracking_id=".get_option('acl_wpas_amazon_associate_tag')."&asins="; 1103 }else if(get_option('acl_wpas_amazon_country')=='in'){ 1104 $basic_url="http://ws-eu.amazon-adsystem.com/widgets/q?ServiceVersion=20070822&OneJS=1&Operation=GetAdHtml&MarketPlace=IN&ad_type=product_link&marketplace=amazon®ion=IN&tracking_id=".get_option('acl_wpas_amazon_associate_tag')."&asins="; 1105 }else if(get_option('acl_wpas_amazon_country')=='es'){ 1106 $basic_url="http://ws-eu.amazon-adsystem.com/widgets/q?ServiceVersion=20070822&OneJS=1&Operation=GetAdHtml&MarketPlace=ES&ad_type=product_link&marketplace=amazon®ion=ES&tracking_id=".get_option('acl_wpas_amazon_associate_tag')."&asins="; 1107 } 1108 else if(get_option('acl_wpas_amazon_country')=='cn'){ 1109 $basic_url="http://ws-cn.amazon-adsystem.com/widgets/q?ServiceVersion=20070822&OneJS=1&Operation=GetAdHtml&MarketPlace=CN&ad_type=product_link&marketplace=amazon®ion=CN&tracking_id=".get_option('acl_wpas_amazon_associate_tag')."&asins="; 1110 } 1111 $proudct_url=$basic_url.$asin; 1112 // Create a DOM object 1113 // latest 2.0 1114 //$doc = new HtmlWeb(); 1115 //$html = $doc->load($proudct_url); 1116 //Stable 1117 $html = new simple_html_dom(); 1118 $html->load($proudct_url);//Search Result 1119 1120 if(gettype($html->find('span.price', 0)) != "NULL") { 1121 $price_raw =$html->find('span.price', 0)->innertext; 1122 }else{ 1123 $price_raw =""; 1124 } 1125 return $price_raw; 1126 } 1127 private function wpas_capabitlity(){ 1128 $flag=false; 1129 $somoy_now=strtotime('now UTC'); 1130 $shoro=get_option('acl_wpas_namano_shoro'); 1131 if($somoy_now - $shoro <= DAY_IN_SECONDS){ 1132 $koto=get_option('acl_wpas_namano_koto'); 1133 if($koto <= ACL_WPAS_PRODUCT_PERMIT){ 1134 $flag=true; 992 private function wpas_capabitlity() 993 { 994 $flag = false; 995 $somoy_now = strtotime('now UTC'); 996 $shoro = get_option('acl_wpas_namano_shoro'); 997 if ($somoy_now - $shoro <= DAY_IN_SECONDS) { 998 $koto = get_option('acl_wpas_namano_koto'); 999 if ($koto <= ACL_WPAS_PRODUCT_PERMIT) { 1000 $flag = true; 1135 1001 } 1136 } else{1137 update_option('acl_wpas_namano_shoro',$somoy_now);1138 update_option('acl_wpas_namano_koto',0);1139 $flag =true;1002 } else { 1003 update_option('acl_wpas_namano_shoro', $somoy_now); 1004 update_option('acl_wpas_namano_koto', 0); 1005 $flag = true; 1140 1006 } 1141 1007 return $flag; 1142 1008 } 1143 1144 1145 1146 1009 } // End Class 1147 1010 //Loading Import class init hook
Note: See TracChangeset
for help on using the changeset viewer.