From e51d02e3d84196b1695f482d0a00f0e09a8a781c Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Fri, 27 Jun 2008 20:25:30 +0000 Subject: [PATCH] Add a new method to FlatDiscount to tell if it is already in the cart. Add a template variable to tell if there is already one in the cart. Modify the default template to include the thank you message and to hide the add to cart button if this coupon is already in the cart. --- docs/changelog/7.x.x.txt | 1 + .../root_import_flat-discount-default.wgpkg | Bin 0 -> 920 bytes lib/WebGUI/Asset/Sku/FlatDiscount.pm | 29 +++++++++++++++--- lib/WebGUI/Help/Asset_FlatDiscount.pm | 1 + lib/WebGUI/i18n/English/Asset_FlatDiscount.pm | 8 ++++- 5 files changed, 34 insertions(+), 5 deletions(-) create mode 100644 docs/upgrades/packages-7.5.15/root_import_flat-discount-default.wgpkg 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 0000000000000000000000000000000000000000..b314b51867dcd7be43342dd9ddc6dab2181fb19f GIT binary patch literal 920 zcmV;J184jniwFP!000001MOB@Z`v>v=DEKj%F`yT5E8;os8VT5L82X6>AGp1CO0v} zBiNDc6xh`NzGElQn9+3)WzwYjAtpIKx9@!Cm~v_V%W<5B@0UujJ9X!Aw>HZuRjZCy zb!)!w)k+q;xK7CemHn?&NW>vDl%OEOPy2gLu99=|$Tcr-IX`RgS`Bn?|EDG_v#+h|DT|^ulko?6vDk3`*{FWu!UqCO|fmYtuN{WEVX@o zr=SGj+(R8Oe5(3LyweFFn zdl+3iy&(E@KDe2kdlKR)W|8t(d*O`93YjY~Dw7z=!;px8r4)YP2})yWXb~~uOftDj zG6c-*i0G3r#8exu8j4fS(qs^xg+yjj*APoQPr!L*v?Jl=8<|)F3qcqy-y>c|;hfO- z^yrq~Qmd03Wrsjw1&m70VsX@|BwF05r&I6W`U+@4@ha9<{e?ZIn7$)t>K*r#cFgHXYNhjiy28SnIsbu zAjK7J)kI>BX{rhN*B%visU8A0N?^?0Z%rUQ3a-eHETD#C_F95C3>oe038>ob{`g|J z6SxRy(~Vg$Q~KLelZYWm*7e+$7Avm3w_1%>%Wt?Q930;h)%BgetCart->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| },