Judah Raine
Total posts: 332
01 Dec 2012 05:56

Hi there - been off sick so now furiously playing catchup...

I'm using the following code to output a link from form input with an image

value; $options = $this->params->get('params.open_url', 1) ? ' target="_blank"' : ''; echo JHtml:: link('http://' . $value[0]['url'], "

It's working well, but now I want to automatically add the affiliate code in the output, i.e. let's say the user inputs the link to their book on Amazon into the form. I need our affiliate code, in this case

/romautjudrai-20

to be added to the link so that when someone clicks on the image in the article display it will open the affiliate link to amazon.

I hope I've explained this properly. I would really appreciate your help.

Thank you

Last Modified: 02 Mar 2014


Sergey
Total posts: 13,748
01 Dec 2012 23:17

ANd where is the affiliate application is hosted? On amazon? What is the syntax of affiliate link?


Judah Raine
Total posts: 332
01 Dec 2012 23:38

I have two, the first is Smashwords and the link would display as:

https://www.smashwords.com/books/view/46046?ref=judahraine - the affiliate code is ?ref=judahraine

The second is Amazon, and there are two types of links

The simple link is:

http://www.amazon.com/gp/product/1606013483/romautjudrai-20 with /romautjudrai-20 as the affiliate part

The second is more complicated and I think unnecessary but you may know better:

http://www.amazon.com/gp/product/1606013483?ie=UTF8& ;camp=1789&creativeASIN=1606013483&linkCode=xm2&tag=romautjudrai-20 in this instance the &linkCode=xm2&tag=romautjudrai-20 indicates the affiliate code.

Many thanks


Sergey
Total posts: 13,748
01 Dec 2012 23:48

Ok. You enter links of amazon products or other people?


Judah Raine
Total posts: 332
01 Dec 2012 23:51

I need my authors to be able to enter the url to the book when adding their book to the bookstore. I would like to then automatically add the affiliate code to the link they have entered if this is possible (otherwise I'm creating 600 x 3 odd links!! Which will take me months :D)


Sergey
Total posts: 13,748
01 Dec 2012 23:57

What is format of already inserted links? Why not to insert links already with affiliate?


Judah Raine
Total posts: 332
02 Dec 2012 00:09

The difficulty is that I'm dealing with authors, many of whom are even less computer savvy than I. Most can copy the link to their book and paste it into the form field without problems, but I cannot rely on them to add the correct affiliate code. I am the affiliate, not them, so it needs to be my site code added. If I'm going to have to physically check each link, then I might as well insert them myself which is what I am trying to avoid. :D


Sergey
Total posts: 13,748
02 Dec 2012 00:34

Give example of link they copy and paste?


pepperstreet VIP
Total posts: 3,837
02 Dec 2012 06:39

In general, that might be a cool option for an input-field template or article template. Let the admin choose and enter his different affiliate codes/patterns... Hide this info from normal users. Users just see their standard input... and links are auto-magically modified and stored.


Judah Raine
Total posts: 332
02 Dec 2012 06:51

Lol, so my dumb questions may have potential after all....:D


Judah Raine
Total posts: 332
03 Dec 2012 22:49

I had a thought, and will try it out later... would it not work to combine 2 fields? One field would be visible to my authors who would then input the link to their book on Amazon. The second field could, eg. be visible only to super user, but with a default value entered. On article display this would then possibly be echo field [1] & field [2] or something along those lines??

Sounds logical to me, but then I'm not the guru here :D


Sergey
Total posts: 13,748
04 Dec 2012 07:40

On the other hand if amason affiliate is just to add /romautjudrai-20 you can in template jsut add it to every url automatically.

Someone entered

http://www.amazon.com/Thick-Black-Line-BookStrand-Publishing/dp/1606013483

and you render

http://www.amazon.com/Thick-Black-Line-BookStrand-Publishing/dp/1606013483/romautjudrai-20


Judah Raine
Total posts: 332
04 Dec 2012 07:56

Which would really be the easiest. However, no matter what I tried I couldn't get it to create the full url :D

(yes, my ignorance again) I was trying field[]&"romautjudrai-20" but it ended up as my actual site url with some weird addition that went nowhere at all


Sergey
Total posts: 13,748
04 Dec 2012 09:11

As you mentioned earlier it have to be

&tag=romautjudrai-20

rather than

field[]&"romautjudrai-20"


Judah Raine
Total posts: 332
04 Dec 2012 09:54

Ah... tag.... thank you :D I promise, as soon as this is running smoothly and I have more time I am going to do that php study in full... Just a thought, do you know of any web-based courses that are worthwhile?


Sergey
Total posts: 13,748
04 Dec 2012 20:28

linda, tutplus


Judah Raine
Total posts: 332
04 Dec 2012 22:12

wonderful, thank you!


Judah Raine
Total posts: 332
04 Dec 2012 23:11

I've added this as follows:

echo JHtml:: link('http://' . $value[0]['url']&tag=romautjudrai-20, "<img src='".JURI::root()."images/bookstore/buyamazon.jpg'", $options ) ;

but get the following error:

Parse error: syntax error, unexpected '=' in /home/classicr/public_html/components/com_cobalt/fields/url/tmpl/output/bookstore amazon.php on line 19

Obviously it's reading the = between tag and romaut but no matter what I try using '' or[] or a combination of both I either get errors or an invalid url. The actual url itself works fine, I have tested that, it's just when I add the affiliate code that things go astray.


Sergey
Total posts: 13,748
05 Dec 2012 22:48

$value[0]['url']&tag=romautjudrai-20

have to be

$value[0]['url'].'&tag=romautjudrai-20'


Judah Raine
Total posts: 332
05 Dec 2012 23:05

Thank you so much - I did discover the the &tag should be ?tag if the amazon link does not contain a ? but aside from that it's working perfectly.

I just have one last question... I have three link options, Amazon, Barnes and Noble and Smashwords. How would I go about displaying these only if they contain information? In other words, my books are not on Smashwords, so I do not want the Smashwords button to display as it will have no link.

Powered by Cobalt