2449382; #--------------------------------------------------------------- my $pMessageList = [ 'The shipping price is formatted incorrectly. It should be formatted like %s.', 'The shipping price is too large. The price must be less than %s.', 'The shipping price is too small. The price must be greater than or equal to %s.', 'The class/location combination you selected were invalid. Please check and re-enter your selection.', 'The catalog shipping database does not have any shipping options defined for this location. Please contact us directly with your order.', 'Free Shipping', 'Standard Shipping', 'Your order has exceeded the shipping tables defined by the supplier, therefore it is not possible to calculate the shipping cost. Please contact the supplier with this information as they will be happy to process your order and will then be able to correct the shipping tables.
Thank you.', 'Please enter a shipping cost.', 'Please select a state or province.', ]; my %ZoneTable = ( "UK" => { "UndefinedRegion" => [1], }, "US" => { "UndefinedRegion" => [9], "US.AL" => [9], "US.AK" => [9], "US.AS" => [9], "US.AZ" => [9], "US.AR" => [9], "US.CA" => [9], "US.CO" => [9], "US.CT" => [9], "US.DE" => [9], "US.DC" => [9], "US.FL" => [9], "US.GA" => [9], "US.GU" => [9], "US.HI" => [9], "US.ID" => [9], "US.IL" => [9], "US.IN" => [9], "US.IA" => [9], "US.KS" => [9], "US.KY" => [9], "US.LA" => [9], "US.ME" => [9], "US.MH" => [9], "US.MD" => [9], "US.MA" => [9], "US.MI" => [9], "US.FM" => [9], "US.MN" => [9], "US.MS" => [9], "US.MO" => [9], "US.MT" => [9], "US.MP" => [9], "US.NE" => [9], "US.NV" => [9], "US.NH" => [9], "US.NJ" => [9], "US.NM" => [9], "US.NY" => [9], "US.NC" => [9], "US.ND" => [9], "US.OH" => [9], "US.OK" => [9], "US.OR" => [9], "US.PW" => [9], "US.PA" => [9], "US.PR" => [9], "US.RI" => [9], "US.SC" => [9], "US.SD" => [9], "US.TN" => [9], "US.TX" => [9], "US.TT" => [9], "US.UT" => [9], "US.VT" => [9], "US.VI" => [9], "US.VA" => [9], "US.WA" => [9], "US.WV" => [9], "US.WI" => [9], "US.WY" => [9], }, "AF" => { "UndefinedRegion" => [9], }, "AL" => { "UndefinedRegion" => [9], }, "DZ" => { "UndefinedRegion" => [9], }, "AD" => { "UndefinedRegion" => [9], }, "AO" => { "UndefinedRegion" => [9], }, "AI" => { "UndefinedRegion" => [9], }, "AQ" => { "UndefinedRegion" => [9], }, "AG" => { "UndefinedRegion" => [9], }, "AR" => { "UndefinedRegion" => [9], }, "AM" => { "UndefinedRegion" => [9], }, "AW" => { "UndefinedRegion" => [9], }, "AU" => { "UndefinedRegion" => [9], }, "AT" => { "UndefinedRegion" => [8], }, "AZ" => { "UndefinedRegion" => [9], }, "BS" => { "UndefinedRegion" => [9], }, "BH" => { "UndefinedRegion" => [9], }, "BD" => { "UndefinedRegion" => [9], }, "BB" => { "UndefinedRegion" => [9], }, "BY" => { "UndefinedRegion" => [9], }, "BE" => { "UndefinedRegion" => [8], }, "BZ" => { "UndefinedRegion" => [9], }, "BJ" => { "UndefinedRegion" => [9], }, "BM" => { "UndefinedRegion" => [9], }, "BT" => { "UndefinedRegion" => [9], }, "BO" => { "UndefinedRegion" => [9], }, "BA" => { "UndefinedRegion" => [9], }, "BW" => { "UndefinedRegion" => [9], }, "BV" => { "UndefinedRegion" => [9], }, "BR" => { "UndefinedRegion" => [9], }, "IO" => { "UndefinedRegion" => [9], }, "BN" => { "UndefinedRegion" => [9], }, "BG" => { "UndefinedRegion" => [9], }, "BF" => { "UndefinedRegion" => [9], }, "BU" => { "UndefinedRegion" => [9], }, "BI" => { "UndefinedRegion" => [9], }, "KH" => { "UndefinedRegion" => [9], }, "CM" => { "UndefinedRegion" => [9], }, "CV" => { "UndefinedRegion" => [9], }, "KY" => { "UndefinedRegion" => [9], }, "CF" => { "UndefinedRegion" => [9], }, "TD" => { "UndefinedRegion" => [9], }, "CL" => { "UndefinedRegion" => [9], }, "CN" => { "UndefinedRegion" => [9], }, "CX" => { "UndefinedRegion" => [9], }, "CC" => { "UndefinedRegion" => [9], }, "CO" => { "UndefinedRegion" => [9], }, "KM" => { "UndefinedRegion" => [9], }, "CG" => { "UndefinedRegion" => [9], }, "CK" => { "UndefinedRegion" => [9], }, "CR" => { "UndefinedRegion" => [9], }, "CI" => { "UndefinedRegion" => [9], }, "HR" => { "UndefinedRegion" => [9], }, "CU" => { "UndefinedRegion" => [9], }, "CY" => { "UndefinedRegion" => [9], }, "CZ" => { "UndefinedRegion" => [9], }, "DK" => { "UndefinedRegion" => [8], }, "DJ" => { "UndefinedRegion" => [9], }, "DM" => { "UndefinedRegion" => [9], }, "DO" => { "UndefinedRegion" => [9], }, "TP" => { "UndefinedRegion" => [9], }, "EC" => { "UndefinedRegion" => [9], }, "EG" => { "UndefinedRegion" => [9], }, "SV" => { "UndefinedRegion" => [9], }, "GQ" => { "UndefinedRegion" => [9], }, "ER" => { "UndefinedRegion" => [9], }, "EE" => { "UndefinedRegion" => [9], }, "ET" => { "UndefinedRegion" => [9], }, "FK" => { "UndefinedRegion" => [9], }, "FO" => { "UndefinedRegion" => [9], }, "FJ" => { "UndefinedRegion" => [9], }, "FI" => { "UndefinedRegion" => [8, 9], }, "FR" => { "UndefinedRegion" => [8], }, "GF" => { "UndefinedRegion" => [9], }, "PF" => { "UndefinedRegion" => [9], }, "TF" => { "UndefinedRegion" => [9], }, "GA" => { "UndefinedRegion" => [9], }, "GM" => { "UndefinedRegion" => [9], }, "GE" => { "UndefinedRegion" => [9], }, "DE" => { "UndefinedRegion" => [8], }, "GH" => { "UndefinedRegion" => [9], }, "GI" => { "UndefinedRegion" => [9], }, "GR" => { "UndefinedRegion" => [8], }, "GL" => { "UndefinedRegion" => [9], }, "GD" => { "UndefinedRegion" => [9], }, "GP" => { "UndefinedRegion" => [9], }, "GU" => { "UndefinedRegion" => [9], }, "GT" => { "UndefinedRegion" => [9], }, "GN" => { "UndefinedRegion" => [9], }, "GW" => { "UndefinedRegion" => [9], }, "GY" => { "UndefinedRegion" => [9], }, "HT" => { "UndefinedRegion" => [9], }, "HM" => { "UndefinedRegion" => [9], }, "HN" => { "UndefinedRegion" => [9], }, "HK" => { "UndefinedRegion" => [9], }, "HU" => { "UndefinedRegion" => [9], }, "IS" => { "UndefinedRegion" => [9], }, "IN" => { "UndefinedRegion" => [9], }, "ID" => { "UndefinedRegion" => [9], }, "IR" => { "UndefinedRegion" => [9], }, "IQ" => { "UndefinedRegion" => [9], }, "IE" => { "UndefinedRegion" => [9], }, "IL" => { "UndefinedRegion" => [9], }, "IT" => { "UndefinedRegion" => [8], }, "JM" => { "UndefinedRegion" => [9], }, "JP" => { "UndefinedRegion" => [9], }, "JO" => { "UndefinedRegion" => [9], }, "KZ" => { "UndefinedRegion" => [9], }, "KE" => { "UndefinedRegion" => [9], }, "KI" => { "UndefinedRegion" => [9], }, "KP" => { "UndefinedRegion" => [9], }, "KR" => { "UndefinedRegion" => [9], }, "KW" => { "UndefinedRegion" => [9], }, "KG" => { "UndefinedRegion" => [9], }, "LA" => { "UndefinedRegion" => [9], }, "LV" => { "UndefinedRegion" => [9], }, "LB" => { "UndefinedRegion" => [9], }, "LS" => { "UndefinedRegion" => [9], }, "LR" => { "UndefinedRegion" => [9], }, "LY" => { "UndefinedRegion" => [9], }, "LI" => { "UndefinedRegion" => [9], }, "LT" => { "UndefinedRegion" => [9], }, "LU" => { "UndefinedRegion" => [8], }, "MO" => { "UndefinedRegion" => [9], }, "MK" => { "UndefinedRegion" => [9], }, "MG" => { "UndefinedRegion" => [9], }, "MW" => { "UndefinedRegion" => [9], }, "MY" => { "UndefinedRegion" => [9], }, "MV" => { "UndefinedRegion" => [9], }, "ML" => { "UndefinedRegion" => [9], }, "MT" => { "UndefinedRegion" => [9], }, "MH" => { "UndefinedRegion" => [9], }, "MQ" => { "UndefinedRegion" => [9], }, "MR" => { "UndefinedRegion" => [9], }, "MU" => { "UndefinedRegion" => [9], }, "YT" => { "UndefinedRegion" => [9], }, "MX" => { "UndefinedRegion" => [9], }, "FM" => { "UndefinedRegion" => [9], }, "MD" => { "UndefinedRegion" => [9], }, "MC" => { "UndefinedRegion" => [9], }, "MN" => { "UndefinedRegion" => [9], }, "MS" => { "UndefinedRegion" => [9], }, "MA" => { "UndefinedRegion" => [9], }, "MZ" => { "UndefinedRegion" => [9], }, "MM" => { "UndefinedRegion" => [9], }, "NA" => { "UndefinedRegion" => [9], }, "NR" => { "UndefinedRegion" => [9], }, "NP" => { "UndefinedRegion" => [9], }, "NL" => { "UndefinedRegion" => [8], }, "AN" => { "UndefinedRegion" => [9], }, "NC" => { "UndefinedRegion" => [9], }, "NZ" => { "UndefinedRegion" => [9], }, "NI" => { "UndefinedRegion" => [9], }, "NE" => { "UndefinedRegion" => [9], }, "NG" => { "UndefinedRegion" => [9], }, "NU" => { "UndefinedRegion" => [9], }, "NF" => { "UndefinedRegion" => [9], }, "MP" => { "UndefinedRegion" => [9], }, "NO" => { "UndefinedRegion" => [9], }, "OM" => { "UndefinedRegion" => [9], }, "PK" => { "UndefinedRegion" => [9], }, "PW" => { "UndefinedRegion" => [9], }, "PA" => { "UndefinedRegion" => [9], }, "PG" => { "UndefinedRegion" => [9], }, "PY" => { "UndefinedRegion" => [9], }, "PE" => { "UndefinedRegion" => [9], }, "PH" => { "UndefinedRegion" => [9], }, "PN" => { "UndefinedRegion" => [9], }, "PL" => { "UndefinedRegion" => [9], }, "PT" => { "UndefinedRegion" => [8], }, "PR" => { "UndefinedRegion" => [9], }, "QA" => { "UndefinedRegion" => [9], }, "RE" => { "UndefinedRegion" => [9], }, "RO" => { "UndefinedRegion" => [9], }, "RU" => { "UndefinedRegion" => [9], }, "RW" => { "UndefinedRegion" => [9], }, "GS" => { "UndefinedRegion" => [9], }, "KN" => { "UndefinedRegion" => [9], }, "LC" => { "UndefinedRegion" => [9], }, "VC" => { "UndefinedRegion" => [9], }, "WS" => { "UndefinedRegion" => [9], }, "SM" => { "UndefinedRegion" => [9], }, "ST" => { "UndefinedRegion" => [9], }, "SA" => { "UndefinedRegion" => [9], }, "SN" => { "UndefinedRegion" => [9], }, "SC" => { "UndefinedRegion" => [9], }, "SL" => { "UndefinedRegion" => [9], }, "SG" => { "UndefinedRegion" => [9], }, "SK" => { "UndefinedRegion" => [9], }, "SI" => { "UndefinedRegion" => [9], }, "Sb" => { "UndefinedRegion" => [9], }, "SO" => { "UndefinedRegion" => [9], }, "ZA" => { "UndefinedRegion" => [9], }, "ES" => { "UndefinedRegion" => [8], }, "LK" => { "UndefinedRegion" => [9], }, "SH" => { "UndefinedRegion" => [9], }, "PM" => { "UndefinedRegion" => [9], }, "SD" => { "UndefinedRegion" => [9], }, "SR" => { "UndefinedRegion" => [9], }, "SJ" => { "UndefinedRegion" => [9], }, "SZ" => { "UndefinedRegion" => [9], }, "SE" => { "UndefinedRegion" => [8], }, "CH" => { "UndefinedRegion" => [9], }, "SY" => { "UndefinedRegion" => [9], }, "TW" => { "UndefinedRegion" => [9], }, "TJ" => { "UndefinedRegion" => [9], }, "TZ" => { "UndefinedRegion" => [9], }, "TH" => { "UndefinedRegion" => [9], }, "TG" => { "UndefinedRegion" => [9], }, "TK" => { "UndefinedRegion" => [9], }, "TO" => { "UndefinedRegion" => [9], }, "TT" => { "UndefinedRegion" => [9], }, "TN" => { "UndefinedRegion" => [9], }, "TR" => { "UndefinedRegion" => [9], }, "TM" => { "UndefinedRegion" => [9], }, "TC" => { "UndefinedRegion" => [9], }, "TV" => { "UndefinedRegion" => [9], }, "UG" => { "UndefinedRegion" => [9], }, "UA" => { "UndefinedRegion" => [9], }, "AE" => { "UndefinedRegion" => [9], }, "UY" => { "UndefinedRegion" => [9], }, "UM" => { "UndefinedRegion" => [9], }, "UZ" => { "UndefinedRegion" => [9], }, "VU" => { "UndefinedRegion" => [9], }, "VA" => { "UndefinedRegion" => [9], }, "VE" => { "UndefinedRegion" => [9], }, "VN" => { "UndefinedRegion" => [9], }, "VG" => { "UndefinedRegion" => [9], }, "VI" => { "UndefinedRegion" => [9], }, "WF" => { "UndefinedRegion" => [9], }, "EH" => { "UndefinedRegion" => [9], }, "YE" => { "UndefinedRegion" => [9], }, "YU" => { "UndefinedRegion" => [9], }, "ZR" => { "UndefinedRegion" => [9], }, "ZM" => { "UndefinedRegion" => [9], }, "ZW" => { "UndefinedRegion" => [9], }, ); my %ShippingTable = ( 11 => { 1 => [ {"ExcessAction" => 'AddFurther', "IncrementalWeight" => 1.000000, "IncrementalCharge" => 95}, { "wt" =>1, "cost" =>350}, { "wt" =>2, "cost" =>500}, { "wt" =>3, "cost" =>690}, { "wt" =>4, "cost" =>690}, { "wt" =>5, "cost" =>795}, { "wt" =>6, "cost" =>795}, { "wt" =>7, "cost" =>795}, { "wt" =>8, "cost" =>975}, { "wt" =>9, "cost" =>975}, { "wt" =>10, "cost" =>975}, ], }, 12 => { 8 => [ {"ExcessAction" => 'AddFurther', "IncrementalWeight" => 1.000000, "IncrementalCharge" => 190}, { "wt" =>1, "cost" =>675}, { "wt" =>2, "cost" =>690}, { "wt" =>3, "cost" =>890}, { "wt" =>4, "cost" =>890}, { "wt" =>5, "cost" =>1090}, { "wt" =>6, "cost" =>1090}, { "wt" =>7, "cost" =>1090}, { "wt" =>8, "cost" =>1490}, { "wt" =>9, "cost" =>1490}, { "wt" =>10, "cost" =>1490}, ], 9 => [ {"ExcessAction" => 'AddFurther', "IncrementalWeight" => 1.000000, "IncrementalCharge" => 200}, { "wt" =>1, "cost" =>79000}, { "wt" =>2, "cost" =>890}, { "wt" =>3, "cost" =>1290}, { "wt" =>4, "cost" =>1290}, { "wt" =>5, "cost" =>1650}, { "wt" =>6, "cost" =>1650}, { "wt" =>7, "cost" =>1650}, { "wt" =>8, "cost" =>2450}, { "wt" =>9, "cost" =>2450}, { "wt" =>10, "cost" =>2450}, ] } ); my ($DefaultWeight, $ShippingBasis, $SimpleCost, $UnknownRegion, $UnknownRegionCost, $WaiveCharges, $WaiveThreshold); $DefaultWeight = 0.06; $ShippingBasis = 'Quantity'; $UnknownRegion = 'Error'; $UnknownRegionCost = 300; $WaiveCharges = 'No'; $WaiveThreshold = 100000.000000; my %ClassTable = ( 11 => "Royal Mail", 12 => "Swift Air" ); my $nHandlingCharge = 0; my $nHandlingProportion = 0; my %ParentZoneTable = ( "US" => [], "CA" => [], ); use strict; no strict 'refs'; my $UNDEFINED = 'UndefinedRegion'; %::s_Ship_nShippingStatus = (); %::s_Ship_sShippingError = (); %::s_Ship_PreliminaryInfoVariables = (); %::s_Ship_ShippingVariables = (); $::s_Ship_bPrelimIsHidden = $::FALSE; $::s_Ship_bShipPhaseIsHidden = $::FALSE; $::s_Ship_sShippingDescription = ''; $::s_Ship_sHandlingDescription = ''; # not used in this plug-in $::s_Ship_sShippingCountryName = ''; $::s_Ship_nShipCharges = 0; $::s_Ship_nShippingStatus{GetHandlingDescription} = $::SUCCESS; $::s_Ship_sShippingError{GetHandlingDescription} = ''; my @Response = ValidatePreliminaryInput(); $::s_Ship_nShippingStatus{ValidatePreliminaryInput} = $Response[0]; $::s_Ship_sShippingError{ValidatePreliminaryInput} = $Response[1]; @Response = ValidateFinalInput(); $::s_Ship_nShippingStatus{ValidateFinalInput} = $Response[0]; $::s_Ship_sShippingError{ValidateFinalInput} = $Response[1]; @Response = RestoreFinalUI(); $::s_Ship_nShippingStatus{RestoreFinalUI} = $Response[0]; $::s_Ship_sShippingError{RestoreFinalUI} = $Response[1]; @Response = CalculateShipping(); $::s_Ship_nShippingStatus{CalculateShipping} = $Response[0]; $::s_Ship_sShippingError{CalculateShipping} = $Response[1]; @Response = IsFinalPhaseHidden(); $::s_Ship_nShippingStatus{IsFinalPhaseHidden} = $Response[0]; $::s_Ship_sShippingError{IsFinalPhaseHidden} = $Response[1]; @Response = GetShippingDescription(); $::s_Ship_nShippingStatus{GetShippingDescription} = $Response[0]; $::s_Ship_sShippingError{GetShippingDescription} = $Response[1]; @Response = CalculateHandling(); $::s_Ship_nShippingStatus{CalculateHandling} = $Response[0]; $::s_Ship_sShippingError{CalculateHandling} = $Response[1]; return($::SUCCESS); sub ValidatePreliminaryInput { if ($ShippingBasis eq 'Simple') { return($::SUCCESS, undef); } if ($::s_sDeliveryRegionCode eq "" || $::s_sDeliveryRegionCode eq $UNDEFINED) { if (defined $ParentZoneTable{$::s_sDeliveryCountryCode} && $#{$ParentZoneTable{$::s_sDeliveryCountryCode}} == -1) { return ($::FAILURE, $$pMessageList[9]); } } my @bands = GetBands(); if ($#bands < 0 && $UnknownRegion ne 'Default') { return($::FAILURE, $$pMessageList[4]); } my ($j, $bFound); $bFound = $::FALSE; OUT: for $j (0 .. $#bands) { my ($Class, $pBandList); while ( ($Class, $pBandList) = each %ShippingTable) { if( defined ${$pBandList}{$bands[$j]} ) { my @costs = @ { ${$pBandList}{$bands[$j]} }; if ($#costs > 0) { $bFound = $::TRUE; last OUT; } } } } my ($Temp); $Temp = keys %ShippingTable; if (!$bFound && $UnknownRegion ne 'Default') { return($::FAILURE, $$pMessageList[3]); } my ($status, $sMessage, %ShipData, @listTemp); ($status, $sMessage, @listTemp) = UnpackData(); if ($status != $::SUCCESS) { return($status, $sMessage); } if ($#listTemp > -1) { %ShipData = @listTemp; } if (exists $ShipData{ShippingZone}) { my $nZoneID; my $bFoundZone = $::FALSE; foreach $nZoneID (@bands) { if ($ShipData{ShippingZone} == $nZoneID) { $bFoundZone = $::TRUE; last; } } if (!$bFoundZone) { undef $::s_Ship_sOpaqueShipData; } } return($::SUCCESS, undef); } sub ValidateFinalInput { if ($ShippingBasis eq 'Simple') { my (@Response); if ($::g_InputHash{SHIPPING}) { $::g_InputHash{SHIPPING} =~ s/^\s*(.*?)\s*$/$1/gs; } if (defined $::g_InputHash{SHIPPING}) { my $sText = (0 == length $::g_InputHash{SHIPPING}) ? ' ' : $::g_InputHash{SHIPPING}; $::s_Ship_sOpaqueShipData = sprintf("Simple;Error-%s;", $sText); } if (!defined $::g_InputHash{'SHIPPING'} ||# if the shipping is undefined, error out length $::g_InputHash{'SHIPPING'} == 0) { return($::FAILURE, $$pMessageList[8]); } @Response = ActinicOrder::ReadPrice($::g_InputHash{SHIPPING}, \%::s_Ship_PriceFormatBlob); if ($Response[0] != $::SUCCESS || $Response[2] != int $Response[2]) { @Response = ActinicOrder::FormatSinglePrice(10000, $::FALSE, \%::s_Ship_PriceFormatBlob); if ($Response[0] != $::SUCCESS) { return($Response[0], $Response[1]); } return($::FAILURE, sprintf($$pMessageList[0], $Response[2])); } my ($nMaxShipping) = 99999999; if ($Response[2] >= $nMaxShipping) { @Response = ActinicOrder::FormatPrice($nMaxShipping, $::TRUE, \%::s_Ship_PriceFormatBlob); if ($Response[0] != $::SUCCESS) { return($Response[0], $Response[1]); } return($::FAILURE, sprintf($$pMessageList[1], $Response[2])); } my ($nMinShipping) = 0; if ($Response[2] < $nMinShipping) { @Response = ActinicOrder::FormatPrice($nMinShipping, $::TRUE, \%::s_Ship_PriceFormatBlob); if ($Response[0] != $::SUCCESS) { return($Response[0], $Response[1]); } return($::FAILURE, sprintf($$pMessageList[2], $Response[2])); } if (defined $::g_InputHash{SHIPPING}) { $::s_Ship_sOpaqueShipData = sprintf("Simple;%s;", $Response[2]); } return($::SUCCESS, undef); } my ($status, $sMessage, %ShipData); ($status, $sMessage, %ShipData) = UnpackData(); if ($status != $::SUCCESS) { return($status, $sMessage); } if (!defined $::s_sDeliveryCountryCode || !defined $::s_sDeliveryRegionCode) { return($::SUCCESS, undef); } if (!defined $::g_InputHash{'ShippingClass'}) { my ($status, $sMessage, $pOptionTitleList, $pOptionIDList) = FormatShippingOptions(%ShipData); if ($status != $::SUCCESS) { return($status, $sMessage); } if ($#{$pOptionIDList} == 0) { $::g_InputHash{'ShippingClass'} = ${$pOptionIDList}[0]; } } if ($::g_InputHash{'ShippingClass'} eq "") { return($::SUCCESS, undef); } my @bands = GetBands(); if ($#bands < 0 && $UnknownRegion ne 'Default') { return($::FAILURE, $$pMessageList[4]); } my @costs; my $j; my $nZoneID = -1; for $j (0 .. $#bands) { @costs = @ {$ShippingTable{$::g_InputHash{'ShippingClass'}}{$bands[$j]}}; if ($#costs > 0) { $nZoneID = $bands[$j]; last; } } $::s_Ship_sOpaqueShipData = sprintf("ShippingClass;%s;ShippingZone;%d;", $::g_InputHash{'ShippingClass'}, $nZoneID); if ($WaiveCharges eq 'Value') { if (CalculatePrice() > $WaiveThreshold) { return($::SUCCESS, undef); } } if ($#costs <= 0) { if ($UnknownRegion eq 'Default') { return($::SUCCESS, undef); } return($::FAILURE, $$pMessageList[3]); } my ($totalWeight); if ($ShippingBasis eq 'Quantity') { $totalWeight = CalculateQuantity(); } elsif ($ShippingBasis eq 'Price') { $totalWeight = CalculatePrice(); } else { $totalWeight = CalculateWeight(); } for $j (0 .. $#costs) { if ($costs[$j]{wt} >= $totalWeight) { return($::SUCCESS, undef); } } if ($costs[0]{'ExcessAction'} eq 'Highest' || $costs[0]{'ExcessAction'} eq 'AddFurther') { return($::SUCCESS, undef); } return($::FAILURE, $$pMessageList[7]); } sub UnpackData { my (@arglist); @arglist = split (';', $::s_Ship_sOpaqueShipData); return ($::SUCCESS, "", @arglist); } sub IsFinalPhaseHidden { my ($status, $sMessage, %ShipData); ($status, $sMessage, %ShipData) = UnpackData(); if ($status != $::SUCCESS) { return($status, $sMessage); } if ($ShippingBasis eq 'Simple') { return($::SUCCESS, undef); } my ($pOptionTitleList, $pOptionIDList); ($status, $sMessage, $pOptionTitleList, $pOptionIDList) = FormatShippingOptions(%ShipData); if ($status != $::SUCCESS) { return($status, $sMessage); } if ($#{$pOptionIDList} == 0) { my @bands = GetBands(); if ($#bands < 0 && $UnknownRegion ne 'Default') { return($::FAILURE, $$pMessageList[4]); } my @costs; my $j; my $nZoneID = -1; for $j (0 .. $#bands) { @costs = @ {$ShippingTable{${$pOptionIDList}[0]}{$bands[$j]}}; if ($#costs > 0) { $nZoneID = $bands[$j]; last; } } $::s_Ship_bShipPhaseIsHidden = $::TRUE; $::s_Ship_sOpaqueShipData = sprintf("ShippingClass;%s;ShippingZone;%d;", ${$pOptionIDList}[0], $nZoneID); } return($::SUCCESS, undef); } sub RestoreFinalUI { my ($status, $sMessage, %ShipData); ($status, $sMessage, %ShipData) = UnpackData(); if ($status != $::SUCCESS) { return($status, $sMessage); } if ($ShippingBasis eq 'Simple') { my (@Response); if (!defined $ShipData{'Simple'}) { @Response = ActinicOrder::FormatSinglePrice($SimpleCost, $::TRUE, \%::s_Ship_PriceFormatBlob); if ($Response[0] != $::SUCCESS) { return($Response[0], $Response[1]); } $::s_Ship_ShippingVariables{"NETQUOTEVAR:SHIPPINGVALUE"} = $Response[2]; } elsif($ShipData{'Simple'} =~ /Error-/) { $ShipData{'Simple'} =~ s/^Error-\s*(.*?)\s*$/$1/g; $::s_Ship_ShippingVariables{"NETQUOTEVAR:SHIPPINGVALUE"} = $ShipData{'Simple'}; } else { $ShipData{'Simple'} =~ s/^\s*(.*?)\s*$/$1/g; @Response = ActinicOrder::FormatSinglePrice($ShipData{'Simple'}, $::TRUE, \%::s_Ship_PriceFormatBlob); if ($Response[0] != $::SUCCESS) { return($Response[0], $Response[1]); } $::s_Ship_ShippingVariables{"NETQUOTEVAR:SHIPPINGVALUE"} = $Response[2]; } return($::SUCCESS, undef); } my ($pOptionTitleList, $pOptionIDList); ($status, $sMessage, $pOptionTitleList, $pOptionIDList) = FormatShippingOptions(%ShipData); if ($status != $::SUCCESS) { return($status, $sMessage); } my ($sShippingControl); my ($ClassID, $sOptionTitle, $nIndex); $nIndex = 0; if ($#{$pOptionIDList} == 0) { $sOptionTitle = ${$pOptionTitleList}[0]; $sShippingControl .= "$sOptionTitle\n"; } else { $sShippingControl = "\n"; } $::s_Ship_ShippingVariables{$::VARPREFIX . 'SHIPPINGSELECT'} = $sShippingControl; return($::SUCCESS, undef); } sub FormatShippingOptions { my (%ShipData) = @_; if ($ShippingBasis eq 'Simple') { return ($::SUCCESS, "", undef, undef); } if (defined @::s_FormattedShippingOptionList) { return ($::SUCCESS, "", \@::s_FormattedShippingOptionList, \@::s_AssociatedClassIDs); } my %ClassCostMap; my $bConstantCost = $::FALSE; my $nConstantCost = 0; my $nClassCount = 0; if ($WaiveCharges eq 'Value' && CalculatePrice() > $WaiveThreshold) { $bConstantCost = $::TRUE; } else { my @bands = GetBands(); if ($#bands < 0) { if ($UnknownRegion ne 'Default') { return($::FAILURE, $$pMessageList[4], undef, undef); } else { $bConstantCost = $::TRUE; $nConstantCost = $UnknownRegionCost; } } else { my $j; my %ValidClasses; for $j (0 .. $#bands) { my ($Class, $pBandList); while ( ($Class, $pBandList) = each %ShippingTable) { if( defined ${$pBandList}{$bands[$j]} ) { my @costs = @ {${$pBandList}{$bands[$j]}}; if ($#costs > 0) { $ValidClasses{$Class} = $::TRUE; } } } my ($Temp); $Temp = keys %ShippingTable; } $nClassCount = keys %ValidClasses; if ($nClassCount < 1) { if ($UnknownRegion ne 'Default') { return ($::FAILURE, $$pMessageList[3], undef, undef); } else { $bConstantCost = $::TRUE; $nConstantCost = $UnknownRegionCost; } } if (!$bConstantCost) { my ($totalWeight); if ($ShippingBasis eq 'Quantity') { $totalWeight = CalculateQuantity(); } elsif ($ShippingBasis eq 'Price') { $totalWeight = CalculatePrice(); } else { $totalWeight = CalculateWeight(); } my ($Class, $null); while ( ($Class, $null) = each %ValidClasses) { my @costs; my $j; for $j (0 .. $#bands) { @costs = @ {$ShippingTable{$Class}{$bands[$j]}}; if ($#costs > 0) { last; } } my $bFound = $::FALSE; my $nCost = 0; for $j (0 .. $#costs) { if ($costs[$j]{wt} >= $totalWeight && defined $costs[$j]{cost}) { $nCost = $costs[$j]{cost}; $bFound = $::TRUE; last; } } if (!$bFound) { if ($costs[0]{'ExcessAction'} eq 'Highest') { $nCost = $costs[$#costs]{cost}; $bFound = $::TRUE; } elsif ($costs[0]{'ExcessAction'} eq 'AddFurther') { my $extraWeight = $totalWeight - $costs[$#costs]{wt}; my ($dWeightIncrement, $nChargeIncrement) = ($costs[0]{'IncrementalWeight'}, $costs[0]{'IncrementalCharge'}); my ($nExtraUnits) = int ($extraWeight / $dWeightIncrement + 0.999); my $extraCharge = $nExtraUnits * $nChargeIncrement; $nCost = $costs[$#costs]{cost} + $extraCharge;# Take the biggest cost from the band + the extra $bFound = $::TRUE; } else { $nCost = 0; $bFound = $::FALSE; } } if ($bFound) { $ClassCostMap{$Class} = $nCost; } } $nClassCount = keys %ClassCostMap; if ($nClassCount < 1) { return ($::FAILURE, $$pMessageList[7], undef, undef); } } } } if ($bConstantCost) { if ($nConstantCost == 0) { push (@::s_FormattedShippingOptionList, $$pMessageList[5]); push (@::s_AssociatedClassIDs, 1); } else { if ($::s_Ship_bDisplayPrices) { my (@PriceResponse) = ActinicOrder::FormatPrice($nConstantCost, $::TRUE, \%::s_Ship_PriceFormatBlob); push (@::s_FormattedShippingOptionList, $$pMessageList[6] . " (" . $PriceResponse[2] . ")"); } else { push (@::s_FormattedShippingOptionList, $$pMessageList[6]); } push (@::s_AssociatedClassIDs, 1); } } else { my (@ClassIDs) = sort { $ClassCostMap{$a} <=> $ClassCostMap{$b} } keys %ClassCostMap; if ($nClassCount == 1) { my ($sClassName) = $ClassTable{$ClassIDs[0]}; if ($::s_Ship_bDisplayPrices) { my (@PriceResponse) = ActinicOrder::FormatPrice($ClassCostMap{$ClassIDs[0]}, $::TRUE, \%::s_Ship_PriceFormatBlob); push (@::s_FormattedShippingOptionList, "$sClassName (" . $PriceResponse[2] . ")"); } else { push (@::s_FormattedShippingOptionList, "$sClassName"); } push (@::s_AssociatedClassIDs, $ClassIDs[0]); } else { my ($ClassID, $sClassName); foreach $ClassID (@ClassIDs) { $sClassName = $ClassTable{$ClassID}; if ($::s_Ship_bDisplayPrices) { my (@PriceResponse) = ActinicOrder::FormatPrice($ClassCostMap{$ClassID}, $::TRUE, \%::s_Ship_PriceFormatBlob); push (@::s_FormattedShippingOptionList, "$sClassName (" . $PriceResponse[2] . ")"); } else { push (@::s_FormattedShippingOptionList, "$sClassName"); } push (@::s_AssociatedClassIDs, $ClassID); } } } return ($::SUCCESS, "", \@::s_FormattedShippingOptionList, \@::s_AssociatedClassIDs); } sub GetShippingDescription() { my ($status, $sMessage, %ShipData); ($status, $sMessage, %ShipData) = UnpackData(); if ($status != $::SUCCESS) { return($status, $sMessage); } my ($pOptionTitleList, $pOptionIDList); ($status, $sMessage, $pOptionTitleList, $pOptionIDList) = FormatShippingOptions(%ShipData); if ($status != $::SUCCESS) { return($status, $sMessage); } if ($#{$pOptionTitleList} == 0) { $::s_Ship_sShippingDescription = ${$pOptionTitleList}[0]; $::s_Ship_sShippingDescription =~ s/([^(]*).*/$1/; $::s_Ship_sShippingDescription =~ s/\s*$//; } else { $::s_Ship_sShippingDescription = $ClassTable{$ShipData{'ShippingClass'}}; } return($::SUCCESS, undef); } sub CalculateShipping() { my ($status, $sMessage, %ShipData); ($status, $sMessage, %ShipData) = UnpackData(); if ($status != $::SUCCESS) { return($status, $sMessage); } if ($ShippingBasis eq 'Simple') { if (!defined $ShipData{'Simple'} || $ShipData{'Simple'} =~ /Error-/) { $::s_Ship_nShipCharges = 0; } else { $::s_Ship_nShipCharges = $ShipData{'Simple'}; } return($::SUCCESS, undef); } if (!defined $::s_Ship_sOpaqueShipData || length $::s_sDeliveryCountryCode == 0 || length $::s_sDeliveryRegionCode == 0 || length $ShipData{'ShippingClass'} == 0) { $::s_Ship_nShipCharges = 0; return($::SUCCESS, undef); } if ($WaiveCharges eq 'Value') { if (CalculatePrice() > $WaiveThreshold) { $::s_Ship_nShipCharges = 0; return ($::SUCCESS, undef); } } my @bands = GetBands(); my @costs; my $j; for $j (0 .. $#bands) { @costs = @ {$ShippingTable{$ShipData{'ShippingClass'}}{$bands[$j]}}; if ($#costs > 0) { last; } } if ($#costs <= 0) { if ($UnknownRegion eq 'Default') { $::s_Ship_nShipCharges = $UnknownRegionCost; return ($::SUCCESS, undef); } return($::SUCCESS, undef); } my ($totalWeight, $extraWeight, $extraCharge); if ($ShippingBasis eq 'Quantity') { $totalWeight = CalculateQuantity(); } elsif ($ShippingBasis eq 'Price') { $totalWeight = CalculatePrice(); } else { $totalWeight = CalculateWeight(); } if (!defined $totalWeight) { $::s_Ship_nShipCharges = 0; return($::SUCCESS, undef); } for $j (0 .. $#costs) { if ($costs[$j]{wt} >= $totalWeight && defined $costs[$j]{cost}) { $::s_Ship_nShipCharges = $costs[$j]{cost}; return($::SUCCESS, undef); } } if ($costs[0]{'ExcessAction'} eq 'Highest') { $::s_Ship_nShipCharges = $costs[$#costs]{cost}; return($::SUCCESS, undef); } if ($costs[0]{'ExcessAction'} eq 'AddFurther') { $extraWeight = $totalWeight - $costs[$#costs]{wt}; my ($dWeightIncrement, $nChargeIncrement) = ($costs[0]{'IncrementalWeight'}, $costs[0]{'IncrementalCharge'}); my ($nExtraUnits) = int ($extraWeight / $dWeightIncrement + 0.999); $extraCharge = $nExtraUnits * $nChargeIncrement; $::s_Ship_nShipCharges = $costs[$#costs]{cost} + $extraCharge;# Take the biggest cost from the band + the extra return($::SUCCESS, undef); } $::s_Ship_nShipCharges = $costs[$#costs]{cost}; return($::FAILURE, $$pMessageList[7]); } sub GetBands { if ($::s_sDeliveryRegionCode eq "" || $::s_sDeliveryRegionCode eq $UNDEFINED) { if ($#{$ParentZoneTable{$::s_sDeliveryCountryCode}} != -1) { return (@{$ParentZoneTable{$::s_sDeliveryCountryCode}}); # return this list (has invalid entries stripped) } } return(@{ $ZoneTable{$::s_sDeliveryCountryCode}{$::s_sDeliveryRegionCode} }); } sub CalculateHandling { $::s_Ship_nHandlingCharges = $nHandlingCharge + int ($::s_Ship_nShipCharges * $nHandlingProportion / $ActinicOrder::PERCENTOFFSET); $::s_Ship_sOpaqueHandleData = sprintf("Handling;%d;", $::s_Ship_nHandlingCharges); return ($::SUCCESS, undef); } sub CalculateWeight { my $j; if (defined $::s_Ship_nTotalWeight) { return ($::s_Ship_nTotalWeight); } $::s_Ship_nTotalWeight = 0; for $j (0 .. $#::s_Ship_sShipProducts) { if ("" ne $::s_Ship_OpaqueDataTables{$::s_Ship_sShipProducts[$j]}) { $::s_Ship_nTotalWeight += $::s_Ship_OpaqueDataTables{$::s_Ship_sShipProducts[$j]} * $::s_Ship_nShipQuantities[$j]; } else { $::s_Ship_nTotalWeight += $DefaultWeight * $::s_Ship_nShipQuantities[$j]; } } return($::s_Ship_nTotalWeight); } sub CalculateQuantity { my $j; if (defined $::s_Ship_nTotalQuantity) { return ($::s_Ship_nTotalQuantity); } $::s_Ship_nTotalQuantity = 0; for $j (0 .. $#::s_Ship_nShipQuantities) { $::s_Ship_nTotalQuantity += $::s_Ship_nShipQuantities[$j]; } return($::s_Ship_nTotalQuantity); } sub CalculatePrice { my $j; if (defined $::s_Ship_nTotalPrice) { return ($::s_Ship_nTotalPrice); } if (defined $::s_Ship_nSubTotal) { return ($::s_Ship_nSubTotal); } $::s_Ship_nTotalPrice = 0; for $j (0 .. $#::s_Ship_sShipProducts) { $::s_Ship_nTotalPrice += ($::s_Ship_nShipPrices[$j] * $::s_Ship_nShipQuantities[$j]); } return($::s_Ship_nTotalPrice); } return ($::SUCCESS);