Jump to content

Affiliates & PrestaShop - Add to cart button link


Tanner Campbell
 Share

Recommended Posts

I'm a guy that likes to do stuff on his own, really give it his all before he asks for help. Well, I'm here, so that means I've already just about thrown my computer through my wall in a brain hemorrhaging furious rage with this problem. There is little about this on the Forum and almost all of it is open ended. Let's SOLVE THIS NOW! :)

I had the brilliant idea to import 1,000's of products from my Google Affiliate Network account, plop them into a shopping cart (PrestaShop was the winner after I almost murdered myself trying to work with ZenCart) and have the add to cart button send people to the affiliates site for purchase. Simple idea right? Wrong.

I've done everything I can think of, and in this order:

1. Re-assigned the form function of add to cart in product.tpl

form id="buy_block" action="{$product->location}" method="get" 



2. Edited the AdminImport.php file accordingly

case $this->entities[$this->l('Products')]:

               self::$validators['image'] = array('AdminImport', 'split');

               $this->available_fields = array(
               'no' => $this->l('Ignore this column'),
               'id' => $this->l('ID'),
               'location' => $this->l('Location'),
               'active' => $this->l('Active (0/1)'),



and

self::setDefaultValues($info);
           $product = new Product(intval($info['id_product']), false, $defaultLanguage);
           $id_product_attribute = $product->addProductAttribute(floatval($info['price']), floatval($info['weight']), floatval($info['ecotax']), intval($info['quantity']), null, strval($info['reference']), strval($info['location']), strval($info['supplier_reference']), strval($info['ean13']), intval($info['default_on']));



3. Extended the database product table for location from a 64 character limit to a 999 character limit (affiliate links tend to be lenghty).

4. Nothing worked

5. Got a piece of heavy rope

6. Got a kitchen table chair

7. Installed a rafter

8. Tried to hang myself.

Let's make this work guys! Let's use me as the test dummy. If we can figure it out I'll spend as much time as I can putting together a comprehensive how-to guide for future developers who want to do this same thing. I need some help here, and I need it presented succinctly. I am willing to wipe my database and start from scratch and I am willing to grant access to my site to PrestaShop moderators.

How do I make the ADD TO CART button execute a link provided in the "location" field of a CSV upload?

Share this post


Link to post
Share on other sites

CodeGrunt,

Oooof. You're right. The store is at http://booksandclothes.com (ignore the look, I'm not styling this thing until I have this figured out) and you can login to it here:

http://booksandclothes.com/manage

Feel free to dig around, the store is complete empty as are my banking details; there's nothing personal in there so have at it.

Also, thanks for the reply! I'm getting on this as early as I can, 8am 730am gmt-5 hope it's a little later where you are!


-Tanner


(also if you need file access, let me know, I will set up an public_ftp account for you.)

Share this post


Link to post
Share on other sites

It looks like you missed changing the class file for products so that the validation step can get past 64 characters.


"# Quantum Mechanics: Concepts and Applications cannot be saved
# Product -> location length > 64


line 157 classes/Product.php:

protected $fieldsSize = array('reference' => 32, 'supplier_reference' => 32, 'location' => 64, 'ean13' => 13);

Cheers

Share this post


Link to post
Share on other sites

Shit. I just posted a response and it didn't post. I will try the editing of the Product.php file, you're correct I did not make that change. I thought the only reference to field length was in the DB. My mistake. As for your other comments in the PM, I did. If you need the new one, let me know I will send them.

What time zone are you in? I will try this solution and let you know.

Share this post


Link to post
Share on other sites

Did it. While I'm sure it was necessary, it did not solve the issue. I get this error upon upload.

Quantum Measurement cannot be saved
Product -> location = http://gan.doubleclick.net/gan_click?lid=41000000012871747&pid=9780521484138&adurl=http://search.barnesandnoble.com/Quantum-Measurement/Vladimir-B-Braginsky/e/9780521484138&usg=AFHzDLu6M1zj_ZBGtfZu1d-c3Ys3Y-EedA&pubid=21000000000334613

Quantum Measurement is listed at Name and that link is the location field, an affiliate link.

This has to be easier, are we missing something? Have I overlooked a crucial document that needs editing?

The Product.php file knows that the add to cart form now fetches location, and we've gotten to a point where we can choose location in the drop down menus during the importation ... we're missing SOMETHING. I would think ... that it should work right now.

What could I have overlooked? Agh. puzzletime.

also my separator is a comma. Does that make a difference?

Perhaps I should wipe the data base and start with a fresh install? What do you think?

Share this post


Link to post
Share on other sites

Well, the example string is 235 characters so length is not the issue. Have you checked that the location field does not have other limits on the content? Looking at the class declaration I see this:

protected $fieldsValidate = array(
[...]
'location' => 'isReference',
[...]

So location has to look like isReference for it to be allowed. What an isreference looks like is defined in "classes/Validate.php":

static public function isReference($reference)
   {
       return preg_match('/^[^<>;={}]*$/ui', $reference);
   }



So your "location" cannot have equals signs unless you change how it is validated. You could try removing the location entry from $fieldsValidate in the product class or change the validation to "isUrl".

I am not sure what location is normally used for so cannot say whether this has any ramifications elsewhere. Try a find + grep on the codebase to see where location gets used maybe just in case:

find  . -type f -name \*.php -exec grep -H 'location' {} \;



Cheers

Share this post


Link to post
Share on other sites

Okay. Success. We're not done, but we're on the right path I think! :cheese:

I ended up opting for the 'isUrl' fix, seemed to be the one that worked the best. But the Add To Cart button is still adding the item to the cart. Doesn't seem to be 'getting' the link. Thoughts?

I'm going to mess around a bit more. Login is the same, have a look around if you've got the time. Again: I really appreciate your help, I feel like this project is a "white whale". Would be so awesome if we figured it out!

Share this post


Link to post
Share on other sites

What about this the entire form in product.tpl??? It's a lot longer than I realized I've made this change:

<form id="buy_block" action="{$product->location}" method="get">



Just noticed that the first few fields don't end the form, in fact it goes on for quite a while. Until I found the submit function:

<input type="submit" name="Submit" value="{l s='Add to cart'}" class="exclusive" />



I'm going to replace it with

<input type="submit" name="Submit" value="{$product->location}" class="exclusive" />



and see what happens.

Fingers crossed! :snake:

--EDIT--

What am I? Fucking retarded? Haha, changing the button value isn't going to do anything. The secret is here, I WILL FIND IT! Brain-farts or not!

Share this post


Link to post
Share on other sites

You are trying to replace the add to cart function here. That logic happens in a number of templates so you will need to track down each one and change the form from one that adds to the cart (and has Javascript hooks as well) to one that just sends the user to the referral link.

This seems to work on the product detail page (though I am not turning on Javascript to test further) but has not been changed on the featured item template for example. You may also be running into JQuery events added to the form object or add to basket submit button. The easiest way to get rid of those is likely to just replace the form with one that only contains what you want and has unique CSS ids.

This is not tested (I do not have the original template in front of me) but something similar should work:

<form id="my_form_id" action="{$product->location}" method="get">
<input type="button" value="Purchase">
</form>



I forget the smarty command but you should run htmlentities() on location value if it is not already happening as well.

Cheers

Share this post


Link to post
Share on other sites

Looks as if the cart automatically appends values to the end of the link. Let's see if I can find where this is happening :-/

--EDIT--

Found it ... was able to eliminate the appended values, but the URL is still malformed to: http://gan.doubleclick.net/gan_click?

Something is truncating this link ... *sigh*

When I was younger, we called this "going on a fucking mission".

Share this post


Link to post
Share on other sites

That's not a valid onclick value, should be something like:

onclick="document.location='{$product->location}';"



You also need to run htmlentities on the location value (which means looking up the argument to pass to Smarty, I forget the format off the top of my head).

Cheers

Share this post


Link to post
Share on other sites

Okay, so let me be sure I understand this. The escape value is used to "escape" certain special characters into their appropriate forms. Like a copyright symbol is © and a space is . I understand this vaguely, but I'll try to soak it up.

So my link:

http://gan.doubleclick.net/gan_click?lid=41000000012871747&pid=9780521484138&adurl=http://search.barnesandnoble.com/Quantum-Measurement/Vladimir-B-Braginsky/e/9780521484138&usg=AFHzDLu6M1zj_ZBGtfZu1d-c3Ys3Y-EedA&pubid=21000000000334613'>http://gan.doubleclick.net/gan_click?lid=41000000012871747&pid=9780521484138&adurl=http://search.barnesandnoble.com/Quantum-Measurement/Vladimir-B-Braginsky/e/9780521484138&usg=AFHzDLu6M1zj_ZBGtfZu1d-c3Ys3Y-EedA&pubid=21000000000334613

is being "escaped" to this:

http://gan.doubleclick.net/gan_click?

...and escaping is causing everything beyond the "?" to be removed?

Okay...I'm not sure I really understand why, but I can live with that. You said something earlier about "PASSING TO SMARTY" ... I'm sorry to seem like such a dunce, but what do you mean by that?

Share this post


Link to post
Share on other sites

Oh wait ... my link isn't being escaped and I need to escape it. I see. Otherwise everything will be dropped off the end of the link. Okay so somewhere in this:

<form action="{$product->location}" method="get">

I have to do something like this:

<form action="urlencode({$product->location})" method="get">

Yes?

Share this post


Link to post
Share on other sites

  • 2 weeks later...
  • 2 weeks later...

Seriously why bother?
You want to feed a datafeed into PS and dump quite a few products?
Can you imagine the url structure when you have dumped 9000 products..
www.yoursite.com/9000-product-name
After you have spent a number of nights pulling your hair out and throwing your computer around...
You could just use Wordpress and a CSV importer, dumped 9000+ products in 5 mins and have nice urls and spend the time doing SEO instead.

Just my opinion :-)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More