Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls

Save Multiple Ship-to Addresses Completed

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #1  
Old 02-27-2005, 12:37 PM
 
instinctual instinctual is offline
 

eXpert
  
Join Date: Nov 2003
Posts: 247
 

Default Save Multiple Ship-to Addresses Completed

Hi all, I've got this mod done and thought I'd share it - allows you to save multiple ship-to addresses on the profile page.

It creates a nice drop-down menu to choose your profile from, and allows you to switch, add, and delete profiles.

Once you've got it going - realize that you have to save your profile the regular x-cart way, and once it's saved you can then hit "create saved profile" to save a copy of it later. Then, modify your profile, click the regular submit to save it, and then click on the "create saved profile" - this will keep adding to the profiles available to "switch to".

First, you need to create a php file called createAlt.php and put it in your root directory:

Code:
<? //this script is to backup / restore user profiles require "top.inc.php"; require "config.php"; db_connect($sql_host, $sql_user, $sql_password); 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_zipcode]')"); 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){ 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'"); } elseif($key == "s_firstname" || $key == "s_lastname" || $key == "s_title"){ //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"){ $new[$key] = $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"); } ?>

Second, you will need to create a new table in the mysql database - you can use this dump file I created:

Code:
-- -- Table structure for table `xcart_shipping_addresses` -- CREATE TABLE `xcart_shipping_addresses` ( `addr_id` int(8) NOT NULL auto_increment, `login` varchar(32) NOT NULL default '', `company` varchar(255) NOT NULL default '', `s_address` varchar(255) NOT NULL default '', `s_city` varchar(255) NOT NULL default '', `s_county` varchar(32) NOT NULL default '', `s_state` varchar(32) NOT NULL default '', `s_country` char(2) NOT NULL default '', `profile` int(11) default NULL, `s_zipcode` varchar(32) default NULL, `s_firstname` varchar(32) default NULL, `s_lastname` varchar(32) default NULL, `s_title` varchar(32) default NULL, UNIQUE KEY `addr_id` (`addr_id`) ) TYPE=MyISAM AUTO_INCREMENT=396 ;



Also, alter the customers table like so (thanks techhead):

Code:
ALTER TABLE `xcart_customers` ADD `profile` INT( 11 ) DEFAULT '0' NOT NULL ;


Third, you will need to modify and create some .tpl files:

Create a new .tpl file and put it in the skin1/main folder and call it register_switch_profile.tpl - here is the code:

Code:
{* $Id: register_switch_profile.tpl*} <tr valign=middle> <td height=20 colspan=3>Switch Shipping Profile<hr size=1 noshade></td> </tr> <tr valign=middle> <td align=right>Choose Profile</td> <td></td> <td nowrap> <select name=switchProfile> {section name=switchProfile loop=$alt_profiles} {*<option {if $userinfo.title eq $alt_profiles[title]}selected{/if}>{$alt_profiles[title]}</option>*} <option value="{$alt_profiles[switchProfile]}">{$alt_profile_names[switchProfile]} {sectionelse} <option>No Alternates Available {/section} </select><input onClick="javascript: submitAlternateProfile(document.registerform, 'switch');" type="button" name="switch" value="Switch Now" {if $smarty.section.switchProfile.total == 0}disabled{/if}> </td> </tr>

Now create another new .tpl file called register_delete_altprofile.tpl and put it in this same spot.

Code:
{* $Id: register_delete_altprofile.tpl*} <tr valign=middle> <td height=20 colspan=3>Remove Shipping Profile<hr size=1 noshade></td> </tr> <tr valign=middle> <td align=right>Delete Profile</td> <td></td> <td nowrap> <select name=deleteProfile> {section name=switchProfile loop=$alt_profiles} {*<option {if $userinfo.title eq $alt_profiles[title]}selected{/if}>{$alt_profiles[title]}</option>*} <option value="{$alt_profiles[switchProfile]}">{$alt_profile_names[switchProfile]} {sectionelse} <option>No Alternates Available {/section} </select><input onClick="javascript: if(confirm('Are you sure you want to delete?'))submitAlternateProfile(document.registerform, 'delete')" type="button" name="switch" value="Delete" {if $smarty.section.switchProfile.total == 0}disabled{/if}> </td> </tr>


Now modify skin1/customer/main/register.tpl - adding this into your chosen location depending on where you want it to showup in the form:

Code:
{* Borealis Media - "profile switch" -grep- the other half of this is in register_contact_info.tpl*} {if $smarty.get.mode eq "update"} {include file="main/register_switch_profile.tpl" userinfo=$userinfo} {include file="main/register_delete_altprofile.tpl" userinfo=$userinfo} {/if} {*/Borealis Media - this is membership profile switch (change) code*}

Then, in this same file, somewhere in the "hidden inputs" or below the regular submit button, add another like this that will show the user the new create saved profile button:

Code:
<input type="hidden" name="createAltFunc"> After hitting the "submit" button above to save your profile, you can then click on "create saved profile" to save this profile for a later use in the dropdown menu above. <input type="button" name="create" value="Create Saved Profile" onClick="submitAlternateProfile(document.registerform, 'create')" >

Ok, now last step - modify one of the "register" .tpl's in the skin1/main folder to add this - I've put mine in the register_contact_info.tpl but it doesn't matter which you put it in.

Code:
{* Borealis Media - the other half of this is in register.tpl*} {if $smarty.get.mode eq "update" } <tr><Td colspan="3" align="center"> {literal} <script language="JavaScript1.2"> function submitAlternateProfile(obj, func){ obj.createAltFunc.value = func; obj.action = 'createAlt.php'; obj.submit(); } </script> {/literal} </td></tr> {/if} {*/Borealis Media*}

Cheers, hope you all find some use of this mod, took me awhile ;o) BTW - I've got it working on both the 3.5.x branch and the 4.0.x branch.

Instinctual
Colorado
X-Cart Versions 3.5.x - 4.0.x
Reply With Quote
  #2  
Old 03-09-2005, 08:27 PM
 
techhead techhead is offline
 

Advanced Member
  
Join Date: Jun 2004
Location: Australia, Melbourne
Posts: 30
 

Default

this looks like just what I'm after... but I'm having a little bit of trouble getting it up and going on 4.0.12.

first I think you missed the following database change:

Code:
ALTER TABLE `xcart_customers` ADD `profile` INT( 11 ) DEFAULT '0' NOT NULL ;

secondly... I now get a sql error when I try and add a new profile along the lines of
Code:
INVALID SQL: 1064 : You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'A'";}' where sessid='15558c80e44a16a535a6f2cdd9cda4d8'' at line ... blah blah... too much to paste in here

any ideas
__________________
xcart v3.5.8 through to v4.0.14
redhat v9
php v4.3.10
MySQL 4.0.22
Reply With Quote
  #3  
Old 03-09-2005, 10:17 PM
 
Bella Forma Bella Forma is offline
 

Senior Member
  
Join Date: Nov 2004
Location: Australia
Posts: 150
 

Default

Any chance of an link to an example?

It sounds interesting but I am not entirely sure what exactly it does
__________________
X-Cart Gold 4.0.12
X-AOM, X-RMA, X-FancyCat
Apache/Linux Server
PHP 4.3.8
Reply With Quote
  #4  
Old 03-10-2005, 06:25 AM
 
instinctual instinctual is offline
 

eXpert
  
Join Date: Nov 2003
Posts: 247
 

Default

Unfortunately where I have this working is password-protected shopping only. However, I've taken a screenshot of the profile page so that you can all see what it does:

http://www.borealismedia.com/multi-ship.jpg

)

Cheers - - - techhead I'm checking out your errors right now...

Instinctual
Colorado
X-Cart Versions 3.5.x - 4.0.x
Reply With Quote
  #5  
Old 03-10-2005, 06:29 AM
 
instinctual instinctual is offline
 

eXpert
  
Join Date: Nov 2003
Posts: 247
 

Default

Techhead - - I'm running this on version 4.0.9 -= the error you're getting seems to be with altering the session - around this line in my code:

// now update the session


Have you checked that .12 still stores sessions in this same table and fields?

Can you paste the rest of the error so I can take a look at it?

Thanks -

Instinctual
Colorado
X-Cart Versions 3.5.x - 4.0.x
Reply With Quote
  #6  
Old 03-10-2005, 03:00 PM
 
Bella Forma Bella Forma is offline
 

Senior Member
  
Join Date: Nov 2004
Location: Australia
Posts: 150
 

Default

Can't see the screen shot
__________________
X-Cart Gold 4.0.12
X-AOM, X-RMA, X-FancyCat
Apache/Linux Server
PHP 4.3.8
Reply With Quote
  #7  
Old 03-10-2005, 03:04 PM
 
Bella Forma Bella Forma is offline
 

Senior Member
  
Join Date: Nov 2004
Location: Australia
Posts: 150
 

Default

Never mind... yes I can just took a while to download

Looks good, think this will go on my 'todo' pile!
__________________
X-Cart Gold 4.0.12
X-AOM, X-RMA, X-FancyCat
Apache/Linux Server
PHP 4.3.8
Reply With Quote
  #8  
Old 03-10-2005, 03:05 PM
 
instinctual instinctual is offline
 

eXpert
  
Join Date: Nov 2003
Posts: 247
 

Default

really? Weird, shows up here for me...

Prolly just taking awhile to load...

Cheers!

Instinctual
Colorado
X-Cart Versions 3.5.x - 4.0.x
Reply With Quote
  #9  
Old 03-10-2005, 03:23 PM
  groovico's Avatar 
groovico groovico is offline
 

X-Man
  
Join Date: Apr 2003
Location: Firetanksoftware.com
Posts: 2,326
 

Default

That's a sweet little mod that one, kudos instinctual!
__________________
Groovico

Used by X-carters the world over:
Marketing Manager Pro Bundle For X-cart
Featured Product Manager for X-cart
Feed manager pro for X-cart

http://www.firetanksoftware.com

Celebrating 7 Years of providing quality X-cart Add ons and X-cart Mods for x-cart 3.X to X-cart 4.4.X
Reply With Quote
  #10  
Old 03-10-2005, 03:38 PM
 
techhead techhead is offline
 

Advanced Member
  
Join Date: Jun 2004
Location: Australia, Melbourne
Posts: 30
 

Default

I've got a client looking over our dev shopping cart at the moment so I wont be able to get the error to you awhile. You're right though, it has to do with the data being (or trying to be) stored in the database.

What you've done looks like you can only select one shipping destination for the cart

What I'm after would be to hack this to allow customers to select different shipping destinations for each product. So if a customer buys 5 copys of the Java Book, the customer can send 2 copies to Peter, 1 copy to Paul, and the other 2 copies to Mary. Tax isn't going to be an issue as it will all be in the same tax zone, however shipping destinations/charges will come into it.
__________________
xcart v3.5.8 through to v4.0.14
redhat v9
php v4.3.10
MySQL 4.0.22
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 06:44 AM.

   

 
X-Cart forums © 2001-2020