private bool CreateOrder(ShoppingCartInfo shoppingCart)
    {
        try
        {
            // Set order culture
            shoppingCart.ShoppingCartCulture = LocalizationContext.PreferredCultureCode;
            // Update customer preferences
            CustomerInfoProvider.SetCustomerPreferredSettings(shoppingCart);
            // Create order
            ShoppingCartInfoProvider.SetOrder(shoppingCart);
        }
        catch (Exception ex)
        {
            // Log exception
            loggedExceptions.Add(ex);
            return(false);
        }

        if (shoppingCart.OrderId > 0)
        {
            // Track order conversion
            var name = ECommerceSettings.OrderConversionName(shoppingCart.SiteName);
            ECommerceHelper.TrackOrderConversion(shoppingCart, name);
            ECommerceHelper.TrackOrderItemsConversions(shoppingCart);
            // Log purchase activity
            if (ActivitySettingsHelper.ActivitiesEnabledForThisUser(MembershipContext.AuthenticatedUser))
            {
                var totalPriceInMainCurrency = shoppingCart.TotalPriceInMainCurrency;
                var formattedPrice           = CurrencyInfoProvider.GetFormattedPrice(totalPriceInMainCurrency, CurrencyInfoProvider.GetMainCurrency(shoppingCart.ShoppingCartSiteID));

                TrackActivityPurchasedProducts(shoppingCart, ContactID);
                TrackActivityPurchase(shoppingCart.OrderId,
                                      ContactID,
                                      totalPriceInMainCurrency,
                                      formattedPrice);
            }

            return(true);
        }

        LogError("Save order action failed", EVENT_CODE_SAVING);
        return(false);
    }
    /// <summary>
    /// Saves order information from ShoppingCartInfo object to database as new order.
    /// </summary>
    public override bool ProcessStep()
    {
        // Load first step if there is no address
        if (ShoppingCart.ShoppingCartBillingAddressID <= 0)
        {
            ShoppingCartControl.LoadStep(0);
            return(false);
        }

        // Check if customer is enabled
        if ((ShoppingCart.Customer != null) && (!ShoppingCart.Customer.CustomerEnabled))
        {
            lblError.Text = GetString("ecommerce.cartcontent.customerdisabled");
            return(false);
        }

        // Deal with order note
        ShoppingCartControl.SetTempValue(ORDER_NOTE, null);
        ShoppingCart.ShoppingCartNote = txtNote.Text.Trim();

        try
        {
            // Set order culture
            ShoppingCart.ShoppingCartCulture = LocalizationContext.PreferredCultureCode;

            // Update customer preferences
            CustomerInfoProvider.SetCustomerPreferredSettings(ShoppingCart);

            // Create order
            ShoppingCartInfoProvider.SetOrder(ShoppingCart);
        }
        catch (Exception ex)
        {
            // Show error
            lblError.Text = GetString("Ecommerce.OrderPreview.ErrorOrderSave");

            // Log exception
            EventLogProvider.LogException("Shopping cart", "SAVEORDER", ex, ShoppingCart.ShoppingCartSiteID, null);
            return(false);
        }

        // Track order items conversions
        ECommerceHelper.TrackOrderItemsConversions(ShoppingCart);

        // Track order conversion
        string name = ShoppingCartControl.OrderTrackConversionName;

        ECommerceHelper.TrackOrderConversion(ShoppingCart, name);

        // Track order activity
        string siteName = SiteContext.CurrentSiteName;

        if (LogActivityForCustomer)
        {
            ShoppingCartControl.TrackActivityPurchasedProducts(ShoppingCart, siteName, ContactID);
            ShoppingCartControl.TrackActivityPurchase(ShoppingCart.OrderId, ContactID,
                                                      SiteContext.CurrentSiteName, RequestContext.CurrentRelativePath,
                                                      ShoppingCart.TotalPriceInMainCurrency, CurrencyInfoProvider.GetFormattedPrice(ShoppingCart.TotalPriceInMainCurrency,
                                                                                                                                    CurrencyInfoProvider.GetMainCurrency(CMSContext.CurrentSiteID)));
        }

        // Raise finish order event
        ShoppingCartControl.RaiseOrderCompletedEvent();

        // When in CMSDesk
        if (ShoppingCartControl.IsInternalOrder)
        {
            if (chkSendEmail.Checked)
            {
                // Send order notification emails
                OrderInfoProvider.SendOrderNotificationToAdministrator(ShoppingCart);
                //OrderInfoProvider.SendOrderNotificationToCustomer(ShoppingCart);
                //EventLogProvider p = new EventLogProvider();
                //p.LogEvent("I", DateTime.Now, "Envoi de mail d'achat au client"+ShoppingCart.Customer.CustomerEmail, "code BO");
                sendconf2(null, null, null);
            }
        }
        // When on the live site
        else if (ECommerceSettings.SendOrderNotification(SiteContext.CurrentSite.SiteName))
        {
            // Send order notification emails
            OrderInfoProvider.SendOrderNotificationToAdministrator(ShoppingCart);
            OrderInfoProvider.SendOrderNotificationToCustomer(ShoppingCart);
        }

        return(true);
    }
    /// <summary>
    /// Saves order information from ShoppingCartInfo object to database as new order.
    /// </summary>
    public override bool ProcessStep()
    {
        // Load first step if there is no currency or no address
        if ((this.ShoppingCartInfoObj.ShoppingCartBillingAddressID <= 0) || (this.ShoppingCartInfoObj.ShoppingCartCurrencyID <= 0))
        {
            this.ShoppingCartControl.LoadStep(0);
            return(false);
        }

        // Deal with order note
        this.ShoppingCartControl.SetTempValue(ORDER_NOTE, null);
        this.ShoppingCartInfoObj.ShoppingCartNote = this.txtNote.Text.Trim();

        try
        {
            // Set order culture
            ShoppingCartInfoObj.ShoppingCartCulture = CMSContext.PreferredCultureCode;

            // Update customer preferences
            CustomerInfoProvider.SetCustomerPreferredSettings(ShoppingCartInfoObj);

            // Create order
            ShoppingCartInfoProvider.SetOrder(this.ShoppingCartInfoObj);
        }
        catch (Exception ex)
        {
            lblError.Text = GetString("Ecommerce.OrderPreview.ErrorOrderSave") + " (" + ex.Message + ")";
            return(false);
        }

        // Track order items conversions
        ECommerceHelper.TrackOrderItemsConversions(ShoppingCartInfoObj);

        // Track order conversion
        string name = this.ShoppingCartControl.OrderTrackConversionName;

        ECommerceHelper.TrackOrderConversion(ShoppingCartInfoObj, name);

        // Track order activity
        string siteName = CMSContext.CurrentSiteName;

        if (ActivitySettingsHelper.ActivitiesEnabledAndModuleLoaded(siteName) && this.LogActivityForCustomer && (this.ContactID > 0))
        {
            // Track individual items
            if (ActivitySettingsHelper.PurchasedProductEnabled(siteName))
            {
                this.ShoppingCartControl.TrackActivityPurchasedProducts(ShoppingCartInfoObj, siteName, this.ContactID);
            }
            // Tack entire purchase
            if (ActivitySettingsHelper.PurchaseEnabled(siteName))
            {
                this.ShoppingCartControl.TrackActivityPurchase(ShoppingCartInfoObj.OrderId, this.ContactID,
                                                               CMSContext.CurrentSiteName, URLHelper.CurrentRelativePath,
                                                               ShoppingCartInfoObj.TotalPriceInMainCurrency, CurrencyInfoProvider.GetFormattedPrice(ShoppingCartInfoObj.TotalPriceInMainCurrency,
                                                                                                                                                    CurrencyInfoProvider.GetMainCurrency(CMSContext.CurrentSiteID)));
            }
        }

        // Raise finish order event
        this.ShoppingCartControl.RaiseOrderCompletedEvent();

        // When in CMSDesk
        if (this.ShoppingCartControl.IsInternalOrder)
        {
            if (chkSendEmail.Checked)
            {
                // Send order notification emails
                OrderInfoProvider.SendOrderNotificationToAdministrator(this.ShoppingCartInfoObj);
                OrderInfoProvider.SendOrderNotificationToCustomer(this.ShoppingCartInfoObj);
            }
        }
        // When on the live site
        else if (ECommerceSettings.SendOrderNotification(CMSContext.CurrentSite.SiteName))
        {
            // Send order notification emails
            OrderInfoProvider.SendOrderNotificationToAdministrator(this.ShoppingCartInfoObj);
            OrderInfoProvider.SendOrderNotificationToCustomer(this.ShoppingCartInfoObj);
        }

        return(true);
    }
    /// <summary>
    /// Saves order information from ShoppingCartInfo object to database as new order.
    /// </summary>
    public override bool ProcessStep()
    {
        // Load first step if there is no address
        if (IsShippingNeeded && ShoppingCart.ShoppingCartBillingAddressID <= 0)
        {
            ShoppingCartControl.LoadStep(0);
            return(false);
        }

        // Check if customer is enabled
        if ((ShoppingCart.Customer != null) && (!ShoppingCart.Customer.CustomerEnabled))
        {
            lblError.Text = GetString("ecommerce.cartcontent.customerdisabled");
            return(false);
        }

        // Deal with order note
        ShoppingCartControl.SetTempValue(ORDER_NOTE, null);
        ShoppingCart.ShoppingCartNote = txtNote.Text.Trim();

        try
        {
            // Set order culture
            ShoppingCart.ShoppingCartCulture = LocalizationContext.PreferredCultureCode;

            // Update customer preferences
            CustomerInfoProvider.SetCustomerPreferredSettings(ShoppingCart);

            // Create order
            ShoppingCartInfoProvider.SetOrder(ShoppingCart);
            ShoppingCart.Order.SetValue("OrderBundleData", ShoppingCart.GetStringValue("ShoppingCartBundleData", string.Empty));
        }
        catch (Exception ex)
        {
            // Show error
            lblError.Text = GetString("Ecommerce.OrderPreview.ErrorOrderSave");

            // Log exception
            EventLogProvider.LogException("Shopping cart", "SAVEORDER", ex, ShoppingCart.ShoppingCartSiteID, null);
            return(false);
        }

        // Track order items conversions
        ECommerceHelper.TrackOrderItemsConversions(ShoppingCart);

        // Track order conversion
        string name = ShoppingCartControl.OrderTrackConversionName;

        ECommerceHelper.TrackOrderConversion(ShoppingCart, name);

        // Track order activity
        string siteName = SiteContext.CurrentSiteName;

        if (LogActivityForCustomer)
        {
            ShoppingCartControl.TrackActivityPurchasedProducts(ShoppingCart, siteName, ContactID);
            ShoppingCartControl.TrackActivityPurchase(ShoppingCart.OrderId, ContactID,
                                                      SiteContext.CurrentSiteName, RequestContext.CurrentRelativePath,
                                                      ShoppingCart.TotalPriceInMainCurrency, CurrencyInfoProvider.GetFormattedPrice(ShoppingCart.TotalPriceInMainCurrency,
                                                                                                                                    CurrencyInfoProvider.GetMainCurrency(CMSContext.CurrentSiteID)));
        }

        // Raise finish order event
        ShoppingCartControl.RaiseOrderCompletedEvent();
        string currentCultureCode = DocumentContext.CurrentDocument.DocumentCulture;
        string template           = "Ecommerce.OrderNotificationToCustomer" + currentCultureCode;

        // When in CMSDesk
        if (ShoppingCartControl.IsInternalOrder)
        {
            if (chkSendEmail.Checked)
            {
                // Send order notification emails
                OrderInfoProvider.SendOrderNotificationToAdministrator(ShoppingCart);


                OrderInfoProvider.SendOrderNotificationToCustomer(ShoppingCart, template);
            }
        }
        // When on the live site
        else if (ECommerceSettings.SendOrderNotification(SiteContext.CurrentSite.SiteName))
        {
            // Send order notification emails
            OrderInfoProvider.SendOrderNotificationToAdministrator(ShoppingCart);


            OrderInfoProvider.SendOrderNotificationToCustomer(ShoppingCart, template);
        }

        /*desactiver le coupon code*/
        if (Session["CouponValue"] != null)
        {
            DiscountCouponInfo dci = DiscountCouponInfoProvider.GetDiscountCouponInfo(Session["CouponValue"].ToString(), ShoppingCart.SiteName);
            if ((dci != null) && (((ShoppingCart.IsCreatedFromOrder) && (ShoppingCart.ShoppingCartDiscountCouponID == dci.DiscountCouponID)) || dci.IsValid))
            {
                DateTime d = DateTime.Now;
                d = d.AddMinutes(5);
                dci.DiscountCouponValidTo = d;
                Session["CouponValue"]    = null;
            }
        }
        /**/

        return(true);
    }