Beispiel #1
0
 public function getCategories()
 {
     if (EbayCategory::find()->count() > 0) {
         return true;
     }
     $service = new TradSer\TradingService(array('apiVersion' => $this->config['tradingApiVersion'], 'siteId' => Constants\SiteIds::US));
     $catconfig = $this->getCategoryConfig();
     $i = 1;
     foreach ($catconfig as $name => $cat) {
         foreach ($cat as $key => $value) {
             $request = new TradType\GetCategoriesRequestType();
             if ($i % 2 == 0) {
                 $request->CategorySiteID = '0';
             } else {
                 $request->CategorySiteID = '215';
             }
             $request->CategoryParent = array($value);
             $request->RequesterCredentials = new TradType\CustomSecurityHeaderType();
             $request->RequesterCredentials->eBayAuthToken = $this->config['production']['userToken'];
             $request->DetailLevel = array('ReturnAll');
             $request->OutputSelector = array('CategoryArray.Category.CategoryID', 'CategoryArray.Category.CategoryParentID', 'CategoryArray.Category.CategoryLevel', 'CategoryArray.Category.CategoryName');
             $cats = $service->getCategories($request)->toArray();
             $this->addCatsToDB($cats, $value);
             $i++;
         }
     }
 }
/**
 * By specifying 'ReturnAll' we are telling the API return the full category hierarchy.
 */
$request->DetailLevel = array('ReturnAll');
/**
 * OutputSelector can be used to reduce the amount of data returned by the API.
 * http://developer.ebay.com/DevZone/XML/docs/Reference/ebay/GetCategories.html#Request.OutputSelector
 */
$request->OutputSelector = array('CategoryArray.Category.CategoryID', 'CategoryArray.Category.CategoryParentID', 'CategoryArray.Category.CategoryLevel', 'CategoryArray.Category.CategoryName');
/**
 * Send the request to the GetCategories service operation.
 *
 * For more information about calling a service operation, see:
 * http://devbay.net/sdk/guides/getting-started/#service-operation
 */
$response = $service->getCategories($request);
/**
 * Output the result of calling the service operation.
 *
 * For more information about working with the service response object, see:
 * http://devbay.net/sdk/guides/getting-started/#response-object
 */
if ($response->Ack !== 'Success') {
    if (isset($response->Errors)) {
        foreach ($response->Errors as $error) {
            printf("Error: %s\n", $error->ShortMessage);
        }
    }
} else {
    /**
     * For the US site this will output approximately 18,000 categories.