# $Id: /local/CPAN/Handel/lib/AxKit/XSP/Handel/Order.pm 1043 2007-06-24T15:35:46.298350Z claco $ ## no critic package AxKit::XSP::Handel::Order; use strict; use warnings; use vars qw($NS); use Handel::ConfigReader; use Handel::Constants qw(:order str_to_const); use Handel::Exception; use Handel::L10N qw(translate); use base 'Apache::AxKit::Language::XSP'; $NS = 'http://today.icantfocus.com/CPAN/AxKit/XSP/Handel/Order'; #{ my @context = 'root'; sub push_context { my @nodes = @_; push @context, @nodes; }; sub pop_context { my $count = shift; foreach (1..$count) { pop @context; }; }; sub start_document { return "use Handel::Order;\nuse Handel::Compat::Currency;\n"; }; sub parse_char { my ($e, $text) = @_; my $tag = $e->current_element(); return unless length($text); if ($tag eq 'type' && $text =~ /^[A-Z]{1}/) { $text = str_to_const($text); }; if ($tag =~ /^(description|id|name|shopper|type| billtofirstname|billtolastname|billtoaddress1|billtoaddress2|billtoaddress3| billtocity|billtostate|billtozip|billtocountry| billtodayphone|billtonightphone|billtofax|billtoemail| comments|created|handling|number|shipmethod|shipping|shiptosameasbillto| shiptofirstname|shiptolastname|shiptoaddress1|shiptoaddress2|shiptoaddress3| shiptocity|shiptostate|shiptozip|shiptocountry| shiptodayphone|shiptonightphone|shiptofax|shiptoemail| tax|subtotal|total||updated)$/x) { if ($context[-1] eq 'new') { return ".q|$text|"; } elsif ($context[-1] eq 'add') { return ".q|$text|"; } elsif ($context[-1] eq 'delete') { return ".q|$text|"; } elsif ($context[-1] eq 'update') { return ".q|$text|"; }; } elsif ($tag =~ /^(sku|price|quantity)$/) { if ($context[-1] eq 'add') { return ".q|$text|"; } elsif ($context[-1] eq 'delete') { return ".q|$text|"; } elsif ($context[-1] eq 'update') { return ".q|$text|"; }; } elsif ($tag eq 'filter') { return ".q|$text|"; }; return ''; }; sub parse_start { my ($e, $tag, %attr) = @_; AxKit::Debug(5, "[Handel] [Order] parse_start [$tag] context: " . join('->', @context)); if (exists $attr{'type'}) { if ($attr{'type'} =~ /^[A-Z]{1}/) { $attr{'type'} = str_to_const($attr{'type'}); }; }; ## order:uuid if ($tag =~ /^(g|u)uid$/) { $e->start_expr($tag); $e->append_to_script("Handel::Order->storage->new_uuid"); $e->end_expr($tag); ## order:new } elsif ($tag eq 'new') { throw Handel::Exception::Taglib( -text => translate('TAG_NOT_ALLOWED_IN_OTHERS', $tag) ) if ($context[-1] ne 'root'); push @context, $tag; my $process = $attr{'process'} || 0; delete $attr{'process'}; my $code = "my \$_xsp_handel_order_new_process = $process;my \$_xsp_handel_order_order;\nmy \$_xsp_handel_order_called_new;\n"; $code .= scalar keys %attr ? 'my %_xsp_handel_order_new_filter = ("' . join('", "', %attr) . '");' : 'my %_xsp_handel_order_new_filter;' ; return "\n{\n$code\n"; ## order:cart } elsif ($tag eq 'cart') { throw Handel::Exception::Taglib( -text => translate('TAG_NOT_ALLOWED_HERE', $tag) ) if ($context[-1] ne 'new'); push @context, $tag; my $code = "my \%_xsp_handel_order_new_cart_filter;\n"; if (scalar keys %attr) { $code .= '%_xsp_handel_order_new_cart_filter = ("' . join('", "', %attr) . '");' . "\n"; }; return $code; ## order:order } elsif ($tag eq 'order') { throw Handel::Exception::Taglib( -text => translate('TAG_NOT_ALLOWED_IN_OTHERS', $tag) ) if ($context[-1] ne 'root'); push @context, $tag; my $code = "my \$_xsp_handel_order_order;\nmy \$_xsp_handel_order_called_load;\n"; $code .= scalar keys %attr ? 'my %_xsp_handel_order_load_filter = ("' . join('", "', %attr) . '");' : 'my %_xsp_handel_order_load_filter;' ; return "\n{\n$code\n"; ## order:orders } elsif ($tag eq 'orders') { throw Handel::Exception::Taglib( -text => translate('TAG_NOT_ALLOWED_IN_OTHERS', $tag) ) if ($context[-1] ne 'root'); push @context, $tag; my $code = "my \@_xsp_handel_order_orders;\nmy \$_xsp_handel_orders_called_load;\n"; $code .= scalar keys %attr ? 'my %_xsp_handel_orders_load_filter = ("' . join('", "', %attr) . '");' : 'my %_xsp_handel_orders_load_filter;' ; return "\n{\n$code\n"; ## order:item } elsif ($tag eq 'item') { throw Handel::Exception::Taglib( -text => translate('Tag [_1] not valid inside of tag [_2]', $tag, $context[-1]) ) if ($context[-1] =~ /^(order(s?))$/); push @context, $tag; my $code = "my \$_xsp_handel_order_item;\nmy \$_xsp_handel_order_called_item;\n"; $code .= scalar keys %attr ? 'my %_xsp_handel_order_item_filter = ("' . join('", "', %attr) . '");' : 'my %_xsp_handel_order_item_filter;' ; return "\n{\n$code\n"; ## order:items } elsif ($tag eq 'items') { throw Handel::Exception::Taglib( -text => translate('Tag [_1] not valid inside of tag [_2]', $tag, $context[-1]) ) if ($context[-1] =~ /^(order(s?))$/); push @context, $tag; my $code = "my \@_xsp_handel_order_items;\nmy \$_xsp_handel_order_called_items;\n"; $code .= scalar keys %attr ? 'my %_xsp_handel_order_items_filter = ("' . join('", "', %attr) . '");' : 'my %_xsp_handel_order_items_filter;' ; return "\n{\n$code\n"; ## order:clear } elsif ($tag eq 'clear') { throw Handel::Exception::Taglib( -text => translate('TAG_NOT_ALLOWED_HERE', $tag) ) if ($context[-1] ne 'results' || $context[-2] !~ /^(order(s?))$/); return "\n\$_xsp_handel_order_order->clear;\n"; ## order:add } elsif ($tag eq 'add') { throw Handel::Exception::Taglib( -text => translate('TAG_NOT_ALLOWED_HERE', $tag) ) if ($context[-1] ne 'results' || $context[-2] !~ /^(new|order(s?))$/); push @context, $tag; my $code = "my \$_xsp_handel_order_item;\nmy \$_xsp_handel_order_called_add;\n"; $code .= scalar keys %attr ? 'my %_xsp_handel_order_add_filter = ("' . join('", "', %attr) . '");' : 'my %_xsp_handel_order_add_filter;' ; return "\n{\n$code\n"; ## order:update } elsif ($tag eq 'update') { throw Handel::Exception::Taglib( -text => translate('TAG_NOT_ALLOWED_HERE', $tag) ) if ($context[-1] ne 'results' || $context[-2] !~ /^((order(s?)|item(s?)))$/); push @context, $tag; if ($context[-3] =~ /^(order(s?))$/) { return "\n\$_xsp_handel_order_order->autoupdate(0);\n"; } elsif ($context[-3] =~ /^(item(s?))$/) { return "\n\$_xsp_handel_order_item->autoupdate(0);\n"; }; return ''; } elsif ($tag eq 'save') { throw Handel::Exception::Taglib( -text => translate('TAG_NOT_ALLOWED_HERE', $tag) ) if ($context[-2] !~ /^(order(s?))$/); return ' $_xsp_handel_order_order->save; $_xsp_handel_order_order->update; '; ## order:delete } elsif ($tag eq 'delete') { throw Handel::Exception::Taglib( -text => translate('TAG_NOT_ALLOWED_HERE', $tag) ) if ($context[-1] ne 'results' || $context[-2] !~ /^(order(s?))$/); push @context, $tag; my $code .= scalar keys %attr ? 'my %_xsp_handel_order_delete_filter = ("' . join('", "', %attr) . '");' : 'my %_xsp_handel_order_delete_filter;' ; return "\n{\n$code\n"; ## order property tags ## order:description, id, name, shopper, type, count, subtotal ## billtofirstname } elsif ($tag =~ /^(description|id|name|shopper|type|count| billtofirstname|billtolastname|billtoaddress1|billtoaddress2|billtoaddress3| billtocity|billtostate|billtozip|billtocountry| billtodayphone|billtonightphone|billtofax|billtoemail| comments|created|handling|number|shipmethod|shipping|shiptosameasbillto| shiptofirstname|shiptolastname|shiptoaddress1|shiptoaddress2|shiptoaddress3| shiptocity|shiptostate|shiptozip|shiptocountry| shiptodayphone|shiptonightphone|shiptofax|shiptoemail| tax|subtotal|updated)$/x) { if ($context[-1] eq 'new' && $tag !~ /^(count)$/) { return "\n\$_xsp_handel_order_new_filter{$tag} = ''"; } elsif ($context[-1] eq 'add' && $tag =~ /^(id|description)$/) { return "\n\$_xsp_handel_order_add_filter{$tag} = ''"; } elsif ($context[-1] eq 'results' && $context[-2] =~ /^(new|order(s?))$/) { $e->start_expr($tag); if ($tag =~ /^(subtotal|tax|handling|shipping)$/ && ($attr{'format'} || $attr{'convert'})) { my $cfg = Handel::ConfigReader->new(); my $code = $attr{'to'} || $attr{'code'} || $cfg->{'HandelCurrencyCode'}; my $format = $attr{'options'} || $cfg->{'HandelCurrencyFormat'}; my $from = $attr{'from'} || $cfg->{'HandelCurrencyCode'}; my $to = $attr{'to'} || $attr{'code'} || $cfg->{'HandelCurrencyCode'}; AxKit::Debug(5, "[Handel] [Order] [$tag] code=$code, format=$format, from=$from, to=$to"); if ($attr{'convert'}) { $e->append_to_script("Handel::Compat::Currency::convert(Handel::Compat::Currency->new(\$_xsp_handel_order_order->$tag->value), '$from', '$to', '".($attr{'format'}||'')."', '$format');\n"); } elsif ($attr{'format'}) { $e->append_to_script("Handel::Compat::Currency::format(Handel::Compat::Currency->new(\$_xsp_handel_order_order->$tag->value), '$code', '$format');\n"); }; } elsif ($tag =~ /^(subtotal|tax|handling|shipping)$/) { $e->append_to_script("\$_xsp_handel_order_order->$tag->value;\n"); } else { $e->append_to_script("\$_xsp_handel_order_order->$tag;\n"); }; } elsif ($context[-1] eq 'results' && $context[-2] eq 'item') { $e->start_expr($tag); $e->append_to_script("\$_xsp_handel_order_item->$tag;\n"); } elsif ($context[-1] eq 'results' && $context[-2] eq 'items') { $e->start_expr($tag); $e->append_to_script("\$_xsp_handel_order_item->$tag;\n"); } elsif ($context[-1] eq 'results' && $context[-2] eq 'add') { $e->start_expr($tag); $e->append_to_script("\$_xsp_handel_order_item->$tag;\n"); } elsif ($context[-1] eq 'delete' && $tag !~ /^(count|subtotal)$/) { return "\n\$_xsp_handel_order_delete_filter{$tag} = ''"; } elsif ($context[-1] eq 'update') { throw Handel::Exception::Taglib( -text => translate('TAG_NOT_ALLOWED_HERE', $tag) ) if ($tag eq 'id'); if ($context[-3] =~ /^(order(s?))$/) { return "\n\$_xsp_handel_order_order->$tag(''"; } elsif ($context[-3] =~ /^(item(s?))$/) { return "\n\$_xsp_handel_order_item->$tag(''"; }; }; ## order item property tags ## order:sku, price, quantity, total } elsif ($tag =~ /^(sku|price|quantity|total)$/) { if ($context[-1] eq 'new') { return "\n\$_xsp_handel_order_new_filter{$tag} = ''"; } elsif ($context[-1] eq 'add') { return "\n\$_xsp_handel_order_add_filter{$tag} = ''"; #} elsif ($context[-1] eq 'results' && $context[-2] eq 'add') { # $e->start_expr($tag); # $e->append_to_script("\$_xsp_handel_order_item->$tag;\n"); } elsif ($context[-1] eq 'results' && $context[-2] =~ /^(add|new|order(s?)|item(s?))$/) { $e->start_expr($tag); if ($tag =~ /^(price|total)$/ && ($attr{'format'} || $attr{'convert'})) { my $cfg = Handel::ConfigReader->new(); my $code = $attr{'to'} || $attr{'code'} || $cfg->{'HandelCurrencyCode'}; my $format = $attr{'options'} || $cfg->{'HandelCurrencyFormat'}; my $from = $attr{'from'} || $cfg->{'HandelCurrencyCode'}; my $to = $attr{'to'} || $attr{'code'} || $cfg->{'HandelCurrencyCode'}; AxKit::Debug(5, "[Handel] [Order] [$tag] code=$code, format=$format, from=$from, to=$to"); if ($attr{'convert'}) { if ($context[-2] =~ /^(new|order(s?))$/) { $e->append_to_script("Handel::Compat::Currency::convert(Handel::Compat::Currency->new(\$_xsp_handel_order_order->$tag->value), '$from', '$to', '".($attr{'format'}||'')."', '$format');\n"); } else { $e->append_to_script("Handel::Compat::Currency::convert(Handel::Compat::Currency->new(\$_xsp_handel_order_item->$tag->value), '$from', '$to', '".($attr{'format'}||'')."', '$format');\n"); }; } elsif ($attr{'format'}) { if ($context[-2] =~ /^(new|order(s?))$/) { $e->append_to_script("Handel::Compat::Currency::format(Handel::Compat::Currency->new(\$_xsp_handel_order_order->$tag->value), '$code', '$format');\n"); } else { $e->append_to_script("Handel::Compat::Currency::format(Handel::Compat::Currency->new(\$_xsp_handel_order_item->$tag->value), '$code', '$format');\n"); }; }; } elsif ($tag =~ /^(price|total)$/) { if ($context[-2] =~ /^(new|order(s?))$/) { $e->append_to_script("\$_xsp_handel_order_order->$tag->value;\n"); } else { $e->append_to_script("\$_xsp_handel_order_item->$tag->value;\n"); }; } else { if ($context[-2] =~ /^(new|order(s?))$/) { $e->append_to_script("\$_xsp_handel_order_order->$tag;\n"); } else { $e->append_to_script("\$_xsp_handel_order_item->$tag;\n"); }; }; } elsif ($context[-1] eq 'delete') { return "\n\$_xsp_handel_order_delete_filter{$tag} = ''"; } elsif ($context[-1] eq 'update') { if ($context[-3] =~ /^(order(s?))$/) { return "\n\$_xsp_handel_order_order->$tag(''"; } elsif ($context[-3] =~ /^(item(s?))$/) { return "\n\$_xsp_handel_order_item->$tag(''"; }; }; ## order:filter } elsif ($tag eq 'filter') { my $key = $attr{'name'} || 'id'; if ($context[-1] eq 'order') { return "\n\$_xsp_handel_order_load_filter{'$key'} = ''"; } elsif ($context[-1] eq 'orders') { return "\n\$_xsp_handel_orders_load_filter{'$key'} = ''"; } elsif ($context[-1] eq 'item') { return "\n\$_xsp_handel_order_item_filter{'$key'} = ''"; } elsif ($context[-1] eq 'items') { return "\n\$_xsp_handel_order_items_filter{'$key'} = ''"; } elsif ($context[-1] eq 'cart') { return "\n\$_xsp_handel_order_new_cart_filter{'$key'} = ''"; }; ## order:results } elsif ($tag =~ /^result(s?)$/) { throw Handel::Exception::Taglib( -text => translate('TAG_NOT_ALLOWED_HERE', $tag) ) if ($context[-1] !~ /^(new|add|order(s?)|item(s?))$/); push @context, $tag; if ($context[-2] eq 'new') { return ' if (!$_xsp_handel_order_called_new && scalar keys %_xsp_handel_order_new_filter) { $_xsp_handel_order_order = Handel::Order->create(\%_xsp_handel_order_new_filter, $_xsp_handel_order_new_process); $_xsp_handel_order_called_new = 1; }; if ($_xsp_handel_order_order) { '; } elsif ($context[-2] eq 'order') { return ' if (!$_xsp_handel_order_called_load) { $_xsp_handel_order_order = (scalar keys %_xsp_handel_order_load_filter) ? Handel::Order->search(\%_xsp_handel_order_load_filter)->next : Handel::Order->search->next; $_xsp_handel_order_called_load = 1; }; if ($_xsp_handel_order_order) { '; } elsif ($context[-2] eq 'orders') { return ' if (!$_xsp_handel_orders_called_load) { @_xsp_handel_order_orders = (scalar keys %_xsp_handel_orders_load_filter) ? Handel::Order->search(\%_xsp_handel_orders_load_filter) : Handel::Order->search; $_xsp_handel_orders_called_load = 1; }; foreach my $_xsp_handel_order_order (@_xsp_handel_order_orders) { '; } elsif ($context[-2] eq 'item') { return ' if (!$_xsp_handel_order_called_item) { $_xsp_handel_order_item = (scalar keys %_xsp_handel_order_item_filter) ? $_xsp_handel_order_order->items(\%_xsp_handel_order_item_filter)->next : $_xsp_handel_order_order->items->next; $_xsp_handel_order_called_item = 1; }; if ($_xsp_handel_order_item) { '; } elsif ($context[-2] eq 'items') { return ' if (!$_xsp_handel_order_called_items) { @_xsp_handel_order_items = (scalar keys %_xsp_handel_order_items_filter) ? $_xsp_handel_order_order->items(\%_xsp_handel_order_items_filter) : $_xsp_handel_order_order->items; $_xsp_handel_order_called_items = 1; }; foreach my $_xsp_handel_order_item (@_xsp_handel_order_items) { '; } elsif ($context[-2] eq 'add') { return ' if (!$_xsp_handel_order_called_add && scalar keys %_xsp_handel_order_add_filter) { $_xsp_handel_order_item = $_xsp_handel_order_order->add(\%_xsp_handel_order_add_filter); $_xsp_handel_order_called_add = 1; }; if ($_xsp_handel_order_item) { '; }; ## order:no-results } elsif ($tag =~ /^no-result(s?)$/) { throw Handel::Exception::Taglib( -text => translate('TAG_NOT_ALLOWED_HERE', $tag) ) if ($context[-1] !~ /^(new|add|order(s?)|item(s?))$/); push @context, $tag; if ($context[-2] eq 'new') { return ' if (!$_xsp_handel_order_called_new && scalar keys %_xsp_handel_order_new_filter) { $_xsp_handel_order_order = Handel::Order->create(\%_xsp_handel_order_new_filter, $_xsp_handel_order_new_process); $_xsp_handel_order_called_new = 1; }; if (!$_xsp_handel_order_order) { '; } elsif ($context[-2] eq 'order') { return ' if (!$_xsp_handel_order_called_load) { $_xsp_handel_order_order = (scalar keys %_xsp_handel_order_load_filter) ? Handel::Order->search(\%_xsp_handel_order_load_filter)->next : Handel::Order->search->next; $_xsp_handel_order_called_load = 1; }; if (!$_xsp_handel_order_order) { '; } elsif ($context[-2] eq 'orders') { return ' if (!$_xsp_handel_orders_called_load) { @_xsp_handel_order_orders = (scalar keys %_xsp_handel_orders_load_filter) ? Handel::Order->search(\%_xsp_handel_orders_load_filter) : Handel::Order->search; $_xsp_handel_orders_called_load = 1; }; if (!scalar @_xsp_handel_order_orders) { '; } elsif ($context[-2] eq 'item') { return ' if (!$_xsp_handel_order_called_item) { $_xsp_handel_order_item = (scalar keys %_xsp_handel_order_item_filter) ? $_xsp_handel_order_order->items(\%_xsp_handel_order_item_filter)->next : $_xsp_handel_order_order->items->next; $_xsp_handel_order_called_item = 1; }; if (!$_xsp_handel_order_item) { '; } elsif ($context[-2] eq 'items') { return ' if (!$_xsp_handel_order_called_items) { @_xsp_handel_order_items = (scalar keys %_xsp_handel_order_items_filter) ? $_xsp_handel_order_order->items(\%_xsp_handel_order_items_filter) : $_xsp_handel_order_order->items; $_xsp_handel_order_called_items = 1; }; if (!scalar @_xsp_handel_order_items) { '; } elsif ($context[-2] eq 'add') { return ' if (!$_xsp_handel_order_called_add && scalar keys %_xsp_handel_order_add_filter) { $_xsp_handel_order_item = $_xsp_handel_order_order->add(\%_xsp_handel_order_add_filter); $_xsp_handel_order_called_add = 1; }; if (!$_xsp_handel_order_item) { '; }; }; return ''; }; sub parse_end { my ($e, $tag) = @_; AxKit::Debug(5, "[Handel] [Order] parse_end [$tag] context: " . join('->', @context)); ## order:new if ($tag eq 'new') { pop @context; return ' if (!$_xsp_handel_order_called_new && scalar keys %_xsp_handel_order_new_filter) { $_xsp_handel_order_order = Handel::Order->create(\%_xsp_handel_order_new_filter); $_xsp_handel_order_called_new = 1; }; };'; ## order:cart } elsif ($tag eq 'cart') { pop @context; return ' if (scalar keys %_xsp_handel_order_new_cart_filter) { $_xsp_handel_order_new_filter{\'cart\'} = \%_xsp_handel_order_new_cart_filter; }; '; ## order:order } elsif ($tag eq 'order') { pop @context; return "\n};\n"; ## order:orders } elsif ($tag eq 'orders') { pop @context; return "\n};\n"; ## order:item } elsif ($tag eq 'item') { pop @context; return "\n};\n"; ## order:items } elsif ($tag eq 'items') { pop @context; return "\n};\n"; ## order:add } elsif ($tag eq 'add') { pop @context; return ' if (!$_xsp_handel_order_called_add && scalar keys %_xsp_handel_order_add_filter) { $_xsp_handel_order_item = $_xsp_handel_order_order->add(\%_xsp_handel_order_add_filter); $_xsp_handel_order_called_add = 1; }; }; '; ## order:update } elsif ($tag eq 'update') { if ($context[-3] =~ /^(order(s?))$/) { pop @context; return ' $_xsp_handel_order_order->update; $_xsp_handel_order_order->autoupdate(1); '; } elsif ($context[-3] =~ /^(item(s?))$/) { pop @context; return ' $_xsp_handel_order_item->update; $_xsp_handel_order_item->autoupdate(1); '; }; pop @context; ## order:delete } elsif ($tag eq 'delete') { pop @context; return ' if (scalar keys %_xsp_handel_order_delete_filter) { $_xsp_handel_order_order->delete(\%_xsp_handel_order_delete_filter); }; }; '; ## order propery tags ## order:description, id, name, shopper, type, count, subtotal } elsif ($tag =~ /^(description|id|name|shopper|type|count| billtofirstname|billtolastname|billtoaddress1|billtoaddress2|billtoaddress3| billtocity|billtostate|billtozip|billtocountry| billtodayphone|billtonightphone|billtofax|billtoemail| comments|created|handling|number|shipmethod|shipping|shiptosameasbillto| shiptofirstname|shiptolastname|shiptoaddress1|shiptoaddress2|shiptoaddress3| shiptocity|shiptostate|shiptozip|shiptocountry| shiptodayphone|shiptonightphone|shiptofax|shiptoemail| tax|subtotal|updated)$/x) { if ($context[-1] eq 'new' && $tag !~ /^(count)$/) { return ";\n"; } elsif ($context[-1] eq 'add' && $tag !~ /^(count|subtotal)$/) { return ";\n"; } elsif ($context[-1] eq 'results') { $e->end_expr($tag); } elsif ($context[-1] eq 'delete' && $tag !~ /^(count|subtotal)$/) { return ";\n"; } elsif ($context[-1] eq 'update') { if ($context[-3] =~ /^(order(s?))$/) { return ");\n"; } elsif ($context[-3] =~ /^(item(s?))$/) { return ");\n"; }; }; ## order item property tags ## order:sku, price, quantity } elsif ($tag =~ /^(sku|price|quantity|total)$/) { if ($context[-1] eq 'add') { return ";\n"; } elsif ($context[-1] eq 'new') { return ";\n"; } elsif ($context[-1] eq 'results' && $context[-2] eq 'new') { $e->end_expr($tag); } elsif ($context[-1] eq 'results' && $context[-2] eq 'add') { $e->end_expr($tag); } elsif ($context[-1] eq 'results' && $context[-2] eq 'item') { $e->end_expr($tag); } elsif ($context[-1] eq 'results' && $context[-2] eq 'items') { $e->end_expr($tag); } elsif ($context[-1] eq 'results' && $context[-2] eq 'order') { $e->end_expr($tag); } elsif ($context[-1] eq 'results' && $context[-2] eq 'orders') { $e->end_expr($tag); } elsif ($context[-1] eq 'delete' && $tag !~ /^(count|subtotal)$/) { return ";\n"; } elsif ($context[-1] eq 'update') { if ($context[-3] =~ /^(order(s?))$/) { return ");\n"; } elsif ($context[-3] =~ /^(item(s?))$/) { return ");\n"; }; }; ## order:filter } elsif ($tag eq 'filter') { if ($context[-1] eq 'order') { return ";\n"; } elsif ($context[-1] eq 'orders') { return ";\n"; } elsif ($context[-1] eq 'item') { return ";\n"; } elsif ($context[-1] eq 'items') { return ";\n"; } elsif ($context[-1] eq 'restore') { return ";\n"; } elsif ($context[-1] eq 'cart') { return ";\n"; }; ## order:results } elsif ($tag =~ /^result(s?)$/) { if ($context[-2] eq 'new') { pop @context; return "\n};\n"; } elsif ($context[-2] eq 'order') { pop @context; return "\n};\n"; } elsif ($context[-2] eq 'orders') { pop @context; return "\n};\n"; } elsif ($context[-2] eq 'item') { pop @context; return "\n};\n"; } elsif ($context[-2] eq 'items') { pop @context; return "\n};\n"; } elsif ($context[-2] eq 'add') { pop @context; return "\n};\n"; }; pop @context; ## order:no-results } elsif ($tag =~ /^no-result(s?)$/) { if ($context[-2] eq 'new') { pop @context; return "\n};\n"; } elsif ($context[-2] eq 'order') { pop @context; return "\n};\n"; } elsif ($context[-2] eq 'orders') { pop @context; return "\n};\n"; } elsif ($context[-2] eq 'item') { pop @context; return "\n};\n"; } elsif ($context[-2] eq 'items') { pop @context; return "\n};\n"; } elsif ($context[-2] eq 'add') { pop @context; return "\n};\n"; }; pop @context; }; return ''; }; #}; 1; __END__ =head1 NAME AxKit::XSP::Handel::Order - AxKit XSP Order Taglib =head1 SYNOPSIS Add this taglib to AxKit in your http.conf or .htaccess: AxAddXSPTaglib AxKit::XSP::Handel::Order Add the namespace to your XSP file and use the tags: ... ... There are currently no items in your order. The order requested could not be found. =head1 DESCRIPTION This tag library provides an interface to use C inside of your AxKit XSP pages. =head1 TAG HIERARCHY value value value value value value value value value value value value value value value value value value value value value value value value value value value value value value value value value value value value value value value value value value value value value value value value value value value value value value value value value value value value value value value value value value value value value value value value value value value value value value value value value value ... ... value value value value value value ... value value value value value value value value value value value value ... value value value value value value value value value value value value value value value value value value value value value value value value value value value value value value value value value value value value value value value ... =head1 TAG REFERENCE =head2 Adds an a item to the current order. You can specify the item properties as attributes in the tag itself: or you can add them as child elements: My New Part 11111111-1111-1111-1111-111111111111 1234 1 1.23 1.23 or any combination of the two: My New Part 11111111-1111-1111-1111-111111111111 1234 1.23 1.23 This tag is only valid within the Corder:resultsE> block for C and C. See C for more information about adding parts to the order. You can also access the newly added item using the Corder:resultsE>. =head2 Context aware tag that gets or sets the bill to address first name. =head2 Context aware tag that gets or sets the bill to address last name. =head2 Context aware tag that gets or sets the bill to address line 1. =head2 Context aware tag that gets or sets the bill to address line 2. =head2 Context aware tag that gets or sets the bill to address line 3. =head2 Context aware tag that gets or sets the bill to address city. =head2 Context aware tag that gets or sets the bill to address state. =head2 Context aware tag that gets or sets the bill to address zip or postal code. =head2 Context aware tag that gets or sets the bill to address country. =head2 Context aware tag that gets or sets the bill to address date time phone number. =head2 Context aware tag that gets or sets the bill to address night time phone number. =head2 Context aware tag that gets or sets the bill to address fax number. =head2 Context aware tag that gets or sets the bill to email address. =head2 Deletes all items in the current order. 11111111-1111-1111-1111-111111111111 The order requested could not be found. =head2 Context aware tag that gets or sets the orders comments. =head2 Returns the number of items in the current order. The order requested could not be found. =head2 Context aware tag that gets or sets the order creation date. =head2 Context aware tag to get or set the description of various other parent tags. Within Corder:addE> or Corder:updateE> it sets the current order items description: My New SKU Description My Updated SKU Description The order item could not be found for updating The order requested could not be found. =head2 Adds a new name/value pair to the filter used in Corder:orderE>, Corder:ordersE>, Corder:deleteE>, Corder:itemE>, Corder:cart>, and Corder:itemsE>. Pass the name of the pair in the C attribute and the value between the start and end filter tags: 12345678-9098-7654-3212-345678909876 sku1234 The order item could not be found for deletion If the same attribute is specified in a filter, the child filter tag value takes precedence over the parent tags attribute. 1 You can supply as many Cs as needed to get the job done. 0 12345678-9098-7654-3212-345678909876 =head2 Context aware tag the gets or sets the handling charge for this order. =head2 Context aware tag to get or set the record id within various other tags. In Corder:orderE> and Corder:itemE> it returns the record id for the object: The order requested could not be found. Within Corder:addE>, Corder:deleteE>, and Corder:newE> it sets the id value used in the operation specified: 11111111-1111-1111-1111-111111111111 The order requested could not be found. ... 11112222-3333-4444-5555-6666777788889999 New Cart It cannot be used within Corder:updateE> and will return a C exception if you try updating the record ids which are the primary keys. =head2 Loops through all items in the current order: Your order is empty The order requested could not be found. =head2 B Starting in version 0.17_04, new no longer automatically creates a checkout process for C. The C<$noprocess> parameter has been renamed to C<$process>. The have the new order automatically run a checkout process, set $process to 1. Creates a new order using the supplied attributes and child tags: 22222222-2222-2222-2222-222222222222 New Cart The child tags take precedence over the attributes of the same name. C B within it's declared namespace. It will throw an C exception otherwise. When true, the C attribute forces new to automatically create a checkout process and initialize the current order. See L for more information on the process flag. =head2 Context aware tag that gets or sets the order number. =head2 Container tag for the current order used to load a specific order. If C or its Cs load more than one order, C will contain only the first order. If you're looking for loop through multiple orders, try Corder:ordersE> instead. 11111111-1111-1111-1111-111111111111 ... ... The order requested could not be found. =head2 Loops through all loaded orders. 11111111-1111-1111-1111-111111111111 ... No orders were found matching your query. =head2 Context aware tag to get or set the price of a order item. In Corder:addE> and Corder:updateE> it sets the price: 1.24 The order requested could not be found. In Corder:itemE> or Corder:itemsE> it returns the price for the order item: Your shopping order is empty The order requested could not be found. =head3 Currency Formatting The currency formatting options from C are now available within the taglib if C is installed. Currency formatting is available for any tag the returns a currency or price like price, total, shipping, handling, tax, etc. =over =item format Toggle switch that enables or disables currency formatting. If empty, unspecified, or set to 0, no formatting will take place and the result price (usually in decimal form) is returned unaltered. If C is set to anything else, the default formatting will be applied. See C for the default currency formatting settings. =item code If formatting is enabled, the C attribute specifies the desired three letter ISO currency code to be used when formatting currency. See C for the available codes. If you are also using the currency conversion options below, the value of C will always be used first, even if C is not empty. If C is empty and C is also empty, the C configuration setting will be used instead. =item options If formatting is enabled, the C attribute specifies the desired formatting options to be used when formatting currency. See C for the available options. =back =head3 Currency Conversion The currency conversion options from C are now available within the taglib if C is installed. Currency conversion is available for any tag the returns a currency or price like price, total, shipping, handling, tax, etc. =over =item convert Toggle switch that enables or disables currency conversion. If empty, unspecified, or set to 0, no currency conversion will take place and the result price is returned unaltered. If C is set to anything else, the default conversion will be applied. See C for the default currency conversion settings. =item from If conversion is enabled, the C attribute specifies the three letter ISO currency code of the price to be converted. If no C is specified, the C configuration setting will be used instead. See C for the available codes. =item to If conversion is enabled, the C attribute specifies what the current C should be converted to. If no C is specified, the C attribute from the formatting options above will be used instead. If both C and C are empty, the C configuration setting will be used as a last resort. =back If you try to convert from and to the same currency, the C is returned as is. =head3 Precedence If you are using both the currency conversion and the currency formatting options, the conversion will be performed first, then the result will be formatted. =head2 Context aware tag to get or set the quantity of a order item. In Corder:addE> and Corder:updateE> it sets the quantity: 1.24 The order requested could not be found. In Corder:itemE> or Corder:itemsE> it returns the quantity for the order item: The item requested could not be found for updating The order requested could not be found. =head2 Context aware tag that gets or sets the order last updated date. =head2 Updates the current order values: ORDER_TYPE_TEMP The order requested could not be found. Corder:idE> is not valid within an update statement. =head2 Contains the results for the current action. both the singular and plural forms are valid for your syntactic sanity: ... =head2 The anti-results or 'not found' tag. This tag is executed when C, C, C, or C fails to find a match for it's filters. As with Corder:resultsE>, both the singular and plural forms are available for your enjoyment: ... =head2 Context aware tag that gets or sets the ship to address first name. =head2 Context aware tag that gets or sets the ship to address last name. =head2 Context aware tag that gets or sets the ship to address line 1. =head2 Context aware tag that gets or sets the ship to address line 2. =head2 Context aware tag that gets or sets the ship to address line 3. =head2 Context aware tag that gets or sets the ship to address city. =head2 Context aware tag that gets or sets the ship to address state. =head2 Context aware tag that gets or sets the ship to address zip or postal code. =head2 Context aware tag that gets or sets the ship to address country. =head2 Context aware tag that gets or sets the ship to address date time phone number. =head2 Context aware tag that gets or sets the ship to address night time phone number. =head2 Context aware tag that gets or sets the ship to address fax number. =head2 Context aware tag that gets or sets the ship to email address. =head2 Context aware tag that gets or sets the selected shipping method. =head2 Context aware tag that gets or sets the shipping cost. =head2 Context aware tag that gets or sets the flag making the ship to address the same as the bill to address. =head2 Context aware tag that gets or sets the shopper id for the current order. =head2 Context aware tag to get or set the sku of a order item. In Corder:addE> and Corder:updateE> it sets the sku: sku1234 The order requested could not be found. In Corder:itemE> or Corder:itemsE> it returns the sku for the current order item: Your shopping order is empty The order requested could not be found. =head2 Gets or sets the subtotal of the items in the current order: The order requested could not be found. The currency formatting options from C are now available within the taglib. The currency conversion options from C are now available within the taglib. See above for further details about price formatting. =head2 Gets or sets the order tax charge. =head2 Gets or sets the total of the current order item: Your shopping order is empty The order requested could not be found. The currency formatting options from C are now available within the taglib. The currency conversion options from C are now available within the taglib. See above for further details about price formatting. =head2 Context aware tag to get or set the type within various other tags. In Corder:orderE> or Corder:ordersE> it returns the type for the object: The order requested could not be found. Within Corder:updateE> and Corder:newE> it sets the type value used in the operation specified: 1 The order requested could not be found. ... 1 =head2 This tag returns a new uuid/guid for use in C and C in the following format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx For those like me who always type the wrong thing, Corder:guid/> returns the same things as Corder:uuid/>. =head1 AUTHOR Christopher H. Laco CPAN ID: CLACO claco@chrislaco.com http://today.icantfocus.com/blog/