Example #1
0
        protected void rblShippingRateEstimates_SelectedIndexChanged(object sender, EventArgs e)
        {
            string[] rateParts = rblShippingRateEstimates.SelectedValue.Split("||");
            checkoutOrderInfo.ShippingRate.ServiceType            = rateParts[0];
            checkoutOrderInfo.ShippingRate.ServiceTypeDescription = rateParts[1];
            checkoutOrderInfo.ShippingRate.Rate = Convert.ToDecimal(rateParts.Length == 3 ? rateParts[2] : rateParts[1]);

            //checkoutOrderInfo.BillingAddress.PostalCode = txtShippingEstimateZip.Text;
            //checkoutOrderInfo.ShippingAddress.PostalCode = txtShippingEstimateZip.Text;
            //checkoutOrderInfo.ShippingAddress.IsResidential = !chkShippingAddressIsBusiness.Checked;

            checkoutOrderInfo.ReCalculateOrderTotals();

            UpdateProductQuantities();
            UpdateCheckoutSession();
        }
Example #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            LoadResourceFileSettings();

            cartController = new CartController(StoreContext);

            checkoutOrderInfo = Session[StoreContext.SessionKeys.CheckoutOrderInfo] as CheckoutOrderInfo ?? new CheckoutOrderInfo()
            {
                Cart = cartController.GetCart(true)
            };
            checkoutOrderInfo.Cart = cartController.GetCart(true);
            checkoutOrderInfo.ReCalculateOrderTotals();

            var payPalStandard = new PayPalStandardProvider(StoreContext.CurrentStore.GetPaymentProviderConfig(PaymentProviderName.PayPalStandard));

            collectPayPalStandardShipping = payPalStandard.ShippingLogic == "Store" && !checkoutOrderInfo.HasOnlyDownloadableProducts;

            if (!IsPostBack)
            {
                int?removeCartItem = WA.Parser.ToInt(Request.QueryString["remove"]);
                if (removeCartItem.HasValue)
                {
                    RemoveCartItemFromCart(removeCartItem.Value);
                    UpdateCheckoutSession();

                    // redirect so that the "mini-cart" updates on the page also...
                    Response.Redirect(StoreUrls.Cart());
                }
                // FEATURE: Add product to the cart via URL/QueryString
                string addProductSlug = Request.QueryString["add"] ?? string.Empty;
                if (!string.IsNullOrEmpty(addProductSlug))
                {
                    var productToAdd = Product.GetBySlug(StoreContext.CurrentStore.Id.Value, addProductSlug);
                    if (productToAdd != null)
                    {
                        //bool IsAvailableForPurchase = productToAdd.IsAvailableForPurchase.GetValueOrDefault(true) && WA.Parser.ToBool(StoreContext.CurrentStore.GetSetting(StoreSettingNames.EnableCheckout)).GetValueOrDefault(true);
                        bool IsAvailableForPurchase = productToAdd.IsPurchaseableByUser;
                        if (IsAvailableForPurchase)
                        {
                            int quantityToAdd = Request.QueryString["q"] != null?Convert.ToInt32(Request.QueryString["q"]) : 1;

                            cartController.AddProductToCart(productToAdd.Id.Value, quantityToAdd, string.Empty);
                        }
                        checkoutOrderInfo.Cart = cartController.GetCart(false);
                        checkoutOrderInfo.ReCalculateOrderTotals();

                        bool redirectBackToReferrer = WA.Parser.ToBool(Request.QueryString["redirect"]).GetValueOrDefault(false);
                        if (redirectBackToReferrer && (Request.UrlReferrer != null))
                        {
                            string redirectUrl = Request.UrlReferrer.ToString();


                            // Remove previous flash message from querystring when redirecting
                            if (redirectUrl.ToLower().Contains("flash"))
                            {
                                int flashIndex = redirectUrl.IndexOf("flash");
                                redirectUrl = redirectUrl.Substring(0, flashIndex - 1);
                            }

                            bool referrerIsOnsite = (Request.UrlReferrer.Host == Request.Url.Host);
                            if (referrerIsOnsite)
                            {
                                // redirect and add a 'flash' message to notify customer that product was added to cart
                                if (IsAvailableForPurchase)
                                {
                                    redirectUrl = redirectUrl.AddUrlParam("flash", HttpUtility.UrlPathEncode(string.Format(@"""{0}"" has been added to your cart", productToAdd.Name)));
                                }
                                else
                                {
                                    redirectUrl = redirectUrl.AddUrlParam("flash", HttpUtility.UrlPathEncode(string.Format(@"""{0}"" is not available for purchase.", productToAdd.Name)));
                                }
                            }
                            //Response.Redirect(redirectUrl, true);
                            Response.Redirect(redirectUrl);
                        }
                        else
                        {
                            if (IsAvailableForPurchase)
                            {
                                flash.InnerHtml = string.Format(@"""{0}"" has been added to your cart", productToAdd.Name);
                            }
                            else
                            {
                                flash.InnerHtml = string.Format(@"""{0}"" is not available for purchase", productToAdd.Name);
                            }
                            flash.Visible = true;
                        }
                    }
                }

                DataBindCartItems();

                var store = StoreContext.CurrentStore;

                //---- checkout buttons
                bool payLaterPaymentEnabled        = StoreContext.CurrentStore.IsPaymentProviderEnabled(PaymentProviderName.PayLater);
                bool cardCaptureOnlyPaymentEnabled = StoreContext.CurrentStore.IsPaymentProviderEnabled(PaymentProviderName.CardCaptureOnly);
                bool authorizeNetAimEnabled        = StoreContext.CurrentStore.IsPaymentProviderEnabled(PaymentProviderName.AuthorizeNetAim);
                bool payPalDirectEnabled           = StoreContext.CurrentStore.IsPaymentProviderEnabled(PaymentProviderName.PayPalDirectPayment);
                bool onsitePaymentProviderEnabled  = payLaterPaymentEnabled || cardCaptureOnlyPaymentEnabled || authorizeNetAimEnabled || payPalDirectEnabled;

                btnCheckoutOnsite.Visible         = onsitePaymentProviderEnabled;
                btnCheckoutPayPalStandard.Visible = StoreContext.CurrentStore.IsPaymentProviderEnabled(PaymentProviderName.PayPalStandard);
                ibtnPayPalExpressCheckout.Visible = StoreContext.CurrentStore.IsPaymentProviderEnabled(PaymentProviderName.PayPalExpressCheckout);
                if (btnCheckoutOnsite.Visible && (btnCheckoutPayPalStandard.Visible || ibtnPayPalExpressCheckout.Visible))
                {
                    spnOr.Visible = true;
                }

                //collectPayPalStandardShipping = payPalStandard.ShippingLogic == "Store";
                //payPalStandard = new PayPalStandardProvider(StoreContext.CurrentStore.GetPaymentProviderConfig(PaymentProviderName.PayPalStandard));)
                if (collectPayPalStandardShipping)
                {
                    string        storeCountry         = store.GetSetting(StoreSettingNames.DefaultCountryCode);
                    var           countries            = DnnHelper.GetCountryListAdoNet();
                    StringBuilder countriesOptionsHtml = new StringBuilder(countries.Count);
                    foreach (var c in countries)
                    {
                        countriesOptionsHtml.AppendFormat(@"<option value=""{0}"" {2}>{1}</option>", c.CountryCode, c.Name, c.CountryCode == storeCountry ? "selected=selected" : string.Empty);
                    }
                    litCountryOptionsHtml.Text = countriesOptionsHtml.ToString();
                }

                //IShippingProvider fedExProvider = ShippingProviderFactory.Get(StoreContext.CurrentStore.Id.Value, ShippingProviderType.FedEx);
                //pnlShippingQuoteForm.Visible = fedExProvider.IsEnabled;
                var shippingServices = StoreContext.CurrentStore.GetEnabledShippingProviders(null, checkoutOrderInfo.Cart.Id);
                if (shippingServices.Count > 0)
                {
                    pnlShippingQuoteForm.Visible = true;
                }

                //----------Show / Hide Coupon Box and Shipping Estimate Boxes

                pnlShippingQuoteForm.Visible = WA.Parser.ToBool(store.GetSetting(StoreSettingNames.ShowShippingEstimate)).GetValueOrDefault(true);
                pnlCouponCodeForm.Visible    = WA.Parser.ToBool(store.GetSetting(StoreSettingNames.ShowCouponBox)).GetValueOrDefault(true);
            }
        }