コード例 #1
0
ファイル: ebay.php プロジェクト: heshuai64/ebo
 public function getStoreCategories($userID = 0)
 {
     global $argv;
     if (!empty($argv[2])) {
         $userID = $argv[2];
         $sql = "select id,site from account where name = '" . $userID . "'";
         $result = mysql_query($sql, eBayListing::$database_connect);
         $row = mysql_fetch_assoc($result);
         $this->setAccount($row['id']);
         $this->configEbay($row['site']);
     } else {
         if (!empty($this->account_id)) {
             $sql = "select name,site from account where id = " . $this->account_id;
             $result = mysql_query($sql, eBayListing::$database_connect);
             $row = mysql_fetch_assoc($result);
             $userID = $row['name'];
             $this->configEbay($row['site']);
         } else {
             echo "error, no account id.";
         }
     }
     echo $userID . "\n";
     try {
         $client = new eBaySOAP($this->session);
         $CategoryStructureOnly = true;
         $Version = $this->version;
         $UserID = $userID;
         $params = array('Version' => $Version, 'CategoryStructureOnly' => $CategoryStructureOnly, 'UserID' => $UserID);
         //print_r($params);
         $results = $client->GetStore($params);
         //print_r($results);
         //----------   debug --------------------------------
         //print "Request: \n".$client->__getLastRequest() ."\n";
         //print "Response: \n".$client->__getLastResponse()."\n";
         $sql = "delete from account_store_categories where AccountId = " . $this->account_id;
         $result = mysql_query($sql, eBayListing::$database_connect);
         echo $sql . "\n";
         $this->saveFetchData("getStoreCategoriesRequest-" . date("Y-m-d H:i:s") . ".xml", $client->__getLastRequest());
         $this->saveFetchData("getStoreCategoriesResponse-" . date("Y-m-d H:i:s") . ".xml", $client->__getLastResponse());
         foreach ($results->Store->CustomCategories->CustomCategory as $customCategory) {
             $level = 1;
             $sql = "INSERT INTO `account_store_categories` (`CategoryID` , `CategoryParentID` ,`Name` ,`Order` ,`AccountId`) VALUES ('" . $customCategory->CategoryID . "','0','" . $customCategory->Name . "','" . $customCategory->Order . "','" . $this->account_id . "')";
             echo $sql . "\n";
             $result = mysql_query($sql, eBayListing::$database_connect);
             //two level
             if (is_array($customCategory->ChildCategory)) {
                 $twoCategoryParentID = $customCategory->CategoryID;
                 $twoChildCategories = $customCategory->ChildCategory;
                 foreach ($twoChildCategories as $twoChildCategory) {
                     $level = 2;
                     $sql = "INSERT INTO `account_store_categories` (`CategoryID` , `CategoryParentID` ,`Name` ,`Order` ,`AccountId`) VALUES ('" . $twoChildCategory->CategoryID . "','" . $twoCategoryParentID . "','" . $twoChildCategory->Name . "','" . $twoChildCategory->Order . "','" . $this->account_id . "')";
                     echo $sql . "\n";
                     $result = mysql_query($sql, eBayListing::$database_connect);
                     //three leve
                     if (is_array($twoChildCategory->ChildCategory)) {
                         $threeCategoryParentID = $twoChildCategory->CategoryID;
                         $threeChildCategories = $twoChildCategory->ChildCategory;
                         foreach ($threeChildCategories as $threeChildCategory) {
                             $level = 3;
                             $sql = "INSERT INTO `account_store_categories` (`CategoryID` , `CategoryParentID` ,`Name` ,`Order` ,`AccountId`) VALUES ('" . $threeChildCategory->CategoryID . "','" . $threeCategoryParentID . "','" . $threeChildCategory->Name . "','" . $threeChildCategory->Order . "','" . $this->account_id . "')";
                             echo $sql . "\n";
                             $result = mysql_query($sql, eBayListing::$database_connect);
                         }
                     } elseif (!empty($twoChildCategory->ChildCategory)) {
                         $threeCategoryParentID = $twoChildCategory->CategoryID;
                         $threeChildCategory = $twoChildCategory->ChildCategory;
                         $level = 3;
                         $sql = "INSERT INTO `account_store_categories` (`CategoryID` , `CategoryParentID` ,`Name` ,`Order` ,`AccountId`) VALUES ('" . $threeChildCategory->CategoryID . "','" . $threeCategoryParentID . "','" . $threeChildCategory->Name . "','" . $threeChildCategory->Order . "','" . $this->account_id . "')";
                         echo $sql . "\n";
                         $result = mysql_query($sql, eBayListing::$database_connect);
                     }
                 }
             } elseif (!empty($customCategory->ChildCategory)) {
                 $twoCategoryParentID = $customCategory->CategoryID;
                 $twoChildCategory = $customCategory->ChildCategory;
                 $level = 2;
                 $sql = "INSERT INTO `account_store_categories` (`CategoryID` , `CategoryParentID` ,`Name` ,`Order` ,`AccountId`) VALUES ('" . $twoChildCategory->CategoryID . "','" . $twoCategoryParentID . "','" . $twoChildCategory->Name . "','" . $twoChildCategory->Order . "','" . $this->account_id . "')";
                 echo $sql . "\n";
                 $result = mysql_query($sql, eBayListing::$database_connect);
             }
         }
     } catch (SOAPFault $f) {
         print $f;
         // error handling
     }
 }