Esempio n. 1
0
        protected void ClearBasketButton_Click(object sender, EventArgs e)
        {
            IBasketService basketService = AbleContext.Resolve <IBasketService>();

            basketService.Clear(AbleContext.Current.User.Basket);
            BindBasketGrid();
        }
        private int ComparerPaymentMethod(DictionaryEntry x, DictionaryEntry y)
        {
            int paymentMethodId1 = (int)x.Key;
            int paymentMethodId2 = (int)y.Key;
            int order1, order2 = 0;

            if (paymentMethodId1 == -1)
            {
                order1 = GetCreditCardSortOrder();
            }
            else if (paymentMethodId1 == -2)
            {
                order1 = AbleContext.Resolve <IPaymentMethodProvider>().GetGiftCertificatePaymentMethod().OrderBy;
            }
            else
            {
                order1 = _AvailablePaymentMethods[_AvailablePaymentMethods.IndexOf(paymentMethodId1)].OrderBy;
            }

            if (paymentMethodId2 == -1)
            {
                order2 = GetCreditCardSortOrder();
            }
            else if (paymentMethodId2 == -2)
            {
                order2 = AbleContext.Resolve <IPaymentMethodProvider>().GetGiftCertificatePaymentMethod().OrderBy;
            }
            else
            {
                order2 = _AvailablePaymentMethods[_AvailablePaymentMethods.IndexOf(paymentMethodId2)].OrderBy;
            }

            return(order1.CompareTo(order2));
        }
        protected void ShipmentList_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            // IF THERE ARE MULTIPLE SHIPMENTS, SHOW THE MULTI SHIPMENT HEADER
            if (this.MultiShipmentDisplay)
            {
                PlaceHolder MultiShipmentHeader = e.Item.FindControl("MultiShipmentHeader") as PlaceHolder;
                if (MultiShipmentHeader != null)
                {
                    MultiShipmentHeader.Visible = true;
                }
            }

            // PREPARE AND DISPLAY SHIPPING ESTIMATE FOR THIS SHIPMENT
            GridView ShipRateGrid = e.Item.FindControl("ShipRateGrid") as GridView;

            if (ShipRateGrid != null)
            {
                BasketShipment shipment = e.Item.DataItem as BasketShipment;
                if (shipment != null)
                {
                    // CREATE AN ADDRESS INSTANCE TO HOLD ESTIMATE DESTINATION
                    // PRESERVE THE CURRENT SHIPPING ADDRESS
                    Address savedAddress = shipment.Address;
                    // TEMPORARILY ASSIGN THE ESTIMATE ADDRESS TO THIS SHIPMENT
                    shipment.SetAddress(_EstimateAddress);
                    // GET THE RATE QUOTES AND BIND TO THE TABLE
                    ShipRateGrid.DataSource = AbleContext.Resolve <IShipRateQuoteCalculator>().QuoteForShipment(shipment);
                    ShipRateGrid.DataBind();
                    // RESTORE THE SAVED ADDRESS
                    shipment.SetAddress(savedAddress);
                }
            }
        }
Esempio n. 4
0
        protected void Page_PreRender(object sender, EventArgs e)
        {
            //GET ANY MESSAGES FROM SESSION
            IList <string> sessionMessages = Session["BasketMessage"] as IList <string>;
            //GET THE BASKET AND RECALCULATE
            Basket         basket             = AbleContext.Current.User.Basket;
            IBasketService preCheckoutService = AbleContext.Resolve <IBasketService>();

            preCheckoutService.Recalculate(basket);
            foreach (var rec in basket.Items)
            {
                rec.Price = Math.Abs(rec.Price);
            }
            //VALIDATE THE BASKET
            ValidationResponse response = preCheckoutService.Validate(basket);

            //DISPLAY ANY WARNING MESSAGES
            if ((!response.Success) || (sessionMessages != null))
            {
                if (sessionMessages != null)
                {
                    Session.Remove("BasketMessage");
                    sessionMessages.AddRange(response.WarningMessages);
                    WarningMessageList.DataSource = sessionMessages;
                }
                else
                {
                    WarningMessageList.DataSource = response.WarningMessages;
                }
                WarningMessageList.DataBind();
            }
            BindBasketGrid();
        }
        protected void ShipToAddressList_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "Pick")
            {
                int  addressId = AlwaysConvert.ToInt(e.CommandArgument);
                User user      = AbleContext.Current.User;
                int  index     = user.Addresses.IndexOf(addressId);
                if (index > -1)
                {
                    // RESET BASKET PACKAGING
                    IBasketService preCheckoutService = AbleContext.Resolve <IBasketService>();
                    preCheckoutService.Package(user.Basket, true);
                    Address address = user.Addresses[index];

                    // UPDATE DESTINATION TO SELECTED ADDRESS AND REDIRECT
                    foreach (BasketShipment shipment in user.Basket.Shipments)
                    {
                        shipment.Address = address;
                    }
                    user.Basket.Save();
                    Response.Redirect("ShipMethod.aspx");
                }
            }
            else if (e.CommandName == "Edit")
            {
                int addressId = AlwaysConvert.ToInt(e.CommandArgument);
                Response.Redirect(string.Format("EditShipAddress.aspx?AddressId={0}", addressId));
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            // LOCATE THE USER THAT THE ORDER IS BEING PLACED FOR
            _UserId = AlwaysConvert.ToInt(Request.QueryString["UID"]);
            _User   = UserDataSource.Load(_UserId);
            if (_User == null)
            {
                Response.Redirect("CreateOrder1.aspx");
            }
            _Basket = _User.Basket;

            // INITIALIZE INVENTORY VARIABLES
            _InventoryManager      = AbleContext.Resolve <IInventoryManager>();
            _StoreInventoryEnabled = AbleContext.Current.Store.Settings.EnableInventory;

            // SHOW QUANTITY AVAILABLE COLUMN IF INVENTORY IS ENABLED
            BasketGrid.Columns[4].Visible = _StoreInventoryEnabled;

            // INITIALIZE THE CAPTION
            string userName = _User.IsAnonymous ? "Unregistered User" : _User.UserName;

            Caption.Text = string.Format(Caption.Text, userName);

            // SEE IF THE ADD PRODUCT FORM SHOULD BE VISIBLE
            int     productId = AlwaysConvert.ToInt(Request.Form[AddProductId.UniqueID]);
            Product product   = ProductDataSource.Load(productId);

            if (product != null)
            {
                ShowProductForm(product);
            }
        }
Esempio n. 7
0
        private void ToggleProgressSQLFts(bool forceProgressDisplaySQLFts)
        {
            ISQLFullTextSearchService searchService = AbleContext.Resolve <ISQLFullTextSearchService>();

            if (searchService.LastReindexDateSQLFts != null && !searchService.IsReindexingSQLFts && !forceProgressDisplaySQLFts)
            {
                LastRebuildDateSQLFts.Text     = string.Format(LastRebuildDateSQLFts.Text, searchService.LastReindexDateSQLFts.Value);
                LastRebuildPanelSQLFts.Visible = true;
            }
            else
            {
                LastRebuildPanelSQLFts.Visible = false;
            }

            if (searchService.IsReindexingSQLFts || forceProgressDisplaySQLFts)
            {
                int seconds = 1;
                if (searchService.IsReindexingSQLFts)
                {
                    seconds = (int)Math.Ceiling(LocaleHelper.LocalNow.Subtract(searchService.ReindexStartDateSQLFts.Value).TotalSeconds);
                }
                int minutes = seconds / 60;
                seconds = seconds - (60 * minutes);
                ProgressLabelSQLFts.Text      = string.Format(ProgressLabelSQLFts.Text, minutes, seconds);
                ProgressPanelSQLFts.Visible   = true;
                RebuildSQLIndexButton.Visible = false;
                Timer2.Enabled = true;
            }
            else
            {
                ProgressPanelSQLFts.Visible   = false;
                RebuildSQLIndexButton.Visible = true;
            }
        }
        protected void ReturnButton_Click(object sender, EventArgs e)
        {
            List <ItemReturnInfo> itemsToReturn = new List <ItemReturnInfo>();
            Order order = OrderDataSource.Load(_OrderId);

            foreach (GridViewRow row in ReturnableItems.Rows)
            {
                int       orderItemId = AlwaysConvert.ToInt(ReturnableItems.DataKeys[row.DataItemIndex].Value);
                OrderItem item        = order.Items.FirstOrDefault(find => find.Id.Equals(orderItemId));
                if (item != null)
                {
                    int returnQuantity = AlwaysConvert.ToInt(((TextBox)row.FindControl("ReturnQuantity")).Text);
                    if (returnQuantity > 0)
                    {
                        itemsToReturn.Add(new ItemReturnInfo(item, returnQuantity, ReturnToInventory.Checked));
                    }
                }
            }
            IOrderService service = AbleContext.Resolve <IOrderService>();

            service.ReturnItems(order, itemsToReturn);

            // add note if indicated
            if (!string.IsNullOrEmpty(OrderNote.Text))
            {
                order.Notes.Add(new OrderNote(order, AbleContext.Current.User, LocaleHelper.LocalNow, OrderNote.Text, OrderNoteIsPrivate.Checked ? NoteType.Private : NoteType.Public));
                order.Save(false, false);
            }

            // display confirmation
            BindGrid(order);
            ReturnedMessage.Visible = true;
        }
Esempio n. 9
0
        protected void GoToNextPage()
        {
            string nextPageUrl = "Payment.aspx";

            if (ShippingAddressPanel.Visible)
            {
                switch (ShipToOption.SelectedValue)
                {
                case "SHIP_TO_BILLING_ADDRESS":
                    // need to ensure all items are going to the billing address
                    Basket         basket             = AbleContext.Current.User.Basket;
                    IBasketService preCheckoutService = AbleContext.Resolve <IBasketService>();
                    preCheckoutService.Package(basket, true);
                    nextPageUrl = "ShipMethod.aspx";
                    break;

                case "SHIP_TO_ADDRESS":
                    nextPageUrl = "ShipAddress.aspx";
                    break;

                case "SHIP_TO_MULTIPLE_ADDRESSES":
                    nextPageUrl = "ShipAddresses.aspx";
                    break;
                }

                Session["SHIP_TO_OPTION"] = ShipToOption.SelectedValue;
            }

            Response.Redirect(nextPageUrl);
        }
Esempio n. 10
0
 /// <summary>
 /// Creates the google feed
 /// </summary>
 public static void CreateFeed(bool manualFeedGeneration)
 {
     try
     {
         // ENSURE APP IS INSTALLED
         Store store = GetInstalledStore();
         if (store != null)
         {
             // SEE IF FEED GENERATION IS ENABLED
             ApplicationSettings appConfig = ApplicationSettings.Instance;
             if (appConfig.GoogleFeedInterval > 0 || manualFeedGeneration)
             {
                 // SEE IF THE FEED IS OLD ENOUGH TO BE REGENERATED
                 int      interval       = (int)(60000 * appConfig.GoogleFeedInterval);
                 string   googleBaseFile = HostingEnvironment.MapPath("~/Feeds/GoogleFeedData.txt");
                 FileInfo fileInfo       = new FileInfo(googleBaseFile);
                 if (!fileInfo.Exists || fileInfo.LastWriteTime.AddMilliseconds(interval) < DateTime.Now)
                 {
                     CreateFeed(googleBaseFile, store.Settings.GoogleFeedIncludeAllProducts, store.Settings.GoogleFeedDefaultBrand, store.Settings.GoogleFeedDefaultCategory);
                 }
             }
         }
     }
     catch
     {
     }
     finally
     {
         AbleContext.ReleaseInstance();
     }
 }
Esempio n. 11
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // verify the provider is configured
            _AmazonProvider = GetAmazonProvider();
            if (_AmazonProvider == null)
            {
                Response.Redirect(NavigationHelper.GetBasketUrl());
            }

            // package the basket on first visit
            Basket basket = AbleContext.Current.User.Basket;

            if (!Page.IsPostBack)
            {
                IBasketService basketService = AbleContext.Resolve <IBasketService>();
                basketService.Package(basket, true);
                basketService.Combine(basket);
                foreach (var shipment in basket.Shipments)
                {
                    shipment.ShipMethod = null;
                }
                basket.Save();
                basketService.Recalculate(basket);
            }

            // bind the amazon widgets
            MethodInfo buttonMethod = _AmazonProvider.GetType().GetMethod("GetAddressWidget");
            string     eventHandler = "document.getElementById('" + RecalculateShippingButton.ClientID + "').click();";

            object[]    parameters    = new object[] { basket, eventHandler, false };
            PlaceHolder addressWidget = (PlaceHolder)buttonMethod.Invoke(_AmazonProvider, parameters);

            this.ShippingAddress.Controls.Add(addressWidget);
            BindBasketGrid();
        }
Esempio n. 12
0
        protected void ShipMethod_SelectedIndexChanged(object sender, EventArgs e)
        {
            int currentShipMethod = AlwaysConvert.ToInt(ShipMethodsList.SelectedValue);

            CommerceBuilder.Shipping.ShipMethod method = ShipMethodDataSource.Load(currentShipMethod);
            if (method != null)
            {
                // set all shipments to the right shipping method
                Basket basket = AbleContext.Current.User.Basket;
                foreach (BasketShipment shipment in basket.Shipments)
                {
                    shipment.ShipMethod = method;
                }
                basket.Save();

                IBasketService service = AbleContext.Resolve <IBasketService>();
                service.Recalculate(basket);

                PaymentPanel.Visible = true;
                BindBasketGrid();

                MethodInfo widgetMethod = _AmazonProvider.GetType().GetMethod("GetPaymentWidget");
                string     eventHandler = "document.getElementById('" + PlaceOrderButton.ClientID + "').style.display = 'block';";
                //string eventHandler = "alert('payment chosen');";
                object[]    parameters    = new object[] { AbleContext.Current.User.Basket, eventHandler, false };
                PlaceHolder paymentWidget = (PlaceHolder)widgetMethod.Invoke(_AmazonProvider, parameters);
                this.phPaymentWidget.Controls.Add(paymentWidget);
            }
        }
        protected void ShipMethodList_SelectedIndexChanged(object sender, EventArgs e)
        {
            // UPDATE SHIPMENTS
            for (int i = 0; i < ShipmentList.Items.Count; i++)
            {
                RepeaterItem item = ShipmentList.Items[i];
                if (item != null)
                {
                    BasketShipment shipment       = _Basket.Shipments[i];
                    DropDownList   ShipMethodList = (DropDownList)item.FindControl("ShipMethodList");
                    if (shipment != null && ShipMethodList != null)
                    {
                        shipment.ShipMethodId = AlwaysConvert.ToInt(ShipMethodList.Items[ShipMethodList.SelectedIndex].Value);
                    }
                }
            }

            // UPDATE THE ORDER ITMES PANEL TO REFLECT ANY CHANGE
            _Basket.Save();
            IBasketService preCheckoutService = AbleContext.Resolve <IBasketService>();

            preCheckoutService.Recalculate(_Basket);

            BindPaymentMethodForms();
            BasketAjax.Update();
        }
Esempio n. 14
0
        //TODO: Move Code to Helper Class
        public Boolean CheckQuoteBasketItems()
        {
            Basket         basket             = AbleContext.Current.User.Basket;
            IBasketService preCheckoutService = AbleContext.Resolve <IBasketService>();

            preCheckoutService.Recalculate(basket);
            return(basket.Items.Any(item => item.OrderItemType == OrderItemType.Product && (item.Price <= 0 || !(item.Product.VolumeDiscounts.Any() && item.Product.VolumeDiscounts[0].Levels.Any()))));
        }
Esempio n. 15
0
 protected void Timer2_Tick(object sender, EventArgs e)
 {
     // DISABLE THE TIMER IF INDEX CREATION IS COMPLETE
     if (!AbleContext.Resolve <ISQLFullTextSearchService>().IsReindexingSQLFts)
     {
         Timer2.Enabled = false;
         RebuildSQLIndexButton.Visible = true;
     }
 }
Esempio n. 16
0
        private IList <BasketItem> GetBasketItems()
        {
            Basket         basket             = AbleContext.Current.User.Basket;
            IBasketService preCheckoutService = AbleContext.Resolve <IBasketService>();

            preCheckoutService.Combine(basket);
            _DisplayedBasketItems = BasketHelper.GetDisplayItems(basket, false);
            return(_DisplayedBasketItems);
        }
Esempio n. 17
0
        protected void Page_Init(object sender, EventArgs e)
        {
            // LOCATE THE USER THAT THE ORDER IS BEING PLACED FOR
            _UserId = AlwaysConvert.ToInt(Request.QueryString["UID"]);
            _User   = UserDataSource.Load(_UserId);
            if (_User == null)
            {
                Response.Redirect("CreateOrder1.aspx");
            }
            _Basket = _User.Basket;
            MiniBasket1.BasketId = _Basket.Id;

            // ENSURE THE BASKET IS PACKAGED
            IBasketService preCheckoutService = AbleContext.Resolve <IBasketService>();

            preCheckoutService.Package(_Basket);

            // INITIALIZE THE CAPTION
            string userName = _User.IsAnonymous ? "Unregistered User" : _User.UserName;

            Caption.Text = string.Format(Caption.Text, userName);

            //INITIALIZE BILLING COUNTRY LIST ON EVERY VISIT
            InitializeBillingCountryAndProvince();

            // INITIALIZE SHIPPING CONTROLS
            trAddressBook.Visible = _Basket.Items.HasShippableProducts();
            if (trAddressBook.Visible)
            {
                // THESE TASKS MUST OCCUR EVER VISIT DUE TO DISABLED VIEWSTATE
                InitializeAddressBook();
                InitializeShippingCountryAndProvince();

                // SEE IF WE NEED TO SHOW THE SHIPPING OFORM
                int shipAddressId = GetShippingAddressId();
                if (shipAddressId == 0 || shipAddressId == _User.PrimaryAddress.Id)
                {
                    // SHIP TO BILLING ADDRESS
                    ShipAddressPanel.Visible       = false;
                    trContinueButton1.Visible      = true;
                    BillAddressPanel.DefaultButton = "ContinueButton";
                }
                else
                {
                    // INITIALIZE SHIPPING ADDRESS
                    ShipAddressPanel.Visible       = true;
                    trContinueButton1.Visible      = false;
                    BillAddressPanel.DefaultButton = "ContinueButton2";
                }
            }

            // POPULATE BILLING FORM ON FIRST PAGE VISIT
            if (!Page.IsPostBack)
            {
                InitializeBillingAddress();
            }
        }
Esempio n. 18
0
        private IList <BasketItem> GetBasketItems()
        {
            User           user               = AbleContext.Current.User;
            Basket         basket             = user.Basket;
            IBasketService preCheckoutService = AbleContext.Resolve <IBasketService>();

            preCheckoutService.Combine(basket);
            _DisplayedBasketItems = new List <BasketItem>();
            foreach (BasketItem item in basket.Items)
            {
                if (Array.IndexOf(displayItemTypes, item.OrderItemType) > -1)
                {
                    if (item.OrderItemType == OrderItemType.Product && item.IsChildItem)
                    {
                        // WHETHER THE CHILD ITEM DISPLAYS DEPENDS ON THE ROOT
                        BasketItem rootItem = item.GetParentItem(true);
                        if (rootItem != null && rootItem.Product != null && rootItem.Product.Kit != null && rootItem.Product.Kit.ItemizeDisplay)
                        {
                            // ITEMIZED DISPLAY ENABLED, SHOW THIS CHILD ITEM
                            _DisplayedBasketItems.Add(item);
                        }
                    }
                    else
                    {
                        // NO ADDITIONAL CHECK REQUIRED TO INCLUDE ROOT PRODUCTS OR NON-PRODUCTS
                        _DisplayedBasketItems.Add(item);
                    }
                }
            }
            // ADD IN ANY CHILD ITEMS

            //ADD IN TAX ITEMS IF SPECIFIED FOR DISPLAY
            if (TaxHelper.GetEffectiveShoppingDisplay(user) == TaxShoppingDisplay.LineItem)
            {
                foreach (BasketItem item in basket.Items)
                {
                    //IS THIS A TAX ITEM?
                    if (item.OrderItemType == OrderItemType.Tax)
                    {
                        ////IS THE TAX ITEM A PARENT ITEM OR A CHILD OF A DISPLAYED ITEM?
                        //if (!item.IsChildItem || (_DisplayedBasketItems.IndexOf(item.ParentItemId) > -1))
                        //{
                        //TAX SHOULD BE SHOWN
                        _DisplayedBasketItems.Add(item);
                        //}
                    }
                }
            }

            // COMBINE ORDER COUPON ITEMS
            _DisplayedBasketItems = _DisplayedBasketItems.CombineOrderCoupons();

            //SORT ITEMS TO COMPLETE INTITIALIZATION
            _DisplayedBasketItems.Sort(new BasketItemComparer());
            return(_DisplayedBasketItems);
        }
Esempio n. 19
0
        protected void ShipmentRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            //CAST DATA ITEM
            BasketShipment shipment = (BasketShipment)e.Item.DataItem;

            //UPDATE SHIPPING WEIGHT
            Literal shipWeight = (Literal)e.Item.FindControl("ShipWeight");

            if (shipWeight != null)
            {
                shipWeight.Text = string.Format(weightFormat, shipment.Items.TotalWeight());
            }
            //SHOW SHIPPING METHODS
            DropDownList ShipMethodsList        = (DropDownList)e.Item.FindControl("ShipMethodsList");
            Localize     ShipMethodErrorMessage = (Localize)e.Item.FindControl("ShipMethodErrorMessage");
            PlaceHolder  phNoShippingMethods    = (PlaceHolder)e.Item.FindControl("phNoShippingMethods");
            PlaceHolder  phShipMessage          = (PlaceHolder)e.Item.FindControl("PHShipMessage");

            if (phShipMessage != null)
            {
                phShipMessage.Visible = AbleContext.Current.Store.Settings.EnableShipMessage;
            }

            if (ShipMethodsList != null)
            {
                _ShipmentIndex = e.Item.ItemIndex;
                IShipRateQuoteCalculator    shippingCalculator = AbleContext.Resolve <IShipRateQuoteCalculator>();
                ICollection <ShipRateQuote> rateQuotes         = shippingCalculator.QuoteForShipment(shipment);
                foreach (var rec in rateQuotes)
                {
                    rec.Rate = Math.Abs(rec.Rate);
                }
                ShipMethodsList.DataSource = GetShipMethodListDs(rateQuotes);
                ShipMethodsList.DataBind();
                if (rateQuotes.Count == 0)
                {
                    ShipMethodErrorMessage.Visible = true;
                    phNoShippingMethods.Visible    = true;
                    ShipMethodsList.Visible        = false;
                    Localize ShipMethodUPSErrorMessage = (Localize)e.Item.FindControl("ShipMethodUPSErrorMessage");
                    // CHECK IF UPS IS ENABLED
                    string classId = Misc.GetClassId(typeof(UPS));
                    IList <ShipGateway> gateways = ShipGatewayDataSource.LoadForClassId(classId);
                    if (gateways.Count > 0)
                    {
                        // CHECK IF PROVIDED ADDRESS IS A PO-BOX ADDRESS
                        if (ValidationHelper.IsPostOfficeBoxAddress(shipment.Address.Address1))
                        {
                            ShipMethodUPSErrorMessage.Visible = true;
                        }
                    }

                    _shippingMethodsAvailable = false;
                }
            }
        }
Esempio n. 20
0
        protected void ContinueButton_Click(object sender, EventArgs e)
        {
            // LOOP EACH ITEM ROW TO DETERMINE GIFT OPTIONS
            List <BasketItemGiftOption> giftOptions = new List <BasketItemGiftOption>();

            foreach (GridViewRow row in GiftItemsGrid.Rows)
            {
                GiftWrapChoices      wrapOptions   = (GiftWrapChoices)row.FindControl("GiftWrapChoices");
                int                  wrapStyleId   = wrapOptions.WrapStyleId;
                string               giftMessage   = wrapOptions.GiftMessage;
                BasketItemGiftOption optionItem    = new BasketItemGiftOption(_BasketItem, wrapStyleId, giftMessage);
                int                  existingIndex = giftOptions.IndexOf(optionItem);
                if (existingIndex > -1)
                {
                    giftOptions[existingIndex].Quantity++;
                }
                else
                {
                    giftOptions.Add(optionItem);
                }
            }

            // LOOP THROUGH GIFT OPTIONS AND UPDATE BASKET ITEMS
            Basket basket = AbleContext.Current.User.Basket;

            for (int i = 0; i < giftOptions.Count; i++)
            {
                BasketItemGiftOption giftOptionItem = giftOptions[i];
                if (i == 0)
                {
                    // FOR FIRST GIFT OPTION, UPDATE THE ORIGINAL BASKET ITEM
                    _BasketItem.Quantity    = giftOptionItem.Quantity;
                    _BasketItem.WrapStyleId = giftOptionItem.WrapStyleId;
                    _BasketItem.GiftMessage = giftOptionItem.GiftMessage;
                }
                else
                {
                    // FOR ADDTIONAL GIFT OPTIONS, CREATE COPIES OF THE ORIGINAL BASKET ITEM
                    BasketItem newItem = _BasketItem.Copy();
                    newItem.Quantity    = giftOptionItem.Quantity;
                    newItem.GiftMessage = giftOptionItem.GiftMessage;
                    newItem.WrapStyleId = giftOptionItem.WrapStyleId;
                    basket.Items.Add(newItem);
                }
            }

            // SAVE, COMBINE, AND RETURN TO THE SHIP METHODS PAGE
            basket.Save();
            IBasketService basketService = AbleContext.Resolve <IBasketService>();

            basketService.Combine(basket);
            Response.Redirect("ShipMethod.aspx");
        }
        protected void Page_PreRender(object sender, System.EventArgs e)
        {
            // GET THE BASKET AND RECALCULATE IT
            IBasketService service = AbleContext.Resolve <IBasketService>();

            service.Combine(_Basket);
            service.Recalculate(_Basket);

            // BIND THE BASKET GRID
            BindBasketGrid();
            InventoryAlertUpdate();
        }
Esempio n. 22
0
        public static void SaveBasket(GridView BasketGrid)
        {
            Basket basket   = AbleContext.Current.User.Basket;
            int    rowIndex = 0;

            foreach (GridViewRow saverow in BasketGrid.Rows)
            {
                int basketItemId = (int)BasketGrid.DataKeys[rowIndex].Value;
                int itemIndex    = basket.Items.IndexOf(basketItemId);
                if ((itemIndex > -1))
                {
                    BasketItem item = basket.Items[itemIndex];
                    if (item.OrderItemType == OrderItemType.Product && !item.IsChildItem)
                    {
                        TextBox quantity = (TextBox)saverow.FindControl("Quantity");
                        if (quantity != null)
                        {
                            int qty = AlwaysConvert.ToInt(quantity.Text, item.Quantity);
                            if (qty > System.Int16.MaxValue)
                            {
                                item.Quantity = System.Int16.MaxValue;
                            }
                            else
                            {
                                item.Quantity = (System.Int16)qty;
                            }

                            // Update for Minimum Maximum quantity of product
                            if (item.Quantity < item.Product.MinQuantity)
                            {
                                item.Quantity = item.Product.MinQuantity;
                                quantity.Text = item.Quantity.ToString();
                            }
                            else if ((item.Product.MaxQuantity > 0) && (item.Quantity > item.Product.MaxQuantity))
                            {
                                item.Quantity = item.Product.MaxQuantity;
                                quantity.Text = item.Quantity.ToString();
                            }
                        }
                    }
                    rowIndex++;
                }
            }
            basket.Save();
            IBasketService preCheckoutService = AbleContext.Resolve <IBasketService>();

            preCheckoutService.Recalculate(basket);
            foreach (var rec in basket.Items)
            {
                rec.Price = Math.Abs(rec.Price);
            }
        }
Esempio n. 23
0
        protected void CreditCardButton_Click(object sender, EventArgs e)
        {
            if (Page.IsValid && CustomValidation())
            {
                //CREATE THE PAYMENT OBJECT
                Payment payment = GetPayment();
                //PROCESS CHECKING OUT EVENT
                bool checkOut = true;
                if (CheckingOut != null)
                {
                    CheckingOutEventArgs c = new CheckingOutEventArgs(payment);
                    CheckingOut(this, c);
                    checkOut = !c.Cancel;
                }
                if (checkOut)
                {
                    //PROCESS A CHECKOUT
                    ICheckoutService checkoutService  = AbleContext.Resolve <ICheckoutService>();
                    CheckoutRequest  checkoutRequest  = new CheckoutRequest(_Basket, payment);
                    CheckoutResponse checkoutResponse = checkoutService.ExecuteCheckout(checkoutRequest, false);
                    if (checkoutResponse.Success)
                    {
                        if (CheckedOut != null)
                        {
                            CheckedOut(this, new CheckedOutEventArgs(checkoutResponse));
                        }
                        Response.Redirect(AbleCommerce.Code.NavigationHelper.GetReceiptUrl(checkoutResponse.Order.OrderNumber));
                    }
                    else
                    {
                        IList <string> warningMessages = checkoutResponse.WarningMessages;
                        if (warningMessages.Count == 0)
                        {
                            warningMessages.Add("The order could not be submitted at this time.  Please try again later or contact us for assistance.");
                        }
                        if (CheckedOut != null)
                        {
                            CheckedOut(this, new CheckedOutEventArgs(checkoutResponse));
                        }
                    }
                }
            }
            else
            {
                CreditCardButton.Text = "Pay With Card";
            }

            // IF NOT SUCCESSFULL / ENABLE THE CHECKOUT BUTTON
            CreditCardButton.Enabled = true;
            FormIsSubmitted.Value    = "0";
        }
Esempio n. 24
0
        protected void ShipmentRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            //CAST DATA ITEM
            BasketShipment shipment = (BasketShipment)e.Item.DataItem;

            //UPDATE SHIPPING WEIGHT
            Literal shipWeight = (Literal)e.Item.FindControl("ShipWeight");

            if (shipWeight != null)
            {
                shipWeight.Text = string.Format(weightFormat, shipment.Items.TotalWeight());
            }
            //SHOW SHIPPING METHODS
            RadioButtonList ShipMethodsList        = (RadioButtonList)e.Item.FindControl("ShipMethodsList");
            Localize        ShipMethodErrorMessage = (Localize)e.Item.FindControl("ShipMethodErrorMessage");
            PlaceHolder     phNoShippingMethods    = (PlaceHolder)e.Item.FindControl("phNoShippingMethods");

            if (ShipMethodsList != null)
            {
                _ShipmentIndex = e.Item.ItemIndex;
                IShipRateQuoteCalculator    shippingCalculator = AbleContext.Resolve <IShipRateQuoteCalculator>();
                ICollection <ShipRateQuote> rateQuotes         = shippingCalculator.QuoteForShipment(shipment);
                ShipMethodsList.DataSource = GetShipMethodListDs(rateQuotes);
                ShipMethodsList.DataBind();
                if (rateQuotes.Count == 0)
                {
                    ShipMethodErrorMessage.Visible = true;
                    phNoShippingMethods.Visible    = true;
                    ShipMethodsList.Visible        = false;
                    Localize ShipMethodUPSErrorMessage = (Localize)e.Item.FindControl("ShipMethodUPSErrorMessage");
                    // CHECK IF UPS IS ENABLED
                    string classId = Misc.GetClassId(typeof(UPS));
                    IList <ShipGateway> gateways = ShipGatewayDataSource.LoadForClassId(classId);
                    if (gateways.Count > 0)
                    {
                        // CHECK IF PROVIDED ADDRESS IS A PO-BOX ADDRESS
                        if (ValidationHelper.IsPostOfficeBoxAddress(shipment.Address.Address1))
                        {
                            ShipMethodUPSErrorMessage.Visible = true;
                        }
                    }

                    ContinueButton.Visible = false;
                }
                else
                {
                    // IN CASE WE HAVE DISABLED THE CONTINUE BUTTON BEFORE
                    ContinueButton.Visible = true;
                }
            }
        }
Esempio n. 25
0
        private Payment GetPayment()
        {
            Payment payment = new Payment();
            IPaymentMethodProvider payMethProvider = AbleContext.Resolve <IPaymentMethodProvider>();

            payment.PaymentMethod = payMethProvider.GetGiftCertificatePaymentMethod();
            payment.Amount        = this.PaymentAmount > 0 ? this.PaymentAmount : AbleContext.Current.User.Basket.Items.TotalPrice();
            AccountDataDictionary instrumentBuilder = new AccountDataDictionary();

            instrumentBuilder["SerialNumber"] = StringHelper.StripHtml(GiftCertificateNumber.Text);
            payment.AccountData     = instrumentBuilder.ToString();
            payment.ReferenceNumber = Payment.GenerateReferenceNumber(GiftCertificateNumber.Text);
            return(payment);
        }
Esempio n. 26
0
        private IList <BasketItem> GetBasketItems()
        {
            Basket basket = AbleContext.Current.User.Basket;

            if (!_Recalculated)
            {
                IBasketService preCheckoutService = AbleContext.Resolve <IBasketService>();
                preCheckoutService.Recalculate(basket);
                preCheckoutService.Combine(basket);
                _Recalculated = true;
            }
            _DisplayedBasketItems = BasketHelper.GetDisplayItemsForInvoice(basket, false);
            return(_DisplayedBasketItems);
        }
Esempio n. 27
0
        protected decimal GetCommissionForOrder(object dataItem)
        {
            decimal   commissionTotal = 0;
            Order     order           = dataItem as Order;
            Affiliate affilate        = order.Affiliate;
            decimal   productSubtotal = order.Items.TotalPrice(OrderItemType.Product);

            if (affilate != null)
            {
                commissionTotal = AbleContext.Resolve <IAffiliateCalculator>().CalculateCommission(affilate, 1, productSubtotal, order.TotalCharges);
            }

            return(commissionTotal);
        }
Esempio n. 28
0
        protected List <ListItem> GetShipMethodList(BasketShipment shipment, bool forceRecalcualte)
        {
            List <ListItem> methodList  = new List <ListItem>();
            bool            hasSelected = false;

            if (shipment != null)
            {
                IShipRateQuoteCalculator  shippingCalculator = AbleContext.Resolve <IShipRateQuoteCalculator>();
                List <LocalShipRateQuote> localQuotes        = null;
                _SavedShipRates.TryGetValue(shipment.Id, out localQuotes);
                if (forceRecalcualte || localQuotes == null)
                {
                    //RECALCULATE THE RATES
                    localQuotes = new List <LocalShipRateQuote>();
                    ICollection <ShipRateQuote> rateQuotes = shippingCalculator.QuoteForShipment(shipment);
                    foreach (ShipRateQuote quote in rateQuotes)
                    {
                        decimal totalRate     = TaxHelper.GetShopPrice(quote.TotalRate, quote.ShipMethod.TaxCodeId, null, new TaxAddress(shipment.Address));
                        string  formattedRate = totalRate.LSCurrencyFormat("ulc");
                        string  methodName    = (totalRate > 0) ? quote.Name + ": " + formattedRate : quote.Name;
                        localQuotes.Add(new LocalShipRateQuote(quote.ShipMethodId, methodName, formattedRate));
                    }
                    _SavedShipRates[shipment.Id] = localQuotes;
                }

                foreach (LocalShipRateQuote quote in localQuotes)
                {
                    ListItem item = new ListItem(quote.Name, quote.ShipMethodId.ToString());
                    if (shipment.ShipMethodId != 0 && shipment.ShipMethodId == quote.ShipMethodId)
                    {
                        item.Selected = true;
                        hasSelected   = true;
                    }
                    methodList.Add(item);
                }

                if (!hasSelected)
                {
                    if (methodList.Count > 0)
                    {
                        methodList[0].Selected = true;
                        shipment.ShipMethodId  = AlwaysConvert.ToInt(methodList[0].Value);
                        shipment.Save();
                    }
                }
            }

            return(methodList);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            string certID = Request["certificateID"];

            Session[TaxCloudProvider.TaxCloudSelectedCertSessionKey]       = certID;
            Session[TaxCloudProvider.TaxcloudSinglePurchaseCertSessionKey] = null;

            // recalculate the current user basket
            Basket basket = AbleContext.Current.User.Basket;

            basket.ContentHash = string.Empty;
            IBasketService preCheckoutService = AbleContext.Resolve <IBasketService>();

            preCheckoutService.Recalculate(basket);
        }
Esempio n. 30
0
        protected void CheckoutButton_Click(object sender, EventArgs e)
        {
            AbleCommerce.Code.BasketHelper.SaveBasket(BasketGrid);
            IBasketService     service  = AbleContext.Resolve <IBasketService>();
            ValidationResponse response = service.Validate(AbleContext.Current.User.Basket);

            if (response.Success)
            {
                Response.Redirect(AbleCommerce.Code.NavigationHelper.GetCheckoutUrl());
            }
            else
            {
                Session["BasketMessage"] = response.WarningMessages;
            }
        }