Strange behavior with hook_line_item()

Posts: 47
Joined: 08/08/2007
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.Not Kulvik

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

Posts: 4256
Joined: 08/07/2007
AdministratorHead Code Monkey - I eat bugs.

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?

Posts: 81
Joined: 08/12/2007
Uber DonorBug FinderInternationalizationizer

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

greetings.

Posts: 47
Joined: 08/08/2007
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.Not Kulvik

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

Posts: 81
Joined: 08/12/2007
Uber DonorBug FinderInternationalizationizer

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

Posts: 47
Joined: 08/08/2007
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.Not Kulvik

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