Virtuemart – shipping method list – invalid markup


A user recently reported an odd problem on a Virtuemart site I maintain. They weren’t able to properly select the bottom two shipping methods listed (both USPS options).

I took a gander at the cart and quickly found the problem. The UPS shipping module was outputting the radio buttons wrapped in a <label> tag. Problem was, it wasn’t doing this consistently, and the last UPS shipping option had an open tag that was encompassing all the remaining radio buttons. This meant that anywhere you clicked in that region would result in the last UPS option being selected.

Now for some reason the USPS shipping module didn’t output labels at all. So I figured the most consistent solution would be to simply prevent the UPS module from outputting those <label> tags.

The method you’re looking for is ups::list_rates(), which is in the ./administrator/components/com_virtuemart/classes/shipping/ups.php file.

You can see the changes I made below on lines 362 and 384. The lines that are commented out are the original ones.

  1. $shipping_rate_id = urlencode(__CLASS__."|UPS|".$value['ServiceName']."|".$charge);
  2. $checked = (@$d["shipping_rate_id"] == $value) ? "checked=\"checked\"" : "";
  3. if (count($shipment) == 1 ) {
  4.         $checked = "checked=\"checked\"";
  5. }
  6. //$html .= '<label for="'.$shipping_rate_id.'">'."\n<input type=\"radio\" name=\"shipping_rate_id\" $checked value=\"$shipping_rate_id\" id=\"$shipping_rate_id\" />\n";
  7. $html .= "<input type=\"radio\" name=\"shipping_rate_id\" $checked value=\"$shipping_rate_id\" id=\"$shipping_rate_id\" />\n";
  9. $_SESSION[$shipping_rate_id] = 1;
  11. $html .= $value['ServiceName'].' ';
  12. $html .= "<strong>(".$value['TransportationCharges'].")</strong>";
  13. if (DEBUG) {
  14.         $html .= " - ".$VM_LANG->_('PHPSHOP_PRODUCT_FORM_WEIGHT').": ".$order_weight." ". $weight_measure.
  15.         ", ".$VM_LANG->_('PHPSHOP_RATE_FORM_VALUE').": [[".$charge_unrated."(".$fsc_rate.")]+".UPS_HANDLING_FEE."](".$taxrate.")]";
  16. }
  18. if (Show_Delivery_Days_Quote == 1) {
  19.         if( !empty($value['GuaranteedDaysToDelivery'])) {
  20.                 $html .= "&nbsp;&nbsp;-&nbsp;&nbsp;".$value['GuaranteedDaysToDelivery']." ".$VM_LANG->_('PHPSHOP_UPS_SHIPPING_GUARANTEED_DAYS');
  21.         }
  22. }
  23. if (Show_Delivery_ETA_Quote == 1) {
  24.         if( !empty($value['ScheduledDeliveryTime'])) {
  25.                 $html .= "&nbsp;(ETA:&nbsp;".$value['ScheduledDeliveryTime'].")";
  26.         }
  27. }
  28. if (Show_Delivery_Warning == 1 && !empty($value['RatedShipmentWarning'])) {
  29.         //$html .= "</label><br/>\n&nbsp;&nbsp;&nbsp;*&nbsp;<em>".$value['RatedShipmentWarning']."</em>\n";
  30.         $html .= "<br/>\n&nbsp;&nbsp;&nbsp;*&nbsp;<em>".$value['RatedShipmentWarning']."</em>\n";
  31. }
  32. $html .= "<br />\n";

Hacking Virtuemart 1.1.3


My first experience with Joomla and Virtuemart has left me less than enthusiastic. By far the most time I spent was trying to figure out what files performed what functions. It seems like there are three files that you need to modify for every change you’d like to make. The Virtuemart developer site is useless, and you have to resort to Google to find any answers. So I thought I’d document some of my findings here.

Finding Files
One of the best tips I can give you is to utilize the Unix find utility if you’re working on a *nix platform. You can locate a file using wildcards like so:

$ find / -name *searchterm*

Virtuemart’s default implementation of the tax module leaves much to be desired. In our case we had to charge Denver City tax in addition to a Colorado State tax. This is simply impossible using the default tax module. Luckily I found someone with the same problem and was able to hack in a work around:

How to configure Virtuemart tax functions to work with U.S. states and zip codes

The key files in this case being:

  • basket.php and ro_basket.php
  • basket_b2c.html.php and basket_b2b.html.php
  • ro_basket_b2c.html.php and ro_basket_b2b.html.php
  • confirmation_email.tpl.php

If you poke around in these files and take a look at the link above it should give you a good start on modifying the way taxes are calculated and displayed to shoppers on your Virtuemart store.

Other Useful Files
I found that by far the most useful file was ps_checkout.php. It seems like Virtuemart runs a lot of its primary functions through this file. Other useful files include:

  • ps_user.php
  • ps_shopper.php

Further Reading

Resurrect Lost Joomla/Virtuemart Error Messages

Let me guess, you’ve got a Joomla/Virtuemart site up, but your visitors aren’t seeing any helpful error messages. Am I right? Say I try and log in with a bogus username, you’d like to see that error message down there.

Username and password do not match or you do not have an account yet.

…but instead you’re just getting a page refresh. Confusing, huh? Well, lucky for you it’s a simple template fix.

  1. Log into the Joomla admin panel and navigate to “Extensions->Template Manager.”
  2. Click on the name of your “Default” template (it should be starred).
  3. Click the “Edit HTML” button in the upper right.
  4. Add the below code to the template file right above the <jdoc:include type="component" /> line.

<!-- Display Error Messages -->
<jdoc:include type="message" />
<!-- End Messages -->
<jdoc:include type="component" />

Source: Login error message not showing, need fix