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; }
public function processReportData($id) { $report = new WPLA_AmazonReport($id); // $data = $report->data; $rows = $report->get_data_rows(); $lm = new WPLA_ListingsModel(); foreach ($rows as $row) { $lm->updateItemFromReportCSV($row, $report->account_id); } $msg = 'Imported: ' . $lm->imported_count . '<br>'; $msg .= 'Updated: ' . $lm->updated_count . '<br>'; $this->showMessage($msg); }
public function importASINs() { $asin_list = trim($_REQUEST['wpla_asin_list']); if (!$asin_list) { $this->showMessage('You need to enter a least one ASIN to import.', 1); return false; } $lm = new WPLA_ListingsModel(); $import_account_id = $_REQUEST['wpla_import_account_id']; if (!$import_account_id) { $import_account_id = get_option('wpla_default_account_id', 1); } $asin_array = explode("\n", $asin_list); foreach ($asin_array as $ASIN) { $ASIN = trim($ASIN); if (!$ASIN) { continue; } $row = array(); $row['asin'] = $ASIN; $row['seller-sku'] = $ASIN; $row['item-name'] = $ASIN . ' (import to fetch title from Amazon)'; $row['open-date'] = date('Y-m-d H:i:s'); $row['item-description'] = ''; $row['fulfillment-channel'] = ''; $row['quantity'] = 0; $row['price'] = 0; $row['source'] = 'foreign_import'; $lm->updateItemFromReportCSV($row, $import_account_id); // $this->showMessage('Product '.$ASIN.' was prepared for import.'); } if ($lm->imported_count) { $this->showMessage($lm->imported_count . ' new products were prepared for import.'); } if ($lm->updated_count) { $this->showMessage($lm->updated_count . ' ASINs already exist and have been skipped.'); } return $lm->imported_count + $lm->updated_count; }