diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index f03886293..4e9d9a2c1 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -2,6 +2,7 @@ - fixed: Colorpicker window would not open (Martin Kamerbeek / Oqapi) - fixed: Reverted change to RichEdit that caused IE6 to stop working - fixed: Subscription: Price not displaying + - fixed: Flat Discount Coupon: Add to Cart button seems broken 7.5.14 - fixed: RSS feeds report modified date instead of create date diff --git a/docs/upgrades/packages-7.5.15/root_import_flat-discount-default.wgpkg b/docs/upgrades/packages-7.5.15/root_import_flat-discount-default.wgpkg new file mode 100644 index 000000000..b314b5186 Binary files /dev/null and b/docs/upgrades/packages-7.5.15/root_import_flat-discount-default.wgpkg differ diff --git a/lib/WebGUI/Asset/Sku/FlatDiscount.pm b/lib/WebGUI/Asset/Sku/FlatDiscount.pm index db085498e..1c6c9087b 100644 --- a/lib/WebGUI/Asset/Sku/FlatDiscount.pm +++ b/lib/WebGUI/Asset/Sku/FlatDiscount.pm @@ -52,10 +52,7 @@ Checks to make sure there isn't already a coupon of this type in the cart. sub addToCart { my ($self, $options) = @_; - my $found = 0; - foreach my $item (@{$self->getCart->getItems()}) { - $found =1 if (ref($item->getSku) eq ref($self)); - } + my $found = $self->hasCoupon(); unless ($found) { $self->{_hasAddedToCart} = 1; $self->SUPER::addToCart($options); @@ -166,6 +163,28 @@ sub getPrice { return 0; } +#------------------------------------------------------------------- + +=head2 hasCoupon + +Returns 1 if this coupon is already in the user's cart. It does a short-circuiting +search for speed. + +=cut + +sub hasCoupon { + my $self = shift; + my $hasCoupon = 0; + ITEM: foreach my $item (@{$self->getCart->getItems()}) { + if (ref($item->getSku) eq ref($self)) { + $hasCoupon=1; + last ITEM; + } + } + return $hasCoupon; +} + + #------------------------------------------------------------------- =head2 isCoupon @@ -215,6 +234,8 @@ sub view { addToCartButton => WebGUI::Form::submit( $session, { value => $i18n->get("add to cart") }), hasAddedToCart => $self->{_hasAddedToCart}, ); + $var{alreadyHasCoupon} = $self->hasCoupon(); + return $self->processTemplate(\%var,undef,$self->{_viewTemplate}); } diff --git a/lib/WebGUI/Help/Asset_FlatDiscount.pm b/lib/WebGUI/Help/Asset_FlatDiscount.pm index 4160dab3c..3d613bad1 100644 --- a/lib/WebGUI/Help/Asset_FlatDiscount.pm +++ b/lib/WebGUI/Help/Asset_FlatDiscount.pm @@ -26,6 +26,7 @@ our $HELP = { { name => "templateId", description=>"template help" }, { name => "hasAddedToCart" , required=>1 }, { name => "thankYouMessage", description=>"thank you message help" }, + { name => "alreadyHasCoupon" }, ], related => [ ], diff --git a/lib/WebGUI/i18n/English/Asset_FlatDiscount.pm b/lib/WebGUI/i18n/English/Asset_FlatDiscount.pm index 0ced69c38..dfb2f58d0 100644 --- a/lib/WebGUI/i18n/English/Asset_FlatDiscount.pm +++ b/lib/WebGUI/i18n/English/Asset_FlatDiscount.pm @@ -112,7 +112,13 @@ our $I18N = { }, 'hasAddedToCart' => { - message => q|A condition indicating that the user has added the product to their cart, so we can display the thank you message.|, + message => q|A conditional indicating that the user has added the product to their cart, so we can display the thank you message.|, + lastUpdated => 1214598286, + context => q|template variable| + }, + + 'alreadyHasCoupon' => { + message => q|A conditional indicating that the user already has this coupon in their cart.|, lastUpdated => 0, context => q|template variable| },