|
From: "<Bryan>" on 29 Dec 2005 17:35 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>
From: Dan Bracuk on 29 Dec 2005 18:14 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#">
From: "<Bryan>" on 30 Dec 2005 10:36 Thanks for your reply Dan. What do you mean, Cold Fusion ignored it? #GetOverWeight# returned an empty string.
From: Dan Bracuk on 30 Dec 2005 11:17 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?
From: dempster on 30 Dec 2005 11:09
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 |