Ejemplo n.º 1
0
 public function showNotifications()
 {
     // get listing status summary
     $summary = WPLA_ListingsModel::getStatusSummary();
     // check for prepared items and display info
     if (isset($summary->prepared)) {
         // $next_schedule = $this->print_schedule_info( 'wpla_update_schedule' );
         // $msg  = '<p>';
         // $msg .= sprintf( __('%d %s product(s) will be submitted to Amazon %s.','wpla'), $summary->prepared, 'prepared', $next_schedule );
         // $msg .= '&nbsp;&nbsp;';
         // $msg .= '<a href="admin.php?page=wpla&listing_status=prepared" id="" class="button button-small wpl_job_button">' . __('Show products','wpla') . '</a>';
         // $msg .= '&nbsp;&nbsp;';
         // $msg .= '<a href="admin.php?page=wpla-feeds&action=submit_pending_feeds_to_amazon" id="" class="button button-small wpl_job_button">' . __('Submit pending feeds','wpla') . '</a>';
         // $msg .= '</p>';
         // $this->showMessage( $msg );
         // check prepared products for problems
         $problems = WPLA_FeedValidator::checkPreparedProducts();
         if ($problems) {
             $this->showMessage($problems, 1);
         }
     }
     // check for changed, matched and prepared items - and show message
     $is_feed_page = isset($_GET['page']) && $_GET['page'] == 'wpla-feeds';
     if (isset($summary->changed) || isset($summary->prepared) || isset($summary->matched)) {
         $next_schedule = $this->print_schedule_info('wpla_update_schedule');
         // build nice combined message
         $summary_msg = '';
         $summary_array = array();
         foreach (array('changed', 'prepared', 'matched') as $status) {
             if (!isset($summary->{$status})) {
                 continue;
             }
             $link_url = 'admin.php?page=wpla&listing_status=' . $status;
             $link_title = $summary->{$status} . ' ' . $status;
             $summary_array[] = '<a href="' . $link_url . '">' . $link_title . '</a>';
         }
         $summary_msg = join(' and ', $summary_array);
         $msg = '<p>';
         $msg .= sprintf(__('%s product(s) will be submitted to Amazon %s.', 'wpla'), $summary_msg, $next_schedule);
         $msg .= '&nbsp;&nbsp;';
         if ($is_feed_page) {
             $msg .= '<a href="admin.php?page=wpla-feeds&action=submit_pending_feeds_to_amazon" id="" class="button button-small wpl_job_button">' . __('Submit pending feeds', 'wpla') . '</a>';
         } else {
             $msg .= '<a href="admin.php?page=wpla-feeds" id="" class="button button-small wpl_job_button">' . __('Visit feeds', 'wpla') . '</a>';
         }
         $msg .= '</p>';
         $this->showMessage($msg);
     }
 }
 static function formatAmazonFeedError($feed_error)
 {
     $error_message = WPLA_FeedValidator::explainAmazonError($feed_error['error-code'], $feed_error['error-message']);
     $error_message = '<b>' . $feed_error['error-type'] . ' ' . $feed_error['error-code'] . ':</b> ' . self::convert_links($error_message);
     if (isset($feed_error['feed_id'])) {
         // get feed permalink
         $feed_id = $feed_error['feed_id'];
         $feed_permalink = admin_url('admin-ajax.php?action=wpla_feed_details') . '&id=' . $feed_id . '&sig=' . md5($feed_id . get_option('wpla_instance'));
         $error_message .= '&nbsp;<a href="' . $feed_permalink . '" title="inspect feed details" target="_blank">[&raquo]</a>';
     }
     return $error_message;
 }
 function checkForInvalidData($post)
 {
     global $page;
     if ('product' != $post->post_type) {
         return;
     }
     if ('auto-draft' == $post->post_status) {
         return;
     }
     if (!get_option('wpla_enable_missing_details_warning')) {
         return;
     }
     $product = get_product($post);
     $invalid_product_ids = array();
     $invalid_skus = array();
     // SKU
     if ($product->sku && !WPLA_FeedValidator::isValidSKU($product->sku)) {
         $invalid_skus[] = $product->sku;
     }
     // UPC / EAN
     $amazon_product_id = get_post_meta($product->id, '_amazon_product_id', true);
     if ($amazon_product_id && !WPLA_FeedValidator::isValidEANorUPC($amazon_product_id)) {
         $invalid_product_ids[] = $amazon_product_id;
     }
     // variable product
     if ($product->product_type == 'variable') {
         // get variations
         $variation_ids = $product->get_children();
         foreach ($variation_ids as $variation_id) {
             $_product = get_product($variation_id);
             $var_info = " (#{$variation_id})";
             // SKU
             if ($_product->sku && !WPLA_FeedValidator::isValidSKU($_product->sku)) {
                 $invalid_skus[] = $_product->sku . $var_info;
             }
             // UPC / EAN
             $amazon_product_id = get_post_meta($variation_id, '_amazon_product_id', true);
             if ($amazon_product_id && !WPLA_FeedValidator::isValidEANorUPC($amazon_product_id)) {
                 $invalid_product_ids[] = $amazon_product_id . $var_info;
             }
         }
         // foreach variation
     }
     // variable product
     // show warning
     $errors_msg = '';
     if (!empty($invalid_skus)) {
         $errors_msg .= __('Warning: This SKU is not valid:', 'wpla') . ' <b>' . htmlspecialchars(join($invalid_skus, ', ')) . '</b> - only letters, numbers, dashes and underscores are allowed.<br>';
     }
     if (!empty($invalid_product_ids)) {
         $errors_msg .= __('Warning: This product ID does not seem to be a valid UPC / EAN:', 'wpla') . ' <b>' . htmlspecialchars(join($invalid_product_ids, ', ')) . '</b><br>';
         $errors_msg .= __('Valid UPCs have 12 digits, EANs have 13 digits.', 'wpla') . '<br>';
     }
     if (!empty($errors_msg)) {
         self::showMessage($errors_msg, 2, 1);
     }
 }
 function displayMessageRow($item)
 {
     $listing_title = '';
     // show errors and warning on online and failed items
     if (in_array($item['status'], array('online', 'failed'))) {
         $history = maybe_unserialize($item['history']);
         $tips_errors = array();
         $tips_warnings = array();
         if (is_array($history)) {
             foreach ($history['errors'] as $feed_error) {
                 $tips_errors[] = WPLA_FeedValidator::formatAmazonFeedError($feed_error);
             }
             foreach ($history['warnings'] as $feed_error) {
                 $tips_warnings[] = WPLA_FeedValidator::formatAmazonFeedError($feed_error);
             }
         }
         if (!empty($tips_errors)) {
             $listing_title .= '<!br><small style="color:darkred">' . join('<br>', $tips_errors) . '</small><br>';
         }
         if (!empty($tips_warnings)) {
             $listing_title .= '<small><!br><a href="#" onclick="jQuery(\'#warnings_container_' . $item['id'] . '\').slideToggle();return false;">&raquo; ' . '' . sizeof($tips_warnings) . ' warning(s)' . '</a></small><br>';
             $listing_title .= '<div id="warnings_container_' . $item['id'] . '" style="display:none">';
             $listing_title .= '<small>' . join('<br>', $tips_warnings) . '</small>';
             $listing_title .= '</div>';
         }
     }
     // show listing quality issues on online and changed items
     if (in_array($item['status'], array('online', 'changed', 'prepared'))) {
         $quality_info = maybe_unserialize($item['quality_info']);
         if (is_array($quality_info)) {
             $error_msg = '<b>' . $quality_info['alert-type'] . '</b>';
             $error_msg .= '<br>' . $quality_info['explanation'] . '';
             $error_msg .= '<br>' . $quality_info['field-name'] . ': ' . $quality_info['current-value'] . ' ';
             $error_msg .= '<br>Status: ' . $quality_info['alert-name'] . ' (' . $quality_info['status'] . ')';
             $error_msg = WPLA_FeedValidator::convert_links($error_msg);
             $listing_title .= '<small style="color:darkred">' . $error_msg . '</small><br>';
         }
     }
     if (empty($listing_title)) {
         return;
     }
     echo '</tr>';
     echo '<tr>';
     // echo '<td colspan="'.sizeof( $this->_column_headers[0] ).'">';
     echo '<td>&nbsp;</td>';
     echo '<td class="wpla_auto_width_column" colspan="7">';
     echo $listing_title;
     echo '</td>';
     echo '<td>&nbsp;</td>';
 }
 public function showNotifications()
 {
     self::checkForDeletedProducts();
     // get listing status summary
     $listingsModel = new WPLA_ListingsModel();
     $summary = WPLA_ListingsModel::getStatusSummary();
     $no_asin = $listingsModel->getAllOnlineWithoutASIN();
     // check for changed, matched and prepared items - and show message
     $is_feed_page = isset($_GET['page']) && $_GET['page'] == 'wpla-feeds';
     if (isset($summary->changed) || isset($summary->prepared) || isset($summary->matched)) {
         $next_schedule = $this->print_schedule_info('wpla_update_schedule');
         // build nice combined message
         $summary_msg = '';
         $summary_array = array();
         foreach (array('changed', 'prepared', 'matched') as $status) {
             if (!isset($summary->{$status})) {
                 continue;
             }
             $link_url = 'admin.php?page=wpla&listing_status=' . $status;
             $link_title = $summary->{$status} . ' ' . $status;
             $summary_array[] = '<a href="' . $link_url . '">' . $link_title . '</a>';
         }
         $summary_msg = join(' and ', $summary_array);
         $msg = '<p>';
         $msg .= sprintf(__('%s product(s) will be submitted to Amazon %s.', 'wpla'), $summary_msg, $next_schedule);
         $msg .= '&nbsp;&nbsp;';
         if ($is_feed_page) {
             $msg .= '<a href="admin.php?page=wpla-feeds&action=submit_pending_feeds_to_amazon" id="" class="button button-small wpl_job_button">' . __('Submit pending feeds', 'wpla') . '</a>';
         } else {
             $msg .= '<a href="admin.php?page=wpla-feeds" id="" class="button button-small wpl_job_button">' . __('Visit feeds', 'wpla') . '</a>';
         }
         $msg .= '</p>';
         $this->showMessage($msg);
     }
     // check for prepared items and display info
     if (isset($summary->prepared)) {
         // $next_schedule = $this->print_schedule_info( 'wpla_update_schedule' );
         // $msg  = '<p>';
         // $msg .= sprintf( __('%d %s product(s) will be submitted to Amazon %s.','wpla'), $summary->prepared, 'prepared', $next_schedule );
         // $msg .= '&nbsp;&nbsp;';
         // $msg .= '<a href="admin.php?page=wpla&listing_status=prepared" id="" class="button button-small wpl_job_button">' . __('Show products','wpla') . '</a>';
         // $msg .= '&nbsp;&nbsp;';
         // $msg .= '<a href="admin.php?page=wpla-feeds" id="" class="button button-small wpl_job_button">' . __('Visit feeds','wpla') . '</a>';
         // $msg .= '</p>';
         // $this->showMessage( $msg );
         // check prepared products for problems
         $problems = WPLA_FeedValidator::checkPreparedProducts();
         if ($problems) {
             $this->showMessage($problems, 1);
         }
     }
     // check changed products for problems
     if (isset($summary->changed)) {
         $problems = WPLA_FeedValidator::checkChangedProducts();
         if ($problems) {
             $this->showMessage($problems, 1);
         }
     }
     // check for new online items without ASIN
     if (sizeof($no_asin)) {
         $msg = '<p>';
         $msg .= sprintf(__('There are %s newly added product(s) which need to be updated from Amazon.', 'wpla'), sizeof($no_asin));
         $msg .= '&nbsp;&nbsp;';
         $msg .= '<a id="btn_batch_update_no_asin" class="btn_batch_update_no_asin button button-primary button-small wpl_job_button">' . __('Update products', 'wpla') . '</a>';
         $msg .= '&nbsp;&nbsp;';
         $msg .= '<a href="admin.php?page=wpla&listing_status=no_asin" id="" class="button button-small wpl_job_button">' . __('Show products', 'wpla') . '</a>';
         $msg .= '<br><!br>';
         $msg .= '<small>This step is required to fetch the ASIN and other details that were assigned by Amazon when the product was created.</small>';
         $msg .= '</p>';
         $this->showMessage($msg);
     }
     // check for imported items and display reminder
     $dismiss_imported_products_notice = self::getOption('dismiss_imported_products_notice');
     $is_imported_page = isset($_GET['listing_status']) && $_GET['listing_status'] == 'imported';
     if ($is_imported_page) {
         $dismiss_imported_products_notice = false;
     }
     if (isset($summary->imported) && !$dismiss_imported_products_notice) {
         $msg = '<p>';
         $msg .= sprintf(__('There are %s imported item(s) which can be created in WooCommerce.', 'wpla'), $summary->imported);
         $msg .= '&nbsp;&nbsp;';
         $msg .= '<a id="btn_batch_create_products_reminder" class="button button-primary button-small wpl_job_button">' . __('Create products', 'wpla') . '</a>';
         if (!$is_imported_page) {
             $msg .= '&nbsp;&nbsp;';
             $msg .= '<a href="admin.php?page=wpla&action=wpla_dismiss_imported_products_notice" class="button button-small wpl_job_button">' . __('Dismiss', 'wpla') . '</a>';
         }
         $msg .= '<br>';
         $msg .= '<small>';
         $msg .= __('If a product with a matching SKU exists in WooCommerce it will be linked to the product on Amazon.', 'wpla');
         $msg .= '</small>';
         $msg .= '</p>';
         $this->showMessage($msg);
     }
 }