5 replies [Last post]
quaoar's picture
Offline
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.Not Kulvik
Joined: 08/08/2007
Juice: 179

We want to add a fixed shipping cost to each order.
To accomplish this we made a small module we named uc_simpleflatrate. One of the hooks we are using is hook_line_item(), which we use to add a line to the cart/checkout - Order Total Preview.
Code to add the line:

drupal_add_js("\$(document).ready( function() { set_line_item('".t('Shipping')."', '". t('Shipping') ."', ". _uc_simpleflatrate_get_amount($qty) .", -8); } );", 'inline');

However, at about 50% of the times when you visit cart/checkout, the line "Shipping xx" is missing, or is only visible for a very short time before disappearing...
I guess this has something to do with the javascript? Any tips appreciated.

Erlend Strømsvik
Ny Media AS
erlend@nymedia.no

Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15422
Re: Strange behavior with hook_line_item()

Yeah man, this is due to my sucky Javascript which I've been wanting to fix for a while (and would happily accept patches for Eye-wink). Basically, the page is running a few asynchronous HTTP requests at the same time using $.post() in that set_line_item() function. Well, they don't always get returned in the same order you call them, so it results in overwrites. I need to either devise a new way of doing that or add some sort of custom mutex that will ensure things get fired off in order. Any ideas?

michels's picture
Offline
Uber DonorBug FinderInternationalizationizer
Joined: 08/12/2007
Juice: 205
Re: Re: Strange behavior with hook_line_item()

Any solutions meanwhile?
Because its really important for the functionality of some modules (like shipping e.g.), isn't it?

greetings.

quaoar's picture
Offline
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.Not Kulvik
Joined: 08/08/2007
Juice: 179
Re: Re: Re: Strange behavior with hook_line_item()

It's not really that important...
Only a cosmetic problem since the correct lines (and all of them) will be shown in checkout/review

Erlend Strømsvik
Ny Media AS
erlend@nymedia.no

michels's picture
Offline
Uber DonorBug FinderInternationalizationizer
Joined: 08/12/2007
Juice: 205
Re: Re: Re: Re: Strange behavior with hook_line_item()

yeah. and that IS important Eye-wink

Your client is killing you, when the "order total preview" sometimes is with Shipping.. sometimes not... Eye-wink

quaoar's picture
Offline
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.Not Kulvik
Joined: 08/08/2007
Juice: 179
Re: Re: Re: Re: Re: Strange behavior with hook_line_item()

Not sure if you are kidding or not, but as I said:
cart/checkout/review - The final "stop" before the user submits his order -will- show all the data correctly. I don't know what page "order total preview" is but "Order review" will show the correct information.

And no, our clients have not killed us yet because of a small JS glitch, which only happens from time to time, at cart/checkout.

Erlend Strømsvik
Ny Media AS
erlend@nymedia.no