Your account is limited to posting only in the Pre-Sales Questions forum.
Support forum access is limited to members with a purchase history.

If you are working on behalf of another member, please contact us with the name of the license holder and we will upgrade your account.
   
 
Update shipping details - via ajax
Posted: 30 April 2011 09:13 AM   [ Ignore ]
Has a Great Personality
Rank
Total Posts:  50
Joined  2010-08-17

Hey guys,

Okay… here’s what I’m trying to do… on the ‘checkout form’ page I show the checkout form (including billing/shipping addresses), AND I show the ‘cart’ details (which includes shipping prices).

So… if a user changes their country (using a select dropdown) on the checkout form, I would like to update the ‘cart’ details using AJAX.  Now, doing the actual update via jquery/ajax is easy (I’m just using a separate template with the cart details listed, then simply call this via AJAX when the country select is ‘changed’).

The issue is updating the customer country code via AJAX.  I’ve created a little custom function in a Plugin which simply uses “set_customer_info()” to update the country code (the following is inside my plugin):

function set_customer_data()
    
{
        $key 
= ($this->EE->TMPL->fetch_param('key') == '') ? '' $this->EE->TMPL->fetch_param('key');    
        
$value = ($this->EE->TMPL->fetch_param('value') == '') ? '' $this->EE->TMPL->fetch_param('value');    
        
        
$this->EE->cartthrob->cart->set_customer_info($key,$value);
    

This is then called at the top of my ‘cart’ details template, parsing in key=“country_code” and value=”{segment_3}”.

The issue is that this isn’t actually updating the shipping costs.  Clearly I’m missing something after the “set_customer_info()” function being called that then takes this information and ‘ripples’ it through to all other data.

I’ve tried setting the the $key and $value to a $_POST, then running “$this->EE->cartthrob->save_customer_info();” but it comes up with the error “Unable to load the requested class: locales”.

*sigh*

What would probably be the best is to be able to run the CT “save_customer_info_form” tag without actually having to submit it… similar to “add_to_cart” vs “add_to_cart_form”.

Any help would be appreciated.

Thanks.

grin

Profile
 
 
Posted: 01 May 2011 05:16 AM   [ Ignore ]   [ # 1 ]
Administrator
Avatar
RankRankRankRankRank
Total Posts:  10369
Joined  2008-09-29

1. If you want, try save_customer_info tag. I believe it’s undocumented, but there.

OR.

2. I think you are overcomplicating… with your plugin, etc. You can update customer info within an update cart form tag… add to cart form tag… or just about any “form” tag in CartThrob. There’s even an example of updating shipping info on the fly in the auto-install cart template. cart/.header has some jquery for doing the following:

a. creating a save customer info form on the fly
b. finding changed fields, and publishing them via that dynamic form
c. updating various totals, etc.

See that template, and review the update fields and load fields jquery functions as well as some of the other jquery in there.

 Signature 

We’re moving away from the forums, though not entirely and not immediately. Lack of support lately is coincidental to that. Unfortunately we’ve had a bad month with it, but we do not forsee that we will have any continued problems with support through our portal going forward, or on forums while we’re still transitioning. We will send out a newsletter and make additional notifications through twitter and other outlets over the coming weeks.

Moving forward; things returning to normal.

Profile
 
 
Posted: 02 May 2011 09:22 AM   [ Ignore ]   [ # 2 ]
Has a Great Personality
Rank
Total Posts:  50
Joined  2010-08-17

Hey Chris,

Thanks for the sanity check.  You were completely right… I was way over complicating it.

I’ve looked over the sample template… and come up with a lovely ajax solution.

Turns out I shouldn’t work on a Saturday afternoon.

wink

Cheers.

Profile
 
 
Posted: 17 October 2011 06:37 PM   [ Ignore ]   [ # 3 ]
Has a Nice Profile
RankRank
Total Posts:  107
Joined  2010-04-27

Hi Agun - I’m in the process of setting up a cart page that sounds identical (ajax update based on shipping country) - I’ve got as far as checking which country has been selected and setting a region accordingly (uk, europe, rotw) but I’m now stuck trying to update the basket accordingly. Did your site mentioned above go live? Could I see how you did it?

Profile
 
 
Posted: 19 October 2011 03:00 PM   [ Ignore ]   [ # 4 ]
Administrator
Avatar
RankRankRankRankRank
Total Posts:  10369
Joined  2008-09-29

Generallly my approach for updating the basket is as follows: I create a template that contains the basket code. If the update is successful, I use a jquery “get” ajax command to load that template, and inject it into the HTML

 Signature 

We’re moving away from the forums, though not entirely and not immediately. Lack of support lately is coincidental to that. Unfortunately we’ve had a bad month with it, but we do not forsee that we will have any continued problems with support through our portal going forward, or on forums while we’re still transitioning. We will send out a newsletter and make additional notifications through twitter and other outlets over the coming weeks.

Moving forward; things returning to normal.

Profile
 
 
Posted: 26 October 2011 05:23 AM   [ Ignore ]   [ # 5 ]
Has a Great Personality
Rank
Total Posts:  50
Joined  2010-08-17

Hey Paul,

Apologies for the delayed response… I’ve been at EECI in New York, and had a bit of a holiday before and after it.  I’m back home in Melbourne now, and like the Cartthrob boys, only now just catching up with my emails!

The site I used this for is http://draculas.com.au - I recommend maybe just adding a photo or two to the cart (at http://draculas.com.au/photos/), and then going through the ‘checkout’ process.  Have a look at the source, and you should be able to figure it all out.

Let me know if you needed anything further.

Cheers.

Andrew.

Profile