Skip to content
This repository
tag: DEB_4_9_8_2
Fetching contributors…

Cannot retrieve contributors at this time

file 136 lines (99 sloc) 2.62 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
UserTag weight Order attribute
UserTag weight addAttr
UserTag weight Routine <<EOR
sub {
my ($attr, $opt) = @_;
$opt ||= {};

my $cart;
if($opt->{cart}) {
$cart = $Vend::Session->{carts}{$opt->{cart}} || [];
}
else {
$cart = $Vend::Items;
}

my $wsub;

my $field = $opt->{field} || 'weight';
my $table = $opt->{table};

if($attr) {
$attr = $opt->{field} || 'weight';
$wsub = sub {
return shift(@_)->{$attr};
};
}
elsif($opt->{fill_attribute}) {
$attr = $opt->{fill_attribute};
$wsub = sub {
my $it = shift;
return $it->{$attr} if defined $it->{$attr};
my $tab = $table || $it->{mv_ib} || $Vend::Cfg->{ProductFiles}[0];
$it->{$attr} = tag_data($tab,$field,$it->{code}) || 0;
return $it->{$attr};
};
}
else {
$wsub = sub {
my $it = shift;
my $tab = $table || $it->{mv_ib} || $Vend::Cfg->{ProductFiles}[0];
return tag_data($tab,$field,$it->{code});
};
}

my $total = 0;
for(@$cart) {
$total += $_->{quantity} * $wsub->($_);
}

unless($opt->{no_set}) {
$::Scratch->{$opt->{weight_scratch} ||= 'total_weight'} = $total;
}

return $total unless $opt->{hide};
return;
}
EOR

UserTag weight Documentation <<EOD
=head1 NAME

ITL tag [weight] -- calculate shipping weight from cart

=head1 SYNOPSIS

 [weight]
 [weight
    attribute=1*
    cart=cartname*
    field=sh_weight*
    fill-attribute=weight*
    hide=1|0*
    no-set=1|0*
    table=weights*
    weight-scratch=sh_weight*
 ]

=head1 DESCRIPTION

Calculates total weight of items in shopping cart, by default setting
a scratch variable (default "total_weight").

=head2 Options

=over 4

=item attribute

If set, weight tag will calculate from the field in the item itself instead
of going to the database. This is the most efficient, and can be enabled
by using this in catalog.cfg:

AutoModifier weight

The default is not set, using the database every time.

=item cart

The cart to calculate for. Defaults to current cart.

=item field

The fieldname to use -- default "weight". This applies both to attribute
and database.

=item fill-attribute

Sets the attribute from the database the first time, and uses it thereafter.
Sets to weight of a single unit, of course.

=item hide

Don't display the weight, only set in Scratch. It makes no sense to
use hide=1 and no-set=1.

=item no-set

Don't set the weight in scratch.

=item table

Specify a table to use to look up weights. Defaults to the table the
product was ordered from (or the first ProductFiles).

=item weight-scratch

The scratch variable name to set -- default is "total_weight".

=back

=head1 AUTHOR

Mike Heins

=cut
EOD
Something went wrong with that request. Please try again.