Beispiel #1
0
 public function prepareProductForListing($post_id, $profile_id = false, $post_content = false, $post_title = false, $parent_id = false)
 {
     global $wpdb;
     // get wp post record
     $post = get_post($post_id);
     $post_title = $post_title ? $post_title : $post->post_title;
     $post_content = $post_content ? $post_content : $post->post_content;
     // skip pending products and drafts
     // if ( $post->post_status != 'publish' ) {
     if (!in_array($post->post_status, array('publish', 'private'))) {
         if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'wpl_prepare_single_listing') {
             wple_show_message(__('Skipped product with status', 'wplister') . ' <em>' . $post->post_status . '</em>: ' . $post_title, 'warn');
         }
         $this->warnings[] = sprintf(__('Skipped product %s with status %s.', 'wpla'), $post_id, $post->post_status);
         return false;
     }
     // skip duplicates
     if ($profile_id) {
         // get profile
         $pm = new ProfilesModel();
         $profile = $pm->getItem($profile_id);
         // check if this product already exists in profile account
         if (WPLE_ListingQueryHelper::productExistsInAccount($post_id, $profile['account_id'])) {
             $this->warnings[] = sprintf(__('"%s" already exists in account %s and has been skipped.', 'wpla'), get_the_title($post_id), $profile['account_id']);
             return false;
         }
     }
     // skip non-existing products
     $product = get_product($post_id);
     if (!$product || !$product->exists()) {
         $this->errors[] = "Product {$post_id} could not be found.";
         return false;
     }
     // support for qTranslate
     if (function_exists('qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage')) {
         $post_title = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($post_title);
         $post_content = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage($post_content);
     }
     // trim title to 255 characters - longer titles will break $wpdb->insert()
     $post_title = strlen($post_title) < 255 ? $post_title : self::mb_substr($post_title, 0, 80);
     // eBay titles can not be longer than 80 characters
     // gather product data
     $data = array();
     $data['post_id'] = $post_id;
     $data['parent_id'] = $parent_id ? $parent_id : 0;
     $data['auction_title'] = $post_title;
     $data['post_content'] = '';
     // not required anymore
     $data['price'] = ProductWrapper::getPrice($post_id);
     $data['locked'] = 0;
     $data['status'] = 'selected';
     WPLE()->logger->info('insert new auction ' . $post_id . ' - title: ' . $data['auction_title']);
     WPLE()->logger->debug(print_r($post, 1));
     // insert in auctions table
     $result = $wpdb->insert($this->tablename, $data);
     // handle unexpected SQL issues properly
     if (!$wpdb->insert_id) {
         WPLE()->logger->info('insert_id: ' . $wpdb->insert_id);
         WPLE()->logger->info('result: ' . print_r($result, 1));
         WPLE()->logger->info('sql: ' . $wpdb->last_query);
         WPLE()->logger->info($wpdb->last_error);
         $this->errors[] = sprintf(__('Error: MySQL failed to create listing record for "%s" (%s) using profile %s. Please contact support and include this error message.', 'wpla'), get_the_title($post_id), $post_id, $profile['profile_id']);
         return false;
     }
     return $wpdb->insert_id;
 }