Jump to content

Linking to cart from external page


Recommended Posts

Hi all,

I've been integrating prestashop with an existing site. In fact we're only using the cart and payment bit of prestashop, the rest (products page, info etc) is all the existing site.

So far I've:

- Changed the look of the cart to match the site.
- Got 'add to cart' buttons on the products page to add and link to the cart.

The problem I'm having is when a user registers/logs in. Once you're logged in, if you then go back to the products page (or indeed any page other than the cart) and then try going back to your cart it comes up with an error message:

"there is 1 error: 01. invalid token"

It's fairly clear what that means but I don't know how to fix it. I've put links to all the js files in the header of the products page and have set these bits as follows:

var baseDir = 'http://www.chancham.com/shop/';
var static_token = '{$static_token}';
var token = '{$token}';
var priceDisplayPrecision = 2;
var roundMode = 2;

Any help greatly appreciated!! :-S
Ben

Ps. Link to the products page: http://www.chancham.com/2010/CC_thegoods3.shtml

Link to comment
Share on other sites

  • 1 month later...

Ok here it is.

Make a .php file in your prestashop folder called tokenGen.php and put this in it

<?php
include(dirname(__FILE__).'/config/config.inc.php');
include(dirname(__FILE__).'/init.php');
echo "var static_token = '".Tools::getToken(false)."';";
echo "var token = '".Tools::getToken()."';";
?>



then from the external page that you want the cart to appear on insert this above the other javascript files *in between some script tags*

<?php
include('/path/to/my/prestashop_install/tokenGen.php');
?>



I think that should work. Let me know.

Xavier

Link to comment
Share on other sites

Hey Xavier,

Thanks so much for that info and your time!

I hadn't checked back on the forum for a while, so I'll go and try this out now and let you know what happens... :)

Thanks again!
Ben

Link to comment
Share on other sites

Hmm.. well, I can't seem to get that working.

I'm wondering if the problem I'm having is the same as the solution you gave? To explain the problem better this is the sequence of events when using the site:

1. I'm on the products page and I click on 'add to cart'.

2. That takes me to the cart page where it lists the product/s I've chosen.

3. If I now click 'continue shopping' it takes me back to the products page.

4. If I then select another product by clicking another 'add to cart' button I go back to the cart page and the new product has been added to the list. So far so good!

5. I then click on 'continue'.

6. I login.

7. I'm now on the address page.

Now, from this point on, if I think "oh, actually I'd like to add something else to my cart before I finish and pay" and click the 'continue shopping' button at the top of the page I go back to the products page. Still so far so good.

BUT if I now click on another 'add to cart' button it takes me to the cart and only displays the error "01.invalid token". To get round this as a user I have to 'sign out' and start all over again, which isn't exactly user-friendly!

:long:

Is that the problem as you understood it first time round? If it is then I must be doing something wrong... :roll:

Any further ideas/help greatly received!!
Ben

Link to comment
Share on other sites

Hi Ben,

I just ammended the code above to include semi-colons at the end of the lines which might help :)
That way you'll actually have some variables to work with.

Are you using the ajax functionality of the cart? Just wondering because it doesn't look that way at the moment.

Have a look at the links on your product page and see if the "&token=123456789" is in the query string. If it's not, you need to append "&token;=" to the href of the "Add to Cart" and then append the *static_token* variable to the end of it.

See if that works for you.

Other option is that you comment out the 'alert' calls in the javascript. Up to you with this one, but you won't be getting any feedback if there are errors with the cart.

Xav

Link to comment
Share on other sites

Hi Xav,

If my current href for the 'add to cart' buttons is:
action="http://www.chancham.com/shop/cart.php"
how would I add the code you gave?

Like this?:
action="&token;=http://www.chancham.com/shop/cart.php&static;_token"
(I know that's not right but it's my best shot!).

Pretty certain I'm not using the ajax functionality currently. Wanted to keep things as simple as possible. So, users can only view their cart from the products page by clicking an 'add to cart' or 'view cart' button (that I haven't put on yet). I don't need the cart to be viewable from anywhere else in the site or anything saying how many things are in the cart etc.

Yeh, not keen on editing out the alerts - as you say, I won't know of any problems.

Thanks again,
Ben

Link to comment
Share on other sites

Ok I've taken a look and I know how you can do it, but there's some issues with what you're trying to do.

include this *between two script tags* at the top of your page, below the jquery and below the other script tags that you created before;

$(document).ready(function () {

$("input[name=token]").each(function() {
$(this).attr('value', static_token);
});

});



That's how you'd do that bit, but you haven't got the first bit right yet unfortunately. Your server isn't processing the php tags because your page ends ".shtml" - you need to open ".htaccess" in your public_html folder and add the following (if it doesn't show up, check that your ftp program is showing hidden files and if it's definitely not there, go ahead and create it);

AddHandler application/x-httpd-php .shtml



Then your server will grab the code properly. At least that's the theory.

I have to say though, the way your going about the integration is a bit funny if I'm honest - understand that you've got to stick with what you know etc. but you're gonna have a hard time getting rid of all the links back to the prestashop product pages. See if the above works for you anyway, and if you decide you need help with the integration on a professional basis, give me a PM ;)

Xav

Link to comment
Share on other sites

Xav,

Yep, you're right, I know I'm doing things in an odd way - it just kinda grew like that! I figure you only ever learn stuff when you get out of your depth...
:gulp:

Anyway, I've been messing around with all your code and helpful suggestions....... aaannnd got nowhere! Hahaha! Html, css, javascript, actionscript - I can do all those, but php stuff is a bit over my head. The way I see it I have 4 options:

1. Keep going as I am and get there eventually (or not).

2. Ask someone like you for a quote to do it for me. Do you do that kinda thing?

3. Rebuild the site actually IN prestashop so there are no integration problems. However, to get it looking the way I want could take a fair amount of time in itself.

4. Look for some other way of doing it!

So the big question is which direction to go in?? Would value your opinion. The site as it stands is quite small and simple but I like to have tight control over the way it looks. Time for a bit more research I think...

Ben

Link to comment
Share on other sites

  • 5 months later...

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
×
×
  • Create New...