function buildItem($id, $session, $reviseItem = false, $preview = false) { // fetch record from db $listing = ListingsModel::getItem($id); $post_id = $listing['post_id']; $profile_details = $listing['profile_data']['details']; $hasVariations = ProductWrapper::hasVariations($post_id); $isVariation = ProductWrapper::isSingleVariation($post_id); // remember listing id and account id for checkItem() and buildPayment() $this->listing_id = $id; $this->account_id = $listing['account_id']; // adjust profile details from product level options $profile_details = $this->adjustProfileDetails($id, $post_id, $profile_details); // create Item $item = new ItemType(); // set quantity // $item->Quantity = $listing['quantity']; // get current quantity from WooCommerce $woocom_stock = ProductWrapper::getStock($post_id); // get max_quantity from profile $max_quantity = isset($profile_details['max_quantity']) && intval($profile_details['max_quantity']) > 0 ? $profile_details['max_quantity'] : PHP_INT_MAX; $item->Quantity = min($max_quantity, intval($woocom_stock)); // handle fixed quantity if (intval($profile_details['quantity']) > 0) { $item->Quantity = $profile_details['quantity']; } if ($item->Quantity < 0) { $item->Quantity = 0; } // prevent error for negative qty // set listing title $item->Title = $this->prepareTitle($listing['auction_title']); // set listing duration $product_listing_duration = get_post_meta($post_id, '_ebay_listing_duration', true); $item->ListingDuration = $product_listing_duration ? $product_listing_duration : $listing['listing_duration']; // omit ListingType when revising item if (!$reviseItem) { $product_listing_type = get_post_meta($post_id, '_ebay_auction_type', true); $ListingType = $product_listing_type ? $product_listing_type : $listing['auction_type']; // handle classified ads if ($ListingType == 'ClassifiedAd') { $ListingType = 'LeadGeneration'; $item->setListingSubtype2('ClassifiedAd'); } $item->setListingType($ListingType); } // set eBay Site $item = $this->setEbaySite($item, $session); // add prices $item = $this->buildPrices($id, $item, $post_id, $profile_details, $listing); // add images $item = $this->buildImages($id, $item, $post_id, $profile_details, $session); // if this is a split variation, use parent post_id for all further processing if ($isVariation) { // prepare item specifics / variation attributes $this->prepareSplitVariation($id, $post_id, $listing); // use parent post_id for all further processing $post_id = ProductWrapper::getVariationParent($post_id); } // add various options from $profile_details $item = $this->buildProfileOptions($item, $profile_details); // add various options that depend on $profile_details and $post_id $item = $this->buildProductOptions($id, $item, $post_id, $profile_details, $listing, $hasVariations, $isVariation); // add payment and return options $item = $this->buildPayment($item, $profile_details); // add shipping services and options $item = $this->buildShipping($id, $item, $post_id, $profile_details, $listing, $isVariation); // add seller profiles $item = $this->buildSellerProfiles($id, $item, $post_id, $profile_details); // add ebay categories and store categories $item = $this->buildCategories($id, $item, $post_id, $profile_details); // add variations if ($hasVariations) { if (@$profile_details['variations_mode'] == 'flat') { // don't build variations - list as flat item $item = $this->flattenVariations($id, $item, $post_id, $profile_details); } else { // default: list as variations $item = $this->buildVariations($id, $item, $profile_details, $listing, $session); } } // add item specifics (attributes) - after variations $item = $this->buildItemSpecifics($id, $item, $listing, $post_id); // add part compatibility list $item = $this->buildCompatibilityList($id, $item, $listing, $post_id); // set listing description - after $item has been built $item->Description = $this->getFinalHTML($id, $item, $preview); // adjust item if this is a ReviseItem request if ($reviseItem) { $item = $this->adjustItemForRevision($id, $item, $profile_details, $listing); } else { $item = $this->buildSchedule($item, $profile_details); } // add UUID to prevent duplicate AddItem or RelistItem calls if (!$reviseItem) { // build UUID from listing Title, product_id, previous ItemID and today's date and hour $uuid_src = $item->Title . $post_id . $listing['ebay_id'] . date('Y-m-d h'); $item->setUUID(md5($uuid_src)); WPLE()->logger->info('UUID src: ' . $uuid_src); } // filter final item object before it's sent to eBay $item = apply_filters('wplister_filter_listing_item', $item, $listing, $profile_details, $post_id); $item = apply_filters('wple_filter_listing_item', $item, $listing, $profile_details, $post_id, $reviseItem); return $item; }