コード例 #1
0
ファイル: ReviseItem.php プロジェクト: dewawi/dewawi
$token = $config[$site]['authToken'];
$location = $config[$site]['gatewaySOAP'];
// Create and configure session
$session = new eBaySession($dev, $app, $cert);
$session->token = $token;
$session->site = 0;
// 0 = US;
$session->location = $location;
// Make AddItem, ReviseItem, and GetItem API calls to demonstate how to modify
// and item listing
try {
    $client = new eBaySOAP($session);
    $PrimaryCategory = array('CategoryID' => 357);
    $Item = array('ListingType' => 'Chinese', 'Currency' => 'USD', 'Country' => 'US', 'PaymentMethods' => 'PaymentSeeDescription', 'RegionID' => 0, 'ListingDuration' => 'Days_3', 'Title' => 'The new item title', 'SubTitle' => 'The new item subtitle', 'Description' => "It's a great new item", 'Location' => "San Jose, CA", 'Quantity' => 1, 'StartPrice' => 24.99, 'BuyItNowPrice' => 54.99, 'PrimaryCategory' => $PrimaryCategory);
    $params = array('Version' => $compatibilityLevel, 'Item' => $Item);
    $results = $client->AddItem($params);
    $ItemID = (string) $results->ItemID;
    print "Listed Item ID: {$ItemID} <br>\n";
    // Get it to confirm
    $params = array('Version' => $compatibilityLevel, 'ItemID' => $ItemID);
    $results = $client->GetItem($params);
    print "Got Item ID: {$ItemID} <br>\n";
    print "It has a title of: " . $results->Item->Title . " <br>\n";
    print "It has a BIN Price of: " . $results->Item->BuyItNowPrice->_ . ' ' . $results->Item->BuyItNowPrice->currencyID . " <br> \n";
    // Revise it and change the Title and raise the BuyItNowPrice
    $Item = array('ItemID' => $ItemID, 'Title' => 'The revised item title', 'BuyItNowPrice' => 99.98999999999999);
    $params = array('Version' => $compatibilityLevel, 'Item' => $Item);
    $results = $client->ReviseItem($params);
    print "<hr>Revised Item ID: {$ItemID} <br>\n";
    // Get it to confirm
    $params = array('Version' => $compatibilityLevel, 'ItemID' => $ItemID);
コード例 #2
0
ファイル: ebay.php プロジェクト: heshuai64/ebo
 private function addItem($item)
 {
     /*
     	<AttributeSetArray> AttributeSetArrayType 
     	    <AttributeSet attributeSetID="int" attributeSetVersion="string"> AttributeSetType 
     		<Attribute attributeID="int"> AttributeType 
     		    <Value> ValType 
     			<ValueID> int </ValueID>
     			<ValueLiteral> string </ValueLiteral>
     		    </Value>
     		    <!-- ... more Value nodes here ... -->
     		</Attribute>
     		<!-- ... more Attribute nodes here ... -->
     	    </AttributeSet>
     	    <!-- ... more AttributeSet nodes here ... -->
     	</AttributeSetArray>
     	
     	<BuyItNowPrice currencyID="CurrencyCodeType"> AmountType (double) </BuyItNowPrice>
      
     	<CategoryMappingAllowed> boolean </CategoryMappingAllowed>
     <Country> CountryCodeType </Country>
     	//CN,HK
     	
     	<Currency> CurrencyCodeType </Currency>
     	//GBP,USD,EUR,AUD
     	
     	<Description> string </Description>
     <DispatchTimeMax> int </DispatchTimeMax>
     <ListingDuration> token </ListingDuration>
     	
     	<ListingEnhancement> ListingEnhancementsCodeType </ListingEnhancement>
     //AdType,Chinese,CustomCode,Dutch,Express(Germany),FixedPriceItem,LeadGeneration,StoresFixedPrice
     	<ListingType> ListingTypeCodeType </ListingType>
     	<Location> string </Location>
     	//China
     	
     	<PaymentMethods> BuyerPaymentMethodCodeType </PaymentMethods>
     	<!-- ... more PaymentMethods nodes here ... -->
     	<PayPalEmailAddress> string </PayPalEmailAddress>
     
     <PictureDetails> PictureDetailsType 
     	    <GalleryDuration> token </GalleryDuration>
     	    Describes the number of days that "Featured" Gallery type applies to a listing.
     	    The values that can be specified in this field are in ListingEnhancementDurationCodeType.
     	    When a seller chooses "Featured" as the Gallery type,
     	    the listing is highlighted and is included at the top of search results.
     	    This functionality is applicable only for Gallery Featured items and returns an error for any other Gallery type.
     	    Additionally, an error is returned if the seller attempts to downgrade from Lifetime to limited duration,
     	    but the seller can upgrade from limited duration to Lifetime duration.
     	    This field is not applicable to auction listings.
     	    <GalleryType> GalleryTypeCodeType </GalleryType>
     	    Featured  Gallery  
     	    <GalleryURL> anyURI </GalleryURL>
     	    <PhotoDisplay> PhotoDisplayCodeType </PhotoDisplay>
     	    <PictureURL> anyURI </PictureURL>
     	    <!-- ... more PictureURL nodes here ... -->
     	</PictureDetails>
     <PostalCode> string </PostalCode>
     <PrimaryCategory> CategoryType 
     	    <CategoryID> string </CategoryID>
     	</PrimaryCategory>
     
     <Quantity> int </Quantity>
     <ReturnPolicy> ReturnPolicyType 
     	    <Description> string </Description>
     	    <EAN> string </EAN>
     	    <RefundOption> token </RefundOption>
     	    <ReturnsAcceptedOption> token </ReturnsAcceptedOption>
     	    <ReturnsWithinOption> token </ReturnsWithinOption>
     	    <ShippingCostPaidByOption> token </ShippingCostPaidByOption>
     	    <WarrantyDurationOption> token </WarrantyDurationOption>
     	    <WarrantyOfferedOption> token </WarrantyOfferedOption>
     	    <WarrantyTypeOption> token </WarrantyTypeOption>
     	</ReturnPolicy>
     
     <ScheduleTime> dateTime </ScheduleTime>
     	
     	<SecondaryCategory> CategoryType 
     	    <CategoryID> string </CategoryID>
     	</SecondaryCategory>
     
     <ShippingDetails>
     	    <InsuranceDetails> InsuranceDetailsType 
     		<InsuranceFee currencyID="CurrencyCodeType"> AmountType (double) </InsuranceFee>
     		<InsuranceOption> InsuranceOptionCodeType </InsuranceOption>
     	     </InsuranceDetails>
     	     <InsuranceFee currencyID="CurrencyCodeType"> AmountType (double) </InsuranceFee>
     	     <InsuranceOption> InsuranceOptionCodeType </InsuranceOption>
     	     <InternationalInsuranceDetails> InsuranceDetailsType 
     		<InsuranceFee currencyID="CurrencyCodeType"> AmountType (double) </InsuranceFee>
     		<InsuranceOption> InsuranceOptionCodeType </InsuranceOption>
     	    </InternationalInsuranceDetails>
         <InternationalShippingServiceOption> InternationalShippingServiceOptionsType 
     		<ShippingService> token </ShippingService>
     		<ShippingServiceAdditionalCost currencyID="CurrencyCodeType"> AmountType (double) </ShippingServiceAdditionalCost>
     		<ShippingServiceCost currencyID="CurrencyCodeType"> AmountType (double) </ShippingServiceCost>
     		<ShippingServicePriority> int </ShippingServicePriority>
     		<ShipToLocation> string </ShipToLocation>
     		<!-- ... more ShipToLocation nodes here ... -->
     	    </InternationalShippingServiceOption>
         <ShippingServiceOptions> ShippingServiceOptionsType 
     		<FreeShipping> boolean </FreeShipping>
     		<ShippingService> token </ShippingService>
     		<ShippingServiceAdditionalCost currencyID="CurrencyCodeType"> AmountType (double) </ShippingServiceAdditionalCost>
     		<ShippingServiceCost currencyID="CurrencyCodeType"> AmountType (double) </ShippingServiceCost>
     		<ShippingServicePriority> int </ShippingServicePriority>
     		<ShippingSurcharge currencyID="CurrencyCodeType"> AmountType (double) </ShippingSurcharge>
     	    </ShippingServiceOptions>
     	    
     	    <ShippingType> ShippingTypeCodeType </ShippingType>
     	    //Calculated,CalculatedDomesticFlatInternational,CustomCode,Flat,FlatDomesticCalculatedInternational,FreightFlat,NotSpecified
     	</ShippingDetails>
     <Site> SiteCodeType </Site>
     	<SKU> SKUType </SKU>
     <StartPrice currencyID="CurrencyCodeType"> AmountType (double) </StartPrice>
     
     <Storefront> StorefrontType 
     	    <StoreCategory2ID> long </StoreCategory2ID>
     	    <StoreCategoryID> long </StoreCategoryID>
     	</Storefront>
     	
     	<SubTitle> string </SubTitle>
     	<Title> string </Title>
     */
     $ShipToLocations = array();
     $sql = "select id from site where name = '" . $item['Site'] . "'";
     $result = mysql_query($sql);
     $row = mysql_fetch_assoc($result);
     $this->configEbay($row['id']);
     try {
         $client = new eBaySOAP($this->session);
         $Version = $this->version;
         $itemArray = array();
         //if($this->getCondition($row['id'], $item['PrimaryCategoryCategoryID'])){
         //$itemArray['ConditionID'] = 1000;
         //}
         if (!empty($item['ConditionID'])) {
             $itemArray['ConditionID'] = $item['ConditionID'];
         } else {
             $itemArray['ConditionID'] = 1000;
         }
         /*
         if(count($item['AttributeSetArray']) > 0){
         		$itemArray['AttributeSetArray'] = $item['AttributeSetArray'];
         }
         */
         if (!empty($item['BuyItNowPrice']) && $item['BuyItNowPrice'] > $item['StartPrice']) {
             $itemArray['BuyItNowPrice'] = $item['BuyItNowPrice'];
         }
         $itemArray['CategoryMappingAllowed'] = true;
         $itemArray['Country'] = $item['Country'];
         $itemArray['Currency'] = $item['Currency'];
         $itemArray['Description'] = $item['Description'];
         if (!empty($item['DispatchTimeMax'])) {
             $itemArray['DispatchTimeMax'] = $item['DispatchTimeMax'];
         }
         if (!empty($item['ItemSpecifics'])) {
             $i = 0;
             $item['ItemSpecifics'] = json_decode($item['ItemSpecifics']);
             foreach ($item['ItemSpecifics'] as $key => $value) {
                 $key = str_replace("----", "'", $key);
                 $itemArray['ItemSpecifics']['NameValueList'][$i]['Name'] = $key;
                 $itemArray['ItemSpecifics']['NameValueList'][$i]['Value'] = $value;
                 $i++;
             }
         }
         $itemArray['ListingDuration'] = $item['ListingDuration'];
         if ($item['BoldTitle'] == true) {
             $itemArray['ListingEnhancement'][] = "BoldTitle";
         }
         if ($item['Border'] == true) {
             $itemArray['ListingEnhancement'][] = "Border";
         }
         if ($item['Featured'] == true) {
             $itemArray['ListingEnhancement'][] = "Featured";
         }
         if ($item['Highlight'] == true) {
             $itemArray['ListingEnhancement'][] = "Highlight";
         }
         if ($item['HomePageFeatured'] == true) {
             $itemArray['ListingEnhancement'][] = "HomePageFeatured";
         }
         $itemArray['ListingType'] = $item['ListingType'];
         if (!empty($item['Location'])) {
             $itemArray['Location'] = $item['Location'];
         }
         if (empty($item['Country']) || $item['Country'] == 'CN' || $item['Country'] == 'HK') {
             $itemArray['Country'] = 'HK';
         }
         $itemArray['PaymentMethods'] = $item['PaymentMethods'];
         $itemArray['PayPalEmailAddress'] = $item['PayPalEmailAddress'];
         //PictureDetails
         if ($item['GalleryTypeFeatured']) {
             $itemArray['PictureDetails']['GalleryType'] = "Featured";
         }
         if ($item['GalleryTypeGallery']) {
             $itemArray['PictureDetails']['GalleryType'] = "Gallery";
         }
         if ($item['GalleryTypePlus']) {
             $itemArray['PictureDetails']['GalleryType'] = "Plus";
         }
         if (!empty($item['GalleryURL'])) {
             $itemArray['PictureDetails']['GalleryURL'] = $item['GalleryURL'];
         }
         if (!empty($item['PictureURL']) && is_array($item['PictureURL'])) {
             $i = 0;
             foreach ($item['PictureURL'] as $p) {
                 $itemArray['PictureDetails']['PictureURL'][$i] = $p;
                 $i++;
             }
         }
         if (!empty($item['PostalCode'])) {
             $itemArray['PostalCode'] = $item['PostalCode'];
         }
         $itemArray['PrimaryCategory']['CategoryID'] = $item['PrimaryCategoryCategoryID'];
         if ($item['Site'] != "Germany") {
             $itemArray['PrivateListing'] = true;
         }
         $itemArray['Quantity'] = $item['Quantity'];
         if (!empty($item['ReturnPolicyReturnsAcceptedOption'])) {
             $itemArray['ReturnPolicy']['ReturnsAcceptedOption'] = $item['ReturnPolicyReturnsAcceptedOption'];
             if (!empty($item['ReturnPolicyDescription'])) {
                 $itemArray['ReturnPolicy']['Description'] = $item['ReturnPolicyDescription'];
             }
             if (!empty($item['ReturnPolicyRefundOption'])) {
                 $itemArray['ReturnPolicy']['RefundOption'] = $item['ReturnPolicyRefundOption'];
             }
             if (!empty($item['ReturnPolicyReturnsWithinOption'])) {
                 $itemArray['ReturnPolicy']['ReturnsWithinOption'] = $item['ReturnPolicyReturnsWithinOption'];
             }
             if (!empty($item['ReturnPolicyShippingCostPaidByOption'])) {
                 $itemArray['ReturnPolicy']['ShippingCostPaidByOption'] = $item['ReturnPolicyShippingCostPaidByOption'];
             }
         }
         if (!empty($item['SecondaryCategoryCategoryID']) && $item['SecondaryCategoryCategoryID'] != 0) {
             $itemArray['SecondaryCategory']['CategoryID'] = $item['SecondaryCategoryCategoryID'];
         }
         if (!empty($item['InsuranceOption'])) {
             $itemArray['ShippingDetails']['InsuranceDetails']['InsuranceOption'] = $item['InsuranceOption'];
             $itemArray['ShippingDetails']['InsuranceDetails']['InsuranceFee'] = $item['InsuranceFee'];
         }
         if (!empty($item['InternationalInsurance'])) {
             $itemArray['ShippingDetails']['InternationalInsuranceDetails']['InsuranceOption'] = $item['InternationalInsurance'];
             $itemArray['ShippingDetails']['InternationalInsuranceDetails']['InsuranceFee'] = $item['InternationalInsuranceFee'];
         }
         $itemArray['ShippingDetails']['ShippingType'] = $item['ShippingType'];
         if (!empty($item['ShippingServiceOptions']) && is_array($item['ShippingServiceOptions'])) {
             $i = 0;
             foreach ($item['ShippingServiceOptions'] as $s) {
                 $itemArray['ShippingDetails']['ShippingServiceOptions'][$i]['FreeShipping'] = $s['FreeShipping'];
                 $itemArray['ShippingDetails']['ShippingServiceOptions'][$i]['ShippingService'] = $s['ShippingService'];
                 $itemArray['ShippingDetails']['ShippingServiceOptions'][$i]['ShippingServiceCost'] = $s['ShippingServiceCost'];
                 $itemArray['ShippingDetails']['ShippingServiceOptions'][$i]['ShippingServiceAdditionalCost'] = $s['ShippingServiceAdditionalCost'];
                 $itemArray['ShippingDetails']['ShippingServiceOptions'][$i]['ShippingServicePriority'] = $s['ShippingServicePriority'];
                 $i++;
             }
         }
         if (!empty($item['InternationalShippingServiceOption']) && is_array($item['InternationalShippingServiceOption'])) {
             $j = 0;
             foreach ($item['InternationalShippingServiceOption'] as $i) {
                 $itemArray['ShippingDetails']['InternationalShippingServiceOption'][$j]['ShippingService'] = $i['ShippingService'];
                 $itemArray['ShippingDetails']['InternationalShippingServiceOption'][$j]['ShippingServiceCost'] = $i['ShippingServiceCost'];
                 $itemArray['ShippingDetails']['InternationalShippingServiceOption'][$j]['ShippingServiceAdditionalCost'] = $i['ShippingServiceAdditionalCost'];
                 $itemArray['ShippingDetails']['InternationalShippingServiceOption'][$j]['ShippingServicePriority'] = $i['ShippingServicePriority'];
                 if (!empty($i['ShipToLocation'])) {
                     if (strpos($i['ShipToLocation'], ',') != false) {
                         //echo "test1";
                         $stl_array = explode(',', $i['ShipToLocation']);
                         foreach ($stl_array as $stl) {
                             if (!in_array($stl, $ShipToLocations)) {
                                 array_push($ShipToLocations, $stl);
                             }
                         }
                         //$ShipToLocations = array_merge($ShipToLocations, explode(',', $i['ShipToLocation']));
                         $itemArray['ShippingDetails']['InternationalShippingServiceOption'][$j]['ShipToLocation'] = explode(',', $i['ShipToLocation']);
                     } else {
                         //echo "test2";
                         if (!in_array($i['ShipToLocation'], $ShipToLocations)) {
                             array_push($ShipToLocations, $i['ShipToLocation']);
                         }
                         $itemArray['ShippingDetails']['InternationalShippingServiceOption'][$j]['ShipToLocation'] = $i['ShipToLocation'];
                     }
                 }
                 $j++;
             }
         }
         //print_r($itemArray['ShippingDetails']['InternationalShippingServiceOption']);
         //exit;
         //ShipToLocations
         //$itemArray['ShipToLocations'] = "Worldwide";
         if (!empty($ShipToLocations)) {
             $itemArray['ShipToLocations'] = $ShipToLocations;
         }
         $itemArray['BuyerResponsibleForShipping'] = false;
         $itemArray['ShippingTermsInDescription'] = true;
         $itemArray['Site'] = $item['Site'];
         if ($item['Site'] == 'Germany' && $item['Motors']) {
             $itemArray['MotorsGermanySearchable'] = true;
         }
         $itemArray['SKU'] = $item['SKU'];
         if (!empty($item['StartPrice'])) {
             $itemArray['StartPrice'] = $item['StartPrice'];
         }
         if (!empty($item['StoreCategoryID'])) {
             $itemArray['Storefront']['StoreCategoryID'] = $item['StoreCategoryID'];
             if (!empty($item['StoreCategory2ID'])) {
                 $itemArray['Storefront']['StoreCategory2ID'] = $item['StoreCategory2ID'];
             } else {
                 $itemArray['Storefront']['StoreCategory2ID'] = 0;
             }
         }
         if (!empty($item['SubTitle'])) {
             $itemArray['SubTitle'] = $item['SubTitle'];
         }
         $itemArray['Title'] = $item['Title'];
         //unset($itemArray['Description']);
         //print_r($itemArray);
         //exit;
         $params = array('Version' => $Version, 'Item' => $itemArray);
         $results = $client->AddItem($params);
         //print_r($results);
         if (!empty($results->Errors)) {
             $sql_0 = "update items set Status = 1 where Id = '" . $item['Id'] . "'";
             //$result_0 = mysql_query($sql_0);
             $this->parseEbayResponse("upload", $item, $results);
             if (!empty($results->ItemID)) {
                 foreach ($results->Fees->Fee as $fee) {
                     switch ($fee->Name) {
                         case "InsertionFee":
                             $InsertionFee = $fee->Fee->_;
                             break;
                         case "ListingFee":
                             $ListingFee = $fee->Fee->_;
                             break;
                     }
                 }
                 $sql = "update items set ItemID = '" . $results->ItemID . "',Status='2',StartTime='" . $results->StartTime . "',\n\t\t    EndTime='" . $results->EndTime . "',InsertionFee='" . $InsertionFee . "',ListingFee='" . $ListingFee . "' where Id = '" . $item['Id'] . "'";
                 echo $sql;
                 $result = mysql_query($sql);
                 $this->log("upload", $item['Id'] . " upload success, ItemID is " . $results->ItemID);
             }
         } elseif (!empty($results->ItemID)) {
             foreach ($results->Fees->Fee as $fee) {
                 switch ($fee->Name) {
                     case "InsertionFee":
                         $InsertionFee = $fee->Fee->_;
                         break;
                     case "ListingFee":
                         $ListingFee = $fee->Fee->_;
                         break;
                 }
             }
             //echo $results->ItemID;
             //echo $results->StartTime;
             //echo $results->EndTime;
             $sql = "update items set ItemID = '" . $results->ItemID . "',Status='2',StartTime='" . $results->StartTime . "',\n\t\tEndTime='" . $results->EndTime . "',InsertionFee='" . $InsertionFee . "',ListingFee='" . $ListingFee . "' where Id = '" . $item['Id'] . "'";
             echo $sql;
             $result = mysql_query($sql);
             $this->log("upload", $item['Id'] . " upload success, ItemID is " . $results->ItemID);
         }
         if (!empty($results->faultcode)) {
             $sql_0 = "update items set Status = 1 where Id = '" . $item['Id'] . "'";
             //$result_0 = mysql_query($sql_0);
             $this->log("upload", $item['Id'] . " " . $results->faultcode . ": " . $results->faultstring, "error");
         }
         //----------   debug --------------------------------
         //print "Request: \n".$client->__getLastRequest() ."\n";
         //print "Response: \n".$client->__getLastResponse()."\n";
         //$this->saveFetchData("addItem-Request-".date("YmdHis").".html", print_r($results, true));
         $this->saveFetchData("addItem-Request-" . date("YmdHis") . ".xml", $client->__getLastRequest());
         $this->saveFetchData("addItem-Response-" . date("YmdHis") . ".xml", $client->__getLastResponse());
     } catch (SOAPFault $f) {
         print $f;
         // error handling
     }
 }