close ad
WARNING PC USERS: Do Not Install the DREAMWEAVER CC 2017 Update »
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Add a flat-rate shipping option to UPS list

Thread began 9/23/2009 4:32 pm by christy342106 | Last modified 9/30/2009 8:49 pm by Eric Mittman | 5251 views | 11 replies |

christy342106

Add a flat-rate shipping option to UPS list

My cart is working perfectly with the UPS shipping options - the cost is set up by weight, and I am offering customers a choice Overnight, 2-day, and 3-day, and Ground. I would like to be able to add two flat-rate options to my list of available shipping rates. My options would be as follows:

Flat Rate USA - $5
Flat Rate International - $10
UPS Shipping Options

Basically, my customer can choose to do a standard $5 shipping for their entire order or they can choose to use UPS for faster, trackable shipping.

I have looked through the previous posts, and it looks like this should be possible to implement, but I'm not quite sure if it is possible to add these options to the same list of shipping options without causing problems with the UPS service code.

Thanks in advance for your help!

Sign in to reply to this post

Eric Mittman

To properly implement this you will need to have two new shipping rules for the flat rate charges.

To get the new rules to work you can add to the select list that you already have in place. The next step would be to check this select list on the confirm page. If the value is set to one of the flat rate shipping options then you can set a session variable. You can set the session variable to one value for the regular and another for the international.

In the new flat rate shipping rule you will check for the presence of this session variable then the value, if it is the US flat rate value the you apply that shipping charge, and if it is the international you would apply that charge.

Along with this you will want to alter your other UPS shipping rule to not trigger if this session variable exists. If you need some specific pointers on this please post back with some questions about any part that you need help with and we will be glad to help you get it worked out.

Sign in to reply to this post

christy342106

Adding Flat Rate to UPS Service

Thanks for your quick reply! You guys are always such a HUGE help for all of my little issues!!

Okay, I just want to make sure I'm changing things in the right places so I don't cause any issues with what it already working --

1. On my checkout page, I have a select list with the UPS service names along with "01, 02, etc." as their list values. I am adding a flat rate USA as well as a flat rate International along with a corresponding number as a list value, such as "50"? I don't make the list value the rate of the shipping in this step, correct?

2. On my confirm page, under the shipping label, I have a piece of code:
switch($_SESSION['UPS_Service']) {
case 01:
echo("Next Day Air");
break;
case 02:
...and so on.
To this list do I add case 50: echo("Standard USA"); break; and another for International?

I'm thinking I should be going to the bindings panel and setting a session variable for the two flat rate items on the list - I'm a little unclear how and where to set this variable.

3. In my ecart object, I am setting up a new shipping rule for each of the flat rate shipping options. The condition for each rule will be if the session variable exists or based on the value of a session variable?

4. Finally, I am editing my UPS shipping rule to have the conditions UPS shipping quote ! = 0 AND the session variable for the flat rate option does not exist, correct? I'm not quite sure how to tell it to not trigger if the session variable does exist.

Thanks again!!

Sign in to reply to this post

Eric Mittman

I think that your switch statement is ok for displaying the service type. When it comes to getting the new flat rate shipping charges working the first thing you will need to do is add in the set session value server behavior. You can get to this in the eCart section of the server behaviors. When you add in the new session variable you can specify the trigger as the posted form element for the service select list you have. For the name just give it something meaningful like flat_shipping. For the value you can just set it to the posted select list value.

Once that has been written to the page you will need to customize it. For the condition you will need to update it so that it is not only looking for the posted element being set but also the two values that indicate flat rate shipping. So you will add in an and condition then some parenthesis to check if the value is equal to one of the flat rate values. It will look something like this when you are done with it:

php:
if(($_POST['your shipping select list'] != "") && (($_POST['your shipping select list'] == '50') || ($_POST['your shipping select list'] == '100')) )     { // I used 50 for US and 100 for internationsl

  $_SESSION["flat_shipping"] = $_POST['your shipping select list'];
}



Once you have got this session variable worked out you can then add in the new shipping rules. For the US just look for the presence of a session variable and specify the flat_shipping variable then also that the value of this session variable is set to '50'. You will do the same thing for the international but you will check to see if it is set to '100'.

Finally to edit the UPS you will just add in two more conditions, you will check to see if your flat_shipping variable is not set to '50' or not set to '100'. If these conditions are met then you should just apply the shipping quote that is returned.

If you have any questions about any part of this please let me know and I will do what I can to help clarify anything for you.

Sign in to reply to this post

christy342106

Okay, I'm getting close, but I've made an error somewhere. My UPS shipping is still working fine, but if I select one of the flat-rate options, I get the error message, "invalid service type" on my shipping failure page. I'm thinking my error is in setting my session server behavior, but I also noticed that when I was making the shipping rules for flat-rate shipping, I would add the $5 or $10 cost (using the wizard for shipping rules), and when I would reopen my cart object, it had been reset to 0.

On my checkout page, I have the following select list for shipping:
<select name="UPS_Service" id="UPS_Service">
<option value="01">UPS Next Day Air</option>
<option value="02">UPS 2nd Day Air</option>
<option value="03" selected="selected">UPS Ground</option>
<option value="50">Standard USA</option>
<option value="100">Standard International</option>
</select>

On my confirm page, I have added the following session, selecting "UPS_Service" from my ecart_checkout_form (this is where I think I have made an error):

<?php
if (!session_id()) session_start();
if((((isset($_POST["UPS_Service"]))?$_POST["UPS_Service"]:"") != "")) {
$_SESSION["flat_shipping"] = "".((isset($_POST["UPS_Service"]))?$_POST["UPS_Service"]:"") ."";
}
if(($_POST["UPS_Service"] != "") && (($_POST["UPS_Service"] == '50') || ($_POST["UPS_Service"] == '100')) ) { // I used 50 for US and 100 for internationsl
$_SESSION["flat_shipping"] = $_POST["UPS_Service"];
}
?>

Below are my reconfigured shipping rules:

UPS Shipping Rule:
function WAEC_TJCart_UPSShipping() {
$totalShipping = 0;
if (true && (("UPS"=="UPS")&&(isset($_SESSION["TJCart_UPS_Quote"]))&&(floatval($_SESSION["TJCart_UPS_Quote"]) != 0) && ((isset($_SESSION['flat_rate'])?$_SESSION['flat_rate']:"") != "0") && ((isset($_SESSION['flat_rate'])?$_SESSION['flat_rate']:"") != "0"))) {
$totalShipping += floatval($_SESSION["TJCart_UPS_Quote"]) + 0;//Result
}
return WA_eCart_FormatNumber($totalShipping, $this->ForceDecimalsC, $this->DecimalPlacesC);
}

Flat-Rate Rules:
//eCart Rule
function WAEC_TJCart_FlatRateUSA() {
$totalShipping = 0;
if (true && ((isset($_SESSION['flat_shipping'])) && ((isset($_SESSION['flat_rate'])?$_SESSION['flat_rate']:"") == "50"))) {
$totalShipping += 0;//Result
}
return WA_eCart_FormatNumber($totalShipping, $this->ForceDecimalsC, $this->DecimalPlacesC);
}
//eCart Rule
//eCart Rule
function WAEC_TJCart_FlatRateInternational() {
$totalShipping = 0;
if (true && ((isset($_SESSION['flat_rate'])) && ((isset($_SESSION['flat_rate'])?$_SESSION['flat_rate']:"") == "100"))) {
$totalShipping += 0;//Result
}
return WA_eCart_FormatNumber($totalShipping, $this->ForceDecimalsC, $this->DecimalPlacesC);
}


Thanks again for all your help!!

Sign in to reply to this post

Eric Mittman

The error you are getting makes sense, I forgot to mention that part. The shipping server behavior is still being triggered and the value that it is trying to use for the service type is not valid.

To account for this you will need to add in a condition to the if statement that serves as the trigger for the shipping server behavior or add in a new if statement around the server behavior. The if statement will be like this:

php:
<?php if( !(isset($_SESSION["flat_shipping"])) )     { ?>

// your UPS shipping quote server behavior here
<?php ?>



As for the issue with the value not being retained in the cart object after you edit it to be correct try closing down DW and opening it again to determine if the problem persists, let us know what you find.

Sign in to reply to this post

christy342106

Can you clarify just where to place that bit of code? I have found a few different spots that I thought were the UPS shipping server behavior, but when I try adding the condition, the shipping does not get charged at all - there is no charge listed on the confirm page regardless of what is chosen from the select list on the checkout page.

On my confirm page, I have a large block of code beginning with:
<?php
if ((((isset($_POST["Checkout_x"]))?$_POST["Checkout_x"]:"") != "")) {
//WA eCart (Copyright 2007, WebAssist)
//WA eCart UPS Shipping - UPS
$Shipping_SuccessURL = "";
$Shipping_FailureURL = "shipping_failure.php";
$Shipping_Packaging = 0;
$Shipping_PackageArray = array();
$Shipping_PackageIndex = 0;
$Shipping_Counter = 0;
...and so on

I thought that was the shipping server behavior that has been set up in the cart wizard.

I also have the session:
<?php
if (!session_id()) session_start();
if((((isset($_POST["UPS_Service"]))?$_POST["UPS_Service"]:"") != "")) {
$_SESSION["UPS_Service"] = "".((isset($_POST["UPS_Service"]))?$_POST["UPS_Service"]:"") ."";
}
?>


I'm either not looking in the right place, or I'm not placing the code in the correct way. I'm not completely confident on if I should be working from the confirm page or the checkout page.

Also, I have restarted DW, and the flat-rate value is still failing to be saved in the cart object. I may not be working with the most updated version of ecart, which could make a difference. I can add that value through the code itself, however, to get around that issue, correct? I'm assuming I change the line $totalShipping += 0;//Result


Thanks for helping me through this. I must be making a silly mistake somewhere that is just cancelling out the shipping altogether. I just wanted to make sure I'm putting the code in the right place before I keep trying to figure out what else could be happening.

Thanks again - I appreciate it!

Sign in to reply to this post

Eric Mittman

The code you posted looks like the UPS shipping server behavior, it should be on the confirm page. If you are unsure you can try selecting it from the server behaviors tab of the application panel. When you select the server behavior the corresponding code on the page should become selected.

Then you just add in the if statement around the entire thing. The point of this is to prevent shipping quote from failing and returning you to the shipping failure page.

If you continue to have trouble with it let me know and I can open a ticket for you on the back end to help determine what is going on.

Also, you may need to update the cart display that you have on the confirm page to reflect your new shipping rules. As a test you can create a new page and add in a cart display to the page. When you are testing your checkout and get to the confirm page you can just visit your test page to confirm that you get the same results on that page.

One other thing is the set session code you have on the confirm page, you need to make sure it is like this:

if(($_POST["UPS_Service"] != "") && (($_POST["UPS_Service"] == '50') || ($_POST["UPS_Service"] == '100')) ) { // I used 50 for US and 100 for internationsl
$_SESSION["flat_shipping"] = $_POST["UPS_Service"];

This will ensure that the flat shipping server behavior will only be set if there is a posted value and it is either 50 or 100.

Sign in to reply to this post

christy342106

I just wanted to run this code by you one more time to make sure I've set everything up correctly. If it looks okay and there seems to be an issue somewhere else, then we can set up a support ticket and go from there. I really appreciate your help with this.

I set up a test page to check the shipping charges in the cart display, and it does show the same result, which is no charge (or label) for shipping at all.


Flat rate set session:
<?php
if (!session_id()) session_start();
if((((isset($_POST["UPS_Service"]))?$_POST["UPS_Service"]:"") != "")) {
$_SESSION["flat_shipping"] = "".((isset($_POST["UPS_Service"]))?$_POST["UPS_Service"]:"") ."";
}
if(($_POST["UPS_Service"] != "") && (($_POST["UPS_Service"] == '50') || ($_POST["UPS_Service"] == '100')) ) { // I used 50 for US and 100 for internationsl
$_SESSION["flat_shipping"] = $_POST["UPS_Service"];
}
?>

UPS set session:
<?php
if (!session_id()) session_start();
if((((isset($_POST["UPS_Service"]))?$_POST["UPS_Service"]:"") != "")) {
$_SESSION["UPS_Service"] = "".((isset($_POST["UPS_Service"]))?$_POST["UPS_Service"]:"") ."";
}
?>

The beginning and end code of my UPS server behavior:
<?php if( !(isset($_SESSION["flat_shipping"])) ) { ?>
<?php
if ((((isset($_POST["Checkout_x"]))?$_POST["Checkout_x"]:"") != "")) {
//WA eCart (Copyright 2007, WebAssist)
//WA eCart UPS Shipping - UPS
$Shipping_SuccessURL = "";
$Shipping_FailureURL = "shipping_failure.php";
$Shipping_Packaging = 0;
$Shipping_PackageArray = array();
$Shipping_PackageIndex = 0;
$Shipping_Counter = 0;
$Shipping_Parameters = array();

etc., etc. ...
$Shipping_Result = WA_eCart_UPS_GetRateQuote($TJCart, $Shipping_Parameters, $Shipping_PackageArray);
if ($Shipping_Result && $Shipping_SuccessURL != "")
$TJCart->redirStr = $Shipping_SuccessURL;
else if (!$Shipping_Result && $Shipping_FailureURL != "") {
Header("Location: " . $Shipping_FailureURL); exit;
}
}
else if (!isset($_SESSION["TJCart_UPS_Success"])) {
WA_eCart_UPS_SetSessionDefaults($TJCart);
}
?>
<?php } ?>

Shipping Rules from cart object:
UPS Shipping Rule:
function WAEC_TJCart_UPSShipping() {
$totalShipping = 0;
if (true && (("UPS"=="UPS")&&(isset($_SESSION["TJCart_UPS_Quote"]))&&(floatval($_SESSION["TJCart_UPS_Quote"]) != 0) && ((isset($_SESSION['flat_rate'])?$_SESSION['flat_rate']:"") != "0") && ((isset($_SESSION['flat_rate'])?$_SESSION['flat_rate']:"") != "0"))) {
$totalShipping += floatval($_SESSION["TJCart_UPS_Quote"]) + 0;//Result
}
return WA_eCart_FormatNumber($totalShipping, $this->ForceDecimalsC, $this->DecimalPlacesC);
}

Flat-Rate Rules:
//eCart Rule
function WAEC_TJCart_FlatRateUSA() {
$totalShipping = 0;
if (true && ((isset($_SESSION['flat_shipping'])) && ((isset($_SESSION['flat_rate'])?$_SESSION['flat_rate']:"") == "50"))) {
$totalShipping += 0;//Result
}
return WA_eCart_FormatNumber($totalShipping, $this->ForceDecimalsC, $this->DecimalPlacesC);
}
//eCart Rule
//eCart Rule
function WAEC_TJCart_FlatRateInternational() {
$totalShipping = 0;
if (true && ((isset($_SESSION['flat_rate'])) && ((isset($_SESSION['flat_rate'])?$_SESSION['flat_rate']:"") == "100"))) {
$totalShipping += 0;//Result
}
return WA_eCart_FormatNumber($totalShipping, $this->ForceDecimalsC, $this->DecimalPlacesC);
}

Sign in to reply to this post

Eric Mittman

There is one major problem that I see with the code you posted. You have two if statements that are working to set the $_SESSION["flat_shipping"] variable. Since the first one is only checking if the $_POST["UPS_Service"] is set it will always set the session variable when you first come to this page. This is no good since the check for running the UPS shipping server behavior relies on this variable having a value, if you give this variable a value when the user has selected a UPS shipping option the shipping will not trigger and nothing will show in the cart. In the code you posted if you remove the first if statement that is setting the $_SESSION["flat_shipping"] variable then the trigger for the UPS shipping should work for you.

The code to get rid of in the example you posted is this:

php:
if((((isset($_POST["UPS_Service"]))?$_POST["UPS_Service"]:"") != "")) {

$_SESSION["flat_shipping"] = "".((isset($_POST["UPS_Service"]))?$_POST["UPS_Service"]:"") ."";
}



The other valid code appears just below this and should work for you, let us know what you experience.

Sign in to reply to this post
loading

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...