function processListingItem($order_id, $ebay_id, $quantity_purchased, $data, $VariationSpecifics, $Transaction) { global $wpdb; $has_been_replenished = false; // check if this listing exists in WP-Lister $listing_id = $wpdb->get_var($wpdb->prepare("SELECT id FROM {$wpdb->prefix}ebay_auctions WHERE ebay_id = %s", $ebay_id)); if (!$listing_id) { $history_message = "Skipped foreign item #{$ebay_id}"; $history_details = array('ebay_id' => $ebay_id); $this->addHistory($order_id, 'skipped_item', $history_message, $history_details); return; } // get current values from db // $quantity_purchased = $data['quantity']; $quantity_total = $wpdb->get_var($wpdb->prepare("SELECT quantity FROM {$wpdb->prefix}ebay_auctions WHERE ebay_id = %s", $ebay_id)); $quantity_sold = $wpdb->get_var($wpdb->prepare("SELECT quantity_sold FROM {$wpdb->prefix}ebay_auctions WHERE ebay_id = %s", $ebay_id)); // increase the listing's quantity_sold $quantity_sold = $quantity_sold + $quantity_purchased; $wpdb->update($wpdb->prefix . 'ebay_auctions', array('quantity_sold' => $quantity_sold), array('ebay_id' => $ebay_id)); // add history record $history_message = "Sold quantity increased by {$quantity_purchased} for listing #{$ebay_id} - sold {$quantity_sold}"; $history_details = array('ebay_id' => $ebay_id, 'quantity_sold' => $quantity_sold, 'quantity_total' => $quantity_total); $this->addHistory($order_id, 'reduce_stock', $history_message, $history_details); // mark listing as sold when last item is sold - unless Out Of Stock Control (oosc) is enabled if (!ListingsModel::thisAccountUsesOutOfStockControl($data['account_id'])) { if ($quantity_sold == $quantity_total && !$has_been_replenished) { // make sure this product is out of stock before we mark listing as sold - free version excluded $listing_item = ListingsModel::getItem($listing_id); if (WPLISTER_LIGHT || ListingsModel::checkStockLevel($listing_item) == false) { $wpdb->update($wpdb->prefix . 'ebay_auctions', array('status' => 'sold', 'date_finished' => $data['date_created']), array('ebay_id' => $ebay_id)); WPLE()->logger->info('marked item #' . $ebay_id . ' as SOLD '); } } } }
public function reviseInventoryForProducts($product_ids) { if (!is_array($product_ids) && !is_numeric($product_ids)) { return; } if (!is_array($product_ids)) { $product_ids = array($product_ids); } $lm = new ListingsModel(); foreach ($product_ids as $post_id) { $listing_id = WPLE_ListingQueryHelper::getListingIDFromPostID($post_id); // if no listing found, check parent_id for variations if (!$listing_id) { $_product = get_product($post_id); if (!$_product) { continue; } if ($_product->product_type == 'variation') { $listing_id = WPLE_ListingQueryHelper::getListingIDFromPostID($_product->parent->id); } } // check if API is allowed to relist ended items if (get_option('wplister_api_enable_auto_relist')) { // check listing status - only ended and sold items can be relisted $allowed_statuses = array('ended', 'sold'); if ($lm->itemHasAllowedStatus($listing_id, $allowed_statuses)) { // ok, we have an ended item - check if it's in stock $listing_item = ListingsModel::getItem($listing_id); if (ListingsModel::checkStockLevel($listing_item)) { // let's relist $this->lastResults[] = $lm->relistItem($listing_id, $this->session); continue; } // is in stock } // is ended } // if API relist enabled // revise inventory status (default) $this->lastResults[] = $lm->reviseInventoryStatus($listing_id, $this->session, false); } // $this->processLastResults(); }