View Full Version : Discount Codes?
ljackson09
24-09-09, 14:55
Not sure if this is a bug but there seems to be several discount codes missing from the api?
for example all the codes from currys, pharmacy2u, Pixmania, Laptops Direct and several others are not listed in the api :(
has anyone else noticed this?
is there a reason for this?
many thanks
Luke
currentstyle
24-09-09, 17:53
Luke, I get currys and pixmania Currys & Pixmania Codes (http://www.easynewshop.com/category-64-3.html) codes via the API (I'm fairly certain i've seen laptops direct as well) So, at least some of them are there, might take some digging to find them.
ljackson09
24-09-09, 18:02
hmmm interesting :)
its good news that they are there however using the code you kindly done for me isnt picking them up? (at least not for me)
could you run this code at your end to see if you are picking the up please?
$storesArray = array(
9,15,65,172,323,380,483,547,550,686,782,854,896,91 1,980,
1052,1084,1107,1109,1132,1134,1184,1186,1198,1202, 1221,1228,
1256,1257,1270,1311,1322,1331,1350,1402,1404,1418, 1472,1487,
1521,1559,1597,1598,1599,1672,1744,1815,1826,1836, 1916,1946,
1947,1964,1970,1995,2026,2038,2041,2066,2124,2147, 2203,2208,
2249,2258,2276,2344,2354,2383,2424,2433,2453,2481, 2487,2526,
2537,2547,2548,2549);
$stores = array('iMerchantId' => $storesArray);
$oClient = ClientFactory::getClient();
$merchantcolumns = array(sStrapline,sDescription,sLogoUrl,sDisplayUrl ,sClickThroughUrl,oDiscountCode);
$multiplemerchantwithcodes = array('iMerchantId' => $storesArray, "sColumnToReturn" => $merchantcolumns, "iAdult" => 1);
$oResponse= $oClient->call('getMerchant', $multiplemerchantwithcodes);
foreach($oResponse->oMerchant as $details){
$iId = $details->iId;
$iId = "AW".$iId;
$smsName =$details->sName;
$sStrapline = $details->sStrapline;
$sDescription = $details->sDescription;
$sLogoUrl = $details->sLogoUrl;
$sDisplayUrl = $details->sDisplayUrl;
$sClickThroughUrl = $details->sClickThroughUrl;
//echo '<p><a href="#" title="'.$smsName.'">'.$smsName.'</a><br/>'.$sStrapline.'<br/><img src="'.$sLogoUrl.'" alt="'.$smsName.'" /><br/>'.$sDescription.'</p>';
$arraycheck1 = $details->oDiscountCode;
if(!empty($arraycheck1)){
echo '<p><h3>Vouchers for '.$smsName.'</h3>';
foreach($details->oDiscountCode as $key=>$details2){
$sCode = $details2->sCode;
$sDescription = $details2->sDescription;
$sUrl = $details2->sUrl;
$sEndDate = $details2->sEndDate;
//$sEndDate = explode('-',$sEndDate);
//$sEndDate = $sEndDate[2].'/'.$sEndDate[1].'/'.$sEndDate[0];
if ($sUrl<>'') {
print $iId;
echo '</div><a href="'.$sUrl.'" title="'.$smsName.'"></a><br><b>Voucher Code: <a href="'.$sUrl.'">'.$sCode.'</a></b><br/> <font color="red">(Expires '.$sEndDate.')</font><br/>'.$sDescription.'</p>';
}
}
}
}?>
thanks mate
Luke
currentstyle
24-09-09, 20:49
I've tried it using just the currys ID and it works fine, I did think that it may fall over if you added too many merchants
ljackson09
25-09-09, 00:50
ok i'll try it with just currys and then if it works i will just run the process several times with less store ids to get all the discount codes :)
stand by for progress :)
cheers
Luke
ljackson09
25-09-09, 01:46
ok having spent a little while trying to get it to work i finaly came up with a way of getting what i want (well almost :D )
i had to search for every discount code which gave me results for all stores even those that i hadent signed up to and then i kept my array and did an if in array check to see if the store id is in the array if it was enter the info into my db.
and its working a treat :)
however there are some codes which are not in the api.
but im not sure why?
pharmacy2u, laptops direct, Iwantoneofthose.com, Pet Supermarket, directtvs, Dixons, sharp, VistaPrint, Focus DIY, Lloydspharmacy
all of the above have codes but dont seem to apear in the api search results for discount codes
any ideas?
thanks mate
Luke
ljackson09
25-09-09, 02:07
sorry forgot to include my code which i used oops :)
here it is
$storeID = array(
9,15,65,172,282,323,380,483,547,550,686,782,854,89 6,911,980,
1052,1084,1107,1109,1132,1134,1184,1186,1198,1202, 1221,1228,
1256,1257,1270,1311,1322,1331,1350,1402,1404,1418, 1472,1487,
1521,1559,1597,1598,1599,1672,1744,1815,1826,1836, 1916,1946,
1947,1964,1970,1995,2026,2038,2041,2066,2117,2124, 2147,2203,2208,
2249,2258,2276,2344,2354,2383,2424,2433,2453,2481, 2487,2526,
2537,2547,2548,2549);
$oClient = ClientFactory::getClient();
$merchantcolumns = array(sStrapline,sDescription,sLogoUrl,sDisplayUrl ,sClickThroughUrl,oDiscountCode);
$multiplemerchantwithcodes = array("sColumnToReturn" => $merchantcolumns, "iAdult" => 1);
$oResponse= $oClient->call('getMerchant', $multiplemerchantwithcodes);
foreach($oResponse->oMerchant as $details){
$iId = $details->iId;
$iId2 = "AW".$iId;
$smsName =$details->sName;
$sStrapline = $details->sStrapline;
$sDescription = $details->sDescription;
$sLogoUrl = $details->sLogoUrl;
$sDisplayUrl = $details->sDisplayUrl;
$sClickThroughUrl = $details->sClickThroughUrl;
if(in_array($iId, $storeID))
{
$arraycheck1 = $details->oDiscountCode;
if(!empty($arraycheck1))
{
echo '<p><h3>Vouchers for '.$smsName.'</h3>';
foreach($details->oDiscountCode as $key=>$details2)
{
$sCode = $details2->sCode;
$sDescription = $details2->sDescription;
$sUrl = $details2->sUrl;
$sEndDate = $details2->sEndDate;
if ($sUrl<>'')
{
$insert_codes = "INSERT INTO
codes (codeID, codeLink, storeID, details, expireDate)
VALUES ('$sCode', '$sUrl', '$iId2', '$sDescription', '$sEndDate')";
$sql = mysql_query($insert_codes);
/*print $iId;
echo '</div><a href="'.$sUrl.'" title="'.$smsName.'"></a><br><b>Voucher Code: <a href="'.$sUrl.'">'.$sCode.'</a></b><br/> <font color="red">(Expires '.$sEndDate.')</font><br/>'.$sDescription.'</p>';*/
}
}
}
}
}
currentstyle
25-09-09, 12:29
OK Luke, I've found the problems;
Firstly, in laptops direct and Lloydspharmacy there are codes, but they are missing the sUrl, so, the code would need to use the sClickThroughUrl property from the merchant details.
Secondly, if there is only one discount code (as Iwantoneofthose.com, Pet Supermarket, Dixons, sharp, VistaPrint, Focus DIY) then the code won't run a for each loop on one object, so, the code needs amending to take only one code into consideration. (which is the reason we see 'Vouchers for. ....' on the page, as the array isn't empty, but contains only one object)
The first problem is addressed in the following code:
$storesArray = array(1107,1599,2453);
$merchantcolumns = array(sStrapline,sDescription,sLogoUrl,sDisplayUrl ,sClickThroughUrl,oDiscountCode);
$multiplemerchantwithcodes = array('iMerchantId' => $storesArray, "sColumnToReturn" => $merchantcolumns, "iAdult" => 1);
$oResponse= $oClient->call('getMerchant', $multiplemerchantwithcodes);
//print_r($oResponse);
foreach($oResponse->oMerchant as $details){
$iId = $details->iId;
$iId = "AW".$iId;
$smsName =$details->sName;
$sStrapline = $details->sStrapline;
$sDescription = $details->sDescription;
$sLogoUrl = $details->sLogoUrl;
$sDisplayUrl = $details->sDisplayUrl;
$sClickThroughUrl = $details->sClickThroughUrl;
echo '<p><a href="#" title="'.$smsName.'">'.$smsName.'</a><br/>'.$sStrapline.'<br/><img src="'.$sLogoUrl.'" alt="'.$smsName.'" /><br/>'.$sDescription.'</p>';
$arraycheck1 = $details->oDiscountCode;
if(!empty($arraycheck1)){
echo '<p><h3>Vouchers for '.$smsName.'</h3>';
foreach($details->oDiscountCode as $key=>$details2){
$sCode = $details2->sCode;
$sDescription = $details2->sDescription;
$sUrl = $details2->sUrl;
if ($sUrl=='') $sUrl = $sClickThroughUrl;
$sEndDate = $details2->sEndDate;
$sEndDate = explode('-',$sEndDate);
$sEndDate = $sEndDate[2].'/'.$sEndDate[1].'/'.$sEndDate[0];
echo '<p><a href="'.$sUrl.'" title="'.$smsName.'"></a><br><b>Voucher Code: <a href="'.$sUrl.'">'.$sCode.'</a></b><br/> <font color="red">(Expires '.$sEndDate.')</font><br/>'.$sDescription.'</p>';
}
}
}
I'll have a look at the second problem later on.
currentstyle
25-09-09, 13:49
OK, the second problem (and the first) is resolved by checking whether or not the oDiscountCode object is actually an array of objects, or just one object.
Code:
$storesArray = array(1107,1599,2453,65,2354,282,1202);
$merchantcolumns = array(sStrapline,sDescription,sLogoUrl,sDisplayUrl ,sClickThroughUrl,oDiscountCode);
$multiplemerchantwithcodes = array('iMerchantId' => $storesArray, "sColumnToReturn" => $merchantcolumns, "iAdult" => 1);
$oResponse= $oClient->call('getMerchant', $multiplemerchantwithcodes);
//print_r($oResponse);
foreach($oResponse->oMerchant as $details){
$iId = $details->iId;
$iId = "AW".$iId;
$smsName =$details->sName;
$sStrapline = $details->sStrapline;
$sDescription = $details->sDescription;
$sLogoUrl = $details->sLogoUrl;
$sDisplayUrl = $details->sDisplayUrl;
$sClickThroughUrl = $details->sClickThroughUrl;
echo '<p><a href="#" title="'.$smsName.'">'.$smsName.'</a><br/>'.$sStrapline.'<br/><img src="'.$sLogoUrl.'" alt="'.$smsName.'" /><br/>'.$sDescription.'</p>';
$arraycheck1 = $details->oDiscountCode;
if(!empty($arraycheck1) and is_array($arraycheck1)){
echo '<p><h3>Vouchers for '.$smsName.'</h3>';
foreach($details->oDiscountCode as $key=>$details2){
$sCode = $details2->sCode;
$sDescription = $details2->sDescription;
$sUrl = $details2->sUrl;
if ($sUrl=='') $sUrl = $sClickThroughUrl;
$sEndDate = $details2->sEndDate;
$sEndDate = explode('-',$sEndDate);
$sEndDate = $sEndDate[2].'/'.$sEndDate[1].'/'.$sEndDate[0];
echo '<p><a href="'.$sUrl.'" title="'.$smsName.'"></a><br><b>Voucher Code: <a href="'.$sUrl.'">'.$sCode.'</a></b><br/> <font color="red">(Expires '.$sEndDate.')</font><br/>'.$sDescription.'</p>';
}
}
elseif(!empty($arraycheck1) and !is_array($arraycheck1))
{
echo '<p><h3>Vouchers for '.$smsName.'</h3>';
$sCode = $details->oDiscountCode->sCode;
$sDescription = $details->oDiscountCode->sDescription;
$sUrl = $details->oDiscountCode->sUrl;
if ($sUrl=='') $sUrl = $sClickThroughUrl;
$sEndDate = $details->oDiscountCode->sEndDate;
$sEndDate = explode('-',$sEndDate);
$sEndDate = $sEndDate[2].'/'.$sEndDate[1].'/'.$sEndDate[0];
echo '<p><a href="'.$sUrl.'" title="'.$smsName.'"></a><br><b>Voucher Code: <a href="'.$sUrl.'">'.$sCode.'</a></b><br/> <font color="red">(Expires '.$sEndDate.')</font><br/>'.$sDescription.'</p>';
}
echo '<hr/>';
}
Which results in this page
Easy New Shop Example Vouchers (http://www.easynewshop.com/11.php)
So, the codes were there, it was my methodology that was at fault :o , although, it would be nice to have the sUrl object populated for each discount code (Dixons, I can't access as I got rejected from them a while ago for some unspecified reason)
ljackson09
25-09-09, 14:57
WOW
got it working a treat :D
your a legend mate thank you!!!!
currentstyle
25-09-09, 15:45
And, thank you for pointing out the flaws, the updated code has gone straight onto my sites.
This is how it's supposed to work :D
ljackson09
25-09-09, 18:24
no worries mate
Luke
Thanks for this code which has been really helpful.
The code $sEndDate = $sEndDate[2].'/'.$sEndDate[1].'/'.$sEndDate[0]; now returns date with time that distorts the format of expiry date. Whats the workaround?
Reversing the order i.e $sEndDate = $sEndDate[0].'/'.$sEndDate[1].'/'.$sEndDate[2];works well but gives the date in the format yyyy-mm-dd which is somehow confusing as it is not in UK format.
ljackson09
27-07-11, 12:15
ok for some strange that exact same code has now stopped working!
not sure if it is a problem AW end or something that they have changed?
here is my code
$storeID = array(
9,65,157,172,282,323,380,427,483,547,550,686,782,8 54,896,911,980,1043,
1052,1084,1107,1109,1132,1134,1152,1184,1186,1198, 1202,1221,1228,
1252,1256,1257,1311,1322,1331,1344,1350,1402,1404, 1418,1472,
1487,1521,1559,1597,1598,1599,1672,1744,1815,1826, 1836,1916,1946,
1947,1964,1970,1971,1995,2026,2038,2041,2066,2117, 2124,2147,2203,2208,
2249,2258,2276,2339,2344,2354,2383,2400,2424,2433, 2453,2481,2526,
2537,2547,2548,2549,2605,2650,2690,2713,2731,2787, 2943,3146,3175,3278);
$oClient = ClientFactory::getClient();
$merchantcolumns = array(sStrapline,sDescription,sLogoUrl,sDisplayUrl ,sClickThroughUrl,oDiscountCode);
$multiplemerchantwithcodes = array("sColumnToReturn" => $merchantcolumns, "iAdult" => 1);
$oResponse= $oClient->call('getMerchant', $multiplemerchantwithcodes);
print_r($oResponse);
foreach($oResponse->oMerchant as $details)
{
$iId = $details->iId;
$iId2 = "AW".$iId;
$smsName =$details->sName;
$sStrapline = $details->sStrapline;
$sDescription = $details->sDescription;
$sLogoUrl = $details->sLogoUrl;
$sDisplayUrl = $details->sDisplayUrl;
$sClickThroughUrl = $details->sClickThroughUrl;
#for merchants with multi codes
if(in_array($iId, $storeID))
{
$arraycheck1 = $details->oDiscountCode;
if(!empty($arraycheck1) and is_array($arraycheck1))
{
echo '<p><h3>Vouchers for '.$smsName.'</h3>';
foreach($details->oDiscountCode as $key=>$details2)
{
$sCode = "";
$sCode = $details2->sCode;
$sDescription = addslashes($details2->sDescription);
$sDescription = str_replace("£","£",$sDescription);
$sUrl = $details2->sUrl;
$sEndDate = $details2->sEndDate;
echo "<p><a href='$sUrl'>".$sCode."<br />".$sDescription."</a><br /></p>";
if ($sUrl == '')
{
$sUrl = $sClickThroughUrl;
}
$insert_codes = "INSERT INTO
tbl_codes (code, codeLink, storeID, details, datestamp, expireDate)
VALUES ('$sCode', '$sUrl', '$iId2', '$sDescription', '$date', '$sEndDate')";
$sql = mysql_query($insert_codes)or die(mysql_error());
}
}
#for merchants with single codes
elseif(!empty($arraycheck1) and !is_array($arraycheck1))
{
echo '<p><h3>Vouchers for '.$smsName.'</h3>';
$sCode = $details->oDiscountCode->sCode;
$sDescription = $details->sDescription;
$sDescription = str_replace("£","£",$sDescription);
$sUrl = $details->oDiscountCode->sUrl;
$sEndDate = $details2->sEndDate;
echo "<p>".$sCode."<br />".$sDescription."<br /></p>";
if ($sUrl=='')
{
$sUrl = $sClickThroughUrl;
}
$insert_codes = "INSERT INTO
tbl_codes (code, codeLink, storeID, details, datestamp, expireDate)
VALUES ('$sCode', '$sUrl', '$iId2', '$sDescription', '$date', '$sEndDate')";
$sql = mysql_query($insert_codes)or die(mysql_error());
}
}
}
but its now not returning any codes but an error instead?
the error says SoapError Object ( [sCode] => HTTP [sString] => Error Fetching http headers [sDetails] => getMerchant: No error message available )
anyone else experiencing the same problem
thanks
Luke
Not sure if this is related, Luke, but my sites all fell over this morning and I'm finding this in the log file:
PHP Fatal error: SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://v3.core.com.productserve.com/ProductServeService.wsdl' : Start tag expected, '<' not found
in /home/xxx/public_html/xxx.co.uk/classes/class.soap_client.php on line 53
They were working yesterday and earlier today, and I haven't touched that file, so I'm not sure if something has happened at my (hosted) server end or at productserve.com...
Gez
Sorry - just realised you are referring to API, whereas I am using v3 Client...
Just to close out my reply, my own issue is now resolved - it was due to a power outage at AW's servers, so maybe this did impact on your problem Luke. If that was the culprit then it should be OK now...
Hello all,
Please see this a4u post (http://www.affiliates4u.com/forums/affiliate-window-buy/188494-affiliate-window-buy-data-centre-outage-2.html#post697465) for more information but there was a power outage.
Kind regards