eXtropia: the open web technology company
Technology | Support | Tutorials | Development | About Us | Users | Contact Us
Development resources
 ::   WebWare 2.1 (Perl)
 ::   WebWare 2.0 (Java)
 ::   Cool hacks
radical hacks
Proposed modifications for showing the shipping on order form for WebStore  
at 3rd Eye Vision Ltd sent in the following workaround....

The following fix inserts an extra screen before the order from, where the user enters their shipping method so that shipping is accurately calculated first time on the order form page. Ppl have been requesting this for a long time, to my knowledge no fix has been posted.

Aaaaaanyway, it involves mods to the main web_store.cgi, web_store_order_lib.pl and web_store_html_lib.pl, cos i have tried to follow the main 'flow' of the program while making it as neat as poss:

NB: all HTML style enclosing braces replaced by [ and ]

1) web_store.cgi:

- replace from the elsif ($form_data{'order_form_button'} ne "") test to the beginning of the next comments, so it reads as follows....

elsif ($form_data{'order_form_button'} ne "")
  {
  &require_supporting_libraries (__VIRTUAL__, __LINE__,
                              "$sc_order_lib_path");

  &input_ship; # JPW NEWLINE: REDIRECT TO INPUT_SHIP (BELOW)
  exit;
  }

elsif ($form_data{'order_form_button_final'} ne "") # BEGIN NEW ELSIF
  {
  &require_supporting_libraries (__VIRTUAL__, __LINE__,
                              "$sc_order_lib_path");

  &display_order_form;
  exit;
  } # END NEW ELSIF - NEXT 3 ELSE TESTS UNCHANGED


elsif ($form_data{'submit_order_form_button'} ne "")
  {
  &require_supporting_libraries (__VIRTUAL__, __LINE__,
                              "$sc_order_lib_path");
  &process_order_form;
  exit;
  }

elsif (($page ne "" || $form_data{'search_request_button'} ne ""
                    || $form_data{'continue_shopping_button'}
                    || $are_any_query_fields_filled_in =~ /yes/i) &&
        ($form_data{'return_to_frontpage_button'} eq ""))
  {
  &display_products_for_sale;
  exit;
  }

else
  {
  &output_frontpage;
  exit;
  }

                # Well that's it.  That is the end of the program!  Well,
                # not exactly.  That is just the end of the main body of
                # logic.  From here on out we will define the logic of the
                # subroutines called in the "if" tests above.

#######################################################################
#                     Input Shipping Rate Form                        #
#######################################################################

                # &input_ship is the NEW subroutine
                # responsible for gathering the shipping details required
                # by order_lib_pl
                #
                # &input_ship;

sub input_ship
  {
  &standard_page_header("Enter Shipping Rate");
  &input_ship_footer;
  }

#######################################################################

[code continues]  

What is happening here is that all requests for a final order form are redirected to my new routine &input_ship;

(i'll describe the elsif ($form_data{'order_form_button_final'} ne "" test in a bit)

&input_ship; prints out a standard page header and a new bit
&input_ship_footer; , which we define in web_store_html_lib.pl to follow existing prgram flow.

2) web_store_html_lib.pl

- add this new routine somewhere in the script, right at the very end might be a good place for clarity.

#######################################################################
#                    input_ship_footer Subroutine                    #
#######################################################################

                # NEW 17.01.99
                # input_ship_footer outputs HTML for gathering 22-shipping 
                # and passing back to main script. It takes no arguments
                # and is called with the
                # following syntax:
                #
                # &input_ship_footer;

sub input_ship_footer
  {

        local($hidden_fields)=&make_hidden_fields;

  print qq!

[P ALIGN=RIGHT][FONT SIZE=5][I]select your shipping type[/I][/font][/P]
[CENTER]

[table cellpadding=0 cellspacing=0 border=0][tr][td bgcolor="#005500"]
[table border=0 cellpadding=5][tr align=center]
[td valign=middle bgcolor="#FFFFFF"]
[B]Select your shipping type:[/B][/TD]
[td align=center bgcolor="#dddddd"]

[SELECT NAME="22-shipping"]
[OPTION VALUE="uk" SELECTED]First Class Post: UK
[OPTION VALUE="eec"]First Class Post: Europe / Eire
[OPTION VALUE="row"]First Class Post: Japan & Australia
[OPTION VALUE="usa"]First Class Post: USA & Rest of World
[OPTION VALUE="rduk"]Recorded Delivery: UK
[OPTION VALUE="rdeec"]Recorded Delivery: Europe / Eire
[OPTION VALUE="rdrow"]Recorded Delivery: Japan & Australia
[OPTION VALUE="rdusa"]Recorded Delivery: USA & Rest of World
[/SELECT]
[/TD][/TR]

[tr align=center]
[td valign=middle bgcolor="#dddddd" colspan=2]
[INPUT TYPE = "submit" NAME = "order_form_button_final" VALUE = "Secure
Checkout - Final Step"]
[/TD][/TR][/table][/table]

[/FORM][hr noshade]

For your information, our shipping rates are shown below:
  [/CENTER]

insert HTML layout of your shipping rates here for customer info

  [/BODY]
  [/HTML]!;
  }

##### end of &input_ship_footer;

What you need to change are the shipping variable OPTION values for your setup, and make sure that the SELECT NAME is the same as your already-defined shipping variable. I like to print my shipping rates here so the customer isn't unpleasantly defined on the order form page if they are short of a bob or two, saving system resources.

(An excellent further mod which could be made here - if the script checked the number of items in cart and displayed the various shipping rates by pulling the details from the shipping type array defined in the .setup file, for that # of items, that would be cool)

Notable here is [INPUT TYPE = "submit" NAME = "order_form_button_final" VALUE = "Secure Checkout - Final Step"]

"order_form_button_final" is checked for in the modifactions we made to webstore.cgi in the first step. When the script sees this, it outputs the order from as standard, except we pass it the shipping variable (in this example, "22-shipping") with the rest of the hidden variables, by making the mod below.

3) web_store_order_lib.pl

- 2 things to do here. Insert a new line, around line 56, to pass our shipping variable as a hidden field, so the code reads as follows. Remeber to substitue your shipping variable whereever it sez 22-shipping:

[FORM METHOD = "post" ACTION = "$sc_order_script_url"]
[INPUT TYPE = "hidden" NAME = "page" VALUE = "$form_data{'page'}"]
[INPUT TYPE = "hidden" NAME = "cart_id" VALUE = "$form_data{'cart_id'}"]
[INPUT TYPE = "hidden" NAME = "22-shipping" VALUE =
"$form_data{'22-shipping'}"]\n!; # JPW NEWLINE
$line = "";

... secondly, change the following line, around line 102:

       $text_of_cart =
         &display_calculations($subtotal,"before",
               $text_of_cart);

to 

       $text_of_cart =
         &display_calculations($subtotal,"at",
               $text_of_cart); # JPW MOD: aboveline was "before"

We can now calculate the Shipping every time, as our variable is always being passed to the order form.

This fix is for those who have posted other fixes to this BBS in the past and all developers of Open Source software.