1. Halo Guest, pastikan Anda selalu menaati peraturan forum sebelum mengirimkan post atau thread baru.

[ask] cara membaca output dari web service CJ gimana ya?

Discussion in 'Pemrograman Web' started by solik, Jul 18, 2009.

  1. solik

    solik Super Hero

    Joined:
    Nov 12, 2007
    Messages:
    899
    Likes Received:
    28
    Dear all master PHP,
    aku bikin skrip untuk akses Commision junction web service, outputnya kayak gini

    stdClass Object
    (
    [out] => stdClass Object
    (
    [count] => 2
    [offset] => 0
    [products] => stdClass Object
    (
    [Product] => Array
    (
    [0] => stdClass Object
    (
    [adId] => 10553769
    [advertiserId] => 2376886
    [advertiserName] => Bplay -- BlackBerry Mobile Entertainment Products
    [buyUrl] => http://www.anrdoezrs.net/click-3238...ay.com/rl/cj/theme.php?t=212&cjsku=lsu_tigers
    [catalogId] => cjo:2460
    [currency] => USD
    [description] => LSU Tigers Theme: LSU Tigers theme for BlackBerry.
    [imageUrl] => http://www.bplay.com/img/themes/lsu_tigers/splash.jpg
    [inStock] =>
    [isbn] =>
    [manufacturerName] =>
    [manufacturerSku] =>
    [name] => LSU Tigers - BlackBerry Theme
    [price] => 5.99
    [retailPrice] => 0
    [salePrice] => 0
    [sku] => lsu_tigers
    [upc] =>
    )

    [1] => stdClass Object
    (
    [adId] => 10553769
    [advertiserId] => 2376886
    [advertiserName] => Bplay -- BlackBerry Mobile Entertainment Products
    [buyUrl] => http://www.kqzyfj.com/click-3238895...om/rl/cj/theme.php?t=281&cjsku=clemson_tigers
    [catalogId] => cjo:2460
    [currency] => USD
    [description] => Clemson Tigers Theme: Clemson Tigers theme for BlackBerry
    [imageUrl] => http://www.bplay.com/img/themes/clemson_tigers/splash.jpg
    [inStock] =>
    [isbn] =>
    [manufacturerName] =>
    [manufacturerSku] =>
    [name] => Clemson Tigers - BlackBerry Theme
    [price] => 5.99
    [retailPrice] => 0
    [salePrice] => 0
    [sku] => clemson_tigers
    [upc] =>
    )

    )

    )

    [totalResults] => 24080
    )

    )


    Nah caranya gimana membaca output itu... biar bisa dimasukkan kedalam database lokal...
    (maaf nggak maksud untuk live link)
     
  2. solik

    solik Super Hero

    Joined:
    Nov 12, 2007
    Messages:
    899
    Likes Received:
    28
    update: udah bisa kok...ternyta output yg dihasilkan berupa object yg berisi array, jadi parsernya agak membingunkan.. tapi alhamduillah udah bisa
     
  3. Pogung177

    Pogung177 Banned

    Joined:
    Sep 25, 2005
    Messages:
    1,994
    Likes Received:
    45
    Sep dah pada pinter, padahal pingin kasih sample code :D
     
  4. downloadmaster

    downloadmaster Hero

    Joined:
    Oct 21, 2008
    Messages:
    641
    Likes Received:
    14
    Location:
    Tulungagung
  5. penyu

    penyu Ads.id Starter

    Joined:
    Feb 17, 2008
    Messages:
    63
    Likes Received:
    0
    bisa minta sample codenya ngga om pogung :hmm:
     
  6. Pogung177

    Pogung177 Banned

    Joined:
    Sep 25, 2005
    Messages:
    1,994
    Likes Received:
    45
    Coba Ini
    Code:
    // Passing parameters in URL to fill datanamese of products
    	$cj_dev ="XXXXXX";
    	$cj_pubid = "XXXXX"; // Publisher ID
    	$cj_aid = "XXXXXXX"; // mercan ID	
        $key     = "$cj_dev";  // The developer Key you get when you initially sign up for webservices
        $siteId   = "$cj_pubid";       // The CID you have with CJ.
        $wdslurl    = 'https://api.cj.com/wsdl/version2/productSearchServiceV2.wsdl';
        $keywords       = "Kewords here" ;  // What you want to search for
    	$advertiseId			= "$cj_aid";
    
    
    try {
                $productClient = new SoapClient($wdslurl,array(
                                                               'trace' => 1,
                                                                'soap_version' => SOAP_1_1,
                                                                'style' => SOAP_DOCUMENT,
                                                                'encoding' => SOAP_LITERAL
                                                            )
                                                );
                $results =  $productClient->search(array(
                                                            "developerKey" => $key,
                                                            "websiteId" => $siteId,
                                                            "advertiserIds" => $advertiseId,
                                                            "keywords"  => "$keywords",
                                                            "serviceableArea" => '',
                                                            "upc" => '',
                                                            "manufacturerName" => '',
                                                            "manufacturerSku" => '',
                                                            "advertiserSku" => '',
                                                            "lowPrice" => '',
                                                            "highPrice" => '',
                                                            "lowSalePrice" => '',
                                                            "highSalePrice" => '',
                                                            "currency" => '',
                                                            "isbn" => '',
                                                            "sortBy" => 'Price',
                                                            "sortOrder" => '',
                                                            "startAt" => $min,
                                                            "maxResults" => 10
                                                )
                                            );
    				//print_r($results);
    				$total = $results->out->totalResults; 
    				
                    foreach ($results->out->products->Product as $product)
                            {
    						$name 	  = $product->name;
    						$name 	  = strtolower($name);
    						$name	  = ucwords($name);
    						$descrip  = $product->description;
    						$store    = $product->advertiserName;
    						$buyurl   = $product->buyUrl;
    						$imageurl = $product->imageUrl;
    						$prc 	  = $product->price;
    						$sku 	  = $product->sku;
    						$price = sprintf('%01.2f', $prc);
    						$img=str_replace("reg.jpg","th.gif","$imageurl");
    						// cek exist	
    						echo"<div class=\"content\">
    						<p>
    						<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">
    						  <tr>
    							<td width=\"70%\" valign=\"top\" align=\"left\" rowspan=\"2\">
    							Item Name:<br><input type=\"text\" value=\"$name\" size=\"92\"><br>
    							Item URL:<br><input type=\"text\" value=\"$buyurl\" size=\"92\"><br>
    							Description:<br><textarea rows=\"3\" class=\"form-large\" cols=\"70\">$descrip</textarea>							
    							</td>
    							<td width=\"30%\" valign=\"top\">Image URL:<br><textarea rows=\"2\" class=\"form-large\" cols=\"30\">$img</textarea></td>
    						  </tr>
    						  <tr>
    						<td width=\"30%\" valign=\"top\">";
    						  if($img!="")
    						  echo"<img src=\"$img\" align=\"right\">";
    						  echo"<font color=\"#990000\" size=\"+1\"><b>Price: $$prc</b></font><br>
    						   </tr>
    						</table>
    						</p>
    						</div>";						
    				}				
        } catch (Exception $e) {
                    print "<p>The following error occured: <div style='margin-left:15px;color:red;'>$e</div></p>";
        }
    
    
     
  7. fathonix

    fathonix Ads.id Fan

    Joined:
    Jun 7, 2007
    Messages:
    192
    Likes Received:
    10
    wow bahasannya ngeri bgt :)
     
  8. mxyzplk

    mxyzplk Ads.id Starter

    Joined:
    Dec 22, 2006
    Messages:
    91
    Likes Received:
    180
    mantaaaaaaaaaappppppppp...
    dari tadi foreach gw error mulu akhirnya mas pogung memberi solusi ;)
     
  9. indrajid

    indrajid Super Hero

    Joined:
    Oct 16, 2007
    Messages:
    3,964
    Likes Received:
    82
    Location:
    Sembada - Berirama
    script-nya freeware? download dimana bro?
     
  10. achmad46

    achmad46 Super Hero

    Joined:
    Aug 11, 2008
    Messages:
    859
    Likes Received:
    9
    Location:
    Jateng
    manteb dah, gw kagak ngarti blas kalau soal ginian...
    :lol::lol:
     
  11. Punjabi

    Punjabi Super Hero

    Joined:
    Oct 7, 2007
    Messages:
    1,048
    Likes Received:
    80
    Location:
    Jln Marabahan GKB Gresik
    Kayaknya punya Om Pogung itu versi lama ada yang lebih baru lagi dari CJ


    HTML:
    
    <?php
    
        $developerKey = "Key API kamu";
        $websiteId = "3350105"; // a1books.com
    
        $ini = ini_set("soap.wsdl_cache_enabled","0");
    
        try {
    
            $client = new SoapClient("https://product.api.cj.com/wsdl/version2/productSearchServiceV2.wsdl", array('trace'=> true));
    
            //Enter the request parameters for productSearch below.
            //For detailed usage of the parameter values, please refer to CJ Web Services online documentation
    
            $results = $client->search(array("developerKey" => $developerKey,
                                                "websiteId" => $websiteId,
                                                "advertiserIds" => '1191832', // tambahkan dengan tanda koma untuk multi advertiser
                                                "keywords" => 'woman',
                                                "serviceableArea" => '',
                                                "upc" => '',
                                                "linkType" => '',
                                                "manufacturerName" => '',
                                                "manufacturerSku" => '',
                                                "advertiserSku" => '',
                                                "lowPrice" => '',
                                                "highPrice" => '',
                                                "lowSalePrice" => '',
                                                "highSalePrice" => '',
                                                   "currency" => '',
                                                 "isbn" => '',
                                                   "sortBy" => '',
                                                 "sortOrder" => '',
                                                "startAt" => 0,
                                                "maxResults" => 10));
    
            // The entire response structure will be printed in the next line
            //print_r($results);
    
           echo "<h3>Your search for '$keywords' generated $results->count results</h3>";
    
            foreach ($results->out->products->Product as $product) {
                    if(strlen(trim($product->imageUrl)) > 0){
                            $price = sprintf('%01.2f', $product->price);
                            echo "<br>".$product->advertiserId."<br>";
                            echo "<br>SKU:".$product->sku."<br>";
                            echo "<a href='$product->buyUrl'><img src ='$product->imageUrl' height='70' ><p>$product->name <br/>$product->isbn <br/> Offered by $product->advertiserName($product->advertiserId) at <b>$price ($product->currency)</b></p></a>";
                    }
            }
    
    
        } catch (Exception $e){
            echo "There was an error with your request or the service is unavailable.\n";
            print_r ($e);
        }
    ?>
    
    
     
  12. Gerrrr

    Gerrrr Ads.id Fan

    Joined:
    Feb 14, 2010
    Messages:
    185
    Likes Received:
    4
    Gan minta pencerahan, Cara makenya gimana . Tolong tutorialnya buat newbe.
     

Share This Page