Example #1
0
 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();
 }