From e3061a1606ccd63d2077cc24b3a6ffccac9ed0b4 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Sat, 24 May 2008 23:14:38 +0000 Subject: [PATCH] begin implementing inventory control. Continue to separate the variants loop and the list of available variants for sale. --- lib/WebGUI/Asset/Sku/Product.pm | 45 ++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/lib/WebGUI/Asset/Sku/Product.pm b/lib/WebGUI/Asset/Sku/Product.pm index 5d213efc8..fc195bb05 100644 --- a/lib/WebGUI/Asset/Sku/Product.pm +++ b/lib/WebGUI/Asset/Sku/Product.pm @@ -73,6 +73,7 @@ cart decrements the quantity by 1. sub addToCart { my $self = shift; my $variant = shift; + my $i18n = WebGUI::International->new($self->session, 'Asset_Product'); $variant->{quantity} -= 1; $self->setCollateral('variantsJSON', 'variantId', $variant); $self->SUPER::addToCart($variant); @@ -390,6 +391,21 @@ sub getFileUrl { #------------------------------------------------------------------- +=head2 getMaxAllowedInCart ( ) + +Returns the quantity after options from a variant have been applied to this +Product via applyOptions. For WebGUI::Shop::CartItem, this is handled by +getSku automatically. + +=cut + +sub getMaxAllowedInCart { + my $self = shift; + return $self->getOptions->{quantity}; +} + +#------------------------------------------------------------------- + =head2 getPrice ( ) Only returns a price after options from a variant have been applied to this @@ -510,6 +526,29 @@ sub moveCollateralUp { } +#------------------------------------------------------------------- + +=head2 onAdjustQuantityInCart ( item, amount ) + +Override the default Sku to handle checking inventory + +=head3 item + +The WebGUI::Shop::CartItem that is having its quantity adjusted. + +=head3 amount + +The amount adjusted. Could be positive or negative. + +=cut + +sub onAdjustQuantityInCart { + my $self = shift; + my $item = shift; + my $amount = shift; +} + + #------------------------------------------------------------------- =head2 prepareView ( ) @@ -1413,10 +1452,10 @@ sub view { 'variant_weight' => $collateral->{weight}, 'variant_quantity' => $collateral->{quantity}, }); - $variants{$id} = $collateral->{shortdesc}; + $variants{$id} = $collateral->{shortdesc} if $collateral->{quantity} > 0; } - if (scalar @variantLoop) { - ##Don't display the form unless you have variants to sell. + if (scalar keys %variants) { + ##Don't display the form unless you have available variants to sell. $var{buy_form_header} = WebGUI::Form::formHeader($session, { action => $self->getUrl} ) . WebGUI::Form::hidden($session, { name=>'func', value=>'buy', } ); $var{buy_form_footer} = WebGUI::Form::formFooter($session);