Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / ColdFusion / Advanced Techniques / December 2005



Tip: Looking for answers? Try searching our database.

Addition Problems

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
<Bryan> - 29 Dec 2005 22:35 GMT
I've inherited a store from another programmer, and was asked by the owner to
create a new function that will allow him tack on extra cost to the shipping
amount that UPS provides. I found the calculate-shipping template and attempted
to apply the following highlighted code at the bottom, but Coldfusion ignored
it.  Can anyone help me figure this out? I'm still crawling out of the novice
stage, so please speak slowly and use small words -- THANKS!

 <cfset ShippingPrice = 0>
 <cfset IntShip = 0>
 
 <!--- Verify if Shipping is International or not --->
 <cfif config.BaseCountry neq ShippingCountry>
  <cfset IntShip = 1>
 </cfif>
 
 <!--- Calculate the TotalWeight and the TotalPrice for the order --->
 <cfset totalweight = 0>
 <cfset totalprice = 0>
 
 <cfloop query="CartList" startrow="1" endrow="#CartList.RecordCount#">
  <cfset totalweight = totalweight + (ItemQuantity * Weight)>
  <cfset totalprice = totalprice + (ItemQuantity * Price)>
 </cfloop>

 <!--- *** SHIPPING CALCULATIONS *** --->
 <cfif #ShipBy# is "1" OR #ShipBy# is "2" OR #ShipBy# is "3" OR #ShipBy# is
"4" OR #ShipBy# is "5" OR #ShipBy# is "101">
  <!--- Calculate Shipping price directly from FedEx.com --->
  <CF_FedExPrice DATASOURCE="#config.datasource#"
FROM="#config.DefaultOriginZipcode#" TO="#shippingzipcode#" SERVICE="#shipby#"
WEIGHT="#totalweight#">
  <!--- <CF_FedExPriceLocal DATASOURCE="#config.datasource#"
TO="#shippingzipcode#" SERVICE="#shipby#" WEIGHT="#totalweight#">    --->
  <CFIF IsDefined("FedEx_Success") AND FedEx_Success is False AND
IsDefined("FedEx_ErrorText")>
      <cfoutput><div class="CTextError" align="center">Error in Fedex Rate
Lookup: #FedEx_ErrorText#</div></cfoutput>
    <CFSET ShippingPrice = 0>
  <cfelse>
    <CFSET #ShippingPrice# = #Val(FedEx_Charge)#>
  </cfif>
 </cfif>   
   
 <cfif #ShipBy# is "GNDRES" OR #ShipBy# is "2DA" OR #ShipBy# is "3DS" OR
#ShipBy# is "1DP" OR #ShipBy# is "1DA" OR #ShipBy# is "1DM">
  <!--- Calculate Shipping price directly from UPS.com thanks to this nifty
TAG --->   
  <CF_UPSPrice FROM="#config.DefaultOriginZipcode#" TO="#shippingzipcode#"
SERVICE="#shipby#" WEIGHT="#totalweight#">   
  <CFSET #ShippingPrice# = #Val(UPS_Charge)#>
 </cfif>
   
 <cfif #ShipBy# is "Priority" OR #ShipBy# is "EXPRESS">
  <!--- Calculate Shipping price for US POSTAL SERVICE --->
  <CF_USPSPrice FROM="#config.DefaultOriginZipcode#" TO="#shippingzipcode#"
SERVICE="#shipby#" WEIGHT="#totalweight#">   
  <CFIF USPS_Error eq 1>
   <CFSET #ShippingPrice# = 10>
  <CFELSE>
   <CFSET #ShippingPrice# = #Val(USPS_Charge)#>
  </cfif>
 </cfif>
   
 <cfif #ShipBy# is "Geography">
  <cfif #shippingcountry# is "United States">
   <cflock name="lock" timeout="30" type="ReadOnly">
    <cfquery name="GetRate" datasource="#config.datasource#">
     select *
     from state
     where St_Abv = '#shippingstate#'
       and StoreID = #storeid#
    </cfquery>
   </cflock>
  <cfelse>
   <cflock name="lock" timeout="30" type="ReadOnly">
    <cfquery name="GetRate" datasource="#config.datasource#">
     select *
     from countries
     where Country = '#shippingcountry#'
       and StoreID = #storeid#
    </cfquery>
   </cflock>
  </cfif>
  <cfset ShippingPrice = #Val(GetRate.s_rate)#>
 </cfif>
   
 <cfif #ShipBy# is "Weight">
  <cfif #config.RatePerPoundNtl# gt 0>
   <cfif #IntShip# is 0>
    <cfset ShippingPrice = #config.RatePerPoundNtl# * #totalweight#>
   <cfelse>
    <cfset ShippingPrice = #config.RatePerPoundInt# * #totalweight#>     
   </cfif>
  <cfelse>
   <cfset value = #totalweight#>
   <cfinclude template = "shipcalcs.cfm">
  </cfif>
 </cfif>
   
 <cfif #ShipBy# is "Price">
  <cfset value = #runningtotal#>
  <cfinclude template = "shipcalcs.cfm">
 </cfif>

   <cfquery name="GetOverWeight" datasource="#config.datasource#">
    select OverWeight
    from catalog
    where catalog.StoreID = #storeid#
     and catalog.ID = 'SHIPPING'
   </cfquery>
 
  <cfif GetOverWeight.OverWeight GT 0>
   <cfset ShippingPrice = ShippingPrice + OverWeight>
  </cfif>
Dan Bracuk - 29 Dec 2005 23:14 GMT
What do you mean, Cold Fusion ignored it?  

Did it not run the query?  
If it did run the query, was exactly one record returned?
If exactly one record was returned, was it a number greater than 0?

If you don't know the answers to these questions, insert this line of code
after your query.
<cfdump var="#GetOverWeight#">
<Bryan> - 30 Dec 2005 15:36 GMT
Thanks for your reply Dan.

What do you mean, Cold Fusion ignored it?
#GetOverWeight# returned an empty string.
dempster - 30 Dec 2005 16:09 GMT
So now you know your query did not return any records and presumably you did
not get any error messages. That means you did have a valid table name
(catalog) and valid field names and types. So I would look at the values in
your query to make sure they are looking for the correct record. You could try
looking for the storeID and see what records come up.

-Paul
Dan Bracuk - 30 Dec 2005 16:17 GMT
Not quite.  If the query ran and return no records, cfdump displays the field
names in nice red boxes.  If GetOverWeight is showing up as an empty string,
that is very strange because the only place it appears to show up is as the
query name.

So, junior member with no name, how did you get an empty string?  
<Bryan> - 30 Dec 2005 17:01 GMT
This is where my Coldfusion experience runs a little dry.
The query did run. It went to the right table (catalog), but the problem is it
appears to have returned the wrong row from the correct field. The row that it
should have returned has a value, but it didn't return that value. Is this
correct?
-Bryan

query - Rows: 1
  OVERWEIGHT
1 [empty string]  
Dan Bracuk - 30 Dec 2005 17:30 GMT
No, that is not correct.  Your query returned the row you requested and that
particular row does not have a value in the overweight field.

Run this query and see if you get values for id, and storeid.

cfquery name="GetOverWeight" datasource="#config.datasource#">
select OverWeight, storeid, id
from catalog
where catalog.StoreID = #storeid#
and catalog.ID = 'SHIPPING'
</cfquery>
<Bryan> - 30 Dec 2005 19:27 GMT
No, that didn't work either.

          ID               OVERWEIGHT    STOREID
1   SHIPPING      [empty string]            1  
Dan Bracuk - 30 Dec 2005 19:48 GMT
Actually it worked perfectly.  It showed you that you got the record you
requested.  Remember suggesting that you may have got the wrong row?

What you have to do is determine why that record has a null value in the
overweight field.
<Bryan> - 30 Dec 2005 21:31 GMT
It now works...kind of. I'm a little confused though. Shipping Cost is $12.59,
add the two OverWeight values and it should of totalled $52.59, instead the
total was $32.59. It appears one of the values wasn't added, but according to
the query results they were.

query - Rows: 2
  ID OVERWEIGHT STOREID
1 KC60001  20.0000  1  
2 KJ61010  20.0000  1  

      <cfquery name="GetOverWeight" datasource="#config.datasource#">
    select OverWeight, storeid, id
    from catalog
    where catalog.StoreID = #storeid#
    and catalog.OverWeight = #'OverWeight'#
    </cfquery>
   
      <cfif #Val(GetOverWeight.OverWeight)# GT 0>
       <cfset #Extra# = #GetOverWeight.OverWeight#>
      </cfif>

      <CFSET ShippingPrice = Val(ShippingPrice + Extra)>
Dan Bracuk - 30 Dec 2005 22:58 GMT
I noticed you changed your query.  

In any event, what is happening to you now is that you have a query with 2
rows, and then this statement.
<cfset #Extra# = #GetOverWeight.OverWeight#>

Since you didn't specify a rownumber for the GetOverWeight query, cold fusion
just takes the the last one (or is the first, I can't remember).  But it you
want both of them, you have to add them together somehow.  There are a few
options available, but the slickest one is to treat each query column as an
array.  So this:
<cfif #Val(GetOverWeight.OverWeight)# GT 0>
<cfset #Extra# = #GetOverWeight.OverWeight#>
</cfif>
becomes (and I might not have the correct syntax)
<cfif GetOverWeight.recordcount gt 0>
<cfset ShippingPrice = ShippingPrice + arraysum(GetOverWeight["OverWeight"])>
</cfif>
This is based on the assumption that you always have a value for Overweight in
the catalog table, event if the value is 0.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.