Radical Hacks : Yet Another Empty Cart Hack for WebStore sent in the following hack...

I'm fairly new to Perl programming (in fact, I don't really have much of a clue what I'm doing)

I've applied some of the cool hacks to the standard Webstore script and think it's a fantastic product.

Anyway, I was searching around for an empty cart fix, whereby if there's no products in the cart, no modification buttons or checkout buttons are displayed and also, if the 'checkout' button is clicked on a product page with an empty cart, it takes you to the cart view instead of to the order form page - here's what I came up with :-


Another empty cart fix.

I couldn't find the "empty cart fix" that has been mentioned in a few places in the cool hacks section, so I made my own.

The following modifications are probably not the most 'clean' method of doing things - I've just started coding Perl so this is indeed very much a crude hack, but it works (so far)

The first fix here is that if the cart is empty, then there should be no 'modification' buttons shown in the cart view - i.e. no delete, quantity change or checkout buttons - just buttons for 'continue shopping' and 'return to frontpage'

The second modification is that if a 'checkout' button is clicked on a product page, a check is done to see if the cart is empty - if it's empty, then the standard cart view is displayed, if not, then it goes to 'checkout' as normal.


In the web_store_html_lib.pl file :-

Replace this code (in the cart_footer Subroutine Subroutine) :-

ub cart_footer
  {
  print qq!
                
  <INPUT TYPE = "submit" NAME = "change_quantity_button"
         VALUE = "Change Quantity">
  <INPUT TYPE = "submit" NAME = "delete_item_button" 
  VALUE = "Delete Items"> 
  <INPUT TYPE = "submit" NAME = "continue_shopping_button"
         VALUE = "Continue Shopping">
  $sc_no_frames_button
  <INPUT TYPE = "submit" NAME = "order_form_button" 
  VALUE = "Checkout Stand">
  </FORM>
  </CENTER>
  </BODY>
  </HTML>!;
  }

With this:

sub cart_footer 
{ 
 
#Check to see if cart is empty - if so, do not display 
#irrelevant buttons, just display the 
#continue_shopping button and some text, if not, display the standard 
#buttons 
 
if (-z $sc_cart_path) { 
 print qq! 
 
 <p>Your cart is empty !</p>
$sc_no_frames_button
  <INPUT TYPE = "submit" NAME = "continue_shopping_button"
         VALUE = "Continue Shopping">!; 
} 

else { 
  print qq! 
  <INPUT TYPE = "submit" NAME = "change_quantity_button"
         VALUE = "Change Quantity">
  <INPUT TYPE = "submit" NAME = "delete_item_button" 
  VALUE = "Delete Items"> 
  <INPUT TYPE = "submit" NAME = "continue_shopping_button"
         VALUE = "Continue Shopping">
  $sc_no_frames_button
  <INPUT TYPE = "submit" NAME = "order_form_button" 
  VALUE = "Checkout Stand">!; 
 }
 
print qq!
</FORM>
</CENTER> 
</BODY> 
</HTML>!; 
} 

In the web_store.cgi file :- Find this code :-

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

Replace that with this:

elsif ($form_data{'order_form_button'} ne "")
  {
  &require_supporting_libraries (__FILE__, __LINE__, 
                              "$sc_order_lib_path"); 
  
if (-z $sc_cart_path) {
  &display_cart_contents;
  exit;
}
else {
&display_order_form;
  exit;
}
  }

Well, that's it - I'm not sure if there's any errors here, as everything appears to function perfectly still - hey, my first Perl code !

Thanks for the excellent product, here's how I've put it to use so far (temporary site) :-

http://www.3r.co.za/storagedirect/