コード例 #1
0
 public static function processInventoryReportPage($report, $rows, $job, $task)
 {
     // process rows
     $lm = new WPLA_ListingsModel();
     $ProductBuilder = new WPLA_ProductBuilder();
     // $update_woo_products_from_reports = get_option( 'wpla_update_woo_products_from_reports' ) == '1' ? true : false;
     $reports_update_woo_stock = get_option('wpla_reports_update_woo_stock', 1) == 1 ? true : false;
     $reports_update_woo_price = get_option('wpla_reports_update_woo_price', 1) == 1 ? true : false;
     $reports_update_woo_condition = get_option('wpla_reports_update_woo_condition', 1) == 1 ? true : false;
     $update_woo_products_from_reports = $reports_update_woo_stock || $reports_update_woo_price || $reports_update_woo_condition;
     foreach ($rows as $report_row) {
         $existing_item = $lm->updateItemFromReportCSV($report_row, $report->account_id);
         if ($existing_item && $update_woo_products_from_reports) {
             $ProductBuilder->updateProductFromItem($existing_item, $report_row);
         }
     }
     //
     // debug
     //
     $msg = '' . $lm->imported_count . ' items were added to the import queue and ' . $lm->updated_count . ' existing listings were updated.<br>';
     $msg = "<div class='updated'><p>{$msg}</p></div>";
     // send debug data as error...
     $error = new stdClass();
     $error->code = 10001;
     $error->HtmlMessage = $msg;
     $errors = array($error);
     $success = true;
     // $errors  = '';
     // build response
     $response = new stdClass();
     $response->job = $job;
     $response->task = $task;
     $response->errors = $errors;
     $response->success = $success;
     $response->imported_count = $lm->imported_count;
     $response->updated_count = $lm->updated_count;
     return $response;
 }
コード例 #2
0
 public function removeAllImportedProducts()
 {
     global $wpdb;
     $listing_ids = $wpdb->get_col("\n            SELECT al.id\n            FROM {$wpdb->prefix}amazon_listings al\n            WHERE al.source = 'imported'\n               OR al.source = 'foreign_import'\n        ");
     $post_ids = $wpdb->get_col("\n            SELECT pm.post_id\n            FROM {$wpdb->postmeta} pm\n            WHERE pm.meta_key   = '_amazon_item_source'\n              AND pm.meta_value = 'imported'\n        ");
     // echo "<pre>";print_r($post_ids);echo"</pre>";die();
     $mode = isset($_REQUEST['mode']) ? $_REQUEST['mode'] : false;
     if ($mode == 'deletion_confirmed') {
         foreach ($post_ids as $post_id) {
             WPLA_ProductBuilder::deleteProduct($post_id);
         }
         foreach ($listing_ids as $listing_id) {
             $wpdb->delete($wpdb->prefix . 'amazon_listings', array('id' => $listing_id), array('%d'));
         }
         wpla_show_message('All imported products and listings have been removed.');
         return;
     }
     if (!empty($post_ids)) {
         $nonce = wp_create_nonce('wpla_tools_page');
         $btn_delete = '<a href="admin.php?page=wpla-tools&tab=developer&action=wpla_remove_all_imported_products&mode=deletion_confirmed&_wpnonce=' . $nonce . '" class="button button-small button-secondary">' . 'Yes, I want to remove all imported products' . '</a>';
         $buttons = ' &nbsp; ' . $btn_delete;
         wpla_show_message('Are you sure you want to remove ' . sizeof($post_ids) . ' products and ' . sizeof($listing_ids) . ' listings which were imported from Amazon? ' . $buttons, 'warn');
     } else {
         wpla_show_message('There are no imported products to remove.');
     }
 }
コード例 #3
0
 public function fixNewVariationListings($variations, $parent_listing)
 {
     WPLA()->logger->info("fixNewVariationListings()");
     $lm = new WPLA_ListingsModel();
     // get post_id of parent which has been created by now
     // $parent_listing = $lm->getItemByASIN( $parent_listing->asin );
     $parent_listing = $lm->getItemBySKU($parent_listing->sku);
     // catch Invalid argument error
     if (!is_array($variations)) {
         WPLA()->logger->error("no variations found for parent variable ASIN {$parent_listing->asin} (not checked)");
         WPLA()->logger->error("no variations found for parent variable SKU  {$parent_listing->sku}");
         WPLA()->logger->error('variations:' . print_r($variations, 1));
         // echo 'Error: no variations found for variable ASIN '.$parent_listing->asin.'<br>';
         // echo "<pre>variations: ";print_r($variations);echo"</pre>";#die();
         return;
     }
     foreach ($variations as $var) {
         $post_id = WPLA_ProductBuilder::getProductIdBySKU($var->sku);
         if (!$post_id) {
             WPLA()->logger->warn("fixing SKU {$var->sku} ... no product found for this SKU!!");
             continue;
         }
         $data = array('post_id' => $post_id, 'parent_id' => $parent_listing->post_id);
         $lm->updateListing($var->listing_id, $data);
         WPLA()->logger->info("fixed SKU {$var->sku} - post_id: {$post_id}");
     }
 }