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)
-   -   Save Multiple Ship-to Addresses Completed (https://forum.x-cart.com/showthread.php?t=12456)

instinctual 02-27-2005 12:37 PM

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

techhead 03-09-2005 08:27 PM

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

Bella Forma 03-09-2005 10:17 PM

Any chance of an link to an example?

It sounds interesting but I am not entirely sure what exactly it does :D

instinctual 03-10-2005 06:25 AM

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

:o)

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

Instinctual
Colorado
X-Cart Versions 3.5.x - 4.0.x

instinctual 03-10-2005 06:29 AM

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

Bella Forma 03-10-2005 03:00 PM

Can't see the screen shot :(

Bella Forma 03-10-2005 03:04 PM

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

Looks good, think this will go on my 'todo' pile!

instinctual 03-10-2005 03:05 PM

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

groovico 03-10-2005 03:23 PM

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

techhead 03-10-2005 03:38 PM

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.

instinctual 03-10-2005 03:50 PM

Wow, yeah, that would be a nice add-on as well. What I've done will just allow you to switch ship-to profiles easily without having to "overwrite" your profile each time you purchase.

It was made for a company that has people ordering and shipping to the same locations all the time, so they just store their shipipng locations in there and I made it so when you login it just redirects you to the modify profile page for you to choose your profile right away.

I've also worked this mod in a way where the entire profile is switchable - not just the ship-to information. That way you can have several people share the same membership level and not worry about overwriting each other's profiles.

Lemme know when you get that done, would love to take a look ;o)

Instinctual
Colorado
X-Cart Versions 3.5.x - 4.0.12

wahrens 03-26-2005 08:40 AM

Did you all have any luck tracking down the sql problem? I'm also getting invalid sql: 1064 in 4.0.5

Thanks for any help,

Bill

dchihorn 04-25-2005 09:33 AM

I am in the process of trying to implement this right now, and just needing a little verification on this step:

Quote:

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:

1. Somewhere in teh hidden inputs - could you be more specific, as I am not a coder. I can find the lines that say hidden input, but not sure if i just throw it in there that it wont mess something else up. Could you give a line number suggestion?

2. Then it says add another one like this... does that mean I actually need to copy paste this in this document twice?

instinctual 05-15-2005 06:07 PM

mhmm
 
Hi there, all I'm referring to is that you need to add this code:


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')" >


Into the area that already contains the hidden inputs that are built-in to the existing x-cart template - you need to have it in that general area but where EXACTLY you put it is upto you. If you take a look at the screenshot, the code above is what's creating the "creat saved profile" button - which is not standard x-cart design - so where you put it is upto you, just make sure you include the code above somewhere in that template where you'd like the button to show up in the html code.

HWT 07-31-2005 01:52 PM

Followed the instructions to the letter, and I'm getting this error:

Code:

Warning: Cannot modify header information - headers already sent by (output started at /homepages/35/d117449933/htdocs/createAlt.php:3) in /homepages/35/d117449933/htdocs/createAlt.php on line 10

Warning: Cannot modify header information - headers already sent by (output started at /homepages/35/d117449933/htdocs/createAlt.php:3) in /homepages/35/d117449933/htdocs/createAlt.php on line 64


Anyone know what how to fix? Complete newbie to both x-cart and PHP, so please reply as if I'm 2. :) TIA

Dongan 07-31-2005 08:07 PM

Hi,

Please read this thread and will solve your problem...

http://forum.x-cart.com/viewtopic.php?t=20678

techhead 08-01-2005 03:13 PM

Make sure that you only have the php code in the createAlt.php. Remove any other code like:

Code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>

<body>

</body>
</html>


It is also better to use long php tags just in case your server doesn't support short tags...
use:
Code:

<?php // code goes here ?>
instead of:
Code:

<? // code goes here ?>

For more information on the error your getting check out www.php.net

HWT 08-01-2005 03:49 PM

techhead, Thanks for your reply.

I just figured out that what I had was a "whitespace error". I had a couple returns before and after the code, causing the errors. Now that that's solved, I'm getting a javascript error in this:

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*}


the error is:
Code:

Object doesn't support this property or method

the error is referring to the line:

Code:

obj.action = 'createAlt.php';

I have chmoded createAlt.php to 777 w/ no change. The javascript is in {literal} {/literal} tags in the .tpl

Any ideas?

robin 09-01-2005 11:37 AM

Mulitple ship to addresses
 
Hi,

I just tried to implement the multiple ship to address drop down and it is working.

I was hoping someone could give me suggestion of how to get it to work.

I also get this error

INVALID SQL: 1064 : You have an error in your SQL syntax near 's Goldberg Variations";s:12:"product_type";s:0:"";s:5:"price" ;d:13.99;s:5:"taxes' at line 1
SQL QUERY FAILURE: update xcart_sessions_data set data = 'a:44:{
..... too much to print.

Was a fix made to this?

Actually, I only started getting this error after I made a bunch of changes to the shipping options (added UPS online and other misc changes)

Before i made all of the shipping option changes, I did not get the session error but it still did not work. I did not get anything to appear in the alt shipping address drop down in my profie.


Anyone made any headway on this??

THanks,
Robin

robin 09-01-2005 11:39 AM

CORRECTION to last email
 
:( I meant to say....

I just tried to implement the multiple ship to address drop down and it is NOT working.

Sorry for the quick typo

alecgraz 10-13-2005 09:23 AM

I love the idea of this mod. In looking over the code, I am confused as to where $alt_profiles gets populated. Maybe I am missing something obvious but it seems like no profiles would get displayed. Any insight would be appriciated
Thanks

instinctual 10-13-2005 10:56 AM

alt_profiles doesn't get written to - that's not a table - it's mentioned in the code in spots as that's what we were calling it when we developed it. We have variable names called that, but otherwise data gets written to xcart_shipping_addresses table.

All of that logic is in createalt.php...

alecgraz 10-13-2005 12:13 PM

Thanks for the reply. I guess I didnt explain my question well enough. In the register_switch_profile.tpl you list out all the profiles in the select box via a loop over all the profiles for that user.

{section name=switchProfile loop=$alt_profiles}

I don't see where you are assigning this data from the PHP to the template. createAlt.php handles the creation, deletion, and switching. But I dont see it handling the population of the data to be displayed in the drop downs.

Thanks!

instinctual 10-13-2005 02:38 PM

ah, that's handled in the javascript that I have in register_contact_info.tpl - one of my last snippets of code there.

JGrubbs 11-28-2005 06:36 AM

I have installed this mod but it doesn't seem to be working right.

When I click on register as a new user the "Create Saved Profile" button is on the page, but doesn't do anything. It will work when I click on the "Modify profile" link because it is passing through mode=update, but it doesn't appear to be saving a profile to the drop down list. I checked the database and see a new entry in xcart_shipping_addresses for every time I pressed the "Create Saved Profile" button, but still nothing showing in the dropdown list:

http://www.strangdirect.com/xcart/register.php

instinctual 11-30-2005 12:30 PM

first - if installed right, this should not be showing up until you've actually already registered and created a profile with user/pass. It needs to be surrounded with some if/then tags that it looks like you missed.

Once you've then logged in after registering for the first time, you will then see a dropdown list that will populate with alternate profiles as they are created. Keep in mind you have to create the first profile and use the regular x-cart submit button, and then can click the "create saved profile" button to copy that profile so that you can enter a new one, save, copy, enter new one, save, copy, etc.

JGrubbs 11-30-2005 12:37 PM

The drop down list is not showing up untill after the registration is complete, the button is showing up but does not do anything even after the registration, unless you first click on modify profile.

Dorette 12-09-2005 10:13 AM

Great Mod, I installed it but have a little hitch

I am able to modify profile and then submit, but when I come back to add the profile it does not add up to the drop down list and I still have no alternative profiles,

i guess I am not able to add the profile , how do I check for that

Jon 01-11-2006 11:17 AM

Re: Mulitple ship to addresses
 
Quote:

Originally Posted by robin
I also get this error

INVALID SQL: 1064 : You have an error in your SQL syntax near 's Goldberg Variations";s:12:"product_type";s:0:"";s:5:"price" ;d:13.99;s:5:"taxes' at line 1
SQL QUERY FAILURE: update xcart_sessions_data set data = 'a:44:


This occurs because the sessions are completely regenerated, which means re-establishing your cart contents.

If one of your cart contents has an apostrophe or quote in it, then it will cause the SQL to break.

To fix this find:

Code:

$new[$key] = $value;

Replace with:

Code:

$new[$key] = addslashes($value);

electronics4less 02-01-2006 01:09 PM

I do not get any errors but it is not saving the addresses.

Any ideas?

electronics4less 02-02-2006 03:19 PM

I think I have a fix for this..I will post as soon as I test it out.

wicnz 02-26-2006 03:59 PM

Missing alternate profiles
 
I think there is something missing from the quoted Javascript for register_contact_info.tpl

I cannot see how/where alt_profiles is populated to allow the drop-down boxes to populate.

I have applied this mod, can create the alternate shipping profiles, but they never appear in the drop-down lists.

This is with XCart Gold 4.0.16

Thanks for any assistance.
Regards,
Stu

xcell67 07-12-2006 01:46 AM

Doesn't work for me either. I didn't get any errors but this is what happens. I register an account and then go to the modify page. I change the address, and then click on submit. Then I wait for it to reload, and I click on create saved profile. Clicking on that takes me to register.php?mode=update?action=cart. The address is not saved into the dropdown.

I tried this on 4.1.2.

mrkenzie 07-22-2006 07:27 AM

Has anyone gotten this to work? I am getting the following error:

Quote:

PHP Notice: Undefined variable: createAltFunc in C:\wwwxcart\createAlt.php on line 17 PHP Notice: Undefined variable: createAltFunc in C:\wwwxcart\createAlt.php on line 74 PHP Notice: Undefined variable: createAltFunc in C:\wwwxcart\createAlt.php on line 155

This is in 4.1.0.

It is like the information is not posting to createAlt.php. I can not figure out what is wrong.

THanks.

manningbrothers 07-26-2006 05:47 AM

Question
 
Hi - has anyone gotten this to work on 4.1 as of yet? And if so what did you do to get this to work?

This is a great mod and would be very useful on my site!

rubberneck 06-18-2007 12:06 PM

Re: Save Multiple Ship-to Addresses Completed
 
Is there a working version of this for 4.1.7? We really need this one in one of our carts.

thanks.

rubberneck 08-17-2007 09:20 PM

Re: Save Multiple Ship-to Addresses Completed
 
Bump. Anyone figured this out?

hal@dbswebsite.com 03-20-2008 05:04 PM

Re: Save Multiple Ship-to Addresses Completed
 
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.

feeble_fuel 04-25-2008 02:14 PM

Re: Save Multiple Ship-to Addresses Completed
 
This looks like a great mod and would like to implement. I was wondering if there is full clean code/instructions for this mod somewhere for 4.1.9?

Is there somewhere where you can download mods in a contained .zip folder and a version tracker?

I've seen this for other open source products but haven't come across it here.

Thanks!

l0st 04-26-2008 10:15 AM

Re: Save Multiple Ship-to Addresses Completed
 
yeah I'd like to use this too.


All times are GMT -8. The time now is 04:48 PM.

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