Tanner Campbell Posted January 11, 2011 Share Posted January 11, 2011 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 worked5. Got a piece of heavy rope6. Got a kitchen table chair7. Installed a rafter8. 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? Link to comment Share on other sites More sharing options...
codegrunt Posted January 11, 2011 Share Posted January 11, 2011 How about a link to the demo site? Hard to say what's up in the template without seeing the rendered result.Cheers Link to comment Share on other sites More sharing options...
Tanner Campbell Posted January 11, 2011 Author Share Posted January 11, 2011 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/manageFeel 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.) Link to comment Share on other sites More sharing options...
codegrunt Posted January 11, 2011 Share Posted January 11, 2011 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 Link to comment Share on other sites More sharing options...
Tanner Campbell Posted January 11, 2011 Author Share Posted January 11, 2011 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. Link to comment Share on other sites More sharing options...
Tanner Campbell Posted January 11, 2011 Author Share Posted January 11, 2011 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 savedProduct -> 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=21000000000334613Quantum 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? Link to comment Share on other sites More sharing options...
codegrunt Posted January 11, 2011 Share Posted January 11, 2011 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 Link to comment Share on other sites More sharing options...
Tanner Campbell Posted January 12, 2011 Author Share Posted January 12, 2011 I'm gonna get on this now. I'll report back. Sorry for the delayed responses, I think we may be in drastically different time zones. Link to comment Share on other sites More sharing options...
Tanner Campbell Posted January 12, 2011 Author Share Posted January 12, 2011 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! Link to comment Share on other sites More sharing options...
Tanner Campbell Posted January 12, 2011 Author Share Posted January 12, 2011 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! Link to comment Share on other sites More sharing options...
codegrunt Posted January 12, 2011 Share Posted January 12, 2011 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 Link to comment Share on other sites More sharing options...
Tanner Campbell Posted January 12, 2011 Author Share Posted January 12, 2011 Ah, but what if I add the onlclick="{$product->location}" attribute to the forms submit function? Let's just see what happens Link to comment Share on other sites More sharing options...
Tanner Campbell Posted January 12, 2011 Author Share Posted January 12, 2011 Wow. CodeGrunt, check the site out and go to the only product on the site. See the Purchase button? Perfect. But press it and watch what happens. Weird. Thoughts? Link to comment Share on other sites More sharing options...
Tanner Campbell Posted January 12, 2011 Author Share Posted January 12, 2011 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". Link to comment Share on other sites More sharing options...
Tanner Campbell Posted January 12, 2011 Author Share Posted January 12, 2011 >. Link to comment Share on other sites More sharing options...
codegrunt Posted January 12, 2011 Share Posted January 12, 2011 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 Link to comment Share on other sites More sharing options...
Tanner Campbell Posted January 12, 2011 Author Share Posted January 12, 2011 I don't know what "pass to Smarty" means. Link to comment Share on other sites More sharing options...
codegrunt Posted January 12, 2011 Share Posted January 12, 2011 Google is your friend - "smarty htmlentities" gave me the following as the first hit:http://www.smarty.net/docsv2/en/language.modifier.escape.tplPrestashop uses Smarty for its template engine.Cheers Link to comment Share on other sites More sharing options...
Tanner Campbell Posted January 12, 2011 Author Share Posted January 12, 2011 Actually midway through it now. Google knows everything. Link to comment Share on other sites More sharing options...
Tanner Campbell Posted January 12, 2011 Author Share Posted January 12, 2011 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=21000000000334613is 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? Link to comment Share on other sites More sharing options...
Tanner Campbell Posted January 12, 2011 Author Share Posted January 12, 2011 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? Link to comment Share on other sites More sharing options...
Tanner Campbell Posted January 12, 2011 Author Share Posted January 12, 2011 It's midnight where I am CodeGrunt, I'm going to call it a night. Hope you're still with me in the morning. Thanks for all your help, I wouldn't have gotten this far without you. Link to comment Share on other sites More sharing options...
bnt76 Posted January 21, 2011 Share Posted January 21, 2011 Did you get anywhere with this? Link to comment Share on other sites More sharing options...
WDSY Posted January 31, 2011 Share Posted January 31, 2011 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 :-) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now