[wellwell-devel] [SCM] Interchange wellwell catalog branch, master, updated. f11093fb0c7fcf36375b104d64e999825cab0e54

Stefan Hornburg racke at rt.icdevgroup.org
Wed Nov 18 10:46:11 UTC 2009


       via  f11093fb0c7fcf36375b104d64e999825cab0e54 (commit)
       via  be3f6e8cc09b04baa2d7347da82c1b9afafceb09 (commit)
      from  7d593eeefb17c778e99406a94eecb0a6e92cb702 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit f11093fb0c7fcf36375b104d64e999825cab0e54
Author: Stefan Hornburg (Racke) <racke at linuxia.de>
Date:   Wed Nov 18 11:45:29 2009 +0100

    form hooks for checkout

commit be3f6e8cc09b04baa2d7347da82c1b9afafceb09
Author: Stefan Hornburg (Racke) <racke at linuxia.de>
Date:   Wed Nov 18 11:44:38 2009 +0100

    [address] tag added

-----------------------------------------------------------------------

Summary of changes and diff:
 code/address.tag            |  128 +++++++++++++++++++++++++++++++++++++++++++
 code/form_checkout_load.sub |   18 ++++++
 code/form_checkout_save.sub |    9 +++
 3 files changed, 155 insertions(+), 0 deletions(-)
 create mode 100644 code/address.tag
 create mode 100644 code/form_checkout_load.sub
 create mode 100644 code/form_checkout_save.sub

diff --git a/code/address.tag b/code/address.tag
new file mode 100644
index 0000000..179b9f1
--- /dev/null
+++ b/code/address.tag
@@ -0,0 +1,128 @@
+UserTag address Order function type name
+UserTag address AddAttr
+UserTag address HasEndTag
+UserTag address Routine <<EOR
+sub {
+	my ($function, $type, $name, $opt, $body) = @_;
+	my ($hash, $prefix, @fields, $fieldstr, %address, $set, $aref, $uid, $aid, $ret);
+
+	$Tag->perl({tables => 'addresses country'});
+
+	if ($opt->{hash}) {
+		$hash = $opt->{hash};
+	}
+	else {
+		$Tag->update('values');
+		$hash = $Values;
+	}
+
+	$prefix = $opt->{prefix} || '';
+
+	@fields = qw(company first_name last_name street_address zip city phone fax country);
+	$fieldstr = join(',', 'aid', @fields);
+
+	$uid = $opt->{uid} || $Session->{username};
+
+	if ($uid =~ /^\d+$/) {
+		# check for an existing address
+		$set = $Db{addresses}->query(qq{select $fieldstr from addresses where uid = %s and type = '%s' and archived is FALSE}, $uid, $type);
+		if (@$set) {
+			$aref = $set->[0];
+			$aid = shift(@$aref);
+			
+			for my $f (@fields) {
+				$address{$f} = shift(@$aref);
+			}
+		}
+	}
+	
+	if ($function eq 'display') {
+		# turn country code into a name
+		if ($address{country}) {
+			$address{country} = $Db{country}->field($address{country}, 'name');
+		}
+		return $Tag->uc_attr_list({hash => \%address, body => $body});
+	}
+	elsif ($function eq 'set') {
+		# create/update address
+		for (@fields) {
+			if (exists $hash->{"${prefix}$_"}) {
+				$address{$_} = $hash->{"${prefix}$_"};
+			} else {
+				$address{$_} = '';
+			}
+		}
+		$address{uid} = $uid;
+		$address{type} = $type;
+		$address{last_modified} = $Tag->time({format => '%s'});
+
+		$ret = $Db{addresses}->set_slice($aid, %address);
+		return $ret;
+	}
+	elsif ($function eq 'compare') {
+		# compare stored address with values submitted by user
+		my (@diffs);
+
+		for (@fields) {
+			if ($address{$_} ne $hash->{"${prefix}$_"}) {
+				push (@diffs, $_);
+			}
+		}		
+
+		wantarray ? @diffs : scalar(@diffs);
+	}
+	elsif ($function eq 'get') {
+		$address{uid} = $uid;
+		$address{type} = $type;
+		if ($name) {
+			if ($name eq 'aid') {
+				return $aid;
+			}
+			return $address{$name};
+		}
+		return \%address;
+	}
+	elsif ($function eq 'archive') {
+		$address{uid} = $uid;
+		$address{type} = $type;
+		$address{archived} = 1;
+		$ret = $Db{addresses}->set_slice('', %address);
+		return $ret;
+	} 
+	elsif ($function eq 'update') {
+		if ($Tag->address({function => 'compare', 
+						type => $type, 
+						prefix => $prefix})) {
+			my ($set_transactions, $set_returns);	
+		
+			# address has changed, check if used in orders/returns
+			$Tag->perl({tables => 'transactions returns'});
+
+			$set_transactions = $Db{transactions}->query(qq{select count(*) from transactions where aid_$type = $aid}); 
+			$set_returns = $Db{returns}->query(qq{select count(*) from returns where rma_aid = $aid}); 
+
+			if ($set_transactions->[0]->[0] || $set_returns->[0]->[0]) {
+				# archive address
+				$Db{addresses}->set_field($aid, archived => 1);
+			}
+
+			# new address
+			$Tag->address({function => 'set', 
+				type => $type, 
+				prefix => $prefix});
+		}
+
+		return $aid;
+	}
+	elsif ($function eq 'load') {
+		for (@fields) {
+			if (exists $address{$_}) {
+				$hash->{"${prefix}$_"} = $address{$_};
+			} else {
+				$hash->{"${prefix}$_"} = '';
+			}
+		}
+		return $aid;
+	}
+}
+EOR
diff --git a/code/form_checkout_load.sub b/code/form_checkout_load.sub
new file mode 100644
index 0000000..5f3bd79
--- /dev/null
+++ b/code/form_checkout_load.sub
@@ -0,0 +1,18 @@
+Sub form_checkout_load <<EOS
+sub {
+	if ($part eq 'shipping') {
+		# load shipping address
+		$Tag->address({function => 'load',
+					type => 'shipping'});
+	}
+
+	if ($part eq 'final') {
+		# trigger 'order_finalize' hook to give plugins
+		# a last chance to mangle the order
+		
+		$Tag->call_hooks('order_finalize');
+	}
+
+	return {};
+}
+EOS
diff --git a/code/form_checkout_save.sub b/code/form_checkout_save.sub
new file mode 100644
index 0000000..c4b9e2e
--- /dev/null
+++ b/code/form_checkout_save.sub
@@ -0,0 +1,9 @@
+Sub form_checkout_save <<EOS
+sub {
+	if ($part eq 'shipping' && $Session->{logged_in}) {
+		# save shipping address
+	}
+
+	return;
+}
+EOS


hooks/post-receive
-- 
Interchange wellwell catalog



More information about the wellwell-devel mailing list