1 # Copyright 2002-2007 Interchange Development Group and others
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version. See the LICENSE file for details.
8 # $Id: discount_space.coretag,v 1.6 2007-03-30 23:40:49 pajamian Exp $
10 UserTag discount_space Documentation <<EOF
11 The discount-space is rather equivalent to the values-space functionality.
12 Interchange keeps discount information in a single hash at $Vend::Session->{discount}.
13 This is fine except when you start using multiple shopping carts to represent different
14 portions of the store and fundamentally different transactions; any common item codes
15 will result in one cart's discounts leaking into that of the other cart...
17 Consequently, we can use a discount space to give a different namespace to various discounts.
18 This can be used in parallel with mv_cartname for different shopping carts.
19 Set up a master hash of different discount namespaces in the session. Treat the default one
20 as 'main' (like Interchange does with the cart). When discount space is called and a name
21 is given, point the $Vend::Session->{discount} to the appropriate hashref held in this master
25 clear - this will empty the discounts for the space specified, after switching to that space.
26 current - this will not change the namespace; it simply returns the current space name.
29 UserTag discount_space order name
30 UserTag discount_space AttrAlias space name
31 UserTag discount_space AddAttr
32 UserTag discount_space Version $Revision: 1.6 $
33 UserTag discount_space Routine <<EOF
35 my ($namespace, $opt) = @_;
36 $namespace ||= 'main';
37 #::logDebug("Tag discount-space called for namespace '$namespace'! Clear: '$opt->{clear}' Current: '$opt->{current}'");
39 unless ($Vend::Session->{discount} and $Vend::Session->{discount_space}) {
40 # Initialize the discount space hash, and just assign whatever's in
41 # the current discount hash to it as the 'main' entry.
42 # Furthermore, instantiate the discount hash if it doesn't already exist, otherwise
43 # the linkage between that hashref and the discount_space hashref might break...
44 #::logDebug('Tag discount-space: initializing discount_space hash; first call to this tag for this session.');
46 = $Vend::Session->{discount}
47 = $Vend::Session->{discount_space}{$Vend::DiscountSpaceName = 'main'}
48 ||= ($Vend::Session->{discount} || {});
49 $Vend::Session->{discount_space}{main} = $Vend::Session->{discount} ||= {};
52 logError('Discount-space tag called but discount spaces are deactivated in this catalog.'), return undef
53 unless $Vend::Cfg->{DiscountSpacesOn};
55 return ($Vend::DiscountSpaceName ||= 'main') if $opt->{current};
57 $::Discounts = $Vend::Session->{discount} = $Vend::Session->{discount_space}{$namespace} ||= {};
58 $Vend::DiscountSpaceName = $namespace;
59 #::logDebug("Tag discount-space: set discount space to '$namespace'");
61 %$::Discounts = () if $opt->{clear};