コード例 #1
0
 public function findMissingProducts()
 {
     $items = WPLA_ListingQueryHelper::findMissingProducts();
     $mode = isset($_REQUEST['mode']) ? $_REQUEST['mode'] : false;
     if ($mode == 'delete') {
         foreach ($items as $item) {
             WPLA_ListingsModel::deleteItem($item->id);
         }
         wpla_show_message(sizeof($items) . ' items have been deleted.');
         return;
     }
     if ($mode == 'import') {
         foreach ($items as $item) {
             $data = array('status' => 'imported');
             WPLA_ListingsModel::updateWhere(array('id' => $item->id), $data);
         }
         wpla_show_message(sizeof($items) . ' items have been added to the import queue.');
         return;
     }
     if (!empty($items)) {
         $nonce = wp_create_nonce('wpla_tools_page');
         $btn_delete = '<a href="admin.php?page=wpla-tools&tab=inventory&action=wpla_check_for_missing_products&mode=delete&_wpnonce=' . $nonce . '" class="button button-small button-secondary">' . 'Delete all from DB' . '</a> &nbsp; ';
         $btn_import = '<a href="admin.php?page=wpla-tools&tab=inventory&action=wpla_check_for_missing_products&mode=import&_wpnonce=' . $nonce . '" class="button button-small button-primary"  >' . 'Add to import queue' . '</a>';
         $buttons = ' &nbsp; ' . $btn_delete . $btn_import;
         wpla_show_message('There are ' . sizeof($items) . ' listing(s) without a linked product in WooCommerce.' . $buttons, 'error');
     } else {
         wpla_show_message('No missing products found.');
     }
 }
コード例 #2
0
 public function displayRepricingPage()
 {
     // handle actions and show notes
     // $this->handleActions();
     if ($this->requestAction() == 'wpla_apply_lowest_price_to_all_items') {
         $this->applyLowestPricesToAllItems();
     }
     if ($this->requestAction() == 'wpla_resubmit_pnq_update') {
         $this->resubmitPnqUpdateForSelectedItems();
     }
     if ($this->requestAction() == 'wpla_bulk_apply_lowest_prices') {
         $this->applyLowestPricesToSelectedItems();
     }
     if ($this->requestAction() == 'wpla_bulk_apply_minmax_prices') {
         $this->applyMinMaxPrices();
     }
     // handle bulk action - get_compet_price
     if ($this->requestAction() == 'get_compet_price') {
         WPLA()->pages['listings']->get_compet_price();
         WPLA()->pages['listings']->get_lowest_offers();
     }
     if ($this->requestAction() == 'wpla_resubmit_all_failed_prices') {
         $lm = new WPLA_ListingsModel();
         $items = $lm->getWhere('pnq_status', -1);
         foreach ($items as $item) {
             // set pnq status to changed (1)
             $lm->updateWhere(array('id' => $item->id), array('pnq_status' => 1));
         }
         $this->showMessage(sprintf(__('%s failed prices were scheduled for resubmission.', 'wpla'), count($items)));
     }
     // create table and fetch items to show
     $this->repricingTable = new WPLA_RepricingTable();
     $this->repricingTable->prepare_items();
     $active_tab = 'repricing';
     $aData = array('plugin_url' => self::$PLUGIN_URL, 'message' => $this->message, 'listingsTable' => $this->repricingTable, 'default_account' => get_option('wpla_default_account_id'), 'tools_url' => 'admin.php?page=' . self::ParentMenuId . '-tools', 'form_action' => 'admin.php?page=' . self::ParentMenuId . '-tools' . '&tab=' . $active_tab);
     $this->display('tools_repricing', $aData);
 }
コード例 #3
0
 public static function updateMinMaxPrices($item_ids)
 {
     // echo "<pre>";print_r($item_ids);echo"</pre>";
     // TODO: sanitize values
     $min_base_price = trim($_REQUEST['min_base_price']);
     $min_price_percentage = trim($_REQUEST['min_price_percentage']);
     $min_price_amount = trim($_REQUEST['min_price_amount']);
     $max_base_price = trim($_REQUEST['max_base_price']);
     $max_price_percentage = trim($_REQUEST['max_price_percentage']);
     $max_price_amount = trim($_REQUEST['max_price_amount']);
     $min_price_amount = str_replace(',', '.', $min_price_amount);
     // convert decimal comma
     $max_price_amount = str_replace(',', '.', $max_price_amount);
     // remember last used options
     $options = array('min_base_price' => $min_base_price, 'max_base_price' => $max_base_price, 'min_price_amount' => $min_price_amount, 'max_price_amount' => $max_price_amount, 'min_price_percentage' => $min_price_percentage, 'max_price_percentage' => $max_price_percentage);
     update_option('wpla_price_wizard_options', $options);
     $lm = new WPLA_ListingsModel();
     foreach ($item_ids as $listing_id) {
         // load listing item
         $item = $lm->getItem($listing_id, OBJECT);
         if (!$item) {
             continue;
         }
         if ($item->product_type == 'variable') {
             continue;
         }
         $post_id = $item->post_id;
         // get base price (min)
         $base_price = 0;
         if ($min_base_price == 'price') {
             $base_price = WPLA_ProductWrapper::getPrice($post_id);
         }
         if ($min_base_price == 'sale_price') {
             $base_price = WPLA_ProductWrapper::getSalePrice($post_id);
         }
         if ($min_base_price == 'msrp') {
             $base_price = get_post_meta($post_id, '_msrp', true) ? get_post_meta($post_id, '_msrp', true) : get_post_meta($post_id, '_msrp_price', true);
         }
         // calculate new min price
         if ($min_price_percentage) {
             $base_price = $base_price + $base_price * floatval($min_price_percentage) / 100;
         }
         if ($min_price_amount) {
             $base_price = $base_price + floatval($min_price_amount);
         }
         if ($min_base_price == 'no_change') {
             $base_price = $item->min_price;
         }
         $new_min_price = round($base_price, 2);
         // get base price (max)
         $base_price = 0;
         if ($max_base_price == 'price') {
             $base_price = WPLA_ProductWrapper::getPrice($post_id);
         }
         if ($max_base_price == 'sale_price') {
             $base_price = WPLA_ProductWrapper::getSalePrice($post_id);
         }
         if ($max_base_price == 'msrp') {
             $base_price = get_post_meta($post_id, '_msrp', true) ? get_post_meta($post_id, '_msrp', true) : get_post_meta($post_id, '_msrp_price', true);
         }
         // calculate new max price
         if ($max_price_percentage) {
             $base_price = $base_price + $base_price * floatval($max_price_percentage) / 100;
         }
         if ($max_price_amount) {
             $base_price = $base_price + floatval($max_price_amount);
         }
         if ($max_base_price == 'no_change') {
             $base_price = $item->max_price;
         }
         $new_max_price = round($base_price, 2);
         // update listing table
         $data = array('min_price' => $new_min_price, 'max_price' => $new_max_price, 'pnq_status' => 1);
         $lm->updateWhere(array('id' => $listing_id), $data);
         // update product
         update_post_meta($item->post_id, '_amazon_minimum_price', $new_min_price);
         update_post_meta($item->post_id, '_amazon_maximum_price', $new_max_price);
     }
     // foreach item
 }
コード例 #4
0
 public function action_update_missing_asins()
 {
     WPLA()->logger->info("do_action: wpla_update_missing_asins");
     $accounts = WPLA_AmazonAccount::getAll();
     $listingsModel = new WPLA_ListingsModel();
     $batch_size = 10;
     // update 10 items at a time
     foreach ($accounts as $account) {
         $account_id = $account->id;
         $listings = $listingsModel->getAllOnlineWithoutASIN($account_id, 10, OBJECT_K);
         if (empty($listings)) {
             continue;
         }
         // process one listing at a time (for now)
         foreach ($listings as $listing) {
             WPLA()->logger->info('fetching ASIN for SKU ' . $listing->sku . ' (' . $listing->id . ') - type: ' . $listing->product_type);
             $api = new WPLA_AmazonAPI($account->id);
             $result = $api->getMatchingProductForId($listing->sku, 'SellerSKU');
             if ($result->success) {
                 if (!empty($result->product->ASIN)) {
                     // update listing ASIN
                     $listingsModel->updateWhere(array('id' => $listing->id), array('asin' => $result->product->ASIN));
                     WPLA()->logger->info('new ASIN for listing #' . $listing->id . ': ' . $result->product->ASIN);
                 } else {
                     // this is what happens when new products are listed but Amazon fails to assign an ASIN
                     // in which case the user might have to contact Amazon seller support...
                     $error_msg = sprintf(__('There was a problem fetching product details for %s.', 'wpla'), $listing->sku);
                     WPLA()->logger->error($error_msg . ' - empty product data!');
                     $error_msg .= ' This SKU does not seem to exist in your inventory on Seller Central. You can try to submit this listing again, but you may have to report this to Amazon Seller Support.';
                     // // build history array (overwrite)
                     // $history = array (
                     //   	'errors' => array (
                     // 	    array (
                     // 			'original-record-number' => '0',
                     // 			'sku'                    => $listing->sku,
                     // 			'error-code'             => '42',
                     // 			'error-type'             => 'Error',
                     // 			'error-message'          => $error_msg,
                     // 	    ),
                     // 	),
                     //   	'warnings' => array(),
                     // );
                     // load existing history data - or init new history array
                     $history = maybe_unserialize($listing->history);
                     if (!is_array($history) || !isset($history['errors'])) {
                         $history = array('errors' => array(), 'warnings' => array());
                     }
                     // add custom error to history array
                     $error_42 = array('original-record-number' => '0', 'sku' => $listing->sku, 'error-code' => '42', 'error-type' => 'Error', 'error-message' => $error_msg);
                     $history['errors'][] = $error_42;
                     // mark as failed - and include error message
                     $listingsModel->updateWhere(array('id' => $listing->id), array('status' => 'failed', 'history' => serialize($history)));
                 }
             } elseif ($result->Error->Message) {
                 $errors = sprintf(__('There was a problem fetching product details for %s.', 'wpla'), $listing->sku) . '<br>Error: ' . $result->Error->Message;
                 WPLA()->logger->error($errors);
             } else {
                 $errors = sprintf(__('There was a problem fetching product details for %s.', 'wpla'), $listing->sku);
                 WPLA()->logger->error($errors);
             }
         }
         // foreach listing
     }
     // each account
 }
コード例 #5
0
 public function process_product_meta_variable($post_id)
 {
     WPLA()->logger->info('process_product_meta_variable() - ' . $post_id);
     if (!isset($_POST['variable_sku'])) {
         return;
     }
     $variable_post_id = $_POST['variable_post_id'];
     $variable_amazon_product_id = $_POST['variable_amazon_product_id'];
     $variable_amazon_id_type = $_POST['variable_amazon_id_type'];
     $variable_amazon_asin = $_POST['variable_amazon_asin'];
     $variable_sku = $_POST['variable_sku'];
     $variable_amazon_price = isset($_POST['variable_amazon_price']) ? $_POST['variable_amazon_price'] : '';
     $variable_amazon_minimum_price = isset($_POST['variable_amazon_minimum_price']) ? $_POST['variable_amazon_minimum_price'] : '';
     $variable_amazon_maximum_price = isset($_POST['variable_amazon_maximum_price']) ? $_POST['variable_amazon_maximum_price'] : '';
     $variable_amazon_condition_type = isset($_POST['variable_amazon_condition_type']) ? $_POST['variable_amazon_condition_type'] : '';
     $variable_amazon_condition_note = isset($_POST['variable_amazon_condition_note']) ? $_POST['variable_amazon_condition_note'] : '';
     $variable_amazon_is_disabled = isset($_POST['variable_amazon_is_disabled']) ? $_POST['variable_amazon_is_disabled'] : '';
     // convert decimal comma for all price fields
     $variable_amazon_price = str_replace(',', '.', $variable_amazon_price);
     $variable_amazon_minimum_price = str_replace(',', '.', $variable_amazon_minimum_price);
     $variable_amazon_maximum_price = str_replace(',', '.', $variable_amazon_maximum_price);
     $lm = new WPLA_ListingsModel();
     $all_variations_with_SKU = array();
     $all_variations_with_ASIN = array();
     $max_loop = max(array_keys($_POST['variable_post_id']));
     for ($i = 0; $i <= $max_loop; $i++) {
         if (!isset($variable_post_id[$i])) {
             continue;
         }
         $variation_id = (int) $variable_post_id[$i];
         // Update post meta
         update_post_meta($variation_id, '_amazon_product_id', trim($variable_amazon_product_id[$i]));
         update_post_meta($variation_id, '_amazon_id_type', $variable_amazon_id_type[$i]);
         update_post_meta($variation_id, '_wpla_asin', trim($variable_amazon_asin[$i]));
         update_post_meta($variation_id, '_amazon_price', isset($variable_amazon_price[$i]) ? trim($variable_amazon_price[$i]) : '');
         update_post_meta($variation_id, '_amazon_minimum_price', isset($variable_amazon_minimum_price[$i]) ? trim($variable_amazon_minimum_price[$i]) : '');
         update_post_meta($variation_id, '_amazon_maximum_price', isset($variable_amazon_maximum_price[$i]) ? trim($variable_amazon_maximum_price[$i]) : '');
         update_post_meta($variation_id, '_amazon_condition_type', isset($variable_amazon_condition_type[$i]) ? trim($variable_amazon_condition_type[$i]) : '');
         update_post_meta($variation_id, '_amazon_condition_note', isset($variable_amazon_condition_note[$i]) ? trim($variable_amazon_condition_note[$i]) : '');
         update_post_meta($variation_id, '_amazon_is_disabled', isset($variable_amazon_is_disabled[$i]) ? $variable_amazon_is_disabled[$i] : '');
         // if ( $variable_amazon_product_id[$i] !== 'parent' )
         //     update_post_meta( $variation_id, '_amazon_product_id', $variable_amazon_product_id[$i] );
         // else
         //     delete_post_meta( $variation_id, '_amazon_product_id' );
         // update min/max prices in listings table
         if (isset($_POST['variable_amazon_minimum_price'])) {
             $min_price = isset($variable_amazon_minimum_price[$i]) ? $variable_amazon_minimum_price[$i] : '';
             $max_price = isset($variable_amazon_maximum_price[$i]) ? $variable_amazon_maximum_price[$i] : '';
             $data = array();
             if ($min_price || $max_price) {
                 if ($listing = $lm->getItemByPostID($variation_id)) {
                     if ($min_price != $listing->min_price) {
                         $data['min_price'] = $min_price;
                         $data['pnq_status'] = 1;
                         // mark as changed
                     }
                     if ($max_price != $listing->max_price) {
                         $data['max_price'] = $max_price;
                         $data['pnq_status'] = 1;
                         // mark as changed
                     }
                     // update listing
                     if (!empty($data)) {
                         $lm->updateWhere(array('id' => $listing->id), $data);
                     }
                 }
             }
         }
         // collect (matched) variations with ASIN
         if ($variable_amazon_asin[$i]) {
             $all_variations_with_ASIN[$variation_id] = $variable_amazon_asin[$i];
         }
         // collect all variations with SKU
         if ($variable_sku[$i]) {
             $all_variations_with_SKU[$variation_id] = $variable_sku[$i];
         }
     }
     // each variation
     WPLA()->logger->info('Variations with ASIN: ' . print_r($all_variations_with_ASIN, 1));
     WPLA()->logger->info('Variations with SKU : ' . print_r($all_variations_with_SKU, 1));
     // process matched variations
     // check all variations with ASIN and add missing ones to listings table
     if (!empty($all_variations_with_ASIN)) {
         $lm = new WPLA_ListingsModel();
         $default_account_id = get_option('wpla_default_account_id', 1);
         if (!$default_account_id) {
             return;
         }
         // ***
         foreach ($all_variations_with_ASIN as $variation_id => $asin) {
             // check if this ASIN / ID already exist - skip if it does
             WPLA()->logger->info("searching for existing listing for #{$variation_id} / {$asin}");
             if ($lm->getItemByASIN($asin, false)) {
                 continue;
             }
             if ($lm->getItemByPostID($variation_id)) {
                 continue;
             }
             WPLA()->logger->info("no listing found for variation #{$variation_id} / {$asin}");
             // skip hidden variations
             if (get_post_meta($variation_id, '_amazon_is_disabled', true) == 'on') {
                 continue;
             }
             // insert matched listing
             $success = $lm->insertMatchedProduct($variation_id, $asin, $default_account_id);
             $error_msg = isset($lm->lastError) ? $lm->lastError : '';
             if ($success) {
                 // TODO: use persistent admin message
                 WPLA()->logger->info("Matched variation #{$variation_id} / {$asin} - {$error_msg}");
             } else {
                 echo "Failed to match variation #{$variation_id} - please report this to support: {$error_msg}";
                 WPLA()->logger->error("Failed to match variation #{$variation_id} / {$asin} - {$error_msg}");
             }
         }
         // each matched variation
     }
     // if $all_variations_with_ASIN
     // add missing variations
     // if the parent product has a listing item, then check for and add missing variation listings
     $lm = new WPLA_ListingsModel();
     $parent_listing = $lm->getItemByPostID($post_id);
     if ($parent_listing) {
         // get account from parent listing
         $account = WPLA_AmazonAccount::getAccount($parent_listing->account_id);
         if (!$account) {
             return;
         }
         foreach ($all_variations_with_SKU as $variation_id => $sku) {
             // check if this SKU / ID already exist - skip if it does
             if ($lm->getItemBySKU($sku, false)) {
                 continue;
             }
             if ($lm->getItemByPostID($variation_id)) {
                 continue;
             }
             WPLA()->logger->info("no listing found for missing variation #{$variation_id} / {$sku}");
             // check if this variation has a UPC/EAN set - skip if empty (unless brand registry is enabled)
             $_amazon_product_id = get_post_meta($variation_id, '_amazon_product_id', true);
             if (!$_amazon_product_id && !$account->is_reg_brand) {
                 continue;
             }
             // skip hidden variations
             if (get_post_meta($variation_id, '_amazon_is_disabled', true) == 'on') {
                 continue;
             }
             // insert variation listing
             $success = $lm->insertMissingVariation($variation_id, $sku, $parent_listing);
             $error_msg = isset($lm->lastError) ? $lm->lastError : '';
             if ($success) {
                 // TODO: use persistent admin message
                 WPLA()->logger->info("Matched missing variation #{$variation_id} / {$sku} - {$error_msg}");
             } else {
                 echo "Failed to match missing variation #{$variation_id} - please report this to support: {$error_msg}";
                 WPLA()->logger->error("Failed to match missing variation #{$variation_id} / {$sku} - {$error_msg}");
             }
         }
         // each variation
     }
     // if parent listing exists
 }
コード例 #6
0
 public function processListingPnqResults($feed_rows, $result_rows)
 {
     $lm = new WPLA_ListingsModel();
     // index results by SKU
     $results = array();
     foreach ($result_rows as $r) {
         if (!isset($r['sku']) || empty($r['sku'])) {
             continue;
         }
         $results[$r['sku']][] = $r;
         WPLA()->logger->info('result sku: ' . $r['sku']);
     }
     // process each result row
     foreach ($feed_rows as $row) {
         $listing_data = array();
         $row_sku = $row['sku'];
         if (!$row_sku) {
             WPLA()->logger->warn('skipping row without SKU: ' . print_r($row, 1));
             continue;
         }
         $row_results = isset($results[$row_sku]) ? $results[$row_sku] : false;
         WPLA()->logger->info('processing feed sku: ' . $row_sku);
         // if there are no result rows for this SKU, set status to 'online'
         if (!$row_results) {
             $listing_data['pnq_status'] = '0';
             $lm->updateWhere(array('sku' => $row_sku, 'pnq_status' => '2', 'account_id' => $this->account_id), $listing_data);
             WPLA()->logger->info('changed status to online: ' . $row_sku);
             continue;
         }
         // handle errors and warnings
         $errors = array();
         $warnings = array();
         $processed_keys = array();
         foreach ($row_results as $row_result) {
             // translate error-type
             if ($row_result['error-type'] == 'Fehler') {
                 $row_result['error-type'] = 'Error';
             }
             // amazon.de
             if ($row_result['error-type'] == 'Warnung') {
                 $row_result['error-type'] = 'Warning';
             }
             if ($row_result['error-type'] == 'Erreur') {
                 $row_result['error-type'] = 'Error';
             }
             // amazon.fr
             if ($row_result['error-type'] == 'Avertissement') {
                 $row_result['error-type'] = 'Warning';
             }
             // compute hash to identify duplicate errors
             $row_key = md5($row_result['sku'] . $row_result['error-code'] . $row_result['error-type'] . $row_result['original-record-number']);
             if ('Error' == $row_result['error-type']) {
                 WPLA()->logger->info('error: ' . $row_sku . ' - ' . $row_key . ' - ' . $row_result['error-message']);
                 if (!in_array($row_key, $processed_keys)) {
                     $errors[] = $row_result;
                     $processed_keys[] = $row_key;
                 }
             } elseif ('Warning' == $row_result['error-type']) {
                 WPLA()->logger->info('warning: ' . $row_sku . ' - ' . $row_key . ' - ' . $row_result['error-message']);
                 if (!in_array($row_key, $processed_keys)) {
                     $warnings[] = $row_result;
                     $processed_keys[] = $row_key;
                 }
             }
         }
         // foreach result row
         // update listing
         if (!empty($errors)) {
             $listing_data['pnq_status'] = '-1';
             $lm->updateWhere(array('sku' => $row_sku, 'pnq_status' => '2', 'account_id' => $this->account_id), $listing_data);
             WPLA()->logger->info('changed PNQ status to FAILED (-1): ' . $row_sku);
             $this->errors = array_merge($this->errors, $errors);
             $this->warnings = array_merge($this->warnings, $warnings);
         } elseif (!empty($warnings)) {
             $listing_data['pnq_status'] = '0';
             $lm->updateWhere(array('sku' => $row_sku, 'pnq_status' => '2', 'account_id' => $this->account_id), $listing_data);
             WPLA()->logger->info('changed PNQ status to 0: ' . $row_sku);
             $this->warnings = array_merge($this->warnings, $warnings);
         }
     }
     // foreach row
 }
コード例 #7
0
 public static function processQualityReportPage($report, $rows, $job, $task)
 {
     $listingsModel = new WPLA_ListingsModel();
     // reset quality info for all products using this account
     $account_id = $report->account_id;
     $update_data = array('quality_status' => null, 'quality_info' => null);
     $listingsModel->updateWhere(array('account_id' => $account_id), $update_data);
     // process rows
     foreach ($rows as $row) {
         $asin = $row['asin'];
         $sku = $row['sku'];
         $quality_info = array('sku' => $row['sku'], 'product-name' => $row['product-name'], 'asin' => $row['asin'], 'field-name' => $row['field-name'], 'alert-type' => $row['alert-type'], 'current-value' => $row['current-value'], 'last-updated' => $row['last-updated'], 'alert-name' => $row['alert-name'], 'status' => $row['status'], 'explanation' => $row['explanation'], 'ts' => time());
         $update_data = array('quality_status' => $row['alert-name'], 'quality_info' => serialize($quality_info));
         if ($asin) {
             $listingsModel->updateWhere(array('asin' => $asin), $update_data);
         }
         if ($sku) {
             $listingsModel->updateWhere(array('sku' => $sku), $update_data);
         }
     }
     // build response
     $response = new stdClass();
     $response->job = $job;
     $response->task = $task;
     $response->errors = '';
     $response->success = true;
     return $response;
 }
コード例 #8
0
 public function jobs_run_task()
 {
     // quit if no job name provided
     if (!isset($_REQUEST['job'])) {
         return false;
     }
     if (!isset($_REQUEST['task'])) {
         return false;
     }
     $job = $_REQUEST['job'];
     $task = $_REQUEST['task'];
     // register shutdown handler
     global $wpla_shutdown_handler_enabled;
     $wpla_shutdown_handler_enabled = true;
     register_shutdown_function(array($this, 'shutdown_handler'));
     WPLA()->logger->info('running task: ' . print_r($task, 1));
     // handle job name
     switch ($task['task']) {
         // update listing from Amazon (current used for new listings without ASIN)
         case 'updateProduct':
             // init
             $lm = new WPLA_ListingsModel();
             $listing = $lm->getItem($task['id']);
             $account = WPLA_AmazonAccount::getAccount($listing['account_id']);
             $api = new WPLA_AmazonAPI($account->id);
             // get product attributes
             // $product = $api->getProduct( $listing['asin'] );
             $result = $api->getMatchingProductForId($listing['sku'], 'SellerSKU');
             // echo "<pre>";print_r($product);echo"</pre>";#die();
             // echo "<pre>";print_r($product);echo"</pre>";die();
             if ($result->success) {
                 if (!empty($result->product->ASIN)) {
                     // update listing attributes
                     $listing_id = $listing['id'];
                     // $lm->updateItemAttributes( $product, $listing_id );
                     // $listing = $lm->getItem( $listing_id ); // update values
                     $lm->updateWhere(array('id' => $listing_id), array('asin' => $result->product->ASIN));
                     WPLA()->logger->info('new ASIN for listing #' . $listing['id'] . ': ' . $result->product->ASIN);
                     // update product
                     // $woo = new WPLA_ProductBuilder();
                     // $woo->updateProducts( array( $listing ) );
                     $success = true;
                     $errors = '';
                 } else {
                     $errors = sprintf(__('There was a problem fetching product details for %s.', 'wpla'), $listing['asin']);
                     $errors .= ' The product data received from Amazon was empty.';
                     $success = false;
                 }
             } elseif ($result->Error->Message) {
                 $errors = sprintf(__('There was a problem fetching product details for %s.', 'wpla'), $listing['asin']) . '<br>Error: ' . $result->Error->Message;
                 $success = false;
             } else {
                 $errors = sprintf(__('There was a problem fetching product details for %s.', 'wpla'), $listing['asin']);
                 $success = false;
             }
             // build response
             $response = new stdClass();
             $response->job = $job;
             $response->task = $task;
             $response->errors = empty($errors) ? array() : array(array('HtmlMessage' => $errors));
             $response->success = $success;
             $this->returnJSON($response);
             exit;
             // create new WooCommerce product from imported listing
         // create new WooCommerce product from imported listing
         case 'createProduct':
             // init
             $lm = new WPLA_ListingsModel();
             // $listing = $lm->getItem( $task['id'] );
             $listing_id = $task['id'];
             // create product
             $ProductsImporter = new WPLA_ProductsImporter();
             $success = $ProductsImporter->createProductFromAmazonListing($listing_id);
             $error = $ProductsImporter->lastError;
             $delay = $ProductsImporter->request_count * 1000;
             // ms
             // build response
             $response = new stdClass();
             $response->job = $job;
             $response->task = $task;
             $response->errors = empty($error) ? array() : array(array('HtmlMessage' => $error));
             $response->success = $success;
             $response->delay = $delay;
             $this->returnJSON($response);
             exit;
             // fetch full product description from Amazon and update WooCommerce product
         // fetch full product description from Amazon and update WooCommerce product
         case 'fetchFullProductDescription':
             $webHelper = new WPLA_AmazonWebHelper();
             $webHelper->loadListingDetails($task['id']);
             // echo "<pre>";print_r($webHelper->images);echo"</pre>";#die();
             $lm = new WPLA_ListingsModel();
             $item = $lm->getItem($task['id']);
             if (!empty($webHelper->description)) {
                 // update product
                 $post_id = $item['post_id'];
                 $post_data = array('ID' => $post_id, 'post_content' => trim($webHelper->description));
                 wp_update_post($post_data);
                 $success = true;
                 $errors = '';
             } else {
                 $errors = sprintf(__('There was a problem fetching product details for %s.', 'wpla'), $item['asin']);
                 $errors .= ' The product description received from Amazon was empty.';
                 $success = false;
             }
             // build response
             $response = new stdClass();
             $response->job = $job;
             $response->task = $task;
             $response->errors = empty($errors) ? array() : array(array('HtmlMessage' => $errors));
             $response->success = $success;
             $this->returnJSON($response);
             exit;
             // process Merchant or FBA Report and create / update listings
         // process Merchant or FBA Report and create / update listings
         case 'processReportPage':
             // process report page - both Merchant and FBA reports
             $response = WPLA_ImportHelper::ajax_processReportPage($job, $task);
             $this->returnJSON($response);
             exit;
             // process single row (SKU) Merchant or FBA Report - and create / update listings
         // process single row (SKU) Merchant or FBA Report - and create / update listings
         case 'processSingleSkuFromReport':
             // process report page - both Merchant and FBA reports
             $response = WPLA_ImportHelper::ajax_processReportPage($job, $task, true);
             $this->returnJSON($response);
             exit;
         default:
             // echo "unknown task";
             // exit();
     }
 }
コード例 #9
0
 static function updateAmazonPrice($item, $target_price, $verbose)
 {
     // make sure we don't go below min_price
     if ($item->min_price) {
         $target_price = max($target_price, $item->min_price);
     }
     // make sure we don't go above max_price (prevent feed error)
     if ($item->max_price) {
         $target_price = min($target_price, $item->max_price);
     }
     // skip if there is no change in price
     if ($target_price == $item->price) {
         return false;
     }
     // update amazon price in WooCommerce
     update_post_meta($item->post_id, '_amazon_price', $target_price);
     // update price in listings table
     $data = array('price' => $target_price, 'pnq_status' => 1);
     WPLA_ListingsModel::updateWhere(array('id' => $item->id), $data);
     // show message
     if ($verbose) {
         wpla_show_message($item->sku . ': price was changed from ' . $item->price . ' to <b>' . $target_price . '</b>');
     }
     // price was changed
     return true;
 }
コード例 #10
0
 public function handleActions()
 {
     // handle save listing
     if ($this->requestAction() == 'save_listing') {
         $this->saveListing();
     }
     // trigger create product
     if ($this->requestAction() == 'create_product') {
         $lm = new WPLA_ListingsModel();
         $listing = $lm->getItem($_REQUEST['listing']);
         if (!$listing) {
             return;
         }
         // create product
         $ProductsImporter = new WPLA_ProductsImporter();
         $success = $ProductsImporter->createProductFromAmazonListing($listing);
         $error = $ProductsImporter->lastError;
         $post_id = $ProductsImporter->lastPostID;
         $message = $ProductsImporter->message;
         if ($success) {
             // get parent post_id - for View Product button
             $_product = get_product($post_id);
             if ('variation' == $_product->product_type) {
                 $post_id = $_product->parent->id;
             }
             $msg = $message ? $message : sprintf(__('A new product (ID %s) was created for ASIN %s.', 'wpla'), $post_id, $listing['asin']);
             $msg .= sprintf('&nbsp;&nbsp;<a href="post.php?post=%s&action=edit" class="button button-small" target="_blank">%s</a>', $post_id, __('View product', 'wpla'));
             $this->showMessage($msg);
         } else {
             $error_msg = sprintf(__('Item %s could not be imported.', 'wpla'), $listing['asin']) . '<br>Error: ' . $error;
             $this->showMessage($error_msg, 1);
         }
     }
     // handle update from Amazon action
     if ($this->requestAction() == 'update') {
         // $this->initAC();
         // $this->EC->updateItemsFromEbay( $_REQUEST['listing'] );
         // $this->EC->closeEbay();
         // $this->showMessage( __('Selected items were updated from Amazon.','wpla') );
         $this->showMessage(__('Not implemented yet.', 'wpla'));
     }
     // handle delete action
     if ($this->requestAction() == 'delete') {
         $lm = new WPLA_ListingsModel();
         if (is_array($_REQUEST['listing'])) {
             foreach ($_REQUEST['listing'] as $id) {
                 $lm->deleteItem($id);
             }
         } elseif (is_numeric($_REQUEST['listing'])) {
             $lm->deleteItem($_REQUEST['listing']);
         }
         $this->showMessage(__('Selected listings were removed from WP-Lister.', 'wpla'));
     }
     // handle trash_listing action
     if ($this->requestAction() == 'trash_listing') {
         $items = is_array($_REQUEST['listing']) ? $_REQUEST['listing'] : array($_REQUEST['listing']);
         $lm = new WPLA_ListingsModel();
         foreach ($items as $id) {
             $lm->updateWhere(array('id' => $id), array('status' => 'trash'));
         }
         $this->showMessage(__('Selected items have been scheduled to be removed from your Amazon account.', 'wpla'));
     }
     // handle resubmit action
     if ($this->requestAction() == 'resubmit') {
         $items = is_array($_REQUEST['listing']) ? $_REQUEST['listing'] : array($_REQUEST['listing']);
         $lm = new WPLA_ListingsModel();
         foreach ($items as $id) {
             $lm->resubmitItem($id);
         }
         $this->showMessage(__('Selected items were prepared for resubmission.', 'wpla'));
     }
     if ($this->requestAction() == 'resubmit_all_failed') {
         $lm = new WPLA_ListingsModel();
         $items = $lm->getWhere('status', 'failed');
         foreach ($items as $item) {
             $lm->resubmitItem($item->id);
         }
         $this->showMessage(sprintf(__('%s failed items were prepared for resubmission.', 'wpla'), count($items)));
     }
     if ($this->requestAction() == 'wpla_clear_import_queue') {
         $lm = new WPLA_ListingsModel();
         $items = $lm->getWhere('status', 'imported');
         foreach ($items as $item) {
             $lm->deleteItem($item->id);
         }
         $this->showMessage(sprintf(__('%s items have been removed from the import queue.', 'wpla'), count($items)));
     }
     // handle toolbar action - prepare listing from product
     if ($this->requestAction() == 'wpla_prepare_single_listing') {
         // get profile
         $profile = isset($_REQUEST['profile_id']) ? WPLA_AmazonProfile::getProfile($_REQUEST['profile_id']) : false;
         if ($profile) {
             // prepare product
             $listingsModel = new WPLA_ListingsModel();
             $success = $listingsModel->prepareProductForListing($_REQUEST['product_id'], $_REQUEST['profile_id']);
             // $listingsModel->applyProfileToNewListings( $profile );
             if ($success) {
                 $this->showMessage(__('New listing was prepared from product.', 'wpla'));
             } else {
                 $this->showMessage(join('<br>', $listingsModel->warnings), 1);
             }
         }
     }
     // handle bulk action - get_compet_price
     if ($this->requestAction() == 'get_compet_price') {
         $this->get_compet_price();
         $this->get_lowest_offers();
         // do both
     }
     // handle bulk action - get_lowest_offers
     if ($this->requestAction() == 'get_lowest_offers') {
         $this->get_lowest_offers();
     }
     // handle wpla_dismiss_imported_products_notice action
     if ($this->requestAction() == 'wpla_dismiss_imported_products_notice') {
         self::updateOption('dismiss_imported_products_notice', '1');
     }
 }