Ejemplo n.º 1
0
 public function displayFeedsPage()
 {
     $this->check_wplister_setup();
     // handle actions and show notes
     $this->handleActions();
     $this->showNotifications();
     // upate pending feed
     WPLA_AmazonFeed::updatePendingFeeds();
     // create table and fetch items to show
     // $this->feedsTable = new WPLA_FeedsTable();
     $this->feedsTable->prepare_items();
     $feeds_in_progress = self::getOption('feeds_in_progress', 0);
     if ($feeds_in_progress > 0) {
         $next_schedule = $this->print_schedule_info('wpla_update_schedule');
         $msg = '<p>';
         $msg .= sprintf(__('%s feed submission(s) are currently in progress.', 'wpla'), $feeds_in_progress);
         // $msg .= ' Please click Update Feeds until all feeds have been processed.';
         $msg .= ' ';
         $msg .= sprintf(__('Next check for updated feeds will be executed %s', 'wpla'), $next_schedule);
         $msg .= '&nbsp;&nbsp;&nbsp;<a href="admin.php?page=wpla-feeds&action=update_feeds" class="button button-small">' . __('Check now', 'wpla') . '</a></p>';
         $this->showMessage($msg);
     }
     $aData = array('plugin_url' => self::$PLUGIN_URL, 'message' => $this->message, 'feedsTable' => $this->feedsTable, 'feeds_in_progress' => $feeds_in_progress, 'form_action' => 'admin.php?page=' . self::ParentMenuId . '-feeds');
     $this->display('feeds_page', $aData);
 }
 public function prepareProductForListing($post_id, $profile_id)
 {
     global $wpdb;
     // get wp post and profile
     $post = get_post($post_id);
     $profile = new WPLA_AmazonProfile($profile_id);
     // if ( ! $profile ) return false;
     // skip duplicates
     // $product = get_product( $post_id );
     if ($item = $this->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 drafts
     // if ( $post->post_status != 'published' ) return;
     // support for qTranslate
     // if ( function_exists('qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage') ) {
     // 	$post_title   = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage( $post_title );
     // 	$post_content = qtrans_useCurrentLanguageIfNotFoundUseDefaultLanguage( $post_content );
     // }
     // gather product data
     $product = get_product($post_id);
     if (!$product || !$product->exists()) {
         $this->errors[] = "Product {$post_id} could not be found.";
         return false;
     }
     // handle custom listing title
     $listing_title = $post->post_title;
     if ($product_value = get_post_meta($post_id, '_amazon_title', true)) {
         $listing_title = $product_value;
     }
     // trim title to 500 characters - longer titles will break $wpdb->insert() on varchar(500) column
     $listing_title = strlen($listing_title) < 500 ? $listing_title : $this->mb_substr($listing_title, 0, 500);
     // Amazon titles can not be longer than 500 characters
     // build listing item
     $data = array();
     $data['post_id'] = $post_id;
     $data['listing_title'] = $listing_title;
     // $data['post_content']  = $post->post_content;
     $data['price'] = WPLA_ProductWrapper::getPrice($post_id);
     $data['quantity'] = WPLA_ProductWrapper::getStock($post_id);
     $data['sku'] = WPLA_ProductWrapper::getSKU($post_id);
     $data['date_created'] = date('Y-m-d H:i:s', time());
     $data['status'] = 'prepared';
     $data['source'] = 'woo';
     $data['profile_id'] = $profile->profile_id;
     $data['account_id'] = $profile->account_id;
     $data['product_type'] = $product->product_type;
     // handle variable products
     if ($product->product_type == 'variable') {
         $last_variation_data = $this->prepareVariations($post_id, $profile, $post, $data);
         $data['vtheme'] = $last_variation_data['vtheme'];
     }
     WPLA()->logger->info('insert new listing ' . $post_id . ' - title: ' . $data['listing_title']);
     // WPLA()->logger->debug( print_r($post,1) );
     WPLA()->logger->debug(print_r($data, 1));
     // insert in listings table
     $wpdb->insert($this->tablename, $data);
     echo $wpdb->last_error;
     WPLA()->logger->debug('insert_id: ' . $wpdb->insert_id);
     WPLA()->logger->debug('sql: ' . $wpdb->last_query);
     WPLA()->logger->debug($wpdb->last_error);
     // apply profile (price)
     $listing_id = $wpdb->insert_id;
     $this->applyProfileToItem($profile, $listing_id);
     // update / create pending feed
     WPLA_AmazonFeed::updatePendingFeeds();
     return $listing_id;
 }
 function update_products_on_shutdown()
 {
     // get queue
     $collected_products = get_option('wpla_updated_products_queue', array());
     if (!is_array($collected_products)) {
         $collected_products = array();
     }
     // DEBUG
     WPLA()->logger->info("CSV: update_products_on_shutdown() - collected_products: " . print_r($collected_products, 1));
     // mark each queued product as modified
     $lm = new WPLA_ListingsModel();
     foreach ($collected_products as $post_id) {
         // do_action( 'wpla_product_has_changed', $post_id );
         $lm->markItemAsModified($post_id, true);
         // set $skip_updating_feeds = true
     }
     // clear queue
     delete_option('wpla_updated_products_queue');
     // update pending feeds - after all items have been updated
     if (!empty($collected_products)) {
         WPLA_AmazonFeed::updatePendingFeeds();
     }
 }