Example #1
0
 function addItem($id, $session)
 {
     // skip this item if item status not allowed
     $allowed_statuses = array('prepared', 'verified');
     if (!$this->itemHasAllowedStatus($id, $allowed_statuses)) {
         return $this->result;
     }
     // build item
     $ibm = new ItemBuilderModel();
     $item = $ibm->buildItem($id, $session);
     if (!$ibm->checkItem($item)) {
         return $ibm->result;
     }
     // eBay Motors (beta)
     if ($item->Site == 'eBayMotors') {
         $session->setSiteId(100);
     }
     // preparation - set up new ServiceProxy with given session
     $this->initServiceProxy($session);
     // switch to FixedPriceItem if product has variations
     $listing_item = self::getItem($id);
     // $useFixedPriceItem = ( ProductWrapper::hasVariations( $listing_item['post_id'] ) ) ? true : false;
     // $useFixedPriceItem = ( 'FixedPriceItem' == $listing_item['auction_type'] ) ? true : false;
     WPLE()->logger->info("Adding #{$id}: " . $item->Title);
     if (self::listingUsesFixedPriceItem($listing_item)) {
         $req = new AddFixedPriceItemRequestType();
         $req->setItem($item);
         WPLE()->logger->debug("Request: " . print_r($req, 1));
         $res = $this->_cs->AddFixedPriceItem($req);
     } else {
         $req = new AddItemRequestType();
         $req->setItem($item);
         WPLE()->logger->debug("Request: " . print_r($req, 1));
         $res = $this->_cs->AddItem($req);
     }
     // handle response and check if successful
     if ($this->handleResponse($res)) {
         // save ebay ID and fees to db
         $listingFee = self::getListingFeeFromResponse($res);
         $data['ebay_id'] = $res->ItemID;
         $data['fees'] = $listingFee;
         $data['status'] = 'published';
         self::updateListing($id, $data);
         // get details like ViewItemURL from ebay automatically
         $this->updateItemDetails($id, $session);
         $this->postProcessListing($id, $res->ItemID, $item, $listing_item, $res, $session);
         WPLE()->logger->info("Item #{$id} sent to ebay, ItemID is " . $res->ItemID);
     }
     // call successful
     self::processErrorsAndWarnings($id, $this->result);
     return $this->result;
 }