static function checkAllProductsWithStatus($status)
 {
     $problems = array();
     // get all prepared products
     $lm = new WPLA_ListingsModel();
     $listings = $lm->findAllListingsByColumn($status, 'status');
     // echo "<pre>";print_r($listings);echo"</pre>";#die();
     // get all post_ids
     global $wpdb;
     $post_ids = $wpdb->get_col("SELECT ID FROM {$wpdb->posts} WHERE post_type = 'product' OR post_type = 'product_variation' ");
     foreach ($listings as $listing_id => $item) {
         // check if product exists
         if (!in_array($item->post_id, $post_ids)) {
             $problems[] = array('msg' => 'The product "' . $item->listing_title . '" does not exist in WooCommerce and will not be included in the next feed submission.', 'post_id' => $item->post_id);
         }
         // check SKU - all products
         if ($item->sku == '') {
             $problems[] = array('msg' => 'The product "' . $item->listing_title . '" has no SKU and will not be included in the next feed submission.', 'post_id' => $item->post_id);
         }
         if (strlen($item->sku) > 40) {
             $problems[] = array('msg' => 'The SKU <b>' . $item->sku . '</b> for product "' . $item->listing_title . '" is longer than 40 characters. Amazon requires SKUs to have 40 characters or less.', 'post_id' => $item->post_id);
         }
         // run checks for variable or simple product
         if ($item->product_type == 'variable') {
             // $problems = self::checkVariableProduct( $item, $problems );
         } elseif ($item->product_type == 'variation') {
             // $problems = self::checkSimpleProduct( $item, $problems );
         } else {
             $problems = self::checkSimpleProduct($item, $problems);
         }
     }
     // foreach listing
     return $problems;
 }
 public function deleteProfiles($profiles)
 {
     if (!is_array($profiles)) {
         $profiles = array($profiles);
     }
     $count = 0;
     foreach ($profiles as $id) {
         if (!$id) {
             continue;
         }
         // check if there are listings using this profile
         $lm = new WPLA_ListingsModel();
         $listings = $lm->findAllListingsByColumn($id, 'profile_id');
         if (!empty($listings)) {
             $this->showMessage('This profile is applied to ' . count($listings) . ' listings and can not be deleted.', 1, 1);
             continue;
         }
         $profile = new WPLA_AmazonProfile($id);
         $profile->delete();
         $count++;
     }
     if ($count) {
         $this->showMessage(sprintf(__('%s profile(s) were removed.', 'wpla'), $count));
     }
 }
 public function renderDupeTable($listings, $column = 'post_id')
 {
     if (empty($listings)) {
         return '';
     }
     // get current page with paging as url param
     $page = $_REQUEST['page'];
     if (isset($_REQUEST['paged'])) {
         $page .= '&paged=' . $_REQUEST['paged'];
     }
     $listingsModel = new WPLA_ListingsModel();
     $msg = '';
     foreach ($listings as $dupe) {
         $account_title = WPLA_AmazonAccount::getAccountTitle($dupe->account_id);
         $msg .= '<b>' . __('Listings for', 'wpla') . ' ' . strtoupper($column) . ' ' . $dupe->{$column} . ' (' . $account_title . '):</b>';
         $msg .= '<br>';
         $duplicateListings = $listingsModel->findAllListingsByColumn($dupe->{$column}, $column, $dupe->account_id);
         $msg .= '<table style="width:100%">';
         foreach ($duplicateListings as $listing) {
             $color = $listing->status == 'archived' ? 'silver' : '';
             // check if WooCommerce SKU matches Amazon SKU
             $woo_sku = get_post_meta($listing->post_id, '_sku', true);
             $sku_label = $listing->sku == $woo_sku ? $woo_sku : '<span style="color:darkred">' . $woo_sku . ' / ' . $listing->sku . '</span>';
             $msg .= '<tr><td style="width:40%;">';
             $msg .= '<span style="color:' . $color . '">';
             $msg .= $listing->listing_title;
             $msg .= '</span>';
             $msg .= '</td><td style="width:10%;">';
             $msg .= '<i style="color:silver">' . $listing->product_type . '</i>';
             $msg .= '</td><td style="width:10%;">';
             $msg .= '<a href="admin.php?page=wpla&s=' . $listing->sku . '" title="SKU" target="_blank">';
             $msg .= $sku_label . '</a>';
             $msg .= '</td><td style="width:10%;">';
             $msg .= '<a href="admin.php?page=wpla&s=' . $listing->asin . '" title="ASIN" target="_blank">';
             $msg .= $listing->asin . '</a>';
             $msg .= '</td><td style="width:10%;">';
             $msg .= '<a href="admin.php?page=wpla&s=' . $listing->post_id . '" title="Product ID" target="_blank">';
             $msg .= 'ID ' . $listing->post_id . '</a>';
             $msg .= '</td><td style="width:10%;">';
             $msg .= '<i>' . $listing->status . '</i>';
             // if ( in_array( $listing->status, array( 'prepared', 'verified', 'ended', 'sold' ) ) ) {
             // 	$archive_link = sprintf('<a class="archive button button-small" href="?page=%s&action=%s&listing=%s">%s</a>',$page,'archive',$listing->id,__('Click to move to archive','wpla'));
             // 	$msg .= '&nbsp;&nbsp;&nbsp;&nbsp;'.$archive_link;
             // 	$msg .= '<br>';
             // }
             $msg .= '</td><td align="right" style="width:10%;">';
             $delete_btn = sprintf('<a class="delete button button-small button-secondary" href="?page=%s&action=%s&listing=%s">%s</a>', $page, 'delete', $listing->id, __('Remove from database', 'wpla'));
             $msg .= $delete_btn;
             $msg .= '</td></tr>';
         }
         $msg .= '</table>';
         $msg .= '<br>';
     }
     return $msg;
 }