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.
This commit is contained in:
Colin Kuskie 2008-06-27 20:25:30 +00:00
parent 59424e1fe3
commit e51d02e3d8
5 changed files with 34 additions and 5 deletions

View file

@ -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

View file

@ -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});
}

View file

@ -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 => [
],

View file

@ -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|
},