This is what I did on 4.1.9 to make it work (sorry if it wraps). I'm new at xcart so I am winging this.
First, the queries to populate the selectboxes are nowhere in this thread. This is what I have near the end of register.php:
Code:
$alt_profile_names = func_query_column("select s_address from xcart_shipping_addresses where login = '$userinfo[login]'");
if(is_array($alt_profile_names)) $smarty->assign("alt_profile_names",$alt_profile_names);
$alt_profiles = func_query_column("select profile from xcart_shipping_addresses where login = '$userinfo[login]'");
if(is_array($alt_profiles)) $smarty->assign('alt_profiles',$alt_profiles);
I had to make several changes to createAlt.php:
Code:
<?php
require "top.inc.php";
require "config.php";
// HB 2008-03-19, we need to initialize xcart.
require_once('init.php');
db_connect($sql_host, $sql_user, $sql_password);
// HB 2008-03-19, this variable was not set.
$createAltFunc = $_POST['createAltFunc'];
if (!isset($createAltFunc)) die('Post Error for CreateAltFunc');
if($createAltFunc == "create"){
Header("Content-type: text/html");
#$my_alt = array_pop(func_query_first("select max(profile) from alt_profiles where login='$uname'"));
#if($my_alt == null){
# $my_alt = 0;
#}
// first write the existing data to alt_profiles in the appropriate place
$data = func_query_first("select * from xcart_customers where login='$uname'");
$profile = func_query_first("select max(profile) as max from xcart_shipping_addresses where login='$uname'");
#$profile0 = 0 + $profile[max];
$profile0 = 0 + $data[profile];
$profile1 = $profile0 + 1 + $profile[max];
foreach($data as $me => $crap){
#print "ME $me $crap";
}
db_query("update xcart_customers set profile=$profile1 where login='$uname'");
//db_query("delete from xcart_shipping_addresses where login='$uname' and profile=$profile0");
//db_query("insert into xcart_shipping_addresses (login, profile, firstname, lastname, s_address, s_city, s_state, s_country, s_zipcode ) values ('$uname', $profile0, '$data[firstname]','$data[lastname]', '$data[s_address]','$data[s_city]','$data[s_state]','$data[s_country]','$data[s_zip
code]')");
db_query("insert into xcart_shipping_addresses (login, profile, s_firstname, s_title, s_lastname, s_address, s_city, s_state, s_country, s_zipcode ) values ('$uname', $profile1, '$s_firstname', '$s_title' , '$s_lastname', '$s_address\n$s_address_2', '$s_city','$s_state','$s_country','$s_zipcode')");
//db_query();
//Header("Location: register.php?mode=update&action=cart");
//switch to this profile
#Header("Content-type: text/html");
$sdata = db_query("select * from xcart_sessions_data");
while ($row = db_fetch_array($sdata)) {
$mdata = unserialize($row[data]);
#print "$mdata[login] $row[sessid]";
if($mdata[login] == $uname){
$mdata[s_firstname] = $data[s_firstname];
$mdata[s_lastname] = $data[s_lastname];
$mdata[s_title] = $data[s_title];
$sessid = $row[sessid];
$new;
foreach($mdata as $key => $value){
#print "MDATA $key $mdata[$key]";
if($key != "extended_userinfo"){
$new[$key] = $value;
}
else{
$edata = unserialize($mdata[$key]);
$edata[s_firstname] = $data[s_firstname];
$edata[s_lastname] = $data[s_lastname];
$edata[s_title] = $data[s_title];
$new[$key] = serialize($edata);
}
}
db_query("update xcart_sessions_data set data = '".serialize($new)."' where sessid='$sessid' ");
#break;
}
}
#//Header ("Location: createAlt.php?createAltFunc=switch&switchProfile=$profile0&uname=$uname"
);
Header("Location: register.php?mode=update&action=cart");
}
elseif($createAltFunc == "switch"){
// save data to alt_profile on switch
// write current profile back to alt_profiles
// get the data
$data = func_query_first("select * from xcart_customers where login='$uname'");
// save the data
// but first check to make sure the record exists
$exists = array_pop(func_query_first("select count(*) from xcart_shipping_addresses where login='$uname' and profile=$data[profile]"));
if($exists == 0){
db_query("insert into xcart_shipping_addresses (login, profile) values ('$uname', $data[profile])");
}
// foreach($data as $key => $value){
// HB, 2008-03-20, spits errors, and do we need this ????
// db_query("update xcart_shipping_addresses set $key='$value' where login='$uname' and profile=$data[profile]");
// }
// then copy the desired profile's data over the old
$data = func_query_first("select * from xcart_shipping_addresses where login='$uname' and profile=$switchProfile");
foreach($data as $key => $value){
if($key == "profile"){
db_query("update xcart_customers set profile=$value where login='$uname'");
}
// HB 2008-03-20, added 'addr_id'
elseif($key == "s_firstname" || $key == "s_lastname" || $key == "s_title" || $key == 'addr_id'){
//dont need to run these into main db
}
else{
db_query("update xcart_customers set $key='$value' where login='$uname'");
}
}
// now update the session
#Header("Content-type: text/html");
$sdata = db_query("select * from xcart_sessions_data");
while ($row = db_fetch_array($sdata)) {
$mdata = unserialize($row[data]);
#print "$mdata[login] $row[sessid]";
if($mdata[login] == $uname){
$new;
$sessid = $row[sessid];
foreach($mdata as $key => $value){
#print "MDATA $key $mdata[$key]";
if($key != "extended_userinfo"){
//HB 2008-03-20, addslashes.
$new[$key] = addslashes($value);
}
else{
$edata = unserialize($mdata[$key]);
foreach($mdata as $ekey => $eval){
if($key == "extended_userinfo"){
foreach($eval as $euikey => $euival){
#print "EUIkey $euikey value $euival";
if($euikey == "s_firstname"){
#print "VAL FOUND $eval[$euikey]";
$eval[$euikey] = $data[s_firstname];
}
if($euikey == "s_lastname"){
#print "VAL FOUND $eval[$euikey]";
$eval[$euikey] = $data[s_lastname];
}
if($euikey == "s_title"){
#print "VAL FOUND $eval[$euikey]";
$eval[$euikey] = $data[s_title];
}
}
}
$edata[$ekey] = $eval;
#print "key $ekey value $eval";
}
#$edata[s_firstname] = $data[s_firstname];
#$edata[s_lastname] = $data[s_lastname];
#$edata[s_title] = $data[s_title];
$new[$key] = serialize($edata);
}
}
db_query("update xcart_sessions_data set data = '".serialize($new)."' where sessid='$sessid' ");
#break;
}
}
#Header("Content-type: text/html");
Header("Location: register.php?mode=update&action=cart");
}
elseif($createAltFunc == "delete"){
db_query("delete from xcart_shipping_addresses where login='$uname' and profile=$deleteProfile");
Header("Location: register.php?mode=update&action=cart");
}
?>
That may have gotten mangled.
I don't remember anything else signficant.
I did move the "Create New Profile" button from after the main submit button, to up where it makes more sense in the form. Seems to work fine there, though I have not really tested any of this much.
Thanks for the original post. Saved me beaucoup time.