Exemple #1
0
    /// <summary>
    /// Saving billing requires recalculation of order. Save action is executed by this custom code.
    /// </summary>
    protected void editOrderBilling_OnBeforeSave(object sender, EventArgs e)
    {
        // Load the shopping cart to process the data
        ShoppingCartInfo sci = ShoppingCartInfoProvider.GetShoppingCartInfoFromOrder(Order.OrderID);

        // Update data only if shopping cart data were changed
        int paymentID  = ValidationHelper.GetInteger(editOrderBilling.FieldEditingControls["OrderPaymentOptionID"].DataValue, 0);
        int currencyID = ValidationHelper.GetInteger(editOrderBilling.FieldEditingControls["OrderCurrencyID"].DataValue, 0);

        // Recalculate order
        if ((sci != null) && ((sci.ShoppingCartPaymentOptionID != paymentID) || (sci.ShoppingCartCurrencyID != currencyID)))
        {
            // Set order new properties
            sci.ShoppingCartPaymentOptionID = paymentID;
            sci.ShoppingCartCurrencyID      = currencyID;

            // Evaluate order data
            ShoppingCartInfoProvider.EvaluateShoppingCart(sci);

            // Update order data
            ShoppingCartInfoProvider.SetOrder(sci, true);
        }

        // Update only one order property
        if (Order.OrderIsPaid != OrderIsPaid)
        {
            Order.OrderIsPaid = OrderIsPaid;
            OrderInfoProvider.SetOrderInfo(Order);
        }

        ShowChangesSaved();

        // Stop automatic saving action
        editOrderBilling.StopProcessing = 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 (ShoppingCart.ShoppingCartBillingAddress == null)
        {
            ShoppingCartControl.LoadStep(0);
            return(false);
        }

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

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

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

            // Log exception
            Service.Resolve <IEventLogService>().LogException("Shopping cart", "SAVEORDER", ex, ShoppingCart.ShoppingCartSiteID);
            return(false);
        }

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

        if (LogActivityForCustomer)
        {
            var mainCurrency             = CurrencyInfoProvider.GetMainCurrency(ShoppingCart.ShoppingCartSiteID);
            var grandTotalInMainCurrency = Service.Resolve <ICurrencyConverterService>().Convert(ShoppingCart.GrandTotal, ShoppingCart.Currency.CurrencyCode, mainCurrency.CurrencyCode, ShoppingCart.ShoppingCartSiteID);
            var formattedPrice           = CurrencyInfoProvider.GetFormattedPrice(grandTotalInMainCurrency, mainCurrency);

            ShoppingCartControl.TrackActivityPurchasedProducts(ShoppingCart, siteName, ContactID);
            ShoppingCartControl.TrackActivityPurchase(ShoppingCart.OrderId, ContactID,
                                                      SiteContext.CurrentSiteName, RequestContext.CurrentRelativePath,
                                                      grandTotalInMainCurrency, formattedPrice);
        }

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

        if (chkSendEmail.Checked)
        {
            // Send order notification emails
            OrderInfoProvider.SendOrderNotificationToAdministrator(ShoppingCart);
            OrderInfoProvider.SendOrderNotificationToCustomer(ShoppingCart);
        }

        return(true);
    }
 private void editOrderBilling_OnAfterSave(object sender, EventArgs e)
 {
     if (mRecalculateOrder)
     {
         var cart = ShoppingCartInfoProvider.GetShoppingCartInfoFromOrder(Order.OrderID);
         // Evaluate order data
         cart.Evaluate();
         // Update order data
         ShoppingCartInfoProvider.SetOrder(cart, true);
     }
 }
Exemple #4
0
 void editOrderBilling_OnAfterSave(object sender, EventArgs e)
 {
     if (recalculateOrder)
     {
         ShoppingCartInfo sci = ShoppingCartInfoProvider.GetShoppingCartInfoFromOrder(Order.OrderID);
         // Evaluate order data
         ShoppingCartInfoProvider.EvaluateShoppingCart(sci);
         // Update order data
         ShoppingCartInfoProvider.SetOrder(sci, true);
     }
 }
    protected void btnOk_Click(object sender, EventArgs e)
    {
        // Check 'EcommerceModify' permission
        if (!ECommerceContext.IsUserAuthorizedForPermission("ModifyOrders"))
        {
            RedirectToAccessDenied("CMS.Ecommerce", "EcommerceModify OR ModifyOrders");
        }

        // Check whether some address is selected
        int addressId = addressElem.AddressID;

        if (addressId <= 0)
        {
            // Show error message
            ShowError(GetString("Order_Edit_Billing.NoAddress"));

            return;
        }

        OrderInfo oi = OrderInfoProvider.GetOrderInfo(orderId);

        EditedObject = oi;

        if (oi != null)
        {
            // Check if paid status was changed
            orderIsPaidChanged = (oi.OrderIsPaid != chkOrderIsPaid.Checked);

            // Load the shopping cart to process the data
            ShoppingCartInfo sci = ShoppingCartInfoProvider.GetShoppingCartInfoFromOrder(orderId);
            if (sci != null)
            {
                // Set order new properties
                sci.ShoppingCartBillingAddressID = addressId;
                sci.ShoppingCartPaymentOptionID  = drpPayment.PaymentID;
                sci.ShoppingCartCurrencyID       = drpCurrency.CurrencyID;

                // Evaluate order data
                ShoppingCartInfoProvider.EvaluateShoppingCart(sci);

                // Update order data
                ShoppingCartInfoProvider.SetOrder(sci, false);
            }

            // Mark order as paid
            oi.OrderIsPaid = chkOrderIsPaid.Checked;
            OrderInfoProvider.SetOrderInfo(oi);

            // Show message
            ShowChangesSaved();
        }
    }
Exemple #6
0
        /// <summary>
        /// Creates a new order from the shopping cart. Saves the shopping cart before the order creation.
        /// </summary>
        /// <param name="cart">Validated shopping cart (<see cref="ShoppingCart"/>) from which an order is created.</param>
        /// <returns><see cref="Order"/> object representing the created order.</returns>
        public virtual Order CreateOrder(ShoppingCart cart)
        {
            cart.Save();
            ShoppingCartInfoProvider.SetOrder(cart.OriginalCart);

            var orderInfo = cart.OriginalCart.Order;

            if (orderInfo != null)
            {
                SendOrderNotifications(cart);
                LogPurchaseActivities(cart);
            }

            return(new Order(orderInfo));
        }
    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);
    }
Exemple #8
0
    protected void OnBeforeSave(object sender, EventArgs e)
    {
        if ((Order == null) || (ShippingAddressSelector == null) || (ShippingOptionSelector == null) || (ShoppingCartFromOrder == null))
        {
            return;
        }

        // Get current values
        var addressID        = ValidationHelper.GetInteger(ShippingAddressSelector.Value, 0);
        var shippingOptionID = ValidationHelper.GetInteger(ShippingOptionSelector.Value, 0);

        // Is shipping needed?
        var isShippingNeeded = ShoppingCartFromOrder.IsShippingNeeded;

        // If shipping address is required
        if (isShippingNeeded || IsTaxBasedOnShippingAddress)
        {
            // If shipping address is not set
            if (addressID <= 0)
            {
                // Show error message
                ShowError(GetString("Order_Edit_Shipping.NoAddress"));
                return;
            }
        }

        try
        {
            // Check if original order shipping option was changed, the check cannot be done on edited object because edited object contains current value (not the original one)
            if (ShoppingCartFromOrder.ShoppingCartShippingOptionID != shippingOptionID)
            {
                PaymentOptionInfo payment = PaymentOptionInfoProvider.GetPaymentOptionInfo(Order.OrderPaymentOptionID);

                // Check if payment is allowed with no shipping
                if ((payment != null) && (!payment.PaymentOptionAllowIfNoShipping && shippingOptionID == 0))
                {
                    // Set payment method to none and display warning
                    ShoppingCartFromOrder.ShoppingCartPaymentOptionID = 0;

                    var paymentMethodName  = ResHelper.LocalizeString(payment.PaymentOptionDisplayName, null, true);
                    var shippingOptionName = HTMLHelper.HTMLEncode(ShippingOptionSelector.ValueDisplayName);

                    ShowWarning(String.Format(GetString("com.shippingoption.paymentsetnone"), paymentMethodName, shippingOptionName));
                }

                // Set order new properties
                ShoppingCartFromOrder.ShoppingCartShippingOptionID = shippingOptionID;

                // Evaluate order data
                ShoppingCartFromOrder.Evaluate();

                // Update order data
                ShoppingCartInfoProvider.SetOrder(ShoppingCartFromOrder, true);
            }

            var newTrackingNumber = ValidationHelper.GetString(orderShippingForm.FieldEditingControls["OrderTrackingNumber"].DataValue, String.Empty).Trim();

            if (!newTrackingNumber.Equals(ShoppingCartFromOrder.Order.OrderTrackingNumber, StringComparison.InvariantCulture))
            {
                // Update on the current order instance
                var order = ShoppingCartFromOrder.Order;
                order.OrderTrackingNumber = newTrackingNumber;
                OrderInfoProvider.SetOrderInfo(Order);
            }

            // Show message
            ShowChangesSaved();

            // Stop automatic saving action
            orderShippingForm.StopProcessing = true;
        }
        catch (Exception ex)
        {
            // Show error message
            ShowError(ex.Message);
        }
    }
    /// <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 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);
    }
    /// <summary>
    /// Process this step.
    /// </summary>
    public override bool ProcessStep()
    {
        // Shopping cart units are already saved in database (on "Update" or on "btnAddProduct_Click" actions)

        bool isOK = false;

        p.LogEvent("I", DateTime.Now, "process cart is not null", "");
        if (ShoppingCart != null)
        {
            p.LogEvent("I", DateTime.Now, "SHOPPING cart is not null", "");
            // Reload data
            ReloadData();

            // Check available items before "Check out"
            ShoppingCartCheckResult checkResult = ShoppingCartInfoProvider.CheckShoppingCart(ShoppingCart);

            if (checkResult.CheckFailed)
            {
                lblError.Text = checkResult.GetHTMLFormattedMessage();
            }
            else if (ShoppingCartControl.CheckoutProcessType == CheckoutProcessEnum.CMSDeskOrderItems)
            {
                // Indicates wheter order saving process is successful
                isOK = true;

                try
                {
                    ShoppingCartInfoProvider.SetOrder(ShoppingCart);
                }
                catch (Exception ex)
                {
                    // Log exception
                    EventLogProvider.LogException("Shopping cart", "SAVEORDER", ex, ShoppingCart.ShoppingCartSiteID, null);
                    isOK = false;
                }

                if (isOK)
                {
                    lblInfo.Text = GetString("general.changessaved");

                    // Send order notification when editing existing order
                    if (ShoppingCartControl.CheckoutProcessType == CheckoutProcessEnum.CMSDeskOrderItems)
                    {
                        if (chkSendEmail.Checked)
                        {
                            OrderInfoProvider.SendOrderNotificationToAdministrator(ShoppingCart);
                            OrderInfoProvider.SendOrderNotificationToCustomer(ShoppingCart);
                        }
                    }
                    // Send order notification emails when on the live site
                    else if (ECommerceSettings.SendOrderNotification(SiteContext.CurrentSite.SiteName))
                    {
                        OrderInfoProvider.SendOrderNotificationToAdministrator(ShoppingCart);
                        OrderInfoProvider.SendOrderNotificationToCustomer(ShoppingCart);
                    }
                }
                else
                {
                    lblError.Text = GetString("ecommerce.orderpreview.errorordersave");
                }
            }
            // Go to the next step
            else
            {
                // Save other options
                if (!ShoppingCartControl.IsInternalOrder)
                {
                    ShoppingCartInfoProvider.SetShoppingCartInfo(ShoppingCart);
                }

                isOK = true;
            }
        }

        return(isOK);
    }
        private void GenerateEcommerceData(int siteID)
        {
            var siteName     = SiteInfoProvider.GetSiteName(siteID);
            var currencyInfo = CurrencyInfoProvider.GetCurrencies(siteID)
                               .Where("CurrencyIsMain", QueryOperator.Equals, 1).TopN(1).FirstOrDefault();
            var list1 = PaymentOptionInfoProvider.GetPaymentOptions(siteID).ToList();
            var list2 = ShippingOptionInfoProvider.GetShippingOptions(siteID).ToList();

            var orderStatusList = OrderStatusInfoProvider.GetOrderStatuses(siteID).ToDictionary(status => status.StatusName);

            var manufacturerExceptionList = new List <int>
            {
                ManufacturerInfoProvider.GetManufacturerInfo("Aerobie", siteName).ManufacturerID,
                //ManufacturerInfoProvider.GetManufacturerInfo("Chemex", siteName).ManufacturerID,
                //ManufacturerInfoProvider.GetManufacturerInfo("Espro", siteName).ManufacturerID
            };
            var list3 = SKUInfoProvider.GetSKUs(siteID).ToList().Where(sku =>
            {
                if (sku.IsProduct)
                {
                    return(!manufacturerExceptionList.Contains(sku.SKUManufacturerID));
                }
                return(false);
            }).ToList();
            int         num1;
            IList <int> intList;

            if (CustomerInfoProvider.GetCustomers().WhereEquals("CustomerSiteID", siteID).Count < 50)
            {
                num1    = customerNames.Length;
                intList = new List <int>();
                for (var index = 0; index < num1; ++index)
                {
                    intList.Add(GenerateCustomer(customerNames[index], siteID).CustomerID);
                }
            }
            else
            {
                intList = DataHelper.GetIntegerValues(CustomerInfoProvider.GetCustomers().Column("CustomerID")
                                                      .WhereEquals("CustomerSiteID", siteID).WhereNotEquals("CustomerEmail", "alex").Tables[0],
                                                      "CustomerID");
                num1 = intList.Count;
            }

            var num2 = 0;
            var num3 = 0;

            for (var index1 = 0; index1 <= 30; ++index1)
            {
                ++num2;
                var num4 = 0;
                if (index1 > 5)
                {
                    num4 = rand.Next(-1, 2);
                }
                for (var index2 = 0; index2 < num2 / 2 + num4; ++index2)
                {
                    var orderStatusInfo = index1 >= 25
                        ? index1 >= 29 ? orderStatusList["New"] : orderStatusList["InProgress"]
                        : orderStatusList["Completed"];
                    var orderInfo = new OrderInfo
                    {
                        OrderCustomerID = intList[num3 % num1],
                        OrderCurrencyID = currencyInfo.CurrencyID,
                        OrderSiteID     = siteID,
                        OrderStatusID   = orderStatusInfo.StatusID,
                        OrderIsPaid     = "Completed".Equals(orderStatusInfo.StatusName, StringComparison.Ordinal) ||
                                          (uint)rand.Next(0, 2) > 0U,
                        OrderShippingOptionID         = list2[rand.Next(list2.Count)].ShippingOptionID,
                        OrderPaymentOptionID          = list1[rand.Next(list1.Count)].PaymentOptionID,
                        OrderGrandTotal               = decimal.Zero,
                        OrderGrandTotalInMainCurrency = decimal.Zero,
                        OrderTotalPrice               = decimal.Zero,
                        OrderTotalPriceInMainCurrency = decimal.Zero,
                        OrderTotalShipping            = new decimal(10),
                        OrderTotalTax = new decimal(10)
                    };
                    OrderInfoProvider.SetOrderInfo(orderInfo);
                    var orderItems = GenerateOrderItems(orderInfo, list3);
                    GenerateOrderAddress(orderInfo.OrderID, GetRandomCountryId(), AddressType.Billing);
                    GenerateOrderAddress(orderInfo.OrderID, GetRandomCountryId(), AddressType.Shipping);
                    orderInfo.OrderDate       = DateTime.Now.AddDays(index1 - 30);
                    orderInfo.OrderTotalPrice = orderItems;
                    orderInfo.OrderTotalPriceInMainCurrency = orderItems;
                    orderInfo.OrderGrandTotal = orderItems;
                    orderInfo.OrderGrandTotalInMainCurrency = orderItems;
                    var cartInfoFromOrder = ShoppingCartInfoProvider.GetShoppingCartInfoFromOrder(orderInfo.OrderID);
                    orderInfo.OrderInvoiceNumber = OrderInfoProvider.GenerateInvoiceNumber(cartInfoFromOrder);
                    orderInfo.OrderInvoice       = ShoppingCartInfoProvider.GetOrderInvoice(cartInfoFromOrder);
                    OrderInfoProvider.SetOrderInfo(orderInfo);
                    ++num3;
                }
            }

            if (UserInfoProvider.GetUserInfo("alex") != null)
            {
                return;
            }
            var customerInfo = new CustomerInfo
            {
                CustomerEmail             = "*****@*****.**",
                CustomerFirstName         = "Alexander",
                CustomerLastName          = "Adams",
                CustomerSiteID            = siteID,
                CustomerCompany           = "Alex & Co. Ltd",
                CustomerTaxRegistrationID = "12S379BDF798",
                CustomerOrganizationID    = "WRQ7987VRG79"
            };

            CustomerInfoProvider.SetCustomerInfo(customerInfo);
            var userInfo = CustomerInfoProvider.RegisterCustomer(customerInfo, "", "alex");
            var roleInfo = RoleInfoProvider.GetRoleInfo("SilverPartner", siteID);

            if (roleInfo != null)
            {
                UserInfoProvider.AddUserToRole(userInfo.UserID, roleInfo.RoleID);
            }
            for (var index = 0; index < 5; ++index)
            {
                var cart = new ShoppingCartInfo();
                cart.ShoppingCartCulture         = CultureHelper.GetDefaultCultureCode(siteName);
                cart.ShoppingCartCurrencyID      = currencyInfo.CurrencyID;
                cart.ShoppingCartSiteID          = siteID;
                cart.ShoppingCartCustomerID      = customerInfo.CustomerID;
                cart.ShoppingCartBillingAddress  = GenerateAddress(GetRandomCountryId(), customerInfo.CustomerID);
                cart.ShoppingCartShippingAddress = GenerateAddress(GetRandomCountryId(), customerInfo.CustomerID);
                cart.User = userInfo;
                ShoppingCartInfoProvider.SetShoppingCartInfo(cart);
                ShoppingCartInfoProvider.SetShoppingCartItem(cart,
                                                             new ShoppingCartItemParameters(list3.ElementAt(rand.Next(list3.Count)).SKUID, rand.Next(5)));
                cart.Evaluate();
                ShoppingCartInfoProvider.SetOrder(cart);
            }
        }
    protected void btnOk_Click(object sender, EventArgs e)
    {
        // check 'EcommerceModify' permission
        if (!ECommerceContext.IsUserAuthorizedForPermission("ModifyOrders"))
        {
            RedirectToAccessDenied("CMS.Ecommerce", "EcommerceModify OR ModifyOrders");
        }

        // Get order
        OrderInfo oi = OrderInfoProvider.GetOrderInfo(orderId);

        if (oi != null)
        {
            // Are taxes based on shipping address?
            bool     taxesBasedOnShipping = false;
            SiteInfo si = SiteInfoProvider.GetSiteInfo(oi.OrderSiteID);
            if (si != null)
            {
                taxesBasedOnShipping = (ECommerceSettings.ApplyTaxesBasedOn(si.SiteName) == ApplyTaxBasedOnEnum.ShippingAddress);
            }

            // Is shipping needed?
            bool isShippingNeeded = ((ShoppingCartInfoObj != null) && (ShippingOptionInfoProvider.IsShippingNeeded(ShoppingCartInfoObj)));

            // If shipping address is required
            if (isShippingNeeded || taxesBasedOnShipping)
            {
                // If shipping address is not set
                if (addressElem.AddressID <= 0)
                {
                    // Show error message
                    ShowError(GetString("Order_Edit_Shipping.NoAddress"));

                    return;
                }
            }

            try
            {
                // Load the shopping cart to process the data
                ShoppingCartInfo sci = ShoppingCartInfoProvider.GetShoppingCartInfoFromOrder(orderId);
                if (sci != null)
                {
                    // Set order new properties
                    sci.ShoppingCartShippingOptionID  = drpShippingOption.ShippingID;
                    sci.ShoppingCartShippingAddressID = addressElem.AddressID;

                    // Evaluate order data
                    ShoppingCartInfoProvider.EvaluateShoppingCart(sci);

                    // Update order data
                    ShoppingCartInfoProvider.SetOrder(sci, false);
                }

                // Update tracking number
                oi.OrderTrackingNumber = txtTrackingNumber.Text.Trim();
                OrderInfoProvider.SetOrderInfo(oi);

                // Show message
                ShowChangesSaved();

                // Update shipping charge in selector
                if (taxesBasedOnShipping)
                {
                    drpShippingOption.ShoppingCart = sci;
                    drpShippingOption.Reload(false);
                }
            }
            catch (Exception ex)
            {
                // Show error message
                ShowError(ex.Message);
            }
        }
    }
    protected void OnBeforeSave(object sender, EventArgs e)
    {
        if ((Order == null) || (ShippingAddressSelector == null) || (ShippingOptionSelector == null))
        {
            return;
        }

        // Get current values
        int addressID        = ValidationHelper.GetInteger(ShippingAddressSelector.Value, 0);
        int shippingOptionID = ValidationHelper.GetInteger(ShippingOptionSelector.Value, 0);

        // Is shipping needed?
        bool isShippingNeeded = ((ShoppingCartFromOrder != null) && ShoppingCartFromOrder.IsShippingNeeded);

        // If shipping address is required
        if (isShippingNeeded || IsTaxBasedOnShippingAddress)
        {
            // If shipping address is not set
            if (addressID <= 0)
            {
                // Show error message
                ShowError(GetString("Order_Edit_Shipping.NoAddress"));
                return;
            }
        }

        try
        {
            // Shipping option changed
            if ((ShoppingCartFromOrder != null) && (Order.OrderShippingOptionID != shippingOptionID))
            {
                // Shipping option and payment method combination is not allowed
                if (PaymentShippingInfoProvider.GetPaymentShippingInfo(Order.OrderPaymentOptionID, shippingOptionID) == null)
                {
                    PaymentOptionInfo payment = PaymentOptionInfoProvider.GetPaymentOptionInfo(Order.OrderPaymentOptionID);

                    // Check if payment is allowed with no shipping
                    if ((payment != null) && !(payment.PaymentOptionAllowIfNoShipping && shippingOptionID == 0))
                    {
                        // Set payment method to none and display warning
                        ShoppingCartFromOrder.ShoppingCartPaymentOptionID = 0;

                        string paymentMethodName  = ResHelper.LocalizeString(payment.PaymentOptionDisplayName, null, true);
                        string shippingOptionName = HTMLHelper.HTMLEncode(ShippingOptionSelector.ValueDisplayName);

                        ShowWarning(String.Format(ResHelper.GetString("com.shippingoption.paymentsetnone"), paymentMethodName, shippingOptionName));
                    }
                }

                // Set order new properties
                ShoppingCartFromOrder.ShoppingCartShippingOptionID = shippingOptionID;

                // Evaluate order data
                ShoppingCartInfoProvider.EvaluateShoppingCart(ShoppingCartFromOrder);

                // Update order data
                ShoppingCartInfoProvider.SetOrder(ShoppingCartFromOrder, true);
            }

            // Update tracking number
            Order.OrderTrackingNumber = ValidationHelper.GetString(orderShippingForm.FieldEditingControls["OrderTrackingNumber"].DataValue, String.Empty).Trim();
            OrderInfoProvider.SetOrderInfo(Order);

            // Show message
            ShowChangesSaved();

            // Stop automatic saving action
            orderShippingForm.StopProcessing = true;
        }
        catch (Exception ex)
        {
            // Show error message
            ShowError(ex.Message);
        }
    }
    /// <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>
    /// Process this step.
    /// </summary>
    public override bool ProcessStep()
    {
        // Do not process step if order is paid
        if (OrderIsPaid)
        {
            return(false);
        }

        // Shopping cart units are already saved in database (on "Update" or on "btnAddProduct_Click" actions)
        bool isOK = false;

        if (ShoppingCart != null)
        {
            // Reload data
            ReloadData();

            // Validate available items before "Check out"
            var cartValidator = new ShoppingCartValidator(ShoppingCart);

            cartValidator.Validate();

            if (!cartValidator.IsValid)
            {
                lblError.Text = cartValidator.GetErrorMessages()
                                .Select(e => HTMLHelper.HTMLEncode(e))
                                .Join("<br />");
            }
            else if (ShoppingCartControl.CheckoutProcessType == CheckoutProcessEnum.CMSDeskOrderItems)
            {
                // Indicates whether order saving process is successful
                isOK = true;

                try
                {
                    ShoppingCartInfoProvider.SetOrder(ShoppingCart);
                }
                catch (Exception ex)
                {
                    // Log exception
                    EventLogProvider.LogException("Shopping cart", "SAVEORDER", ex, ShoppingCart.ShoppingCartSiteID);
                    isOK = false;
                }

                if (isOK)
                {
                    lblInfo.Text = GetString("general.changessaved");

                    // Send order notification when editing existing order
                    if (ShoppingCartControl.CheckoutProcessType == CheckoutProcessEnum.CMSDeskOrderItems)
                    {
                        if (chkSendEmail.Checked)
                        {
                            OrderInfoProvider.SendOrderNotificationToAdministrator(ShoppingCart);
                            OrderInfoProvider.SendOrderNotificationToCustomer(ShoppingCart);
                        }
                    }
                    // Send order notification emails when on the live site
                    else if (ECommerceSettings.SendOrderNotification(SiteContext.CurrentSite.SiteName))
                    {
                        OrderInfoProvider.SendOrderNotificationToAdministrator(ShoppingCart);
                        OrderInfoProvider.SendOrderNotificationToCustomer(ShoppingCart);
                    }
                }
                else
                {
                    lblError.Text = GetString("ecommerce.orderpreview.errorordersave");
                }
            }
            // Go to the next step
            else
            {
                // Save other options
                if (!ShoppingCartControl.IsInternalOrder)
                {
                    ShoppingCartInfoProvider.SetShoppingCartInfo(ShoppingCart);
                }

                isOK = true;
            }
        }

        return(isOK);
    }
    /// <summary>
    /// Process this step.
    /// </summary>
    public override bool ProcessStep()
    {
        // Shopping cart units are already saved in database (on "Update" or on "btnAddProduct_Click" actions)
        bool isOK = false;

        if (ShoppingCartInfoObj != null)
        {
            // Reload data
            ReloadData();

            // Check available items before "Check out"
            string error = ShoppingCartInfoProvider.CheckShoppingCart(this.ShoppingCartInfoObj);
            if (!string.IsNullOrEmpty(error))
            {
                lblError.Text = error.Replace(";", "<br />");
            }
            else if (this.ShoppingCartControl.CheckoutProcessType == CheckoutProcessEnum.CMSDeskOrderItems)
            {
                // Indicates wheter order saving process is successful
                isOK = true;

                try
                {
                    ShoppingCartInfoProvider.SetOrder(this.ShoppingCartInfoObj);
                }
                catch
                {
                    isOK = false;
                }

                if (isOK)
                {
                    lblInfo.Text = GetString("General.ChangesSaved");

                    // Send order notification when editing existing order
                    if (this.ShoppingCartControl.CheckoutProcessType == CheckoutProcessEnum.CMSDeskOrderItems)
                    {
                        if (chkSendEmail.Checked)
                        {
                            OrderInfoProvider.SendOrderNotificationToAdministrator(this.ShoppingCartInfoObj);
                            OrderInfoProvider.SendOrderNotificationToCustomer(this.ShoppingCartInfoObj);
                        }
                    }
                    // Send order notification emails when on the live site
                    else if (ECommerceSettings.SendOrderNotification(CMSContext.CurrentSite.SiteName))
                    {
                        OrderInfoProvider.SendOrderNotificationToAdministrator(this.ShoppingCartInfoObj);
                        OrderInfoProvider.SendOrderNotificationToCustomer(this.ShoppingCartInfoObj);
                    }
                }
                else
                {
                    lblError.Text = GetString("Ecommerce.OrderPreview.ErrorOrderSave");
                }
            }
            // Go to the next step
            else
            {
                // Save other options
                if (!this.ShoppingCartControl.IsInternalOrder)
                {
                    ShoppingCartInfoProvider.SetShoppingCartInfo(ShoppingCartInfoObj);
                }
                isOK = true;
            }
        }

        return(isOK);
    }
Exemple #18
0
    protected void btnOk_Click(object sender, EventArgs e)
    {
        // check 'EcommerceModify' permission
        if (!ECommerceContext.IsUserAuthorizedForPermission("ModifyOrders"))
        {
            RedirectToAccessDenied("CMS.Ecommerce", "EcommerceModify OR ModifyOrders");
        }

        // Get order
        OrderInfo oi = OrderInfoProvider.GetOrderInfo(orderId);

        if (oi != null)
        {
            // Get order site
            SiteInfo si = SiteInfoProvider.GetSiteInfo(oi.OrderSiteID);

            // If shipping address is required
            if (((this.ShoppingCartInfoObj != null) && (ShippingOptionInfoProvider.IsShippingNeeded(this.ShoppingCartInfoObj))) ||
                ((si != null) && (ECommerceSettings.ApplyTaxesBasedOn(si.SiteName) == ApplyTaxBasedOnEnum.ShippingAddress)))
            {
                // If shipping address is not set
                if (this.addressElem.AddressID <= 0)
                {
                    lblError.Visible = true;
                    lblError.Text    = GetString("Order_Edit_Shipping.NoAddress");

                    return;
                }
            }

            try
            {
                // Load the shopping cart to process the data
                ShoppingCartInfo sci = ShoppingCartInfoProvider.GetShoppingCartInfoFromOrder(orderId);
                if (sci != null)
                {
                    // Set order new properties
                    sci.ShoppingCartShippingOptionID  = drpShippingOption.ShippingID;
                    sci.ShoppingCartShippingAddressID = this.addressElem.AddressID;

                    // Evaulate order data
                    ShoppingCartInfoProvider.EvaluateShoppingCart(sci);

                    // Update order data
                    ShoppingCartInfoProvider.SetOrder(sci, false);
                }

                // Update tracking number
                oi.OrderTrackingNumber = txtTrackingNumber.Text.Trim();
                OrderInfoProvider.SetOrderInfo(oi);

                lblInfo.Visible = true;
                lblInfo.Text    = GetString("General.ChangesSaved");
            }
            catch (Exception ex)
            {
                lblError.Visible = true;
                lblError.Text    = ex.Message;
            }
        }
    }
Exemple #19
0
    /// <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.ShoppingCartBillingAddress == null)
        {
            ShoppingCartControl.LoadStep(0);
            return(false);
        }

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

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

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

        if (!ShoppingCartControl.IsInternalOrder)
        {
            // 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(SiteContext.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);
            }
        }
        // When on the live site
        else if (ECommerceSettings.SendOrderNotification(SiteContext.CurrentSite.SiteName))
        {
            // Send order notification emails
            OrderInfoProvider.SendOrderNotificationToAdministrator(ShoppingCart);
            OrderInfoProvider.SendOrderNotificationToCustomer(ShoppingCart);
        }

        return(true);
    }