File: D:/web/hyperflight/! previous changes 2/2025-08-11/removed/CustomGetDeliveryOriginal.asp
<%
' this routine must exist if CustomDeliveryEnabled, -1 is returned if delivery cost could not be determined, user should be alerted using SetAlertMessage
' (SS,05/07/12) custom delivery to charge extra if carbon rod type item in basket (i.e. with "Postal Length" attribute >=90 and any option value is >= 90)
' (SS,04/10/12) replaced GetAttributeInBasketCountNumValCompare with GetAttributeInBasketMaxOptionValue which returns maximum option value
' (SS,09/12/14) added AByPriceDeliveryCost, AByWeightDeliveryCost to make compatible with latest apputils
' (SS,01/12/16) added setting of Priority for order, N.B. this routine isn't called if "delivery will collect", custom routine CustomGetPriority will always be called (see below) this can be used to set priority for "delivery will collect"
' (SS,08/03/17) modified to remove VAT from Value for Priority calculation
' (SS,25/07/17) improvements to Lipo delivery cost calculation
' (SS,31/10/17) adjustment to postal tube delivery for EU, EU2 and RW
' (SS,02/11/17) adjustment to priority 3
' (SS,26/01/18) minor change to priority
' (SS,28/06/18) modified to add delivery option code for tracked delivery
' (SS,16/07/18) change to priority when tracked delivery chosen
' (SS,15/02/19) Priority 7, changed to use grand total value not excluding VAT Value (requested by Deborah)
' (SS,22/04/21) added expedited delivery option, this adds an extra 30% to the delivery cost
' (SS,26/04/21) correction, due to extra 5.42 being charged incorrectly for tracked
' (SS,30/04/21) modified to call GetWeightRangeForCategory for reduced delivery for multiple RC Models
' (SS,05/05/21) modified GetDeliveryFromTable (in apputils.asp) to interpolate delivery costs from delivery costs table
' (SS,06/05/21) change to restrict LiPo to specific countries (previous setting was for region RW, LA, or USA)
' (SS,07/05/21) added call to SetAdjustedTotalWeight to set the adjusted total weight
' (SS,10/05/21) added check for delivery cost of <= 0 to abort, or >= 20000 and not UK to abort with error
' (SS,12/05/21) modified call to GetWeightRangeForCategory to remove RC_MODEL_MEDIUM_REF_WEIGHT and replaced LAboveMediumRCModelWeight with LHeavyRCModelTotalWeight
' (SS,03/06/21) fixed issue with Google Shopping Data Feed by not calling GetWeightRangeForCategory when in DoGoogleShoppingDataFeed
' (SS,11/06/21) bug fix to Tracked overriding Expedited delivery option, also set priority to 9 for expedited
' (SS,11/06/21) bug fix for Google Shopping Data Feed to ensure minimum UK delivery for all products
' (SS, 8/07/22) renamed from CustomGetDelivery to CustomGetDeliveryOriginal, i.e. old version for comparison purposes, can be deleted
' (SS,15/11/22) added CustomShowSetDeliveryVars
Function CustomGetDeliveryOriginal(ATotalValue, AValueOfNonWeightedGoods, ATotalWeight, AVATContent, ATotalItems, ANormalDeliveryCost, AByPriceDeliveryCost, AByWeightDeliveryCost, APostcode, ARegionCode, ADeliveryRegion, ACountry)
Const SHOW_DEBUG_INFO = False
' *** DEBUG CODE ***
If SHOW_DEBUG_INFO Then
Response.Write "*** DEBUG START ***" & BR
Response.Write "TotalValue: " & ATotalValue & BR
Response.Write "ValueOfNonWeightedGoods: " & AValueOfNonWeightedGoods & BR
Response.Write "TotalWeight: " & ATotalWeight & BR
Response.Write "VATContent: " & AVATContent & BR
Response.Write "TotalItems: " & ATotalItems & BR
Response.Write "NormalDeliveryCost: " & ANormalDeliveryCost & BR
Response.Write "ByPriceDeliveryCost: " & AByPriceDeliveryCost & BR
Response.Write "ByWeightDeliveryCost: " & AByWeightDeliveryCost & BR
Response.Write "Postcode: " & APostcode & BR
Response.Write "RegionCode: " & ARegionCode & BR
Response.Write "DeliveryRegion: " & ADeliveryRegion & BR
Response.Write "Country: " & ACountry & BR
Response.Write "*** DEBUG END ***" & BR
Response.Write "" & BR
End If
' *** DEBUG CODE END ***
' (SS,12/5/21) removed LAboveMediumRCModelWeight, added LHeavyRCModelTotalWeight
Dim LHeaviestRCModelWeight, LHeavyRCModelTotalWeight, LRCModelTotalWeight, LTotalWeight, LAdjustedWeight, LNormalDeliveryCost
' (SS,12/5/21) removed RC_MODEL_MEDIUM_REF_WEIGHT
Const RC_MODEL_HEAVY_REF_WEIGHT = 1500
' Const RC_MODEL_MEDIUM_REF_WEIGHT = 1000
Const RC_MODEL_WEIGHT_ADJUSTMENT_FACTOR = 0.3
' (SS,3/6/21) move following here from Else section in If below, due to adding of InGoogleShoppingDataFeed
LTotalWeight = ATotalWeight
LNormalDeliveryCost = ANormalDeliveryCost
' (SS,12/5/21) removed parameters RC_MODEL_MEDIUM_REF_WEIGHT (3rd), replaced LAboveMediumRCModelWeight with LHeavyRCModelTotalWeight
' values RC_MODEL_MEDIUM_REF_WEIGHT and LRCModelTotalWeight are ByRef and passed back here
' (SS,3/6/21) routine GetWeightRangeForCategory is not compatible with or applicable to the Google Shopping Data Feed i.e. DoGoogleShoppingDataFeed
' it prevents DoGoogleShoppingDataFeed from working by giving oRS type mismatch error, fixed issue by not calling GetWeightRangeForCategory
' when this routine gets called from DoGoogleShoppingDataFeed by using Not InGoogleShoppingDataFeed
' N.B.!!! modifying GetWeightRangeForCategory to use OpenQuery2 instead of OpenQuery or DoGoogleShoppingDataFeed to use OpenQuery2 or OpenQuery3 won't work due to use of GetPricingFromProductRecord
If Not InGoogleShoppingDataFeed Then
If GetWeightRangeForCategory("RC Models", RC_MODEL_HEAVY_REF_WEIGHT, LHeaviestRCModelWeight, LHeavyRCModelTotalWeight, LRCModelTotalWeight, LTotalWeight) Then
If SHOW_DEBUG_INFO Then
Response.Write "*** HEAVY RC MODEL DETECTED ***" & BR
Response.Write "RC_MODEL_HEAVY_REF_WEIGHT: " & RC_MODEL_HEAVY_REF_WEIGHT & BR
'Response.Write "RC_MODEL_MEDIUM_REF_WEIGHT: " & RC_MODEL_MEDIUM_REF_WEIGHT & BR
Response.Write "RC_MODEL_WEIGHT_ADJUSTMENT_FACTOR: " & RC_MODEL_WEIGHT_ADJUSTMENT_FACTOR & BR
Response.Write "HeaviestRCModelWeight: " & LHeaviestRCModelWeight & BR
'Response.Write "AboveMediumRCModelWeight: " & LAboveMediumRCModelWeight & BR
Response.Write "HeavyRCModelTotalWeight: " & LHeavyRCModelTotalWeight & BR
Response.Write "RCModelTotalWeight: " & LRCModelTotalWeight & BR
Response.Write "TotalWeight: " & LTotalWeight & BR
End If
' (SS,12/5/21) replaced LAboveMediumRCModelWeight with LHeavyRCModelTotalWeight
LAdjustedWeight = LTotalWeight - Int((LHeavyRCModelTotalWeight - LHeaviestRCModelWeight) * (1 - RC_MODEL_WEIGHT_ADJUSTMENT_FACTOR))
LTotalWeight = LAdjustedWeight
LNormalDeliveryCost = GetDeliveryFromTable(ARegionCode, False, "W", LAdjustedWeight)
' (SS,7/6/21) sets the new TotalWeight to save later in the order record
If ATotalWeight <> LAdjustedWeight Then
SetAdjustedTotalWeight(LAdjustedWeight)
Else
SetAdjustedTotalWeight(0) ' (SS,5/10/22) clear adjusted total weight in case another routine had set it
End If
If SHOW_DEBUG_INFO Then
Response.Write "AdjustedWeight: " & LAdjustedWeight & BR
Response.Write "NewNormalDeliveryCost: " & LNormalDeliveryCost & BR
Response.Write "*** HEAVY RC MODEL DETECTED END ***" & BR
Response.Write "" & BR
End If
' (SS,10/5/21) if 0 or less returned from GetDeliveryFromTable then show alert and flag error with -1
If (LNormalDeliveryCost <= 0) Or (LAdjustedWeight >= 20000 And ARegionCode <> "UK" And ARegionCode <> "UK2") Then
SetAlertMessage("Sorry, your package is too heavy for normal delivery, please contact us")
CustomGetDeliveryOriginal = -1
Exit Function
End If
End If
Else ' (SS,11/6/21) i.e. if InGoogleShoppingDataFeed
' set tracked and expedited to False, to prevent subsequent products in feed from defaulting to tracked
' when heavy or expensive item encountered which will set default to tracked and delivery too high for following products
SetTrackedDeliverySelected False
SetExpeditedDeliverySelected False
End If
Dim LExtraDeliveryCost, LPostalTubeMaxLength
LExtraDeliveryCost = 0
'Response.Write "###" & GetAttributeInBasketCount("Exclude Delivery to RW", "") & "###" & ARegionCode & BR
' (SS,8/1/16) restrict delivery of batteries to RW
'If GetAttributeInBasketCount("Exclude Delivery to RW", "") > 0 Then
' If ARegionCode = "RW" Or ARegionCode = "LA" Or ARegionCode = "USA" Then
' (SS,6/5/21) replaced above two with following to allow LiPos only in these countries
If GetAttributeInBasketCount("LiPo", "") > 0 Then
If InStr(",United Kingdom,Belgium,France,Germany,Italy,Netherlands,Spain,", "," & ACountry & ",") = 0 Then
SetAlertMessage("Sorry we can't deliver batteries to your region, please remove from basket")
CustomGetDeliveryOriginal = -1
Exit Function
End If
End If
' *** All these prices should NOT contain VAT - it will be added later if required. ***
' (SS,4/10/12) get max length of option for product with attribute "Requires Postal Tube"
' if no product in basket with this attribute then -1 is returned
' 0 is returned if product exists in basket with this attribute but has no option value
' if option value exists then the maximum integer value is returned
LPostalTubeMaxLength = GetAttributeInBasketMaxOptionValue("Requires Postal Tube")
' (SS,25/7/17) moved following lipo code here from priority setting code below, because we need to use it to calculate delivery
Dim LLiPo
LLiPo = GetAttributeInBasketCount("LiPo", "") > 0
' if at least one such item then add extra cost according to region
' (NS,12/3/13) Added ATotalWeight < 3000 parameter so charges are not added when sending a big box
' (NS, 4/7/13} Edited values, added LA code
' (NS 5/6/14) Changed weight opton to 1500g and changed logic
' (NS 27/8/15) Increased UK charges
' (SS,9/8/18) changed ATotalWeight <= 1500 to ATotalWeight < 1500
' (SS,30/4/21) changed all ATotalWeight below to LTotalWeight and ANormalDeliveryCost to LNormalDeliveryCost
If LTotalWeight < 1500 Then
If LPostalTubeMaxLength >= 0 Then 'reduce these ' (SS,25/17/17) changed from > 0 to >= 0
If ARegionCode = "UK" Or ARegionCode = "UK2" Then
LExtraDeliveryCost = 2.50 ' ex VAT - was 2.09
ElseIf ARegionCode = "EU" Or ARegionCode = "EU2" Then
LExtraDeliveryCost = 3.00 ' (SS,31/10/17) changed to 3.00 was incorrectly set to 1.92
ElseIf ARegionCode = "USA" Or ARegionCode = "RW" Or ARegionCode = "LA" Then
LExtraDeliveryCost = 3.70 ' (SS,31/10/17) was 3.50, changed to 3.70
End If
If LPostalTubeMaxLength >= 90 Then
If ARegionCode = "UK" Or ARegionCode = "UK2" Then
LExtraDeliveryCost = 6.49 ' ex VAT - was 2.09, 4.34, 5.29, changed to 6.49 (from 5.29) on 20/11/18 (SS&NS)
ElseIf ARegionCode = "EU" Or ARegionCode = "EU2" or ARegionCode = "EU3" Then
LExtraDeliveryCost = 15.00
ElseIf ARegionCode = "USA" Or ARegionCode = "RW" Then
LExtraDeliveryCost = 30.00
ElseIf ARegionCode = "LA" Then
LExtraDeliveryCost = 10.00 'don't need add much for this region as it is sent by courier anyway
End If
End If
End If ' (SS,25/17/17) added End If to separate ElseIf LPostalTubeMaxLength = 0 into separate calc for Lipo delivery below
' (NS 5/6/14 added short courier opton. No Length opton required. Use for products that needs to be sent by courier always, eg LiPos.
' Remember to update the {LiPost} token text if these prices are changed.
'ElseIf LPostalTubeMaxLength = 0 Then
' (SS,25/7/17) replaced above ElseIf with If LLipo and replaced LExtraDeliveryCost with LExtraLipoDeliveryCost
Dim LExtraLipoDeliveryCost' (SS,25/7/17)
If LLipo Then
If ARegionCode = "UK" Then
LExtraLipoDeliveryCost = 2.30 ' ex VAT (SS,25/7/17) changed from 1.10 to 2.30
ElseIf ARegionCode = "UK2" Or ARegionCode = "EU" Or ARegionCode = "EU2" or ARegionCode = "EU3" Then
LExtraLipoDeliveryCost = 11.00
ElseIf ARegionCode = "USA" Or ARegionCode = "RW" Then 'don't need OR ARegionCode = "LA" as this region is sent by courier anyway
LExtraLipoDeliveryCost = 24.00
End If
Else ' i.e. no Lipo
LExtraLipoDeliveryCost = 0
End If
' (SS,25/7/17) set extra delivery cost to whichever is the greater lipo or postal tube
LExtraDeliveryCost = Max(LExtraDeliveryCost, LExtraLipoDeliveryCost)
End If
' (SS,11/7/22)
If SHOW_DEBUG_INFO Then
Response.Write "*** Extra ***" & BR
Response.Write "ExtraDeliveryCost before Uplift: " & LExtraDeliveryCost & BR
End If
' Add 1% of the basket value to the delivery cost if the delivery address is RW or USA or LA
' (SS,2/11/12) added "LExtraDeliveryCost > 0" so that adhoc sales have no delivery, i.e. if there's no extra delivery then don't increase it
' (SS,16/11/12) removed LExtraDeliveryCost > 0 because it's incorrect, we're changing extra 2% of the total value, added - AValueOfNonWeightedGoods to remove the ad hoc items
' (NS, 18/8/16) changed from 2% to 1% uplift
Dim LDeliveryAdditionForRW_USA_LA ' (SS,15/11/22)
If ARegionCode = "USA" Or ARegionCode = "RW" Or ARegionCode = "LA" then ' (NS 5/6/14) added OR LA
' LExtraDeliveryCost = LExtraDeliveryCost + (ATotalValue - AValueOfNonWeightedGoods) * 0.01 ' add 1% (was 2%)
' (SS,15/11/22) replaced above with following
LDeliveryAdditionForRW_USA_LA = Round2dp((ATotalValue - AValueOfNonWeightedGoods) * 0.01) ' add 1% (was 2%)
LExtraDeliveryCost = LExtraDeliveryCost + LDeliveryAdditionForRW_USA_LA
End If
' (SS,11/7/22)
If SHOW_DEBUG_INFO Then
Response.Write "ExtraDeliveryCost after Uplift: " & LExtraDeliveryCost & BR
Response.Write "*** DEBUG END ***" & BR & BR
End If
' ========== START OF DELIVERY OPTION ==========
' (SS,28/6/18) add addition cost for Tracked Delivery, set the DeliveryOption, don't allow option to be changed for certain countries
' if order value >= 200 then tracking always ticked and no extra cost
' if value below 200 then allow ticking and charge extra if ticked
' for certain countries i.e. Russia, Ukraine, Turkey, South Africa, Latin America, always tick and don't allow unticking
Dim LTrackedDelivery, LTrackedDeliverySelectionAllowed, LAlwaysTracked
LTrackedDelivery = False
LTrackedDeliverySelectionAllowed = True
' (SS,22/4/21)
Dim LExpeditedDelivery, LExpeditedDeliverySelectionAllowed
LExpeditedDelivery = False
LExpeditedDeliverySelectionAllowed = True
' (SS,22/4/21) expedited not allowed in UK
If ARegionCode = "UK" Or ARegionCode = "UK2" Then
LExpeditedDeliverySelectionAllowed = False
End If
Dim LUntrackedDeliverySelectionAllowed
LUntrackedDeliverySelectionAllowed = True
' get from user selection
LTrackedDelivery = GetTrackedDeliverySelected
LExpeditedDelivery = GetExpeditedDeliverySelected
' (SS,26/4/21) if expedited selected and not allowed then default to tracked
If LExpeditedDelivery And Not LExpeditedDeliverySelectionAllowed Then
LTrackedDelivery = True
SetTrackedDeliverySelected True
LExpeditedDelivery = False
SetExpeditedDeliverySelected False
End If
' (SS,9/8/18) added Or ATotalWeight >= 1500 to force tracked when weight is over 1500g
If ATotalValue >= 200 Or LTotalWeight >= 1500 Then
LTrackedDelivery = True
SetTrackedDeliverySelected True' (SS,26/4/21) to make sure untracked isn't selected
' LTrackedDeliverySelectionAllowed = False
LUntrackedDeliverySelectionAllowed = False ' (SS,22/4/21) replaces above
Else ' less than 200
LAlwaysTracked = GetCountryOptions(ACountry) = "T"
If LAlwaysTracked Then
LTrackedDelivery = True
SetTrackedDeliverySelected True' (SS,26/4/21)
' LTrackedDeliverySelectionAllowed = False
LUntrackedDeliverySelectionAllowed = False ' (SS,22/4/21) replaces above, i.e. allows tracked and expedited
Else
' get from user selection
LTrackedDelivery = GetTrackedDeliverySelected
End If
' extra delivery cost for tracked delivery
' (SS,9/8/18) modified from 4.17 (5.00 inc VAT) to 5.42 (6.50 inc VAT)
' (SS,26/4/21) added Or LExpeditedDelivery because this extra delivery is also added for expedited for multiply by a factor later
If LTrackedDelivery Or LExpeditedDelivery Then LExtraDeliveryCost = LExtraDeliveryCost + 5.42 ' (i.e. 6.50 inc VAT)
End If
' (SS,22/4/21) for expedited add 30% more, later changed to 75% more
If LExpeditedDelivery Then LExtraDeliveryCost = LExtraDeliveryCost + Round2dp((LNormalDeliveryCost + LExtraDeliveryCost) * 0.75)
' (SS,22/4/21) if expedited allowed then allow tracked selection too
If LExpeditedDeliverySelectionAllowed Then LTrackedDeliverySelectionAllowed = True
' (SS,22/4/21) added expedited
' (SS,29/4/21) removed " Delivery" from end of "Tracked" and "Expedited"
' (SS,11/6/21) fixed bug where Tracked was overriding Expedited, we want Expedited to override Tracked, fixed by swapping the if so LExpeditedDelivery is before LTrackedDelivery
If LExpeditedDelivery Then
SetDeliveryOption "Expedited"
LTrackedDelivery = False ' (SS,11/6/21) added this to ensure "Expedited" is overriden later, i.e. we can't have both Expedited and Tracked
ElseIf LTrackedDelivery Then
SetDeliveryOption "Tracked"
Else
' (SS,29/4/21) changed from "" to "Untracked", value can also be "Collection" when customer choses to collect
' when that occurs delivery cost is set 0 and this function isn't called
SetDeliveryOption "Untracked"
End If
' set the values for the checkbox
SetTrackedDeliverySelected LTrackedDelivery
SetTrackedDeliverySelectionAllowed LTrackedDeliverySelectionAllowed
' (SS,22/4/21)
SetUntrackedDeliverySelectionAllowed LUntrackedDeliverySelectionAllowed
SetExpeditedDeliverySelected LExpeditedDelivery
SetExpeditedDeliverySelectionAllowed LExpeditedDeliverySelectionAllowed
' ========== END OF DELIVERY OPTION ==========
' ========== START OF SET PRIORITY ==========
' (SS,1/12/16) Set priority
' (SS,2/2/18) added courier or air mail comments for 7, 8, 9 after discussing with Deborah
' 9 - weight > 2 kg (courier)
' 8 - weight > 1 kg (courier (uk) or air mail (might be tracked))
' 7 - value >= £400 (8/3/17 exc VAT) (courier)
' 6 - postal tube > 88 or LiPo
' 5 - inc postal upgrade
' 4 - UK & value > £200
' 3 - Non-UK & value >= £200 (2/11/17 added = and now inc VAT)
' 2 - UK low value
' 1 - non-UK low value
' 0 - collecting
' (SS,25/7/17) Lipo attribute code moved from here to delivery cost above
' (SS,2/11/17) Changed priority 3 to "=" and inc VAT
' (SS,16/7/18) added "Or LTrackedDelivery" to set priority to 4 for UK or 3 for non0Uk if tracked
' (SS,15/2/19) Priority 7, changed to use grand total value not excluding VAT Value (requested by Deborah)
Dim LPriority, LIncPostalUpgrade
LIncPostalUpgrade = GetAttributeInBasketCount("Postal Upgrade", "") > 0
'Response.Write "###TotalValue: " & ATotalValue & "###VATContent: " & AVATContent & BR ' ***
' (SS,8/3/17) adjusted ATotalValue by removing VAT from it
Dim LTotalValueExcVAT
LTotalValueExcVAT = ATotalValue - AVATContent
' (SS,9/8/18) added = to ATotalWeight > 2000 and ATotalWeight > 1000
' (SS,11/6/21) also set priority of 9 if expedited chosen
If LTotalWeight >= 2000 Or LExpeditedDelivery Then
LPriority = 9
ElseIf LTotalWeight >= 1000 Then
LPriority = 8
ElseIf ATotalValue >= 400 Then ' (SS,2/2/18 added =) ' (SS,15/2/19) Changed LTotalValueExcVAT to ATotalValue, requested by Deborah
LPriority = 7
ElseIf LPostalTubeMaxLength > 88 Or LLiPo Then
LPriority = 6
ElseIf LIncPostalUpgrade Or LExpeditedDelivery Then ' (SS,22/4/21) added Or LExpeditedDelivery, i.e. if expedited then ensure at least 5
LPriority = 5
ElseIf ARegionCode = "UK" Or ARegionCode = "UK2" Then
' (SS,16/7/18) added Or LTrackedDelivery
If ATotalValue >= 200 Or LTrackedDelivery Then ' (SS,26/1/18) changed from LTotalValueExcVAT to ATotalValue, also > to >= as requested by Deborah
LPriority = 4
Else
LPriority = 2
End If
Else ' non-UK
' (SS,16/7/18) added Or LTrackedDelivery
If ATotalValue >= 200 Or LTrackedDelivery Then ' (SS,2/10/17) changed from LTotalValueExcVAT > 200 to ATotalValue >= 200 as requested by Deborah
LPriority = 3
Else
LPriority = 1
End If
End If
SetPriority LPriority
' (SS,1/7/21) added following for debugging purposes to investigate cause of wrong priority sometimes being set, e.g. UK order being set to priority 1
CustomAddPriorityLog LPriority, APostcode, ARegionCode, ADeliveryRegion, ACountry, ATotalValue, LTotalWeight, ATotalItems, LNormalDeliveryCost, LExtraDeliveryCost, GetDeliveryOption
' ========== END OF SET PRIORITY ==========
' VAT is added later to delivery, prices above include VAT, so we remove the VAT from the extra
' CustomGetDelivery = Round2dp(ANormalDeliveryCost + (LExtraDeliveryCost / (1 + GetVATRate)))
CustomGetDeliveryOriginal = Round2dp(LNormalDeliveryCost + LExtraDeliveryCost) ' decided to add ex VAT cost
' (SS,15/11/22) for debugging (ANormalDelivery, AExtraDelivery, ADeliveryAdditionForRW_USA_LA, AMaxPackagedWeight, ATrackedDelivery, AExpeditedDelivery))
CustomShowSetDeliveryVars LNormalDeliveryCost, LExtraDeliveryCost, LDeliveryAdditionForRW_USA_LA, "", LTrackedDelivery, LExpeditedDelivery
End Function
%>