'accept terms and conditions' checkbox

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
14 anos atrás
Hi, i need to implement a checkbox in checkoutconfirm.ascx

i have made alterations :
<asp:Button runat="server" ID="btnNextStep" Text="<% $NopResources:Checkout.ConfirmButton %>"
    OnClick="btnNextStep_Click" SkinID="ConfirmOrderNextStepButton" />  
 &nbsp;&nbsp;&nbsp;
    <asp:CheckBox id="tcbox" Text="     " runat="server" style="position: relative; top: 3px;" />
    tick  to confirm  you have read and accepted our terms and conditions.
   <asp:Label id="tclabel" Font-Names="arial" font-size="10pt" runat="server" ForeColor="#CC0000" />
</div>  
  
to add the box beside my 'confirm' button but i'm not sure how best to change the code behind to stop the order confirmation from progressing unless the checkbox is ticked.

i changed:
    protected void btnNextStep_Click(object sender, EventArgs e)
        {
  if (tcbox.Checked == false)
            {
                Response.Redirect("~/CheckoutConfirm.aspx");
                tclabel.Text = "box must be checked";
            }
if (Page.IsValid)

and this reloads the page if the box is not checked but i do not feel this is the best approach (and the label does not work ) - i am also unsure if it has repercussions with the order - is it causing multiple confirmations of the order?
  can anyone advise?
14 anos atrás
anybody have a suggestion for me?
14 anos atrás
Your label doesn't work because you are redirecting to the current page before setting the label text. Instead of modifying the "btnNextStep_Click" method, you can add a custom validator to ensure the checkbox is checked (the following changes are for version 1.40).

1. Edit File: Modules\CheckoutConfirm.ascx (included is the entire SelectButton DIV, I've commented out your label as it's not needed and added a CustomValidator. Just replace "Your Error Message" with the message you want to show when customers click confirm without checking the box).

<div class="SelectButton">
    <asp:Button runat="server" ID="btnNextStep" Text="<% $NopResources:Checkout.ConfirmButton %>"
        OnClick="btnNextStep_Click" SkinID="ConfirmOrderNextStepButton" />
    &nbsp;&nbsp;&nbsp;
    <asp:CheckBox ID="tcbox" Text="     " runat="server" Style="position: relative; top: 3px;" />
    tick to confirm you have read and accepted our terms and conditions.
    <%--
    <asp:Label ID="tclabel" Font-Names="arial" Font-Size="10pt" runat="server" ForeColor="#CC0000" />
    --%>
    <asp:CustomValidator id="cvTCBox" runat="server" OnServerValidate="ValidateTCBox" Display="Static"
        Font-Names="arial" Font-Size="10pt"  ForeColor="#CC0000"
        ErrorMessage="Your Error Message"
    />
</div>

2. Add to File: Modules\CheckoutConfirm.ascx.cs

protected void ValidateTCBox(object source, ServerValidateEventArgs args)
{
    args.IsValid = (tcbox.Checked == true);
}

3. In the same file, you can revert the btnNextStep_Click method to its default implementation:
protected void btnNextStep_Click(object sender, EventArgs e)
{
    if (Page.IsValid)
    {
        try
        {
            PaymentInfo paymentInfo = this.PaymentInfo;
            if (paymentInfo == null)
                Response.Redirect("~/CheckoutPaymentInfo.aspx");
            paymentInfo.BillingAddress = NopContext.Current.User.BillingAddress;
            paymentInfo.ShippingAddress = NopContext.Current.User.ShippingAddress;
            paymentInfo.CustomerLanguage = NopContext.Current.WorkingLanguage;
            paymentInfo.CustomerCurrency = NopContext.Current.WorkingCurrency;

            int orderID = 0;
            string result = OrderManager.PlaceOrder(paymentInfo, NopContext.Current.User, out orderID);
            this.PaymentInfo = null;
            Order order = OrderManager.GetOrderByID(orderID);
            if (!String.IsNullOrEmpty(result))
            {
                lError.Text = Server.HtmlEncode(result);
                return;
            }
            else
            {
                PaymentManager.PostProcessPayment(order);
            }

            Response.Redirect("~/CheckoutCompleted.aspx");
        }
        catch (Exception exc)
        {
            LogManager.InsertLog(LogTypeEnum.OrderError, exc.Message, exc);
            lError.Text = Server.HtmlEncode(exc.ToString());
        }
    }
}


You will need to recompile the solution and you may want to add a hyperlink to the terms and conditions (opening on a new page) so your customers know what they are accepting.

.
14 anos atrás
cheers mb

the checkbox is a legal requirement in the uk now and it was my last stumbling block (lol, i think ) before i get the site up and running so a big thank you for that.

-hayden
14 anos atrás
hi mb

to add the check box would the above 2 steps be the steps to implement it because ive tried but im not sure what to take out or replace in the checkout confirms

if you wonted mind copying and pasting here the full codes for each file i have to change

thanks
14 anos atrás
Below are the complete modified file contents for CheckoutConfirm.ascx and CheckoutConfirm.ascx.cs. The changes from the original files are in bold. Replace "Your Error Message" as needed. Backup your copies and then recompile the solution after updating the files -this is for version 1.40.

File: Modules\CheckoutConfirm.ascx

<%@ Control Language="C#" AutoEventWireup="true" Inherits="NopSolutions.NopCommerce.Web.Modules.CheckoutConfirmControl"
    CodeBehind="CheckoutConfirm.ascx.cs" %>
<%@ Register TagPrefix="nopCommerce" TagName="OrderSummary" Src="~/Modules/OrderSummary.ascx" %>
<div class="CheckoutPage">
    <div class="title">
        <%=GetLocaleResourceString("Checkout.ConfirmYourOrder")%>
    </div>
    <div class="clear">
    </div>
    <div class="CheckoutData">
        <div class="ConfirmOrder">
            <div class="SelectButton">
                <asp:Button runat="server" ID="btnNextStep" Text="<% $NopResources:Checkout.ConfirmButton %>"
                    OnClick="btnNextStep_Click" SkinID="ConfirmOrderNextStepButton" />
               &nbsp;&nbsp;&nbsp;
                <asp:CheckBox ID="tcbox" Text="  tick to confirm you have read and accepted our terms and conditions." runat="server" Style="position: relative; top: 3px;" />
                <asp:CustomValidator ID="cvTCBox" runat="server" OnServerValidate="ValidateTCBox"
                    Display="Static" Font-Names="arial" Font-Size="10pt" ForeColor="#CC0000" ErrorMessage="Your Error Message" />

            </div>
            <div class="clear">
            </div>
            <div class="ErrorBlock">
                <div class="messageError">
                    <asp:Literal runat="server" ID="lError" EnableViewState="false"></asp:Literal>
                </div>
            </div>
        </div>
        <div class="clear">
        </div>
        <div class="OrderSummaryTitle">
            <%=GetLocaleResourceString("Checkout.OrderSummary")%>
        </div>
        <div class="clear">
        </div>
        <div class="OrderSummaryBody">
            <nopCommerce:OrderSummary ID="OrderSummaryControl" runat="server" IsShoppingCart="false">
            </nopCommerce:OrderSummary>
        </div>
    </div>
</div>

----------------------------------------------------------------------

File: Modules\CheckoutConfirm.ascx.cs

//------------------------------------------------------------------------------
// The contents of this file are subject to the nopCommerce Public License Version 1.0 ("License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at  https://www.nopcommerce.com/License.aspx.
//
// Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
// See the License for the specific language governing rights and limitations under the License.
//
// The Original Code is nopCommerce.
// The Initial Developer of the Original Code is NopSolutions.
// All Rights Reserved.
//
// Contributor(s): _______.
//------------------------------------------------------------------------------


using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Text;
using System.Threading;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using NopSolutions.NopCommerce.BusinessLogic;
using NopSolutions.NopCommerce.BusinessLogic.Audit;
using NopSolutions.NopCommerce.BusinessLogic.CustomerManagement;
using NopSolutions.NopCommerce.BusinessLogic.Orders;
using NopSolutions.NopCommerce.BusinessLogic.Payment;
using NopSolutions.NopCommerce.BusinessLogic.Shipping;
using NopSolutions.NopCommerce.Common.Utils;


namespace NopSolutions.NopCommerce.Web.Modules
{
    public partial class CheckoutConfirmControl : BaseNopUserControl
    {
        ShoppingCart Cart = null;

       protected void ValidateTCBox(object source, ServerValidateEventArgs args)
        {
            args.IsValid = (tcbox.Checked == true);
        }


        protected void btnNextStep_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                try
                {
                    PaymentInfo paymentInfo = this.PaymentInfo;
                    if (paymentInfo == null)
                        Response.Redirect("~/CheckoutPaymentInfo.aspx");
                    paymentInfo.BillingAddress = NopContext.Current.User.BillingAddress;
                    paymentInfo.ShippingAddress = NopContext.Current.User.ShippingAddress;
                    paymentInfo.CustomerLanguage = NopContext.Current.WorkingLanguage;
                    paymentInfo.CustomerCurrency = NopContext.Current.WorkingCurrency;

                    int orderID = 0;
                    string result = OrderManager.PlaceOrder(paymentInfo, NopContext.Current.User, out orderID);
                    this.PaymentInfo = null;
                    Order order = OrderManager.GetOrderByID(orderID);
                    if (!String.IsNullOrEmpty(result))
                    {
                        lError.Text = Server.HtmlEncode(result);
                        return;
                    }
                    else
                    {
                        PaymentManager.PostProcessPayment(order);
                    }

                    Response.Redirect("~/CheckoutCompleted.aspx");
                }
                catch (Exception exc)
                {
                    LogManager.InsertLog(LogTypeEnum.OrderError, exc.Message, exc);
                    lError.Text = Server.HtmlEncode(exc.ToString());
                }
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if ((NopContext.Current.User == null) || (NopContext.Current.User.IsGuest && !CustomerManager.AnonymousCheckoutAllowed))
            {
                string loginURL = CommonHelper.GetLoginPageURL(true);
                Response.Redirect(loginURL);
            }

            Cart = ShoppingCartManager.GetCurrentShoppingCart(ShoppingCartTypeEnum.ShoppingCart);
            if (Cart.Count == 0)
                Response.Redirect("~/ShoppingCart.aspx");

            this.btnNextStep.Attributes.Add("onclick", "this.disabled = true;" + Page.ClientScript.GetPostBackEventReference(this.btnNextStep, ""));
        }

        protected PaymentInfo PaymentInfo
        {
            get
            {
                if (this.Session["OrderPaymentInfo"] != null)
                    return (PaymentInfo)(this.Session["OrderPaymentInfo"]);
                return null;
            }
            set
            {
                this.Session["OrderPaymentInfo"] = value;
            }
        }
    }
}




.
14 anos atrás
i tried applying this principle in v1.5 and it just confirms the order even if the checkbox isn't checked

it seems to move on without validating it - any takes on why ?
14 anos atrás
Hi,

Here is another simple way of doing it add this to modules/checkoutconfirm.ascx

<asp:CheckBox ID="chkbox" Text="tick to confirm you have read and accepted our terms and conditions." runat="server" />

<asp:Label runat="server" ID="lblError" ForeColor="Red"></asp:Label>


now add this in modules/checkoutconfirm.ascx

protected void btnNextStep_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                if (chkbox.Checked == false)
                {
                    lblError.Text = "Custom error here";
                }
                else
                {
                    try
                    {
                        var paymentInfo = this.PaymentInfo;
                        if (paymentInfo == null)
                        {
                            var args1 = new CheckoutStepEventArgs() { OrderConfirmed = false };
                            OnCheckoutStepChanged(args1);
                            if (!this.OnePageCheckout)
                            {
                                Response.Redirect("~/CheckoutPaymentInfo.aspx");
                            }
                            else
                            {
                                return;
                            }
                        }
                        paymentInfo.BillingAddress = NopContext.Current.User.BillingAddress;
                        paymentInfo.ShippingAddress = NopContext.Current.User.ShippingAddress;
                        paymentInfo.CustomerLanguage = NopContext.Current.WorkingLanguage;
                        paymentInfo.CustomerCurrency = NopContext.Current.WorkingCurrency;

                        int orderID = 0;
                        string result = OrderManager.PlaceOrder(paymentInfo, NopContext.Current.User, out orderID);
                        this.PaymentInfo = null;
                        var order = OrderManager.GetOrderByID(orderID);
                        if (!String.IsNullOrEmpty(result))
                        {
                            lConfirmOrderError.Text = Server.HtmlEncode(result);
                            return;
                        }
                        else
                        {
                            PaymentManager.PostProcessPayment(order);
                        }
                        var args2 = new CheckoutStepEventArgs() { OrderConfirmed = true };
                        OnCheckoutStepChanged(args2);
                        if (!this.OnePageCheckout)
                            Response.Redirect("~/CheckoutCompleted.aspx");
                    }
                    catch (Exception exc)
                    {
                        LogManager.InsertLog(LogTypeEnum.OrderError, exc.Message, exc);
                        lConfirmOrderError.Text = Server.HtmlEncode(exc.ToString());
                    }
                }
            }
        }


Hope this works for you, mike..
14 anos atrás
Thanks mike - pefect
:)

- hayden
14 anos atrás
this isnt working for me. I have 1.40 but setting it up on a local server. Any thoughts?

this is the error i keep getting.

CS1061: 'ASP.modules_checkoutconfirm_ascx' does not contain a definition for 'ValidateTCBox' and no extension method 'ValidateTCBox' accepting a first argument of type 'ASP.modules_checkoutconfirm_ascx' could be found (are you missing a using directive or an assembly reference?)

hope someone can help??
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.