[wellwell/interchange6: 5/5] Renamed columns form DatabaseCart to be (almost) compatible with IC6

Stefan Hornburg interchange-cvs at icdevgroup.org
Fri Mar 3 07:53:39 UTC 2017


commit 4d8eb0f188fb2af5de71512f9b2a9075c08e43c6
Author: Marco Pessotto <melmothx at gmail.com>
Date:   Tue Dec 17 14:36:05 2013 +0100

    Renamed columns form DatabaseCart to be (almost) compatible with IC6

 database/mysql/cart_products.sql |   12 +++++++-----
 database/mysql/carts.sql         |   17 +++++++++--------
 lib/WellWell/DatabaseCart.pm     |   36 +++++++++++++++++++-----------------
 3 files changed, 35 insertions(+), 30 deletions(-)
---
diff --git a/database/mysql/cart_products.sql b/database/mysql/cart_products.sql
index 133a8e8..7d2bc5d 100644
--- a/database/mysql/cart_products.sql
+++ b/database/mysql/cart_products.sql
@@ -1,8 +1,10 @@
 CREATE TABLE cart_products (
-  cart integer NOT NULL,
+  carts_id integer NOT NULL,
   sku varchar(32) NOT NULL,
-  position integer NOT NULL,
-  options varchar(500) NOT NULL,
-  quantity integer NOT NULL DEFAULT 1
+  cart_position integer NOT NULL,
+  options varchar(500) NOT NULL, -- extra field
+  quantity integer NOT NULL DEFAULT 1,
+  when_added datetime NOT NULL
 );
-CREATE UNIQUE INDEX cart_products_idx ON cart_products (cart, sku, options);
+-- IC6 would have just carts_id, sku
+CREATE UNIQUE INDEX cart_products_idx ON cart_products (carts_id, sku, options);
diff --git a/database/mysql/carts.sql b/database/mysql/carts.sql
index e05cd9b..ef4b5b4 100644
--- a/database/mysql/carts.sql
+++ b/database/mysql/carts.sql
@@ -1,10 +1,11 @@
 CREATE TABLE carts (
-  code serial PRIMARY KEY,
-  name varchar(255) NOT NULL default '',
-  type varchar(32) NOT NULL default '',
-  status varchar(32) NOT NULL default '',
-  uid varchar(255) NOT NULL,
-  session_id varchar(32) NOT NULL,
-  created integer NOT NULL,
-  last_modified integer NOT NULL default 0
+  carts_id serial PRIMARY KEY,
+  name varchar(255) NOT NULL DEFAULT '',
+  users_id integer, -- this would be NOT NULL in IC6
+  username varchar(255), -- extra field
+  sessions_id varchar(255) NOT NULL,
+  created timestamp NOT NULL,
+  last_modified timestamp NOT NULL,
+  approved boolean,
+  status varchar(32) NOT NULL DEFAULT ''
 );
diff --git a/lib/WellWell/DatabaseCart.pm b/lib/WellWell/DatabaseCart.pm
index cac19b2..2f10f3c 100644
--- a/lib/WellWell/DatabaseCart.pm
+++ b/lib/WellWell/DatabaseCart.pm
@@ -135,7 +135,7 @@ sub get_cart_by_name {
 
 	$db_carts = database_exists_ref('carts');
 
-	$set = $db_carts->query(q{select code from carts where name = '%s' and uid = '%s'},
+	$set = $db_carts->query(q{select carts_id from carts where name = '%s' and username = '%s'},
 							$name, $uid);
 
 	if (@$set) {
@@ -143,12 +143,14 @@ sub get_cart_by_name {
 	}
 	elsif ($create) {
 		$code = $db_carts->autosequence();
-
-		$code = $db_carts->set_slice($code, uid => $uid,
-								  created => Vend::Tags->time({format => '%s'}),
-                                  session_id => $Vend::Session->{id},
-								  type => $type,
-								  name => $name);
+        my $now = Vend::Tags->time({format => '%Y-%m-%d %H:%M:%S'});
+		$code = $db_carts->set_slice($code,
+                                     name => $name,
+                                     username => $uid,
+                                     sessions_id => $Vend::Session->{id},                                     
+                                     created => $now,
+                                     last_modified => $now,
+                                    );
 	}
 
 	if ($code) {
@@ -179,9 +181,11 @@ sub add_item {
 
 	unless (exists $item->{inactive} && $item->{inactive}) {
         my $opts = item_options_string($item);
+        my $now = Vend::Tags->time({format => '%Y-%m-%d %H:%M:%S'});
 		$self->{db_products}->set_slice([$self->{code}, $item->{code}, $opts],
                                         quantity => $item->{quantity},
-										position => 0);
+                                        when_added => $now,
+										cart_position => 0);
 		$self->touch();
 	}
 }
@@ -226,7 +230,7 @@ sub touch {
 	my ($self) = @_;
 	my ($last_modified);
 
-	$last_modified = Vend::Tags->time({format => '%s'});
+	$last_modified = Vend::Tags->time({format => '%Y-%m-%d %H:%M:%S'});
 	
 	$self->{db_carts}->set_field($self->{code}, 'last_modified', $last_modified);
 }
@@ -234,8 +238,7 @@ sub touch {
 # clear cart (usually after order has been finished)
 sub clear {
 	my ($self) = @_;
-
-	$self->{db_products}->query(qq{delete from cart_products where cart = $self->{code}});
+	$self->{db_products}->query(qq{delete from cart_products where carts_id = $self->{code}});
 
 	$self->touch();
 }
@@ -243,18 +246,17 @@ sub clear {
 # restore cart from database into session cart
 sub restore {
 	my ($self, $set, $item) = @_;
-	
 	# empty session cart first
 	@$Vend::Items = ();
     # take over the cart, if it exits with the same session
     if (my $sid = $Vend::Session->{id}) {
-        $set = $self->{db_carts}->query(qq{select code from carts where session_id = '%s' and uid = session_id}, $sid);
+        $set = $self->{db_carts}->query(qq{select carts_id from carts where sessions_id = '%s' and username = sessions_id}, $sid);
         for my $cart (@$set) {
-            $self->{db_carts}->query(qq{update cart_products set cart = $self->{code} where cart = $cart->[0]});
+            $self->{db_carts}->query(qq{update cart_products set carts_id = $self->{code} where carts_id = $cart->[0]});
         }
     }
 
-	$set = $self->{db_carts}->query(qq{select sku,quantity,options from cart_products where cart = $self->{code}});
+	$set = $self->{db_carts}->query(qq{select sku,quantity,options from cart_products where carts_id = $self->{code}});
 	for (@$set) {
         my ($sku, $quantity, $opts) = @$_;
         my @args;
@@ -269,7 +271,7 @@ sub restore {
 	}
 
     # update the session id of the cart
-    $self->{db_carts}->set_field($self->{code}, session_id => $Vend::Session->{id});
+    $self->{db_carts}->set_field($self->{code}, sessions_id => $Vend::Session->{id});
 	return;
 }
 
@@ -278,7 +280,7 @@ sub item_list {
 	my ($self, $complete) = @_;
 	my ($set, @list);
 	
-	$set = $self->{db_products}->query(qq{select sku,quantity from cart_products where cart = $self->{code}});
+	$set = $self->{db_products}->query(qq{select sku,quantity from cart_products where carts_id = $self->{code}});
 
 	for (@$set) {
 		my $item;



More information about the interchange-cvs mailing list