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:
parent
59424e1fe3
commit
e51d02e3d8
5 changed files with 34 additions and 5 deletions
|
|
@ -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});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 => [
|
||||
],
|
||||
|
|
|
|||
|
|
@ -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|
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue