Jump to content

SOLVED: Rearrange UPS shipping order in shipping dropdown box


campusman

Recommended Posts

OK...time for me to give back to this community. I ran into an issue where UPS was displaying the most expensive shipping options (Next Day Air) first and the least expensive options (Ground) last, and hidden at the bottom of the shipping dropdown list. This can be a real turnoff for customers when it is displayed this way and I was looking for an alternate display method or a way to rearrange the shipping options to my liking.

I searched all over these forums and google and found several posts on this same topic (and for USPS too) of people with this same issue but no replies to their calls for help. So since I was stuck I tracked down a solution myself and it works and works great and this forum posting is to serve as record of how I fixed this issue just in case other people run into it in the future and need help. Below are my personal notes I saved on this topic while I worked on it, they may not all be accurate, but its a start. (like I'm not sure how close this might be to helping USPS people with the same issue as I am only using UPS and not USPS at this time, but maybe someone else can check on that).

The dropdown shipping menu by default with UPS (and maybe USPS) is designed to display the most expensive option first with the least expensive shipping options hidden by the dropdown forcing you to click to see options such as "Ground"

This mod will help you rearrange the way items are displayed in the shipping dropdown box so that you can rearrange the option to your desire, usually from cheapest to most expensive shipping options.

Shipping works this way:

When you activate a shipping module such as UPS, you need to enable specific shipping options such as ground and next day. After you choose these options and click to update the module, CubeCart generates an array for that shipping module in the database that stores your newly chosen options.

This array is stored in the database in the table "yourstorename_CubeCart_config". There is a row called "UPS" and the array is the data stored in it. This might also apply to USPS, but your mileage may vary...someone else needs to test on this to see if its true or not.

As far as I can tell this array is generated using the PHYSICAL ORDER of the shipping options in the HTML of the index.php of the UPS module in the admin section. This same list is also located in the calc.php for the UPS shipping module in the public_html side of the cart. I dont think it has anything to do with the array, but I havent been able to do testing so it might, but since I didnt have time to mess with it, I changed the lists in both the admin/modules/shipping/UPS/index.php and the public/modules/shipping/UPS/calc.php files so their shipping options matched.

Once someone places an order, this array is called by the calc.php and UPS.php modules somehow and fed to UPS which spits back a shipping quote which then populates the shipping dropdown box on the frontend of the cart during checkout. Everyone following along still?

HOW TO CHANGE ORDER:

NOTE: BACKUP YOUR FILES before attempting any changes.

1. To change the order of shipping, you should figure out what shipping options you want to use and then rearrange them in the order you want, I did cheapest (Ground) to most expensive (Air). Then I went into BOTH admin/index.php and public/calc.php and deleted the options I didnt want to use first and then rearranged the options I did want to use in the code in the order I wanted them to physically appear in the dropdown box. Pay special attention to making sure the php code matches when you rearrange rows in the index.php. Once you are done making changes DO NOT UPLOAD YET.

Here are some hints of what you are looking to delete/rearrange:

In public/calc.php:

----------------------------------

case "GND":

$desc = $lang['misc']['ground'];

break;


----------------------------------



In admin/index.php

----------------------------------


<tr>

	  <td align="left" class="tdText"><strong>Next Day Air</strong></td>

	  <td class="tdText"><select name="module[product_1DA]">

		<option value="1" <?php if($module['product_1DA']==1) echo "selected='selected'"; ?>>Enabled</option>

		<option value="0" <?php if($module['product_1DA']==0) echo "selected='selected'"; ?>>Disabled</option>

	  </select></td>

	</tr>

----------------------------------

****SPECIAL NOTE on index.php: The above code will select/move an entire row in the UPS admin module. For whatever reason, the very top visible option in that module is missing a <tr> tag at the beginning. Well OK, its not missing, its just caught up in the code above it. So in that case I manually just changed the top visible option to what I wanted it to be in both name and with the product code in the PHP string. Use the above as an example and you should be OK...just make sure you put the right product_*** string in to match the listed option.***

2. Once all my files were changed and saved, Then I went into the admin backend of the cart and disabled all the UPS shipping options and erased the zipcode and packing preferences, updated those changes, then I went back and disabled the UPS module all together and updated that. So now UPS is off. This step maybe redundant, but I wasnt sure if it was going to actually wipe out the array so I was being extra careful. This step may have been unnecessary.

3. I went into the database using PHPmyAdmin, did a search for UPS in the database, selected the "yourstorename_CubeCart_config" from the results and in the only UPS row there, I went to edit the array (which looks like nonsense code stings), I copied the array as one long text string and pasted it locally into a text file for safe keeping just in case. Then I deleted the text string/array and saved that and exited phpmyadmin. Once again, I'm not sure if this step is needed either, the array might have been disabled or cleared out in step 2, but I was just being extra careful and making sure the array was recreated from a null value.

4. I uploaded both the new admin/index.php file and the public/calc.php to the server in their respective places.

5. I went back into the store admin backend and reenabled the UPS module and the specified shipping options (of which there should only be the rows I wanted and they should now be in the order I want too). I did notice a weird error string at the top of the module selection page as well as the UPS specific module page in the backend when I tried to set it up, but once I enabled my changes and closed out and went back into the admin section, the errors were gone and everything appeared normal. I chalked this up to CC freaking out because I didnt have a UPS array or entry anymore, but by re-enabling the UPS module, it seemed to re-insert a new entry and all was fine after that.

6. Tested an order and UPS now shows up with Ground first and then Air at the bottom of the dropdown menu. Success!

So thats it. I'll keep an eye on this thread and if I hear feedback from others I'll re-edit this post to reflect new information. (Like maybe one of you people want to try this with USPS too)

In the meantime, I am also attaching the 2 files I changed that are live on my site so you can see how the finished mods work. Good luck! :)

index.php

calc.php

Link to comment
Share on other sites

  • 4 months later...

In public/calc.php:

----------------------------------

case "GND":

$desc = $lang['misc']['ground'];

break;

----------------------------------

I don't have a directory named "public" anywhere in my cube cart install. Is this a mistake? I found a file named calc.php in the modules/shipping/UPS folder though. After viewing both files in winmerge, I'm pretty sure this is the file you are referring to?

Thanks for the work. I'm attempting the mod right now!

Link to comment
Share on other sites

  • 1 year later...
  • 1 year later...
Guest Amos Vryhof

Since I just wanted UPS Ground first and didn't care about the rest too much, I just added krsort($module); before the first foreach in calc.php

I bet I could come up with something better, but this is quick and easy.

Link to comment
Share on other sites

  • 4 weeks later...
Guest Mint Mate

To sort the USPS shipping options from lowest to highest, open up calc.php and find:

(Around line 180)

$rates = $usps->get_rates(0);

$usps->get_package_error($package_id);

if(is_array($rates)){

foreach($rates as $key => $value){

Add an asort($rates) (or ksort, or any http://www.php.net/manual/en/array.sorting.php you want) as below:

$rates = $usps->get_rates(0);

$usps->get_package_error($package_id);

if(is_array($rates)){

[b]asort($rates);[/b]

foreach($rates as $key => $value){

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...