URL: http://www.uburst.com/cgi-bin/dcforum/dcboard.cgi
Forum: ushp_general_purpose
Thread Number: 369
[ Go back to previous page ]

Original Message
"Passing variables to CP pages"

Posted by garylane on at 01:05 PM
I'm finding U-Shop a little inflexible on the order-processing side.

I want to pass variables to fields in the form templates. For example, I want the Thank You message to include "order number" and "order value" and I want the Credit Card template to include the "order total".

Alternatively, at the sake of being radical, is there a way I can use the U-shop basket to populate a shopping basket but construct my own order-processing pages with the flexibility I want - and not use U-shop for this part of the transaction?


Table of contents

Messages in this discussion
"RE: Passing variables to CP pages"
Posted by Bill Weiner on at 04:41 AM
In regard to adding the order number to the Thank You page, refer to my postings at:

http://www.uburst.com/dcforum/ushop_prog_tips/83.html#2

... for instructions on how to do that.

In regard to the "order value", the order total is already included on the Thank You page. So I'm not sure what you mean there.

In regard to displaying the "order total" on the credit card entry page, at this time that would require making a slight modification of the "display_credit_card_form" subroutine in the ushop-lib.pl script... as per the instructions below:

STEP 1: Make a backup of your ushop-lib.pl script... just in case.

STEP 2: Open your ushop-lib.pl script with any text editor such as WordPad.

STEP 3: Do a search on the following line:

sub display_credit_card_form

(This will get you to the start of the subroutine that displays the credit card entry form.)

STEP 4: About 17 lines down further in that subroutine, locate the following line:

$order_footer = &get_hidden_java_parameters();

STEP 5: Immediately BEFORE that line, add this line:

$order_form_html =~ s/USHOP_TOTAL/$totals_total/g;

STEP 6: Save the script... as TEXT if your editor asks... and try it out as per the instructions below.

The above modification will allow you to add the keyword "USHOP_TOTAL" anywhere on your creditcard_template.html file... and that "USHOP_TOTAL" keyword will be replaced at runtime by the current order total.

Let me know if you have any questions.


"RE: Passing variables to CP pag"
Posted by garylane on at 08:29 AM
Thanks a lot for that very constructive advice and the pointer to your other page which will help a lot.

Two follow-up questions:

1) How can I format the numbers output (using the code you suggested I get a 5 decimal place figure (presumably the result of the tax calculations)?

2) One of the problems we're having is caused by the use of the same template for all your main "basket" pages. Based upon your advice in the previous post, I take it that my editing the .pl file, one can replace the field with any HTML we like (including use of variables) to effectively customise these pages far more than is allowed through the control panel.


"RE: RE: Passing variables to CP pag"
Posted by Bill Weiner on at 04:38 AM
Glad that information helped. In regard to your follow-ups:

1) You can format the total to two decimal places using code like this:

# Convert total to a number.
$totals_total = &strip_letters($totals_total);

# Format a new total variable.
$formatted_total = sprintf("%s %.2f",$currency_symbol,$totals_total);

2) uShop does use a few templates during the order process that can be customized however you like using just a standard HTML editor:

- The "template_cart.html" page (located in your "classes" directory) allows you to customize the look of the first "Review Cart" page that is displayed after the customer presses the uShopOrderButton applet. Refer to section 7.1.1 in the uShop Users Guide for information about customizing that template. (http://www.uburst.com/uShop/reference/users_guide.html)

- The "order_template.html" file is used to display the order form that the customer fills out on the CGI side of things. Refer to section 9 in the uShop Users Guide for information about customizing that template. (http://www.uburst.com/uShop/reference/users_guide.html)

Otherwise, yes, there are additional ways to customize the uShop CGI scripts themselves to make additional changes... depending on what exactly you would like to do... but for the most part, usually any desired changes can be made directly to the aforementioned template files.


""RE: RE: Passing variables to CP pag""
Posted by Les on at 07:54 AM
Bill, where do you make these changes (what script)in order to display the price as, for example, £39.48, at the moment the price would be something like £39.48250235.

Many thanks in advance for your help.


"RE: RE: Passing variables to CP pag"
Posted by Bill Weiner on at 04:56 AM
You would add these lines:

# Convert total to a number.
$totals_total = &strip_letters($totals_total);

# Format a new total variable.
$formatted_total = sprintf("%s %.2f",$currency_symbol,$totals_total);

...directly BEFORE you add the line in STEP 5 of my August 23,2002 posting above.

(Just follow the instructions in my August 23,2002 posting above... and in STEP 5 add the formatting lines before the "$order_form_html =~ s/USHOP_TOTAL/$totals_total/g;" line.)


""RE: RE: Passing variables to CP pag""
Posted by Les on at 09:29 AM
Hi Bill,

I've tries that but it doesn't seem to work, still get 6 digits after the . eg we're still getting things like £109.350006

I copied and pasted the code as you have above.

Any ideas?

Thanks

Les


"RE: RE: Passing variables to CP pag"
Posted by Bill Weiner on at 06:51 AM
Exactly when/where in the order process are you seeing the additional digits? The formatting described above would need to be added at that point.

""RE: RE: Passing variables to CP pag""
Posted by Les on at 08:31 AM
Bill,

I am seeing the extra digits on the credit card page, where the customer enters their credit card details. e.g. we have some text asking the customer to confirm the amount of £xx.xx to be put on their credit card but we get the following £xx.xxxxxxxx

I put the code in where you said but I still get a load of extra digits after the .


It's not any brackets? or any code that has not been displayed that is causing the problem is it, as I think I read on the forum that sometimes certain things don't display as they should.

Regards

Les


"RE: RE: Passing variables to CP pag"
Posted by Bill Weiner on at 05:05 AM
Oh, Ok. I understand.

What needs to be done is instead of using "$totals_total" the line:

$order_form_html =~ s/USHOP_TOTAL/$totals_total/g;

We need to use "$formatted_total":

$order_form_html =~ s/USHOP_TOTAL/$formatted_total/g;

So the full set of instructions should look like this:

----------

STEP 1: Make a backup of your ushop-lib.pl script... just in case.

STEP 2: Open your ushop-lib.pl script with any text editor such as WordPad.

STEP 3: Do a search on the following line:

sub display_credit_card_form

(This will get you to the start of the subroutine that displays the credit card entry form.)

STEP 4: About 17 lines down further in that subroutine, locate the following line:

$order_footer = &get_hidden_java_parameters();

STEP 5: Immediately BEFORE that line, add these three lines:

$totals_total = &strip_letters($totals_total);
$formatted_total = sprintf("%s %.2f",$currency_symbol,$totals_total);
$order_form_html =~ s/USHOP_TOTAL/$formatted_total/g;

STEP 6: Save the script... as TEXT if your editor asks... and try it out as per the instructions below.

The above modification will allow you to add the keyword "USHOP_TOTAL" anywhere on your creditcard_template.html file... and that "USHOP_TOTAL" keyword will be replaced at runtime by the current order total.... FORMATTED TO TWO DECIMAL PLACES.


""RE: RE: Passing variables to CP pag""
Posted by Les on at 06:07 AM
Bill,

That's sorted it out :)

Thank you very much.

I really appreciate your help.

Thanks again

Regards

Les