# Zend_Service_Ebay_Finding

## Introduction

Zend_Service_Ebay_Finding provides a client for the eBay Finding. Per eBay website, "The Finding API provides programmatic access to the next generation search capabilities on the eBay platform. It lets you search and browse for items listed on eBay, and provides useful metadata to refine searches and enhance the search experience."

In order to use Zend_Service_Ebay_Finding, you should already have an eBay Application ID. To get a key and for more information, please visit the eBay Developers Program web site.

## Create a client object

Instantiate a Zend_Service_Ebay_Finding object, passing it your private keys:

Creating an instance of the eBay Finding service

    $finding = new Zend_Service_Ebay_Finding('my-app-id');

Instantiate a Zend_Service_Ebay_Finding object, passing it your private keys and setting options:

Creating an instance of the eBay Finding service

    $options = array(Zend_Service_Ebay_Abstract::OPTION_APP_ID    => 'my-app-id',
                     Zend_Service_Ebay_Abstract::OPTION_GLOBAL_ID => 'EBAY-GB');
    $finding = new Zend_Service_Ebay_Finding($options);

## Finding items

There are five available methods to search items:

- findItemsByKeywords($keywords)

- findItemsByProduct($productId)

- findItemsByCategory($categoryId)

- findItemsAdvanced($keywords)

- findItemsInEbayStores($storeName)

Many ways to find items

    $finding  = new Zend_Service_Ebay_Finding('my-app-id');
    $response = $finding->findItemsByKeywords('zend framework book');
    foreach ($response->searchResult->item as $item) {
        $item->title;
        $item->listingInfo->buyItNowPrice;
        $item->listingInfo->viewItemURL;

        // inner call, find for items of same current product
        // like $finding->findItemsByProduct($item->productId, $item->attributes('productId', 'type'))
        $response2 = $item->findItemsByProduct($finding);

        // inner call, find for items of same store
        // like $finding->findItemsInEbayStores($item->storeInfo->storeName)
        $response3 = $item->storeInfo->findItems($finding);
    }

## Keywords Recommendation

This operation checks specified keywords and returns correctly spelled keywords for best search results.

Searching keywords recomendation

    // searching keywords
    $finding = new Zend_Service_Ebay_Finding('my-app-id');
    $result  = $finding->getSearchKeywordsRecommendation('zend');
    echo 'Did you mean ' . $result->keyword . '?';

    // inner call
    // like $finding->findItemsByKeywords($result->keyword)
    $result2 = $result->findItems($finding);

## Histograms

Per eBay website, this operation "category and/or aspect histogram information for the eBay category ID you specify. Histograms are item counts for the associated category or aspect value. Input category ID numbers in the request using the categoryId field".

Fetching histogram

    $finding = new Zend_Service_Ebay_Finding('my-app-id');
    $result  = $finding->getHistograms($categoryId);

    foreach ($result->categoryHistogramContainer->categoryHistogram as $category) {
        $category->categoryId;
        $category->categoryName;

        // inner call
        // like $finding->findItemsByCategory($category->categoryId);
        $result2 = $category->findItems($finding);
    }