示例#1
0
 /**
  * Imports and adds a sync flag to all the loaded products from LightSpeed
  * Idea - leave image import to a later time? i.e. set a flag for each imported item, and
  * if that flag exists, try and import those images.
  */
 public function import_and_sync_all_load_prods()
 {
     $nonce = $_POST['wclsi_admin_nonce'];
     if (!wp_verify_nonce($nonce, 'wclsi_load_ls_prods')) {
         header("HTTP/1.0 409 Security Check.");
         exit;
     }
     // First pass, return JSON of prod IDs
     if (true == $_POST['init_import']) {
         echo json_encode(array('ls_prod_ids' => array_keys(wclsi_glue_chunks(true))));
         exit;
     }
     // After first pass, start importing products
     if (isset($_POST['prod_id'])) {
         $prod_id = (int) $_POST['prod_id'];
         $wclsi_cat_cache = get_option('wclsi_cat_cache');
         // Get the products chunk ID and key
         $ls_prod_info = wclsi_get_ls_prod_chunk_info($prod_id);
         if (is_array($ls_prod_info)) {
             $prod_key = $ls_prod_info['key'];
             $chunk_id = $ls_prod_info['chunk_id'];
             // Get the product's chunk that it belongs to
             $wclsi_prod_chunk = get_option('wclsi_prod_chunk_' . $chunk_id);
             // If it's there, convert it
             if (isset($wclsi_prod_chunk->Item[$prod_key])) {
                 $ls_prod = $wclsi_prod_chunk->Item[$prod_key];
                 $wc_prod_id = $this->convert_to_wc_prod($ls_prod, $wclsi_cat_cache);
                 // Check if everything went ok
                 if (!is_wp_error($wc_prod_id)) {
                     // Update the chunk after we've imported the product
                     $wclsi_prod_chunk->Item[$prod_key]->wc_prod_id = $wc_prod_id;
                     $wclsi_prod_chunk->Item[$prod_key]->last_import = current_time('mysql');
                     update_option('wclsi_prod_chunk_' . $chunk_id, $wclsi_prod_chunk);
                     // Save our progress in case something gets f'ed
                     update_option('wclsi_import_progress', array('prod_id' => $prod_id, 'progress' => $_POST['import_progress']));
                     echo json_encode(array('success' => $wc_prod_id, 'prod_id' => $prod_id));
                 } else {
                     // Otherwise return an error
                     header("HTTP/1.0 409 " . sprintf(__('Could not convert product with ID %d. Error: %s', 'woocommerce-lightspeed-pos'), $prod_id, $wc_prod_id->get_error_message()));
                     exit;
                 }
             } else {
                 header("HTTP/1.0 409 " . sprintf(__('Product with ID %d does not exist!', 'woocommerce-lightspeed-pos'), $prod_id));
                 exit;
             }
         }
     } else {
         header("HTTP/1.0 409 " . __('Could not find a product ID to import!', 'woocommerce-lightspeed-pos'));
         exit;
     }
     exit;
 }
示例#2
0
 /**
  * Handles row actions defined in @see column_prod_name()
  */
 function process_row_actions()
 {
     if (isset($_GET['action']) && isset($_GET['prod_id'])) {
         $row_action = (string) $_GET['action'];
         if (!in_array($row_action, $this->get_row_actions())) {
             return;
         }
         $prod_chunk_info = wclsi_get_ls_prod_chunk_info($_GET['prod_id']);
         if (false !== $prod_chunk_info) {
             $update_msg = '';
             $prod_chunk = get_option('wclsi_prod_chunk_' . $prod_chunk_info['chunk_id']);
             $LSI_Import_Page = new LSI_Import_Page();
             $wclsi_cat_cache = get_option('wclsi_cat_cache');
             $update_type = 'updated';
             switch ($_GET['action']) {
                 case 'import_and_sync':
                     $this->process_single_import($prod_chunk->Item[$prod_chunk_info['key']], $prod_chunk_info, $wclsi_cat_cache, $LSI_Import_Page, true);
                     $update_msg = sprintf(__('1 product successfully imported & synced! You can view the imported product <a href="%s">here</a>.', 'woocommerce-lightspeed-pos'), admin_url('edit.php?post_type=product'));
                     $update_type = 'updated';
                     break;
                 case 'sync':
                     $update_info = $this->process_single_sync($_GET['prod_id'], true);
                     $update_msg = $update_info['msg'];
                     $update_type = $update_info['type'];
                     break;
                 case 'import':
                     $this->process_single_import($prod_chunk->Item[$prod_chunk_info['key']], $prod_chunk_info, $wclsi_cat_cache, $LSI_Import_Page);
                     $update_msg = sprintf(__('1 product successfully imported! You can view the imported product <a href="%s">here</a>.', 'woocommerce-lightspeed-pos'), admin_url('edit.php?post_type=product'));
                     $update_type = 'updated';
                     break;
                 case 'update':
                     $update_info = $this->process_single_manual_sync($prod_chunk->Item[$prod_chunk_info['key']]);
                     $update_msg = $update_info['msg'];
                     //__( '1 product successfully updated.', 'woocommerce-lightspeed-pos' );
                     $update_type = $update_info['type'];
                     break;
                 case 'delete':
                     $this->process_single_delete($prod_chunk_info['key'], $prod_chunk, $prod_chunk_info['chunk_id']);
                     $update_msg = __('1 product successfully deleted.', 'woocommerce-lightspeed-pos');
                     $update_type = 'updated';
                     break;
             }
             if (!empty($update_msg)) {
                 // Display update message
                 add_settings_error('wclsi_settings', 'wclsi_prod_imported', $update_msg, $update_type);
             }
         } else {
             // Display error message that the product could not be found
             add_settings_error('wclsi_settings', 'wclsi_prod_imported', __('Something went wrong! Could not find the product to perform the action on.', 'woocommerce-lightspeed-pos'), 'error');
         }
     }
 }