Beispiel #1
0
 public function updateEndedListings($session)
 {
     global $wpdb;
     // set listing status to archived for all listings with an end_date < 90 days in the past
     $items = WPLE_ListingQueryHelper::getAllOldListingsToBeArchived();
     WPLE()->logger->info('getAllOldListingsToBeArchived() found ' . sizeof($items) . ' items');
     foreach ($items as $item) {
         // TODO: use self::updateWhere()
         $wpdb->update($this->tablename, array('status' => 'archived'), array('id' => $item['id']));
         WPLE()->logger->info('updateEndedListings() changed item ' . $item['id'] . ' to status archived');
     }
     // set listing status to ended for all listings with an end_date in the past
     $items = WPLE_ListingQueryHelper::getAllPastEndDate();
     WPLE()->logger->info('getAllPastEndDate() found ' . sizeof($items) . ' items');
     $auto_update_ended_items = get_option('wplister_auto_update_ended_items');
     foreach ($items as $item) {
         // if quantity sold is greater than quantity, mark as sold instead of ended
         // $status = intval( $item['quantity_sold'] ) < intval( $item['quantity'] ) ? 'ended' : 'sold';
         // check if details for ended items should be fetched from ebay automatically
         // diabled by default for performance reasons - it is not recommended to relist items on eBay anyway
         if ($auto_update_ended_items) {
             // suggested by Kim - to check if an ended item has been relisted
             $oldItemID = $item['ebay_id'];
             $this->updateItemDetails($item['id'], $session);
         }
         // default status is ended
         $status = 'ended';
         // load item details
         $item = self::getItem($item['id']);
         // check eBay available quantity first - if all were sold
         if (intval($item['quantity_sold']) >= intval($item['quantity'])) {
             // if eBay indicates item was sold, check WooCommerce stock - updateDetails does the same
             if (!self::checkStockLevel($item)) {
                 $status = 'sold';
             }
         }
         // check item details to make sure we don't end GTC items
         // (if GTC listings are imported from eBay and assigned a listing profile not using GTC, they would be ended...)
         if (is_object($item_details = self::decodeObject($item['details']))) {
             $actual_listing_duration = $item_details->getListingDuration();
             if ('GTC' == $actual_listing_duration) {
                 WPLE()->logger->info('skipped GTC item, assuming it is still published: ' . $item['ebay_id']);
                 continue;
             }
         }
         // check if ebay ID has changed - ie. item has been relisted
         if ($auto_update_ended_items) {
             if ($oldItemID != $item['ebay_id']) {
                 $status = 'published';
             }
         }
         $wpdb->update($this->tablename, array('status' => $status), array('id' => $item['id']));
         WPLE()->logger->info('updateEndedListings() changed item ' . $item['ebay_id'] . ' (' . $item['id'] . ') to status ' . $status);
     }
     #WPLE()->logger->info('sql: '.$wpdb->last_query );
     #WPLE()->logger->info( $wpdb->last_error );
 }