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

Stefan Hornburg racke at rt.icdevgroup.org
Tue Jan 19 14:41:49 UTC 2010


       via  9d1b65051fb23a088ff8e0a50d0732e48f7821fa (commit)
       via  9956e4ffa146f7bacc830c874c8603456915bc6c (commit)
      from  aa0df7cf9e292f9b5eee59b5e172207ec61db087 (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 9d1b65051fb23a088ff8e0a50d0732e48f7821fa
Author: Stefan Hornburg (Racke) <racke at linuxia.de>
Date:   Tue Jan 19 09:41:27 2010 -0500

    added [cart-item] tag
    provide cart_add hook

commit 9956e4ffa146f7bacc830c874c8603456915bc6c
Author: Stefan Hornburg (Racke) <racke at linuxia.de>
Date:   Tue Jan 19 09:40:39 2010 -0500

    Core module added, providing new Hook directive

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

Summary of changes and diff:
 lib/WellWell/Cart.pm |   26 +++++++++++++++--
 lib/WellWell/Core.pm |   75 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 98 insertions(+), 3 deletions(-)
 create mode 100644 lib/WellWell/Core.pm

diff --git a/lib/WellWell/Cart.pm b/lib/WellWell/Cart.pm
index 1ba4fdd..59e960e 100644
--- a/lib/WellWell/Cart.pm
+++ b/lib/WellWell/Cart.pm
@@ -1,3 +1,4 @@
+# WellWell::Cart - WellWell cart routines
 #
 # Copyright (C) 2009,2010 Stefan Hornburg (Racke) <racke at linuxia.de>.
 #
@@ -29,12 +30,18 @@ Vend::Config::parse_tag('UserTag', 'cart_add Order sku quantity');
 Vend::Config::parse_tag('UserTag', 'cart_add AddAttr');
 Vend::Config::parse_tag('UserTag', 'cart_add MapRoutine WellWell::Cart::cart_add');
 
+Vend::Config::parse_tag('UserTag', 'cart_item Order sku quantity');
+Vend::Config::parse_tag('UserTag', 'cart_item AddAttr');
+Vend::Config::parse_tag('UserTag', 'cart_item MapRoutine WellWell::Cart::cart_item');
+
 Vend::Config::parse_tag('UserTag', 'cart_refresh MapRoutine WellWell::Cart::cart_refresh');
 Vend::Config::parse_subroutine('GlobalSub', 'cart_refresh WellWell::Cart::cart_refresh_form_action');
 
-sub cart_add {
+# [cart-item] - returns item hash ready to put it into cart
+
+sub cart_item {
 	my ($sku, $quantity, $opt) = @_;
-    my ($db_products, $product_ref, %item);
+	my ($db_products, $product_ref, %item);
 
 	unless ($db_products = database_exists_ref('products')) {
 		die errmsg("Database missing: %s", 'products');
@@ -59,7 +66,20 @@ sub cart_add {
 		}
 	}
 
-    push(@$Vend::Items, \%item);
+	return \%item;
+}
+
+# [cart-add] - add item to cart
+
+sub cart_add {
+	my ($sku, $quantity, $opt) = @_;
+	my ($itemref);
+	
+	$itemref = cart_item($sku, $quantity, $opt);
+	
+    WellWell::Core::hooks('run', 'cart_add', $itemref);
+	
+    push(@$Vend::Items, $itemref);
 
     return;
 }
diff --git a/lib/WellWell/Core.pm b/lib/WellWell/Core.pm
new file mode 100644
index 0000000..e29c331
--- /dev/null
+++ b/lib/WellWell/Core.pm
@@ -0,0 +1,75 @@
+# WellWell::Core - WellWell core routines
+#
+# Copyright (C) 2010 Stefan Hornburg (Racke) <racke at linuxia.de>.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public
+# License along with this program; if not, write to the Free
+# Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA 02110-1301, USA.
+
+package WellWell::Core;
+
+use Vend::Config;
+
+use WellWell::Cart;
+
+# setup configuration directives
+Vend::Config::parse_directive('Hook', 'Hook hook');
+
+sub plugins {
+	my @plugins;
+	
+	# simply return a list of plugins sitting in $Variable
+	@plugins = split(/,/, $::Variable->{PLUGINS});
+
+	return @plugins;
+}
+
+sub hooks {
+	my ($function, $name, @args) = @_;
+
+	if ($function eq 'run') {
+		::logError("Running hooks $name.");
+
+		if (exists $Vend::Cfg->{Hook}->{$name}) {
+			my @hooks = @{$Vend::Cfg->{Hook}->{$name}};
+
+			for my $hook (@hooks) {
+				$hook->(@args);
+			}
+		}
+	}
+}
+
+package Vend::Config;
+
+sub parse_hook {
+	my ($item, $settings) = @_;
+
+	# parse routine is called once per catalog, regardless of configuration
+	# directives
+	return {} unless $settings;
+
+	my ($name, $param, $value) = split(/\s+/, $settings);
+
+	if (exists $C->{Sub}->{$param}) {
+		push(@{$C->{$item}->{$name}}, $C->{Sub}->{$param});
+	}
+	else {
+		config_error('Subroutine %s missing.', $param);
+	}
+	
+	return $C->{$item};
+}
+
+1;


hooks/post-receive
-- 
Interchange wellwell catalog



More information about the wellwell-devel mailing list