How can I add a must accept terms and conditions checkbox to the checkout process?

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
13 years ago
Does anyone know how I can add a must accept terms and conditions checkbox to the checkout process?

I am using nopcommerce 1.50.

I perfer a global solution to the add it to each product solution. (but don't we all :) )

Thanks,
Anthony
13 years ago
Hello Anthony,

Here's the solution: (After using this code, you need to rebuild before trying/running your project)

[You can just copy and paste/replace the whole code with your default code]

conditionspopup.aspx   is a   separate page you wish to create to show the topic contents of  conditions topic ( to test the checkbox, you could just temporarily replace
<%=Page.ResolveUrl("~/ConditionsPopup.aspx")%>      with   another existing page eg
<%=Page.ResolveUrl("~/AboutUs.aspx")%>

this way you can get your checkbox working first !

1) checkoutconfirm.ascx


<%@ Control Language="C#" AutoEventWireup="true" Inherits="NopSolutions.NopCommerce.Web.Modules.CheckoutConfirmControl"
    CodeBehind="CheckoutConfirm.ascx.cs" %>
<div class="checkout-data">
    <div class="confirm-order">
        <div class="select-button">
            <asp:Button runat="server" ID="btnNextStep" Text="<% $NopResources:Checkout.ConfirmButton %>"
                OnClick="btnNextStep_Click" CssClass="confirmordernextstepbutton" ValidationGroup="CheckoutConfirm" />
                
<!--  -->
<asp:CheckBox ID="chkbox" Text="     " runat="server"  />   tick to accept            
<a href="<%=Page.ResolveUrl("~/ConditionsPopup.aspx")%>" target="_blank"    >terms and conditions
</a>.    
<asp:Label runat="server" ID="lblError" ForeColor="Red"></asp:Label>                
                
                
                
        </div>
        <div class="clear">
        </div>
        <div class="error-block">
            <div class="message-error">
                <asp:Literal runat="server" ID="lConfirmOrderError" EnableViewState="false"></asp:Literal>
            </div>
        </div>
    </div>
</div>


=============================================================================

1) checkoutconfirm.ascx.cs


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.SEO;
using NopSolutions.NopCommerce.BusinessLogic.Shipping;
using NopSolutions.NopCommerce.Common.Utils;


namespace NopSolutions.NopCommerce.Web.Modules
{
    public partial class CheckoutConfirmControl : BaseNopUserControl
    {
        protected CheckoutStepChangedEventHandler handler;
        protected ShoppingCart cart = null;

        protected void btnNextStep_Click(object sender, EventArgs e)
        {

            if (Page.IsValid)
            {

                if (chkbox.Checked == false)
                {
                    lblError.Text = GetLocaleResourceString("Checkout.AcceptTerms.Error");
                }

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

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

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

        protected override void OnPreRender(EventArgs e)
        {
            this.btnNextStep.Attributes.Add("onclick", "this.disabled = true;" + Page.ClientScript.GetPostBackEventReference(this.btnNextStep, ""));

            base.OnPreRender(e);
        }
        
        protected virtual void OnCheckoutStepChanged(CheckoutStepEventArgs e)
        {
            if (handler != null)
            {
                handler(this, e);
            }
        }

        public void BindData()
        {

        }

        public event CheckoutStepChangedEventHandler CheckoutStepChanged
        {
            add
            {
                handler += value;
            }
            remove
            {
                handler -= value;
            }
        }

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

        public ShoppingCart Cart
        {
            get
            {
                if (cart == null)
                {
                    cart = ShoppingCartManager.GetCurrentShoppingCart(ShoppingCartTypeEnum.ShoppingCart);
                }
                return cart;
            }
        }

        public bool OnePageCheckout
        {
            get
            {
                if (ViewState["OnePageCheckout"] != null)
                    return (bool)ViewState["OnePageCheckout"];
                return false;
            }
            set
            {
                ViewState["OnePageCheckout"] = value;
            }
        }
    }
}



====================================================================
13 years ago
Just for the information: This feature will be available in 1.6 version
13 years ago
Thanks for the quick reply,

One thing I wasn't sure of was the rebuild part.

Here's the solution:
(After using this code, you need to rebuild before trying/running your project)
13 years ago
yea re-building solution is required here as you are doing modifications in .cs files

you know how to re-build your solution ?

Let me know if you need any help as without re-buidling your solution you won't be able to see any changes in your project.
13 years ago
Sorry I had a brain freeze there for a minute. I have rebuilt. Do you know which files were affected so I don't have to reupload the whole site. I have made minor edits here and there. I wouldn't want to screw those up today...

Thanks,
Anthony
13 years ago
So I figured it out and it works great...Thank you so much. I appreciate you guys that are willing to take the time and help others it's awesome.

Thanks Again,
Anthony
13 years ago
[email protected] wrote:
Sorry I had a brain freeze there for a minute. I have rebuilt. Do you know which files were affected so I don't have to reupload the whole site. I have made minor edits here and there. I wouldn't want to screw those up today...

Thanks,
Anthony


Whenever you change anything in .cs that belongs to nopCommerceFolder , usually after re-build nopCommercestore.dll gets updated/refreshed
13 years ago
Hi Mike

using 1.5 and its displaying the checkbox but allowing the order to go through regardless.

any thoughts?

Regards Chris King
13 years ago
Hi Mike

using 1.5 and its displaying the checkbox but allowing the order to go through regardless.

any thoughts?

Regards Chris King
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.