[ic] Shipping to different zip code USERTAG

Paul Jordan interchange-users@icdevgroup.org
Fri May 2 14:49:01 2003


> > Quoting gurs@sbcglobal.net (gurs@sbcglobal.net):
> [snip]
> >
> > The only reasonable way that anyone could do better would be to have
> > a c_lname and c_fname field for the actual name of the person in the
> > account. In Interchange, this is as simple as adding the fields to
> > the database and copying the information over when you collect the
> > initial address.
> >
> > If you were limited to one shipping address -- that would be a
> > big problem.
> >
> > Most of the software that you think of is limited in that way. You
> > have one billing address and that is it.
> >
> > Interchange has the ability to have both multiple shipping and
> > multiple billing addresses. So why worry?
> >
> > The thing that I would *most* like to do would be to set up a new
> > "addresses" database that allows you to store these addresses in a table
> > fashion, routing them to either billing or shipping address as you wish.
> > It is actually a pretty simple concept, but no one has funded the work
> > yet for me to do it. I believe some others have done implementations,
> > but have not taken the time to generalize and polish it enough for
> > public consumption.
> >
> > --
> > Mike Heins
> > Perusion -- Expert Interchange Consulting    http://www.perusion.com/
> > phone +1.513.523.7621      <mike@perusion.com>
> >
> > Experience is what allows you to recognize a mistake the second
> > time you make it. -- unknown
> > _______________________________________________
> > interchange-users mailing list
> > interchange-users@icdevgroup.org
> > http://www.icdevgroup.org/mailman/listinfo/interchange-users
>
> Thanks for clearing all that up Mike!
>
> Now I have a much much better understanding of how you look at
> because it does
> make much more sense. I think now when I go to modify it in a few
> weeks I will use the
> addresses database style and whatever/however I implement it I will
> post it on the list
> and maybe that could be a starting point for someone else.
>
> Thanks,
> Gurs


GURS!

I admired your verbose and accurate addressing ideals! I have an address
usertag, that accompanies a table. It was designed by Kevin Walsh, (yes, of The
Kevin Walsh). It follows:


UserTag address Order op type nick username cgi
UserTag address Routine <<EOR
sub {
    my ($op,$type,$nick,$username,$cgi) = @_;

    $op ||= 'list';
    $op = lc($op);

    $username ||= $::Session->{username} if $::Session->{logged_in};
    return undef unless $username;

    my $columns = $::Variable->{ADDRESS_COLUMNS} or die qq{ADDRESS_COLUMNS
variable is not defined};
    $columns =~ s/^[\s,]+|[\s,]+$//g;
    my @col_array = split(/[\s,]+/,$columns);
    $columns = join(',',@col_array);

    my $table = ($::Variable->{ADDRESS_TABLE} || 'address');
    my $db = ::database_exists_ref($table) or die qq{The "$table" table doesn't
exist};
    $username = $db->quote($username);

    if ($op eq 'list'){
	my $query = qq{
	    SELECT  nickname
	    FROM    $table
	    WHERE   username = $username
	    ORDER BY nickname
	};
	my $resultset = $db->query($query) or die qq{Cannot SELECT from $table};

	my $var = $cgi ? $::CGI : $::Values;
	$var->{nicknames} = '';
	$var->{nicknames} .= "$_->[0] " for @$resultset;
	return undef;
    }

    return undef unless $nick;
    $nick = $db->quote($nick);

    $type = lc($type);
    $type = 'shipping' unless $type eq 'billing';

    if ($op eq 'load'){
	my $query = qq{
	    SELECT  $columns
	    FROM    $table
	    WHERE   username = $username
	    AND     nickname = $nick
	};
	my $resultset = $db->query($query) or die qq{Cannot SELECT from $table};

	if (scalar @$resultset){
	    grep {$_ = "b_$_"} @col_array if $type eq 'billing';

	    my $var = $cgi ? $::CGI : $::Values;
	    for (0 .. int(scalar(@{$resultset->[0]})) - 1){
		$var->{$col_array[$_]} = $resultset->[0]->[$_];
	    }
	}
    }
    elsif ($op eq 'save'){
	grep {$_ = "b_$_"} @col_array if $type eq 'billing';

	my $var = $cgi ? $::CGI : $::Values;
	my $values = '';
	$values .= $db->quote($var->{$_}) . ',' for (@col_array);
	$values =~ s/,$//;

	my $query = qq{
	    REPLACE INTO $table (
		username, nickname, $columns
	    )
	    VALUES (
		$username, $nick, $values
	    )
	};
	my $resultset = $db->query($query) or die qq{Cannot REPLACE into $table};
    }
    undef;
}
EOR


TABLE:

NoImport address

Database address address.txt  __TESTDSN__
Database address USER         __TESTUSER__
Database address PASS         __TESTPASS__
Database address KEY          username
Database address COLUMN_DEF   "username=CHAR(50) NOT NULL PRIMARY KEY"
Database address COLUMN_DEF   "nickname=CHAR(16)"
Database address COLUMN_DEF   "address1=VARCHAR(60)"
Database address COLUMN_DEF   "address2=VARCHAR(60)"
Database address COLUMN_DEF   "address3=VARCHAR(60)"
Database address COLUMN_DEF   "city=VARCHAR(30)"
Database address COLUMN_DEF   "state=VARCHAR(30)"
Database address COLUMN_DEF   "zip=VARCHAR(10)"
Database address COLUMN_DEF   "country=CHAR(3)"



If you would like to get it working in a logical fashion and post it back that
would be great.

----
You will need to add the following lines to your catalog.cfg file,
or make the appropriate changes to your variable.txt:

    Variable ADDRESS_COLUMNS  address1 address2 address3 city state zip country
    Variable ADDRESS_TABLE    address

[address op type nick username cgi]

    op       - list, load or save (defaults to list)
    type     - billing or shipping (defaults to shipping)
    nick     - nickname
    username - username (defaults to the logged-in user's name)
    cgi      - If cgi=1 then load/save using CGI variables
---

It works great, but i could never get a "sensible" operation out of it.... that
was logical for the user... it would make users confused and they would faint.

Paul