[ic] MaxQuantityField, cart.pm modification;
to allow for stock at multiple locations
Kevin Walsh
kevin at cursor.biz
Sun Apr 18 20:57:44 EDT 2004
John1 [list_subscriber at yahoo.co.uk] wrote:
> It would be good if the MaxQuantityField code in cart.pm could cope with
> more than 1 quantity field in the inventory table.
>
> e.g. In a scenario where there are 3 warehouses:
>
> MaxQuantityFiled inventory::quantity1::quantity2::quantity3
>
> where quantity1, quantity2 and quantity3 are 3 separate fields in table
> "inventory", recording stock levels at the 3 warehouse.
>
> Personally I need to maintain stock levels at 2 separate locations so have
> made a bespoke modification to cart.pm to cope with this scenario.
> However, I only have a very basic knowledge of Perl so would struggle to
> put together the code to allow the MaxQuantityField configuration
> directive to cope with an arbitrary number of columns/warehouses. So, if
> others also think this would be a useful feature, please could I submit
> this as a feature request :-) Thanks
>
> For illustration, starting at line 223 of cart.pm, my code modification
> to cope with 2 columns is:
>
> if($Vend::Cfg->{MaxQuantityField}) {
> my ($tab, $col1, $col2) = split /:+/, $Vend::Cfg->{MaxQuantityField};
> if(! length $col1) { $col1 = $tab;
> $tab = $item->{mv_ib} || $Vend::Cfg->{ProductFiles}[0]; }
> $item->{mv_max_quantity} = ::tag_data($tab, $col1, $item->{code}) +
> > > tag_data($tab, $col2, $item->{code});
>
As you said, the above will extend the MaxQuantityField to allow two
(and only two - not one or three etc.) quantity columns. You could
possibly allow for any number as follows:
if($Vend::Cfg->{MaxQuantityField}) {
my ($tab, @cols) = split /:+/, $Vend::Cfg->{MaxQuantityField};
my $max = 0;
unless (scalar(@cols)) {
push(@cols,$tab);
$tab = $item->{mv_ib} || $Vend::Cfg->{ProductFiles}[0];
}
foreach (@cols) {
next unless $_;
$max += ::tag_data($tab, $_, $item->{code}) || 0;
}
$item->{mv_max_quantity} = $max if $max;
...
}
Just typed in - untested.
If this was thought to be a generally useful feature then I'd prefer
to see it not as "inventory::quantity1::quantity2::quantity3", but rather
as "inventory::quantity1, inventory::quantity2, sometable::somecol",
which would allow for multiple inventory tables and/or multiple columns
in any table. That might look a little like this:
if($Vend::Cfg->{MaxQuantityField}) {
my $max = 0;
foreach my $pair (split('[\s,]+',$Vend::Cfg->{MaxQuantityField})) {
next unless $pair;
my ($tab, $col) = split /:+/, $pair;
if(! length $col) {
$col = $tab;
$tab = $item->{mv_ib} || $Vend::Cfg->{ProductFiles}[0];
}
$max += ::tag_data($tab, $col, $item->{code}) || 0;
}
$item->{mv_max_quantity} $max if $max;
...
}
Again, the above was just typed in - no testing was performed.
A similar change would probably need to be made to the MinQuantityField
code for consistency.
If you would like to create, test and submit a patch then its inclusion
in future releases will be considered.
--
_/ _/ _/_/_/_/ _/ _/ _/_/_/ _/ _/
_/_/_/ _/_/ _/ _/ _/ _/_/ _/ K e v i n W a l s h
_/ _/ _/ _/ _/ _/ _/ _/_/ kevin at cursor.biz
_/ _/ _/_/_/_/ _/ _/_/_/ _/ _/
More information about the interchange-users
mailing list