diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 5716e6758..5ddb6fcc4 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -19,6 +19,7 @@ - added Survey now has a loading mask on Survey edit ajax calls. - fixed: Sliders fixed. Improved algorithm for determining pixel step size. - rfe #9355: Password Recovery email subject (SDH Consulting Group) + - added: Users can now set a minimum cart amount required for checkout. (Martin Kamerbeek / Oqapi ) 7.6.14 - fixed: IE6 shows Admin Bar over Asset Manager diff --git a/docs/upgrades/packages-7.7.0/default-shopping-cart-template.wgpkg b/docs/upgrades/packages-7.7.0/default-shopping-cart-template.wgpkg new file mode 100644 index 000000000..ff866b146 Binary files /dev/null and b/docs/upgrades/packages-7.7.0/default-shopping-cart-template.wgpkg differ diff --git a/docs/upgrades/upgrade_7.6.14-7.7.0.pl b/docs/upgrades/upgrade_7.6.14-7.7.0.pl index 8140cae2a..2ec1eaa05 100644 --- a/docs/upgrades/upgrade_7.6.14-7.7.0.pl +++ b/docs/upgrades/upgrade_7.6.14-7.7.0.pl @@ -39,6 +39,7 @@ surveyDoAfterTimeLimit($session); surveyRemoveResponseTemplate($session); surveyEndWorkflow($session); installAssetHistory($session); +addMinimumCartCheckoutSetting( $session ); # Passive Analytics pa_installLoggingTables($session); @@ -303,13 +304,23 @@ sub addTransactionItemFlags { #---------------------------------------------------------------------------- sub createShopAcccountPluginSettings { my $session = shift; - print "Creating default settings for the account plugin..." unless $quiet; + print "\tCreating default settings for the account plugin..." unless $quiet; $session->setting->add('shopMySalesTemplateId', '-zxyB-O50W8YnL39Ouoc4Q'); print "Done.\n" unless $quiet; } +#---------------------------------------------------------------------------- +sub addMinimumCartCheckoutSetting { + my $session = shift; + print "\tAdding setting for minimum cart checkout..." unless $quiet; + + $session->setting->add( 'shopCartCheckoutMinimum', '0.00' ); + + print "Done.\n" unless $quiet; +} + #---------------------------------------------------------------------------- # Describe what our function does #sub exampleFunction { diff --git a/lib/WebGUI/Shop/Admin.pm b/lib/WebGUI/Shop/Admin.pm index bcc7ef7d5..e8d92017b 100644 --- a/lib/WebGUI/Shop/Admin.pm +++ b/lib/WebGUI/Shop/Admin.pm @@ -152,6 +152,13 @@ sub www_editSettings { label => $i18n->get('who is a cashier'), hoverHelp => $i18n->get('who is a cashier help'), ); + $form->float( + name => 'shopCartCheckoutMinimum', + value => $setting->get('shopCartCheckoutMinimum'), + defaultValue=> '0.00', + label => $i18n->get('cart checkout minimum'), + hoverHelp => $i18n->get('cart checkout minimum help'), + ); $form->template( name => "shopCartTemplateId", value => $setting->get("shopCartTemplateId"), @@ -203,13 +210,21 @@ sub www_editSettingsSave { my $self = shift; return $self->session->privilege->adminOnly() unless ($self->session->user->isAdmin); my ($setting, $form) = $self->session->quick(qw(setting form)); + + # Save shop templates foreach my $template (qw(shopMyPurchasesDetailTemplateId shopMyPurchasesTemplateId shopCartTemplateId shopAddressBookTemplateId shopAddressTemplateId)) { $setting->set($template, $form->get($template, "template")); } + + # Save group settings foreach my $group (qw(groupIdCashier groupIdAdminCommerce)) { $setting->set($group, $form->get($group, "group")); } + + # Save mininmum cart checkout + $setting->set( 'shopCartCheckoutMinimum', $form->get( 'shopCartCheckoutMinimum', 'float' ) ); + return $self->www_editSettings(); } diff --git a/lib/WebGUI/Shop/Cart.pm b/lib/WebGUI/Shop/Cart.pm index 82c4e6135..8d18a7802 100644 --- a/lib/WebGUI/Shop/Cart.pm +++ b/lib/WebGUI/Shop/Cart.pm @@ -498,7 +498,7 @@ Returns whether all the required properties of the the cart are set. sub readyForCheckout { my $self = shift; - + # Check if the shipping address is set and correct my $address = eval{$self->getShippingAddress}; return 0 if WebGUI::Error->caught; @@ -513,6 +513,12 @@ sub readyForCheckout { # fail if there are multiple recurring items or if return 0 if ($self->hasMixedItems); + # Check minimum cart checkout requirement + my $requiredAmount = $self->session->setting->get( 'shopCartCheckoutMinimum' ); + if ( $requiredAmount > 0 ) { + return 0 if $self->calculateTotal < $requiredAmount; + } + # All checks passed so return true return 1; } @@ -801,6 +807,10 @@ sub www_view { shipToButton => WebGUI::Form::submit($session, {value=>$i18n->get("ship to button"), extras=>q|onclick="setCallbackForAddressChooser(this.form);"|}), subtotalPrice => $self->formatCurrency($self->calculateSubtotal()), + minimumCartAmount => $session->setting->get( 'shopCartCheckoutMinimum' ) > 0 + ? sprintf( '%.2f', $session->setting->get( 'shopCartCheckoutMinimum' ) ) + : 0 + , ); # get the shipping address @@ -846,10 +856,11 @@ sub www_view { # calculate price adjusted for in-store credit $var{totalPrice} = $var{subtotalPrice} + $var{shippingPrice} + $var{tax}; my $credit = WebGUI::Shop::Credit->new($session, $posUser->userId); - $var{inShopCreditAvailable} = $credit->getSum; - $var{inShopCreditDeduction} = $credit->calculateDeduction($var{totalPrice}); - $var{totalPrice} = $self->formatCurrency($var{totalPrice} + $var{inShopCreditDeduction}); - + $var{ inShopCreditAvailable } = $credit->getSum; + $var{ inShopCreditDeduction } = $credit->calculateDeduction($var{totalPrice}); + $var{ totalPrice } = $self->formatCurrency($var{totalPrice} + $var{inShopCreditDeduction}); + $var{ readyForCheckout } = $self->readyForCheckout; + # render the cart my $template = WebGUI::Asset::Template->new($session, $session->setting->get("shopCartTemplateId")); return $session->style->userStyle($template->process(\%var)); diff --git a/lib/WebGUI/i18n/English/Shop.pm b/lib/WebGUI/i18n/English/Shop.pm index 8311e03b4..86e202b3d 100644 --- a/lib/WebGUI/i18n/English/Shop.pm +++ b/lib/WebGUI/i18n/English/Shop.pm @@ -1528,6 +1528,23 @@ our $I18N = { context => q|template variable for Cart template|, }, + 'cart checkout minimum' => { + message => q|Minimum checkout amount|, + lastUpdated => 0, + context => q|shop setting label|, + }, + + 'cart checkout minimum help' => { + message => q|Use this setting to require a minimum cart value to allow users to check out.|, + lastUpdated => 0, + context => q|shop setting hover help|, + }, + + 'required minimum order amount' => { + message => q|Minimum order:|, + lastUpdated => 0, + context => q|message that is displayed in the cart view screen|, + }, }; 1;