X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (https://forum.x-cart.com/forumdisplay.php?f=20)
-   -   Calc Shipping with different Address than Company Address (https://forum.x-cart.com/showthread.php?t=17102)

velander 10-05-2005 11:55 PM

Calc Shipping with different Address than Company Address
 
Modification to version 4.0.16 to specify Shipping Origin Address separate from Company Address

The changes posted below change the version 4.0.16 cart so that the Shipping Origin address used in calculating shipping charges is no longer the Company address, but is entered separately in the Shipping section of admin.

The DIFF code that I have included was created by hand as I don't know how else to create them.

I have only tested these changes with UPS OnLine Tools, but I made the changes so that all of the integrated shipping calculations will use the new address as the Origin of the shipment.

Code:

## SQL Changes

INSERT INTO `xcart_config` ( `name` , `comment` , `value` , `category` , `orderby` , `type` , `defvalue` )
VALUES (
'origin_city', 'Origin City', '', 'Shipping', '31', 'text', ''
), (
'origin_country', 'Origin Country', '', 'Shipping', '34', 'text', ''
), (
'origin_zipcode', 'Origin Zipcode', '', 'Shipping', '33', 'text', ''
), (
'origin_address', 'Origin Address', '', 'Shipping', '30', 'text', ''
), (
'origin_state', 'Origin State', '', 'Shipping', '32', 'text', ''
);
Insert xcart_languages (code, descr, name, value, topic) values ('US', 'Shipping Origin', 'txt_shipping_origin_note', 'Enter Shipping Origin Location for UPS rate calculations.', 'Text')



## PHP and Template changes

Index: admin/main/configuration.tpl
===================================================================

@@ -50,3 +50,3 @@
 {section name=cat_num loop=$configuration}

+{if $configuration[cat_num].name eq "origin_address"}
+<TR><TD colspan="2"></TD></TR>
+<TR><TD colspan="2" align="center" class="TableHead">
+{$lng.txt_shipping_origin_note}
+</TD>
+</TR>
+{/if}
+
 {if $configuration[cat_num].name eq "realtime_shipping"}

@@ -100,32 +100,32 @@
 {if $configuration[cat_num].name eq "default_country"}
 <SELECT name="{$configuration[cat_num].name}">
 {section name=country_idx loop=$countries}
 <OPTION value="{$countries[country_idx].country_code}" {if $countries[country_idx].country_code eq $configuration[cat_num].value}selected{/if}>{$countries[country_idx].country}</OPTION>
 {/section}
 </SELECT>
 
-{elseif $configuration[cat_num].name eq "location_state" or $configuration[cat_num].name eq "default_state"}
-{if $configuration[cat_num].name eq "location_state"}
-{assign var="country" value=$config.Company.location_country}
-{else}
-{assign var="country" value=$config.General.default_country}
-{/if}
-{include file="main/states.tpl" states=$states name=$configuration[cat_num].name default=$configuration[cat_num].value default_country=$country}
+{elseif $configuration[cat_num].name eq "location_state" or $configuration[cat_num].name eq "default_state" or $configuration[cat_num].name eq "origin_state"}
+{if $configuration[cat_num].name eq "location_state"}
+{assign var="country" value=$config.Company.location_country}
+{elseif $configuration[cat_num].name eq "default_state"}
+{assign var="country" value=$config.General.default_country}
+{else}
+{assign var="country" value=$config.Shipping.origin_country}
+{/if}
+{include file="main/states.tpl" states=$states name=$configuration[cat_num].name default=$configuration[cat_num].value default_country=$country}

 {elseif $configuration[cat_num].name eq "location_country"}
 <SELECT name="{$configuration[cat_num].name}">
 {section name=country_idx loop=$countries}
 <OPTION value="{$countries[country_idx].country_code}" {if $countries[country_idx].country_code eq $configuration[cat_num].value}selected{/if}>{$countries[country_idx].country}</OPTION>
 {/section}
 </SELECT>
+
+{elseif $configuration[cat_num].name eq "origin_country"}
+<SELECT name="{$configuration[cat_num].name}">
+{section name=country_idx loop=$countries}
+<OPTION value="{$countries[country_idx].country_code}" {if $countries[country_idx].country_code eq $configuration[cat_num].value}selected{/if}>{$countries[country_idx].country}</OPTION>
+{/section}
+</SELECT>
 
 {elseif $configuration[cat_num].name eq "httpsmod"}
 <SELECT name="{$configuration[cat_num].name}">



Index: shipping/mod_UPS.php
===================================================================

@@ -124,11 +124,11 @@
        #
        # The origin address - from Company options
        # (suppose that ShipperAddress and ShipFrom is equal)
        #
-        $src_country_code = $config["Company"]["location_country"];
-        $src_city = func_ups_xml_quote($config["Company"]["location_city"]);
-        $src_zipcode = $config["Company"]["location_zipcode"];
+        $src_country_code = $config["Shipping"]["origin_country"];
+        $src_city = func_ups_xml_quote($config["Shipping"]["origin_city"]);
+        $src_zipcode = $config["Shipping"]["origin_zipcode"];

        #
        # The destination address - from user's profile
        #


Index: /admin/main/test_shippings.tpl
===================================================================

@@ -36,27 +36,27 @@
 <TR valign="middle">
 <TD align="right" width="25%">{$lng.lbl_city}</TD>
 <TD></TD>
-<TD nowrap width="75%">{$config.Company.location_city} </TD>
+<TD nowrap width="75%">{$config.Shipping.origin_city} </TD>
 </TR>
 
 <TR valign="middle">
 <TD align="right">{$lng.lbl_state}</TD>
 <TD></TD>
-<TD nowrap>{$config.Company.location_state_name}</TD>
+<TD nowrap>{$config.Shipping.origin_state_name}</TD>
 </TR>
 
 <TR valign="middle">
 <TD align="right">{$lng.lbl_country}</TD>
 <TD></TD>
-<TD nowrap>{$config.Company.location_country_name}</TD>
+<TD nowrap>{$config.Shipping.origin_country_name}</TD>
 </TR>
 
 <TR valign="middle">
 <TD align="right">{$lng.lbl_zip_code}</TD>
 <TD></TD>
-<TD nowrap>{$config.Company.location_zipcode}</TD>
+<TD nowrap>{$config.Shipping.origin_zipcode}</TD>
 </TR>
 
 <TR valign="middle">
 <TD height="20" colspan="3"></TD>
 </TR>


Index: include/get_language.php
===================================================================

@@ -157,7 +157,7 @@
                }
        }

 $config["Company"]["location_country_name"] = func_get_country($config["Company"]["location_country"]);
 $config["Company"]["location_state_name"] = func_get_state($config["Company"]["location_state"], $config["Company"]["location_country"]);
+$config["Shipping"]["origin_country_name"] = func_get_country($config["Shipping"]["origin_country"]);
+$config["Shipping"]["origin_state_name"] = func_get_state($config["Shipping"]["origin_state"], $config["Shipping"]["origin_country"]);
 $smarty->assign("config",$config);
 $mail_smarty->assign("config",$config);


Index: modules/UPS_OnLine_Tools/ups_register.php
===================================================================
@@ -401,15 +401,15 @@
 #
 # Prepare to fill register form
 #
        $userinfo = "";
        if (!empty($ups_userinfo))
                $userinfo = $ups_userinfo;
        else {
-                $userinfo["address"] = $config["Company"]["location_address"];
+                $userinfo["address"] = $config["Shipping"]["origin_address"];
-                $userinfo["city"] = $config["Company"]["location_city"];
+                $userinfo["city"] = $config["Shipping"]["origin_city"];
-                $userinfo["state"] = $config["Company"]["location_state"];
+                $userinfo["state"] = $config["Shipping"]["origin_state"];
-                $userinfo["country"] = $config["Company"]["location_country"];
+                $userinfo["country"] = $config["Shipping"]["origin_country"];
-                $userinfo["postal_code"] = $config["Company"]["location_zipcode"];
+                $userinfo["postal_code"] = $config["Shipping"]["origin_zipcode"];
                $userinfo["phone"] = $config["Company"]["company_phone"];
                $userinfo["email"] = $config["Company"]["site_administrator"];
                $userinfo["url"] = $http_location;


Index: modules/UPS_OnLine_Tools/ups_rss.php
===================================================================
@@ -64,8 +64, 8
 $smarty->assign("title", $ups_title);
 
 $smarty->assign("mode", "rss");
 
-if (in_array($config["Company"]["location_country"], array("CA","DO","PR","US")))
+if (in_array($config["Shipping"]["origin_country"], array("CA","DO","PR","US")))
        $dim_units = "inches";
 else
        $dim_units = "cm";


Index: modules/UPS_OnLine_Tools/ups_shipping_methods.php
===================================================================
@@ -41,13 +41,13 @@
 if ( !defined('XCART_SESSION_START') ) { header("Location: ../"); die("Access denied"); }
 
 
-if (in_array($config["Company"]["location_country"], array("US","CA","PR","MX")))
+if (in_array($config["Shipping"]["origin_country"], array("US","CA","PR","MX")))
 #
 # Origin is US, Canada, Puerto Rico or Mexico
 #
-        $origin_code = $config["Company"]["location_country"];
+        $origin_code = $config["Shipping"]["origin_country"];
 
-elseif (in_array($config["Company"]["location_country"], array("AT","BE","DK","FI","FR","DE","GR","IE","IT","LU","NL","PT","ES","SE","GB")))
+elseif (in_array($config["Shipping"]["origin_country"], array("AT","BE","DK","FI","FR","DE","GR","IE","IT","LU","NL","PT","ES","SE","GB")))
 #
 # Origin is European Union
 #


Index: shipping/intershipper.php
===================================================================
@@ -82,8 +82,8 @@
        $delivery=$params["param00"];
        $shipmethod=$params["param01"];
 
-        $CO=$config["Company"]["location_country"];
-        $ZO=urlencode($config["Company"]["location_zipcode"]);
+        $CO=$config["Shipping"]["origin_country"];
+        $ZO=urlencode($config["Shipping"]["origin_zipcode"]);
 
        $CD=$__intershipper_userinfo["s_country"];
        $ZD=urlencode($__intershipper_userinfo["s_zipcode"]);

@@ -91,7 +91,7 @@
        if (!empty($intershipper_countries[$CD])) $CD = $intershipper_countries[$CD];
        if (!empty($intershipper_countries[$CO])) $CO = $intershipper_countries[$CO];
        $__intershipper_userinfo["s_country"] = $CD;
-        $config["Company"]["location_country"] = $CO;
+        $config["Shipping"]["origin_country"] = $CO;
 
        $length=(double)$params["param02"];
        $width=(double)$params["param03"];

@@ -184,5 +184,5 @@
                if($intershipper_carrier && ($intershipper_service || $intershipper_sn) && $intershipper_rate) {
                        $saved = -1;
-                        $destination = ($__intershipper_userinfo["s_country"]==$config["Company"]["location_country"])?"L":"I";
+                        $destination = ($__intershipper_userinfo["s_country"]==$config["Shipping"]["origin_country"])?"L":"I";
                        foreach ($allowed_shipping_methods as $sk=>$sv) {
                                if( $sv["code"]==$intershipper_carrier && $sv["destination"]==$destination && ($intershipper_sn&&$sv["intershipper_code"]==$intershipper_sn||$intershipper_service&&stristr($sv["shipping"],$intershipper_service)) ) {


Index: shipping/mod_ARB.php
===================================================================
@@ -56,15 +56,15 @@
 #
 # Currently shipping only from US is supported
 #
-if (!empty($ab_id) && !empty($ab_password) && !empty($ab_ship_accnum) && $userinfo["s_country"]=="US" && $config["Company"]["location_country"] == "US") {
+if (!empty($ab_id) && !empty($ab_password) && !empty($ab_ship_accnum) && $userinfo["s_country"]=="US" && $config["Shipping"]["origin_country"] == "US") {
        if ($ab_testmode == 'Y')
                $ab_url = "https://ecommerce.airborne.com:443/ApiLandingTest.asp";
        else
                $ab_url = "https://ecommerce.airborne.com:443/ApiLanding.asp";
 
-        $ab_ship_key = ab_get_ship_key($ab_url, $ab_id, $ab_password, $ab_ship_accnum, $config["Company"]["location_zipcode"], $ab_testmode);
+        $ab_ship_key = ab_get_ship_key($ab_url, $ab_id, $ab_password, $ab_ship_accnum, $config["Shipping"]["origin_zipcode"], $ab_testmode);
        if (empty($ab_ship_key)) {
                if ($debug == "Y") ab_show_faults();
                ab_conv_faults();
                return;
        }


Index: shipping/mod_CPC.php
===================================================================
@@ -40,5 +40,5 @@
 if ( !defined('XCART_SESSION_START') ) { header("Location: ../"); die("Access denied"); }
 
-if( $config["Company"]["location_country"] == "CA" && !empty($config["Shipping"]["CPC_merchant_id"]) ) {
+if( $config["Shipping"]["origin_country"] == "CA" && !empty($config["Shipping"]["CPC_merchant_id"]) ) {
 
        $params = func_query_first ("SELECT * FROM $sql_tbl[shipping_options] WHERE carrier='CPC'");


@@ -66,9 +66,9 @@
        $cp_dest_zip = $userinfo["s_zipcode"];
        $cp_dest_state = $userinfo["s_state"];
 
-        $cp_orig_zip=$config["Company"]["location_zipcode"];
+        $cp_orig_zip=$config["Shipping"]["origin_zipcode"];
 
        if( $config["Shipping"]["CPC_test_mode"] == "Y" )
                $cp_host = "206.191.4.228";
        else
                $cp_host = "216.191.36.73";


Index: shipping/mod_USPS.php
===================================================================
@@ -73,6 +73,6 @@
          $USPS_file=($USPS_servername=="testing.shippingapis.com")? "/ShippingAPITest.dll" : "/ShippingAPI.dll";
 
-          if ($userinfo["s_country"] != $config["Company"]["location_country"]) {
+          if ($userinfo["s_country"] != $config["Shipping"]["origin_country"]) {
                $query=<<<EOT
 <IntlRateRequest USERID="$USPS_username" PASSWORD="$USPS_password">
  <Package ID="0">


@@ -115,7 +115,7 @@
            xml_set_character_data_handler($xml_parser, "USPS_intl_characterData");
            xml_parse($xml_parser, $result);
            xml_parser_free($xml_parser);
          } else {
-                $ZO=$config["Company"]["location_zipcode"];
+                $ZO=$config["Shipping"]["origin_zipcode"];
                $ZD=$userinfo["s_zipcode"];
                $query=<<<EOT


Index: shipping/shipping.php
===================================================================
@@ -100,16 +100,16 @@
        if (!empty($active_modules["UPS_OnLine_Tools"]) and $config["Shipping"]["realtime_shipping"] == "Y" and $config["Shipping"]["use_intershipper"] != "Y") {
                $_carriers["UPS"] = func_query_first_cell("SELECT COUNT(*) FROM $sql_tbl[shipping] WHERE code='UPS' AND service_code!='' AND (weight_limit='0' OR weight_limit>='$total_weight_shipping') AND active='Y'");
                $_carriers["other"] = func_query_first_cell("SELECT COUNT(*) FROM $sql_tbl[shipping] WHERE code<>'UPS' AND (weight_limit='0' OR weight_limit>='$total_weight_shipping') AND active='Y'");
                if ($_carriers["UPS"] == 0 || $_carriers["other"] == 0) {
                        $current_carrier = ($_carriers["UPS"] == 0 ? "" : "UPS");
                        x_session_save("current_carrier");
                }
                else
                        $smarty->assign("show_carriers_selector", "Y");
        }
               
        if ($enable_shipping || $config["Shipping"]["enable_all_shippings"] != "Y") {
-                $destination_condition = " AND destination=".(!empty($userinfo) && $userinfo["s_country"] == $config["Company"]["location_country"] ? "'L'" : "'I'");
+                $destination_condition = " AND destination=".(!empty($userinfo) && $userinfo["s_country"] == $config["Shipping"]["origin_country"] ? "'L'" : "'I'");
        }
 
        if (!$enable_shipping || $config["Shipping"]["realtime_shipping"] != "Y") {


I hope that someone find this useful. If you discover any bugs with this code please post information here, and don't blame me as this code is provided with no warranty and you use at your own risk.

balinor 10-10-2005 03:16 PM

Excellent....quite a few people have asked this question, now I have somewhere to point them :) Thanks for sharing!

nucura50 10-12-2005 01:21 AM

question
 
hello,

I have a couple of questions if you don't mind ;-)

You have to enter a default address in your admin area. This would mean that they still only get one option via international and national? At the moment when customers checkout only international comes up, what if they are national? This would not fix the problem?

I have found with other carts, that the customer chooses their shipping needs.

Secondly, will this world with custom charges. I have inserted royal mail into the shipping options. It will be the only option with international and national.


All times are GMT -8. The time now is 12:50 AM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.