View Full Version : is this possible? using api to show all products matching a query?
ljackson09
18-12-09, 15:55
Hi All,
i will try and explain this as best as i can :)
i want to beable to allow the user of my site to look up a product, any product, i have a drop down box with the categorys in, and when the user sumits which category they want e.g dvds i want the api to get all the dvd titles that are in the api, but to only find each title once. is this at all possible
i have tried to code an array where it adds the titles to an array if its not already present in the array but i dont think its working :(
i would like to to display the number of products found on my page somewhere so i can easily see how many products are there
here is my code
<?php
$category = $_GET['category'];
if($category == "DVD"){
$AW_catid = "235";
$category = "DVDs";
$AW_catid2 = "240";
$category2 = "DVDs";
}
elseif($category == "CD"){
$AW_catid = "241";
$category = "Music";
$AW_catid2 = "245";
$category2 = "CDs";
}
print $category;//works ok
$oRefineBy = new stdClass();
$oRefineBy -> iId = 4;
$oRefineBy -> sName = 'Category';
$oRefineByDefinition = new stdClass();
$oRefineByDefinition -> sId = $category;
$oRefineByDefinition -> sName = '';
$oRefineBy -> oRefineByDefinition = array($oRefineByDefinition, $oRefineByDefinition2);
$aParams = array("iAdult" => 1, "oActiveRefineByGroup" => $oRefineBy);
$oResponse= $oClient->call('getProductList', $aParams);
$onePerItem = array();
$x = 0;
if(count($oResponse->oProduct) <> 0){;
foreach($oResponse->oProduct as $oProduct){
//if(isset($oProduct->
if(!in_array($oProduct->name,$onePerItem))
{ #makes sure we dont already have a product in the array
# add merchantID to $onePerMerchant Array
$onePerItem[$x] = $oProduct->name;
$merchantname = $oProduct->iMerchantId;
$merchant = "AW".$oProduct->iMerchantId;
$productPrice = number_format($oProduct->fPrice, 2, '.', '');
$PnP = number_format($oProduct->fDeliveryCost, 2, '.', '');
$totalPrice = number_format((($oProduct->fPrice)+($oProduct->fDeliveryCost)), 2, '.', '');
$link = $oProduct->sAwDeepLink;
print $merchant;
$x++;
}
}
}
think my array code is wrong?
any help would be greatly appreciated :)
thanks
Luke
Simple coding error mate:
$oRefineByDefinition -> sId = $category;
Should be:
$oRefineByDefinition -> sId = $AW_catid;
You were sending the category name rather than the ID.
:D
ljackson09
18-12-09, 17:13
Hi Andy,
thanks for your reply :)
unfortunatly i am still unable to get my request to work?
this code prints nothing :(
$category = $_GET['category'];
if($category == "DVD"){
$AW_catid = "235";
$category1 = "DVDs";
$AW_catid2 = "240";
$category2 = "DVDs";
$additionalInfo = $_POST['actor'];
}
elseif($category == "CD"){
$AW_catid = "241";
$category1 = "Music";
$AW_catid2 = "245";
$category2 = "CDs";
$additionalInfo = $_POST['artist'];
}
print $category;
$oRefineBy = new stdClass();
$oRefineBy -> iId = 4;
$oRefineBy -> sName = 'Category';
$oRefineByDefinition = new stdClass();
$oRefineByDefinition -> sId = $AW_catid;
$oRefineByDefinition -> sName = '';
$oRefineBy -> oRefineByDefinition = array($oRefineByDefinition, $oRefineByDefinition2);
$aParams = array("sQuery" => "Bruno", "iAdult" => 1, "oActiveRefineByGroup" => $oRefineBy);
$oResponse= $oClient->call('getProductList', $aParams);
print_r($oResponse);
not sure why thought?
also do i need to set the sQuery in order to recieve some results? thanks
appreciate your help
Luke
ljackson09
18-12-09, 18:42
ok managed to get my request working :) was missing
$oClient = ClientFactory::getClient(API_USERNAME, API_PASSWORD, API_USER_TYPE);
will now try and get my array working :)
thanks
Luke
EDIT
===
Array is working :) sweet!!!
may be back soon as im sure to run into a problem at some point :)
thanks
Luke
ljackson09
18-12-09, 23:43
ok is it possible to get more than 10 results returned???
i only get a maximum of 10, any ideas
here is my updated code
$oRefineBy = new stdClass();
$oRefineBy -> iId = 4;
$oRefineBy -> sName = 'Category';
$oRefineByDefinition = new stdClass();
$oRefineByDefinition -> sId = $AW_catid;
$oRefineByDefinition -> sName = $AW_cat;
$oRefineBy -> oRefineByDefinition = $oRefineByDefinition;
$aParams = array("sQuery" => "cheryl cole", "iAdult" => 1, "oActiveRefineByGroup" => $oRefineBy);
$oResponse= $oClient->call('getProductList', $aParams);
print_r($oResponse);
print "<p>";
print count($oResponse->oProduct)." Products Found";
print "</p>";
$onePerItem = array();
$x = 0;
if(count($oResponse->oProduct) <> 0){;
foreach($oResponse->oProduct as $oProduct){
//if(isset($oProduct->
if(!in_array($oProduct->sName,$onePerItem))
{ #makes sure we dont already have a product in the array
# add merchantID to $onePerMerchant Array
$onePerItem[$x] = $oProduct->sName;
$merchantname = $oProduct->iMerchantId;
$merchant = "AW".$oProduct->iMerchantId;
$productPrice = number_format($oProduct->fPrice, 2, '.', '');
$PnP = number_format($oProduct->fDeliveryCost, 2, '.', '');
$totalPrice = number_format((($oProduct->fPrice)+($oProduct->fDeliveryCost)), 2, '.', '');
$link = $oProduct->sAwDeepLink;
$x++;
}
}
}
thanks
Luke
ljackson09
19-12-09, 20:14
ok i have found something from another thread on here, which gives this code
$aParams7 = array( 'iCategoryId' => 97, "bIncludeTree" => true);
$oResponse= $oClient->call('getProductList', $aParams7);
$iTotalCount = $oResponse->iTotalCount; // get the total count before the next call
$aParams17 = array('iLimit' => $iTotalCount, 'iCategoryId' => 97, "bIncludeTree" => true); // use => for the parameters not ->
$oResponse1= $oClient->call('getProductList', $aParams17);
print_r($oResponse1); // It's not really a useful method to echo an array
which is great, all i want is the total number of products but it give an error
SoapError Object ( [sCode] => ns1:Client.LIMIT [sString] => Number of products requested exceeds the limits [sDetails] => getProductList: )
because of the number of items being returned... like i say i only want the number of ites which its getting, how do i remove the error???
many thanks
Luke
EDIT
===
All sorted :) thanks
ljackson09
21-12-09, 01:30
hi,
is it possible to return only unique product titles i.e if the product already exists then dont include it?
i have this code
$keywords = $_POST['dvd_search'];
$oRefineBy = new stdClass();
$oRefineBy -> iId = 4;
$oRefineBy -> sName = 'Category';
$oRefineByDefinition = new stdClass();
$oRefineByDefinition -> sId = '235';
$oRefineByDefinition -> sName = 'DVDs';
$oRefineBy -> oRefineByDefinition = $oRefineByDefinition;
$aParams = array("sQuery" => "$keywords", "bIncludeTree" => true, "oActiveRefineByGroup" => $oRefineBy);
$oResponse= $oClient->call('getProductList', $aParams);
$iTotalCount = $oResponse->iTotalCount; // get the total count before the next call
$aParams2 = array('iLimit' => $iTotalCount, "bIncludeTree" => true, "oActiveRefineByGroup" => $oRefineBy);
$oResponse2= $oClient->call('getProductList', $aParams2);
which usually returns anywhere between 10 and 10000 products (note im only getting the number of products, im not trying to display them, yet.
the problem with this code is that if i only had 100 products(think thats the limit per call) 40 of the products might have the same title which would be a waste for what i want to do, is it possible at this stage to get the only one of each product title.
i have this code which does what i want but i think it only works after making the request
$onePerItem = array();
$x = 0;
if(count($oResponse1->oProduct) <> 0){;
foreach($oResponse1->oProduct as $oProduct){
//if(isset($oProduct->
if(!in_array($oProduct->sName,$onePerItem))
{ #makes sure we dont already have a product in the array
# add merchantID to $onePerMerchant Array
$onePerItem[$x] = $oProduct->sName;
$merchantname = $oProduct->iMerchantId;
$merchant = "AW".$oProduct->iMerchantId;
$productPrice = number_format($oProduct->fPrice, 2, '.', '');
$PnP = number_format($oProduct->fDeliveryCost, 2, '.', '');
$totalPrice = number_format((($oProduct->fPrice)+($oProduct->fDeliveryCost)), 2, '.', '');
$link = $oProduct->sAwDeepLink;
print $oProduct->sName;
print "<br />";
$x++;
}
}
i will try it with the above code see if i can get it to work. is there another way to do this?
many thanks
Luke
ljackson09
21-12-09, 01:52
it turns out it does kinda work :)
the main problem at the mo is that the array only seems to store uptp 10 unique products unless its a coincidence that the 5 or 6 searches have exactly 10 different titles out of about 400 results?
my full code is
$keywords = $_POST['dvd_search'];
$oRefineBy = new stdClass();
$oRefineBy -> iId = 4;
$oRefineBy -> sName = 'Category';
$oRefineByDefinition = new stdClass();
$oRefineByDefinition -> sId = '235';
$oRefineByDefinition -> sName = 'DVDs';
$oRefineBy -> oRefineByDefinition = $oRefineByDefinition;
$aParams = array("sQuery" => "$keywords", "bIncludeTree" => true, "oActiveRefineByGroup" => $oRefineBy);
$oResponse= $oClient->call('getProductList', $aParams);
$iTotalCount = $oResponse->iTotalCount; // get the total count before the next call
$aParams2 = array('iLimit' => $iTotalCount, "bIncludeTree" => true, "oActiveRefineByGroup" => $oRefineBy);
$oResponse2= $oClient->call('getProductList', $aParams2);
$onePerItem = array();
$x = 0;
if(count($oResponse->oProduct) <> 0){;
foreach($oResponse->oProduct as $oProduct){
//if(isset($oProduct->
if(!in_array($oProduct->sName,$onePerItem))
{ #makes sure we dont already have a product in the array
# add merchantID to $onePerMerchant Array
$onePerItem[$x] = $oProduct->sName;
$merchantname = $oProduct->iMerchantId;
$merchant = "AW".$oProduct->iMerchantId;
$productPrice = number_format($oProduct->fPrice, 2, '.', '');
$PnP = number_format($oProduct->fDeliveryCost, 2, '.', '');
$totalPrice = number_format((($oProduct->fPrice)+($oProduct->fDeliveryCost)), 2, '.', '');
$link = $oProduct->sAwDeepLink;
$x++;
}
}
}
}