From 7dc385b362686d7279f8917d4269cf9157598638 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Sun, 11 May 2008 04:34:13 +0000 Subject: [PATCH] override addToCart in the Product Sku for doing inventory control --- lib/WebGUI/Asset/Sku/Product.pm | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lib/WebGUI/Asset/Sku/Product.pm b/lib/WebGUI/Asset/Sku/Product.pm index 24ea8ab1c..e660ecf23 100644 --- a/lib/WebGUI/Asset/Sku/Product.pm +++ b/lib/WebGUI/Asset/Sku/Product.pm @@ -56,6 +56,28 @@ sub addRevision { return $newSelf; } +#------------------------------------------------------------------- + +=head2 addToCart ( variant ) + +Override/extend Sku's addToCart method to handle inventory control. + +=head3 variant + +A hashref of variant information for the variant of the Product +that is being added to the cart. Adding the variant to the +cart decrements the quantity by 1. + +=cut + +sub addToCart { + my $self = shift; + my $variant = shift; + $variant->{quantity} -= 1; + $self->setCollateral('variantsJSON', 'vid', $variant); + $self->SUPER::addToCart($variant); +} + #------------------------------------------------------------------- sub definition { my $class = shift;