PDA

View Full Version : Single Merchant with voucher codes


currentstyle
22-08-09, 12:53
This one will show you a single merchant with up to 8 vouchers that exist for that merchant (adjust the number by changing 7 in this line ($sUrl<>'' and $key<7) to however many you want to show, or delete the and $key<7 to show all.

The merchant ID is found here in this line:
$singlemerchantwithcodes = array('iMerchantId' => array(429), "sColumnToReturn" => $merchantcolumns);

Excuse my css styling, it's become a habit :D

define('API', 'PS');
require_once('constants.inc.php');
require_once('classes/class.ClientFactory.php');
$oClient = ClientFactory::getClient();
$merchantcolumns = array(sStrapline,sDescription,sLogoUrl,sDisplayUrl ,sClickThroughUrl,oDiscountCode);
$singlemerchantwithcodes = array('iMerchantId' => array(429), "sColumnToReturn" => $merchantcolumns);
$oResponse= $oClient->call('getMerchant', $singlemerchantwithcodes);

$iId = $oResponse->oMerchant->iId;
$sName =$oResponse->oMerchant->sName;
$sStrapline = $oResponse->oMerchant->sStrapline;
$sDescription = $oResponse->oMerchant->sDescription;
$sLogoUrl = $oResponse->oMerchant->sLogoUrl;
$sDisplayUrl = $oResponse->oMerchant->sDisplayUrl;
$sClickThroughUrl = $oResponse->oMerchant->sClickThroughUrl;
echo '<a href="'.$sClickThroughUrl.'" title="'.$sName.'">'.$sName.'</a><br/>'.$sStrapline.'<br/><img src="'.$sLogoUrl.'" alt="'.$sName.'" /><br/>'.$sDescription.'';
$arraycheck1 = $oResponse->oMerchant->oDiscountCode;
if(!empty($arraycheck1)){
echo '<div style="margin: 5px 0; background: #D5D5D5; line-height: 0; height: 1px;"></div><h3>Vouchers for '.$sName.'</h3>';
foreach($oResponse->oMerchant->oDiscountCode as $key=>$details2){
$sCode = $details2->sCode;
$sDescription = $details2->sDescription;
$sUrl = $details2->sUrl;
$sEndDate = $details2->sEndDate;
if ($sUrl<>'' and $key<7) {
echo '<div style="margin: 5px 0; background: #D5D5D5; line-height: 0; height: 1px;"></div><a href="'.$sUrl.'" title="'.$sName.'"><img src="'.$sLogoUrl.'" alt="'.$sName.'" border="0"/></a><br><b>Voucher Code: <a href="'.$sUrl.'">'.$sCode.'</a></b><br/> <font color="red">(Expires '.$sEndDate.')</font><br/>'.$sDescription.'';
}
}
}

GeorgeGaz
24-08-09, 10:03
Hello currentstyle,

Once again you have posted content that the community is going to find useful and will be a valuable resource.

Thank you

Amoochi
24-08-09, 14:21
Thank you very much for sharing this. It is the sort of thing that had been requested by a couple of people, including myself, who had said it should be a default thing, but nobody had wanted to share, so again, thank you very much for being prepared to share your work like this.

infocraze
25-08-09, 12:08
Is this for V3 users or is it applicable to v2 as well?

GeorgeGaz
25-08-09, 12:21
Hi info,

Voucher codes are only available via the v3 software.

Cheers

sspyrou
03-09-09, 01:47
really appreciate that.. will try to integrate tomorrow...
Thanks.. you're a star.
s

infocraze
07-09-09, 10:19
Has anyone tried implementing this code? Is this meant for the api or applicable to client software as well? I have created a php file within my client software with the code given but all it returns is junk codes. Please advise.

currentstyle
07-09-09, 10:45
I've posted this code in the ShopWindow API v3 forum because, as far as I know, it's only applicable to the API

apwade
10-09-09, 00:34
Why share it when you would have an edge over your competitors? The problem with using the internal discount codes you can never apply them to the actual price of the product (easily).

By the end of the week i should have customised my shopwindow to apply the discount code to the price!

currentstyle
10-09-09, 12:01
Why share it when you would have an edge over your competitors?Call me old-fashioned if you like, but, I possess an Old Labour sense of community and collaboration rather than a New Labour (Conservative) one of competition, I'd rather work with people than against them, remember, in the voucher code arena, there are one or two firms that take most of the available money, I prefer to see a more level playing field, and am doing everything in my coding power to achieve this.

Good luck trying to marry up voucher codes for specific items to the price of that item, let us know how you did it when its done will you?

apwade
11-09-09, 00:55
Originally Posted by apwade View Post
Why share it when you would have an edge over your competitors?

In its basic form my shopwindow applies the discount codes, i need to add further code to cope with delivery and specific discounts for specific items.

try www.discounthypermarket.com/compare_prices/

Obviously i am testing my site and changing its appearance, say try searching for "iphone" and you will see the discount applied to the price.

Regards,

Andrew

currentstyle
11-09-09, 10:54
I really like it, I would put the offer details closer to the 'Best Price' bit and make it more 'zingy', but, I guess when you're no longer doubling up the products in testing, then it will be closer anyway, nice work. :D

Just had a thought. Do you have to handcode and create variables for each voucher/offer?

I ask because I can't concieve of an automagic way to do it.

If the answer is yes, then it might be worthwile just leaving it to the consumer to work out the deal?

ljackson09
20-09-09, 23:41
Hi currentstyle,

thanks for sharing this code, have found it very helpful :)

i have one question which i have tried to answer but havent found the correct formula :(

how do i set it to find the discount codes from an array of stores instead of just the one?

here is what i tried:

$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);
$singlemerchantwithcodes = array('iMerchantId' => $stores, "sColumnToReturn" => $merchantcolumns);
$oResponse= $oClient->call('getMerchant', $singlemerchantwithcodes);

$iId = $oResponse->oMerchant->iId;
$sName =$oResponse->oMerchant->sName;
$sStrapline = $oResponse->oMerchant->sStrapline;
$sDescription = $oResponse->oMerchant->sDescription;
$sLogoUrl = $oResponse->oMerchant->sLogoUrl;
$sDisplayUrl = $oResponse->oMerchant->sDisplayUrl;
$sClickThroughUrl = $oResponse->oMerchant->sClickThroughUrl;
echo '<a href="'.$sClickThroughUrl.'" title="'.$sName.'">'.$sName.'</a><br/>'.$sStrapline.'<br/><img src="'.$sLogoUrl.'" alt="'.$sName.'" /><br/>'.$sDescription.'';
$arraycheck1 = $oResponse->oMerchant->oDiscountCode;
if(!empty($arraycheck1))
{
echo '<div style="margin: 5px 0; background: #D5D5D5; line-height: 0; height: 1px;"></div>
<h3>Vouchers for '.$sName.'</h3>';
foreach($oResponse->oMerchant->oDiscountCode as $key=>$details2)
{
$sCode = $details2->sCode;
$sDescription = $details2->sDescription;
$sUrl = $details2->sUrl;
$sEndDate = $details2->sEndDate;

if ($sUrl<>'')
{
echo '<div style="margin: 5px 0; background: #D5D5D5; line-height: 0;
height: 1px;"></div><a href="'.$sUrl.'" title="'.$sName.'"><img src="'
.$sLogoUrl.'" alt="'.$sName.'" border="0"/></a><br><b>Voucher Code:
<a href="'.$sUrl.'">'.$sCode.'</a></b><br/> <font color="red">(Expires '
.$sEndDate.')</font><br/>'.$sDescription.'';
}
}
}


but im not getting anything display on my page, i can get your example to work fine (prob because you know what your doing and i dont :D).

im trying to pull out all the discount codes from the array of storeIDs?

is this possible
thanks mate

Luke

currentstyle
21-09-09, 02:13
Hi Luke, this code should do the trick (and put the expiry date into a GB readable format)


<?php
require_once('constants.inc.php');
require_once('classes/class.ClientFactory.php');
$oClient = ClientFactory::getClient();
$merchantcolumns = array(sStrapline,sDescription,sLogoUrl,sDisplayUrl ,sClickThroughUrl,oDiscountCode);
$multiplemerchantwithcodes = array('iMerchantId' => array(429,15,782,1418), "sColumnToReturn" => $merchantcolumns, "iAdult" => 1);
$oResponse= $oClient->call('getMerchant', $multiplemerchantwithcodes);

foreach($oResponse->oMerchant as $details){
$iId = $details->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 '<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<>'' and $key<7) {
echo '</div><a href="'.$sUrl.'" title="'.$smsName.'"><img src="'.$sLogoUrl.'" alt="'.$smsName.'"/></a><br><b>Voucher Code: <a href="'.$sUrl.'">'.$sCode.'</a></b><br/> <font color="red">(Expires '.$sEndDate.')</font><br/>'.$sDescription.'';
}
}
}
}
?>


I think it'll fall over if you try too many merchant IDs, I haven't tried any more than the four that are there, but they all work.

Let me know how you get on?

Tony

(I've just tried it with another 10 or so IDs added and it seemed OK)

ljackson09
21-09-09, 15:07
Hi Tony,

thank you very much for this, ive tried it for 50 plus stores and althought not all stores are listed i think all the stores with discount codes are :)

really appreciate this mate
thanks

Luke

currentstyle
21-09-09, 19:13
Its odd that not all the stores are listed Luke, as thats the first bit of the code, I'll have another look at it later tonight.

ljackson09
21-09-09, 20:08
ok mate here is the code i have used, slightly modified to allow the store array

$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<>'') {
$insert_codes = "INSERT INTO
codes (codeID, codeLink, storeID, details, expireDate)
VALUES ('$sCode', '$sUrl', '$iId', '$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>';*/
}
}
}
}?>


and the stores it prints out are
Vouchers for 1staudiovisual
Vouchers for Appliances Direct
Vouchers for Bennetts Electrical
Vouchers for CD WOW!
Vouchers for Currys
Vouchers for directtvs
Vouchers for Focus DIY
Vouchers for Iwantoneofthose.com
Vouchers for Laptops Direct
Vouchers for Lloydspharmacy
Vouchers for Mesh Computers
Vouchers for NikeStore
Vouchers for Pet Supermarket
Vouchers for Pharmacy2U
Vouchers for Pixmania
Vouchers for Play.com
Vouchers for Sharp
Vouchers for Vodafone Ltd

but thats it.

even with your earlier example of 4 stores i only got 3 print out?

but i think all the discount codes are there :)


thanks mate
Luke

currentstyle
21-09-09, 21:05
I see now as you're only inserting codes into a table, and it will only pick up merchants who have codes. So, it's inserting all the existing codes into your table correctly?

ljackson09
21-09-09, 23:03
yes mate as far as i know :)

but as far as im aware this line
echo '<p><h3>Vouchers for '.$smsName.'</h3>';

should only print the store name if there are any discount codes? its currently printing the list i posted earlier with most of those stores having no codes, maybe in the api it still says they did have codes before but have none currently if you see what i mean?

im still getting good results :), i will check the discount codes on my account to see if its picking them all up.

thanks
Luke

ljackson09
22-09-09, 00:27
Hi Tony,

I have checked the discount codes with the ones in my affiliate area and there are some codes which are not appearing :(

is it that they are not in the api?

here are a few
65 Pharmacy2U AW587Q
1107 Laptops Direct FREEDELNB
1107 Laptops Direct FREEDEL
1322 Pet Supermarket promosep2

amoungst others :(

any ideas mate

thanks
Luke

currentstyle
22-09-09, 02:00
but as far as im aware this line
echo '<p><h3>Vouchers for '.$smsName.'</h3>';

should only print the store name if there are any discount codes?

You're right, it should, perhaps there needs to be a better check than

$arraycheck1 = $details->oDiscountCode;
if(!empty($arraycheck1)){
echo '<p><h3>Vouchers for '.$smsName.'</h3>';

I would have thought that if the oDiscountCode object was empty, then the 'Vouchers for' etc. shouldn't be displayed, but maybe theres some rogue data getting into the oDiscountCode object, I can't answer that one.

Again, if there are codes which should appear and aren't, then I don't know what's happening there.

Tony

ljackson09
22-09-09, 02:05
me neither mate?

will just have to enter those few in automatically for the time being :)

thanks again for all your time and assistance, really appreciate it, if you do find a solution as to why some are not appearing in the api please let me know :)

cheers mate
Luke

vhound
17-12-09, 16:40
currentstyle, this code is great but...now you knew there would be a but didn't you..is there a way to get the merchant id automatically? At the moment, using your code you have to assign the $singlemerchantwithcodes value manually. Is there a way of getting this value from the $oProduct->iMerchantId variable, which is present in the product_display.tpl file? Then the code could get the relevant vouchers for that merchant.

I've tried all ways of getting this done but am new to smarty. I figured in anyone knew how you may.

currentstyle
24-12-09, 11:34
Hi vhound, unfortunately, I have no time to play with smarty, nor the will to do so either, whatever I post is relevant to the API not the Client software.

vhound
04-01-10, 14:27
I got my vouchers to display but have noticed that if the result is just voucher to show then it doesn't. If there are more than 1 voucher then they will display as expected. I have tried changing this line from this:

if ($sUrl<>'' and $key<7) {

to this:

if ($sUrl<>'') {

but makes no difference. I read that there was a problem with some not displaying and was wondering if you managed to fix this.

DDF
14-03-11, 14:05
I am embarrased to even ask this LOL

Where exactly does this code go please :confused:

Claire x