private void BindShipMethods()
        {
            // bind the configured methods
            IList <ShipMethod> configuredMethods = ShipMethodDataSource.LoadForShipGateway(this.ShipGatewayId);

            if (configuredMethods.Count > 0)
            {
                ViewPanel.Visible         = true;
                ShipMethodGrid.DataSource = configuredMethods;
                ShipMethodGrid.DataBind();
            }
            else
            {
                ViewPanel.Visible = false;
            }

            // bind the add panel
            ShipMethodList.Items.Clear();
            ListItem[] servicesArray = _ShipGateway.GetProviderInstance().GetServiceListItems();
            foreach (ListItem item in servicesArray)
            {
                bool isConfigured = configuredMethods.Where(x => x.ShipGatewayId == _ShipGateway.Id && x.ServiceCode.Equals(item.Value)).Count() > 0;
                if (!isConfigured)
                {
                    ShipMethodList.Items.Add(item);
                }
            }
            AddPanel.Visible = ShipMethodList.Items.Count > 0;
        }
예제 #2
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);
            }
        }
예제 #3
0
        protected void ShipMethods_Databound(object sender, EventArgs e)
        {
            DropDownList ddl = (DropDownList)sender;

            if (ddl != null)
            {
                int            shipmentId = AlwaysConvert.ToInt(ddl.Attributes["ShipmentId"]);
                BasketShipment shipment   = _basket.Shipments.Find(a => a.Id == shipmentId);
                if (shipment != null)
                {
                    if (shipment.ShipMethod != null)
                    {
                        ListItem item = ddl.Items.FindByValue(shipment.ShipMethodId.ToString());
                        if (item != null)
                        {
                            item.Selected = true;
                        }
                    }
                    else
                    {
                        if (ddl.Items.Count > 0)
                        {
                            var shipMethod = ShipMethodDataSource.Load(AlwaysConvert.ToInt(ddl.Items[0].Value));
                            if (shipMethod != null)
                            {
                                shipment.ShipMethod = shipMethod;
                                shipment.Save();
                            }
                        }
                    }
                }
            }
        }
예제 #4
0
        protected void Page_Init(object sender, System.EventArgs e)
        {
            _ShipMethodId = AlwaysConvert.ToInt(Request.QueryString["ShipMethodId"]);
            _ShipMethod   = ShipMethodDataSource.Load(_ShipMethodId);
            if (_ShipMethod == null)
            {
                RedirectMe();
            }
            //BIND TAX CODES
            IList <TaxCode> taxCodes = AbleContext.Current.Store.TaxCodes;

            TaxCode.DataSource = taxCodes;
            TaxCode.DataBind();
            ListItem item = TaxCode.Items.FindByValue(_ShipMethod.TaxCodeId.ToString());

            if (item != null)
            {
                TaxCode.SelectedIndex = TaxCode.Items.IndexOf(item);
            }

            SurchargeTaxCode.DataSource = taxCodes;
            SurchargeTaxCode.DataBind();
            item = SurchargeTaxCode.Items.FindByValue(_ShipMethod.SurchargeTaxCodeId.ToString());
            if (item != null)
            {
                SurchargeTaxCode.SelectedIndex = SurchargeTaxCode.Items.IndexOf(item);
            }
        }
예제 #5
0
 protected void BindShipMethods()
 {
     ShipMethodList.Visible = (ShipMethodRule.SelectedIndex > 0);
     if (ShipMethodList.Visible)
     {
         ShipMethodList.DataSource = ShipMethodDataSource.LoadAll("Name");
         ShipMethodList.DataBind();
     }
 }
예제 #6
0
        protected void ContinueButton_Click(object sender, EventArgs e)
        {
            //LOOP SHIPMENTS, GET SHIPPING METHODS
            Basket basket = AbleContext.Current.User.Basket;
            IList <BasketShipment> shipments = basket.Shipments;

            _ShipmentIndex = 0;
            bool allMethodsValid = true;

            foreach (BasketShipment shipment in shipments)
            {
                // shipment.ShipMethod = ShipMethodDataSource.Load(AlwaysConvert.ToInt(Request.Form["ShipMethod" + _ShipmentIndex]));
                RadioButtonList ShipMethodsList = ShipmentRepeater.Items[_ShipmentIndex].FindControl("ShipMethodsList") as RadioButtonList;
                shipment.ShipMethod = ShipMethodDataSource.Load(AlwaysConvert.ToInt(ShipMethodsList.SelectedValue));
                TextBox shipMessage = ShipmentRepeater.Items[_ShipmentIndex].FindControl("ShipMessage") as TextBox;

                if (shipMessage != null && !string.IsNullOrEmpty(shipMessage.Text))
                {
                    shipMessage.Text = StringHelper.StripHtml(shipMessage.Text.Trim());
                    if (shipMessage.Text.Length > 255)
                    {
                        shipMessage.Text = shipMessage.Text.Substring(0, 255);
                    }
                    shipment.ShipMessage = shipMessage.Text;
                }
                else
                {
                    shipment.ShipMessage = "";
                }
                shipment.Save();
                if (shipment.ShipMethod == null)
                {
                    allMethodsValid = false;
                }
                _ShipmentIndex++;
            }
            if (allMethodsValid)
            {
                Response.Redirect("Payment.aspx");
            }
            else
            {
                ShipmentRepeater.DataSource = AbleContext.Current.User.Basket.Shipments;
                ShipmentRepeater.DataBind();

                //HANDLE ERROR MESSAGE (UNEXPECTED)
                InvalidShipMethodPanel.Visible = true;
            }
        }
예제 #7
0
        private void BindServiceCodes()
        {
            ServiceCode.Items.Clear();
            int         shipGatewayId = AlwaysConvert.ToInt(Provider.SelectedValue);
            ShipGateway provider      = GetProvider(shipGatewayId);

            if (provider != null)
            {
                IList <ShipMethod> Shipmethods   = ShipMethodDataSource.LoadForShipGateway(shipGatewayId);
                ListItem[]         servicesArray = provider.GetProviderInstance().GetServiceListItems();
                foreach (ListItem item in servicesArray)
                {
                    ServiceCode.Items.Add(item);
                }
            }
        }
예제 #8
0
 protected void BindShipMethods()
 {
     ShipMethodList.Visible = (ShipMethodRule.SelectedIndex > 0);
     if (ShipMethodList.Visible)
     {
         ShipMethodList.DataSource = ShipMethodDataSource.LoadAll("Name");
         ShipMethodList.DataBind();
         foreach (ShipMethod shipMethod in _Coupon.ShipMethods)
         {
             ListItem listItem = ShipMethodList.Items.FindByValue(shipMethod.Id.ToString());
             if (listItem != null)
             {
                 listItem.Selected = true;
             }
         }
     }
 }
예제 #9
0
 protected void MultipleRowDelete_Click(object sender, EventArgs e)
 {
     // Looping through all the rows in the GridView
     foreach (GridViewRow row in ShipMethodGrid.Rows)
     {
         CheckBox checkbox = (CheckBox)row.FindControl("DeleteCheckbox");
         if ((checkbox != null) && (checkbox.Checked))
         {
             // Retreive the GiftCertificateId
             int        shipMethodId = Convert.ToInt32(ShipMethodGrid.DataKeys[row.RowIndex].Value);
             ShipMethod sm           = ShipMethodDataSource.Load(shipMethodId);
             if (sm != null)
             {
                 sm.Delete();
             }
         }
     }
     ShipMethodGrid.DataBind();
 }
예제 #10
0
        private bool UpdateShipments()
        {
            //LOOP SHIPMENTS, GET SHIPPING METHODS
            Basket basket = AbleContext.Current.User.Basket;
            IList <BasketShipment> shipments = basket.Shipments;

            _ShipmentIndex = 0;
            bool allMethodsValid = true;

            foreach (BasketShipment shipment in shipments)
            {
                // shipment.ShipMethod = ShipMethodDataSource.Load(AlwaysConvert.ToInt(Request.Form["ShipMethod" + _ShipmentIndex]));
                DropDownList ShipMethodsList = ShipmentRepeater.Items[_ShipmentIndex].FindControl("ShipMethodsList") as DropDownList;
                shipment.ShipMethod = ShipMethodDataSource.Load(AlwaysConvert.ToInt(ShipMethodsList.SelectedValue));
                TextBox shipMessage = ShipmentRepeater.Items[_ShipmentIndex].FindControl("ShipMessage") as TextBox;

                if (shipMessage != null && !string.IsNullOrEmpty(shipMessage.Text))
                {
                    shipMessage.Text = StringHelper.StripHtml(shipMessage.Text.Trim());
                    if (shipMessage.Text.Length > 255)
                    {
                        shipMessage.Text = shipMessage.Text.Substring(0, 255);
                    }
                    shipment.ShipMessage = shipMessage.Text;
                }
                else
                {
                    shipment.ShipMessage = "";
                }
                shipment.Save();
                if (shipment.ShipMethod == null)
                {
                    allMethodsValid = false;
                }
                _ShipmentIndex++;
            }
            return(allMethodsValid);
        }
예제 #11
0
        protected void ShipMethodsList_SelectedIndexChanged(object sender, EventArgs e)
        {
            DropDownList ddl        = sender as DropDownList;
            int          shipmentId = AlwaysConvert.ToInt(ddl.Attributes["ShipmentId"]);
            var          shipMethod = ShipMethodDataSource.Load(AlwaysConvert.ToInt(ddl.SelectedValue));

            if (shipMethod == null)
            {
                return;
            }
            foreach (BasketShipment shipment in _basket.Shipments)
            {
                if (shipment.Id == shipmentId)
                {
                    shipment.ShipMethodId = shipMethod.Id;
                    shipment.Save();
                    _basketService.Recalculate(_basket);
                    _CurrentBasketHash = _basket.GetContentHash(OrderItemType.Product);
                    break;
                }
            }
            _basket.Save();
        }
예제 #12
0
        protected void ShipMethodGrid_RowCommand(object sender, System.Web.UI.WebControls.GridViewCommandEventArgs e)
        {
            IList <ShipMethod> shipMethods = ShipMethodDataSource.LoadAll(ShipMethodGrid.SortExpression);

            if (e.CommandName.StartsWith("Do_"))
            {
                int shipMethodId = AlwaysConvert.ToInt(e.CommandArgument.ToString());
                int index;
                index = shipMethods.IndexOf(shipMethodId);
                switch (e.CommandName)
                {
                case "Do_Up":
                    ReorderMethod(shipMethods, index, index - 1);
                    ShipMethodGrid.DataBind();
                    break;

                case "Do_Down":
                    ReorderMethod(shipMethods, index, index + 1);
                    ShipMethodGrid.DataBind();
                    break;
                }
            }
        }
        protected void GCheckoutButton_Click(object sender, ImageClickEventArgs e)
        {
            if (_BasketGrid != null)
            {
                //First Save the updated Basket
                AbleCommerce.Code.BasketHelper.SaveBasket(_BasketGrid);
            }

            GCheckoutButton.Currency = AbleContext.Current.Store.BaseCurrency.ISOCode;
            CheckoutShoppingCartRequest Req = GCheckoutButton.CreateRequest();

            System.Xml.XmlDocument tempDoc = new System.Xml.XmlDocument();

            Basket basket = AbleContext.Current.User.Basket;

            // Add a "BasketId" node.
            System.Xml.XmlNode tempNode2 = tempDoc.CreateElement("BasketId");
            tempNode2.InnerText = basket.Id.ToString();
            Req.AddMerchantPrivateDataNode(tempNode2);

            tempNode2           = tempDoc.CreateElement("BasketContentHash");
            tempNode2.InnerText = GetBasketContentHash(basket);
            Req.AddMerchantPrivateDataNode(tempNode2);

            // We just created this structure on the order level:
            // <merchant-private-data>
            //   <BasketId xmlns="">xxxxxx</BasketId>
            // </merchant-private-data>

            // Now we are going to add the basket items.
            XmlNode[] itemPrivateData;
            foreach (BasketItem item in basket.Items)
            {
                switch (item.OrderItemType)
                {
                case OrderItemType.Product:
                    itemPrivateData = BuildPrivateData(item);
                    bool isDigitalContent = item.Product == null ? false : item.Product.IsDigitalGood;
                    if (isDigitalContent)
                    {
                        Req.AddItem(AcHelper.SanitizeText(item.Name), AcHelper.SanitizeText(item.Product.Description), (Decimal)item.Price, item.Quantity, isDigitalContent, AcHelper.SanitizeText(string.Format("The download will be available from your {0} order receipt once payment is processed.", AbleContext.Current.Store.Name)), itemPrivateData);
                    }
                    else
                    {
                        Req.AddItem(AcHelper.SanitizeText(item.Name), AcHelper.SanitizeText(item.Product.Description), (Decimal)item.Price, item.Quantity, itemPrivateData);
                    }
                    break;

                case OrderItemType.Charge:
                    itemPrivateData = BuildPrivateData(item);
                    Req.AddItem(AcHelper.SanitizeText(item.Name), "Charge", (Decimal)item.Price, item.Quantity, itemPrivateData);
                    break;

                case OrderItemType.Credit:
                    itemPrivateData = BuildPrivateData(item);
                    Req.AddItem(AcHelper.SanitizeText(item.Name), "Credit", (Decimal)item.Price, item.Quantity, itemPrivateData);
                    break;

                case OrderItemType.GiftWrap:
                    itemPrivateData = BuildPrivateData(item);
                    Req.AddItem(AcHelper.SanitizeText(item.Name), "Gift Wrapping", (Decimal)item.Price, item.Quantity, itemPrivateData);
                    break;

                case OrderItemType.Coupon:     //on callback as well
                    itemPrivateData = BuildPrivateData(item);
                    Req.AddItem(AcHelper.SanitizeText(item.Name), "Your coupon has been applied.", (Decimal)item.Price, item.Quantity, itemPrivateData);
                    break;

                case OrderItemType.Discount:
                    itemPrivateData = BuildPrivateData(item);
                    Req.AddItem(AcHelper.SanitizeText(item.Name), "Discount", (Decimal)item.Price, item.Quantity, itemPrivateData);
                    break;

                case OrderItemType.GiftCertificate:     //on callback
                    break;

                case OrderItemType.Handling:     //on callback
                    break;

                case OrderItemType.Shipping:     //on callback
                    break;

                case OrderItemType.Tax:     //on callback
                    break;
                }
            }

            //setup other settings
            Req.AcceptMerchantCoupons          = GCheckoutButton.GatewayInstance.CouponsEnabled;
            Req.AcceptMerchantGiftCertificates = GCheckoutButton.GatewayInstance.GiftCertificatesEnabled;
            //Req.CartExpiration = expirationDate;
            string storeDomain  = UrlHelper.GetDomainFromUrl(AbleContext.Current.Store.StoreUrl);
            string storeBaseUrl = "http://" + storeDomain;

            Req.ContinueShoppingUrl   = storeBaseUrl + this.ResolveUrl("~/Default.aspx");
            Req.EditCartUrl           = storeBaseUrl + this.ResolveUrl("~/Basket.aspx");
            Req.MerchantCalculatedTax = true;
            //add at least one tax rule
            Req.AddZipTaxRule("99999", 0F, false);
            string storeBaseSecureUrl = AbleContext.Current.Store.Settings.SSLEnabled ? storeBaseUrl.Replace("http://", "https://") : storeBaseUrl;

            Req.MerchantCalculationsUrl = storeBaseSecureUrl + this.ResolveUrl("~/Checkout/Google/MerchantCalc.ashx");
            Req.PlatformID = 769150108975916;
            Req.RequestBuyerPhoneNumber = true;
            Req.SetExpirationMinutesFromNow(GCheckoutButton.GatewayInstance.ExpirationMinutes);

            //add ship methods
            IList <ShipMethod>   shipMethods      = ShipMethodDataSource.LoadAll();
            List <string>        shipMethodsAdded = new List <string>();
            string               shipMethName;
            decimal              basketTotal      = basket.Items.TotalPrice();
            decimal              defaultRate      = GCheckoutButton.GatewayInstance.DefaultShipRate;
            ShippingRestrictions shipRestrictions = new ShippingRestrictions();

            shipRestrictions.AddAllowedWorldArea();

            foreach (ShipMethod shipMethod in shipMethods)
            {
                if (!shipMethod.Name.Equals("Unknown(GoogleCheckout)") &&
                    (shipMethod.MinPurchase <= 0 || shipMethod.MinPurchase <= basketTotal))
                {
                    //add all other shipmethods as merchant calculated irrespective of whether they
                    //are applicable or not. It will be determined on call-back
                    //GoogleCheckout does not allow to mix merchant calculated shipping methods with other methods
                    if (shipMethod.ShipMethodType == ShipMethodType.FlatRate)
                    {
                        defaultRate = GetFlatShipRate(shipMethod);
                    }
                    else
                    {
                        defaultRate = GCheckoutButton.GatewayInstance.DefaultShipRate;
                    }
                    shipMethName = BuildShipMethodName(shipMethod, shipMethodsAdded);
                    Req.AddMerchantCalculatedShippingMethod(shipMethName, defaultRate, shipRestrictions, shipRestrictions);
                    shipMethodsAdded.Add(shipMethName.ToLowerInvariant());
                }
            }

            GCheckoutResponse Resp = Req.Send();

            if (Resp.IsGood)
            {
                Response.Redirect(Resp.RedirectUrl, true);
            }
            else
            {
                DataList msgList;
                if (_WarningMessageList != null)
                {
                    msgList = _WarningMessageList;
                }
                else
                {
                    msgList            = GCWarningMessageList;
                    phWarnings.Visible = true;
                }
                if (msgList != null)
                {
                    List <string> googleMessages = new List <string>();
                    googleMessages.Add("Google Checkout Failed.");
                    googleMessages.Add("Google Checkout Response.IsGood = " + Resp.IsGood);
                    googleMessages.Add("Google Checkout Error Message = " + Resp.ErrorMessage);
                    msgList.DataSource = googleMessages;
                    msgList.DataBind();
                }
            }
        }
예제 #14
0
        protected void ChangeShipMethodOKButton_Click(object source, EventArgs e)
        {
            int shipmentId = AlwaysConvert.ToInt(Request.Form[ChangeShipMethodShipmentId.UniqueID]);
            int index      = _Order.Shipments.IndexOf(shipmentId);

            if (index > -1)
            {
                // WE FOUND THE TARGET SHIPMENT. REMOVE OLD SHIPPING LINE ITEMS
                OrderShipment shipment = _Order.Shipments[index];
                for (int i = shipment.OrderItems.Count - 1; i >= 0; i--)
                {
                    OrderItemType itemType = shipment.OrderItems[i].OrderItemType;
                    if (itemType == OrderItemType.Shipping || itemType == OrderItemType.Handling)
                    {
                        shipment.OrderItems.DeleteAt(i);
                    }
                }

                // SEE IF WE HAVE A NEW SELECTED SHIPMETHOD
                int        shipMethodId = AlwaysConvert.ToInt(Request.Form[NewShipMethod.UniqueID]);
                ShipMethod shipMethod   = ShipMethodDataSource.Load(shipMethodId);
                if (shipMethod != null)
                {
                    ShipRateQuote rate = shipMethod.GetShipRateQuote(shipment);
                    if (rate != null)
                    {
                        // ADD NEW SHIPPING LINE ITEMS TO THE ORDER
                        OrderItem shipRateLineItem = new OrderItem();
                        shipRateLineItem.OrderId         = _Order.Id;
                        shipRateLineItem.OrderItemType   = OrderItemType.Shipping;
                        shipRateLineItem.OrderShipmentId = shipmentId;
                        shipRateLineItem.Name            = shipMethod.Name;
                        shipRateLineItem.Price           = rate.Rate;
                        shipRateLineItem.Quantity        = 1;
                        shipRateLineItem.TaxCodeId       = shipMethod.TaxCodeId;
                        shipRateLineItem.Save();
                        shipment.OrderItems.Add(shipRateLineItem);
                        if (rate.Surcharge > 0)
                        {
                            shipRateLineItem                 = new OrderItem();
                            shipRateLineItem.OrderId         = _Order.Id;
                            shipRateLineItem.OrderItemType   = OrderItemType.Handling;
                            shipRateLineItem.OrderShipmentId = shipmentId;
                            shipRateLineItem.Name            = shipMethod.Name;
                            shipRateLineItem.Price           = rate.Surcharge;
                            shipRateLineItem.Quantity        = 1;
                            shipRateLineItem.TaxCodeId       = shipMethod.TaxCodeId;
                            shipRateLineItem.Save();
                            shipment.OrderItems.Add(shipRateLineItem);
                        }

                        //Add the Tracking Number
                        ShipGateway shipGateway = shipMethod.ShipGateway;
                        foreach (TrackingNumber tn in shipment.TrackingNumbers)
                        {
                            tn.ShipGateway = shipGateway;
                        }
                    }
                }

                // UPDATE THE SHIPMENT WITH NEW METHOD ASSOCIATION
                shipment.ShipMethodId   = shipMethodId;
                shipment.ShipMethodName = (shipMethod != null ? shipMethod.Name : string.Empty);
                shipment.Save();

                // RELOAD ORDER AND REBIND THE PAGE FOR UPDATED INFO
                _Order = OrderDataSource.Load(_Order.Id);
                BindShipmentsGrid();
            }
        }
예제 #15
0
        protected void EditShipmentsGrid_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "DelShp")
            {
                int shipmentId = AlwaysConvert.ToInt(e.CommandArgument);
                int index      = _Order.Shipments.IndexOf(shipmentId);
                if (index > -1)
                {
                    OrderShipment shipment = _Order.Shipments[index];

                    // DELETE FROM ORDER
                    _Order.Shipments.Remove(shipment);
                    foreach (OrderItem item in shipment.OrderItems)
                    {
                        _Order.Items.Remove(item);
                    }

                    _Order.Save(true, false);
                    BindShipmentsGrid();
                }
            }
            else if (e.CommandName == "ChangeShipMethod")
            {
                int shipmentId = AlwaysConvert.ToInt(e.CommandArgument);
                int index      = _Order.Shipments.IndexOf(shipmentId);
                if (index > -1)
                {
                    // SHOW THE CHANGE SHIPMENT POPUP
                    ChangeShipMethodShipmentId.Value   = shipmentId.ToString();
                    ChangeShipMethodDialogCaption.Text = string.Format(ChangeShipMethodDialogCaption.Text, index + 1);
                    OrderShipment shipment = _Order.Shipments[index];
                    ExistingShipMethod.Text = shipment.ShipMethodName;

                    // GENERATE RATE QUOTES FOR ALL SHIPPING METHODS
                    List <ShipRateQuote> rateQuotes  = new List <ShipRateQuote>();
                    IList <ShipMethod>   shipMethods = ShipMethodDataSource.LoadAll();
                    foreach (ShipMethod method in shipMethods)
                    {
                        ShipRateQuote quote = method.GetShipRateQuote(shipment);
                        if (quote != null)
                        {
                            rateQuotes.Add(quote);
                        }
                    }

                    // GET LIST OF SHIPPING METHODS THAT WOULD BE AVAILABLE TO THE CUSTOMER
                    IList <ShipMethod> customerShipMethods = ShipMethodDataSource.LoadForShipment(shipment);

                    // ADD RATE QUOTES TO THE DROPDOWN
                    foreach (ShipRateQuote quote in rateQuotes)
                    {
                        string name = string.Format("{0} : {1}", quote.Name, quote.Rate.LSCurrencyFormat("lc"));
                        if (customerShipMethods.IndexOf(quote.ShipMethodId) < 0)
                        {
                            // SHOW NOTE IF HIDDEN SHIPPING METHODS ARE AVAIALBLE
                            name = "** " + name;
                            HiddenShipMethodWarning.Visible = true;
                        }
                        NewShipMethod.Items.Add(new ListItem(name, quote.ShipMethodId.ToString()));
                    }
                    ChangeShipMethodPopup.Show();
                }
            }
            else if (e.CommandName == "VoidShp")
            {
                int shipmentId = AlwaysConvert.ToInt(e.CommandArgument);
                int index      = _Order.Shipments.IndexOf(shipmentId);
                if (index > -1)
                {
                    OrderShipment shipment = _Order.Shipments[index];
                    shipment.Void();

                    _Order.Save(true, false);
                    BindShipmentsGrid();
                }
            }
        }
 protected void ShipMethodGrid_RowDeleting(object sender, GridViewDeleteEventArgs e)
 {
     ShipMethodDataSource.LoadForShipGateway(this.ShipGatewayId).DeleteAt(e.RowIndex);
     BindShipMethods();
 }
예제 #17
0
 /// <summary>
 /// Apply a ship method to this basket shipment
 /// </summary>
 /// <param name="shipMethodId">Id of the ship method to apply</param>
 public void ApplyShipMethod(int shipMethodId)
 {
     ApplyShipMethod(ShipMethodDataSource.Load(shipMethodId));
 }
예제 #18
0
        public override ShippingResult GetShippingResult(string ShipMethodName, Order ThisOrder, AnonymousAddress Address)
        {
            TraceContext   trace  = WebTrace.GetTraceContext();
            ShippingResult RetVal = new ShippingResult();

            RetVal.Shippable = false;

            CommerceBuilder.Orders.Basket basket = ThisOrder.AcBasket;
            if (basket == null)
            {
                basket = AcHelper.GetAcBasket(ThisOrder.ShoppingCart, true);
                if (basket != null)
                {
                    basket.Package(false);
                }
                ThisOrder.AcBasket = basket;
            }

            if (basket == null || basket.Shipments.Count == 0)
            {
                return(RetVal);
            }

            ShipMethodCollection shipMethods = ThisOrder.AcShipMethods;

            if (shipMethods == null)
            {
                shipMethods             = ShipMethodDataSource.LoadForStore();
                ThisOrder.AcShipMethods = shipMethods;
            }

            if (shipMethods == null || shipMethods.Count == 0)
            {
                return(RetVal);
            }

            ShipMethod shipMethod;
            string     methodName   = "";
            int        shipMethodId = AcHelper.ExtractShipMethodId(ShipMethodName, out methodName);

            if (shipMethodId != 0)
            {
                shipMethod = AcHelper.FindShipMethod(shipMethods, shipMethodId);
            }
            else
            {
                shipMethod = AcHelper.FindShipMethod(shipMethods, methodName);
            }
            if (shipMethod == null)
            {
                return(RetVal);
            }

            CommerceBuilder.Users.Address acAddress = AcHelper.GetAnonAcAddress(basket.User, Address);
            if (!shipMethod.IsApplicableTo(acAddress))
            {
                return(RetVal);
            }

            ShipRateQuote rateQuote;

            //TODO : should assign a default ship rate
            RetVal.ShippingRate = 0;
            bool isValid = true;

            foreach (Orders.BasketShipment bshipment in basket.Shipments)
            {
                bshipment.SetAddress(acAddress);
                if (!bshipment.IsShipMethodApplicable(shipMethod))
                {
                    isValid = false;
                    break;
                }
                rateQuote = shipMethod.GetShipRateQuote(bshipment);
                if (rateQuote != null && rateQuote.TotalRate > 0)
                {
                    RetVal.ShippingRate += rateQuote.TotalRate;
                }
                else if (rateQuote == null)
                {
                    //this ship method is not applicable
                    isValid = false;
                    break;
                }
            }

            if (isValid)
            {
                RetVal.Shippable = true;
            }

            return(RetVal);
        }
예제 #19
0
        protected void Page_PreRender(object sender, EventArgs e)
        {
            List <string> alertList;
            DateTime      cacheDate;
            CacheWrapper  alertWrapper = Cache.Get("AdminAlerts") as CacheWrapper;

            if (alertWrapper == null)
            {
                alertList = new List <string>();

                //Check if installation directory still exists
                if (System.IO.Directory.Exists(Request.MapPath("~/Install")))
                {
                    string alertText = "The 'Install' directory still exists in your store. It should be removed immediately after the Installation is complete.";
                    alertList.Add(alertText);
                }

                // CHECK IF EMAIL TEMPLATES ARE CONFIGURED, WITHOUT EMAIL SERVER SETTINGS
                Store store = AbleContext.Current.Store;
                if ((store.EmailTemplates.Count > 0))
                {
                    if (string.IsNullOrEmpty(store.Settings.SmtpServer))
                    {
                        string alertText = "You have email templates configured, but you have not provided an SMTP (mail) server.  Without a serv" +
                                           "er, email notifications cannot be sent.  <a href=\'Store/EmailTemplates/Settings.aspx\'>Click here</a> to configure " +
                                           "email now.";
                        alertList.Add(alertText);
                    }
                }
                //VALIDATE ORDER STATUSES
                //CHECK FOR A STATUS ATTACHED TO THE ORDER PLACED EVENT
                OrderStatus status = OrderStatusTriggerDataSource.LoadForStoreEvent(StoreEvent.OrderPlaced);
                if (status == null)
                {
                    status             = new OrderStatus();
                    status.Name        = "Payment Pending";
                    status.DisplayName = "Payment Pending";
                    status.IsActive    = false;
                    status.IsValid     = true;
                    status.Triggers.Add(new OrderStatusTrigger(StoreEvent.OrderPlaced, status));
                    status.Save();
                    alertList.Add("You did not have an order status assigned to the 'Order Placed' event, so one was created for you.  <a href=\"Store/OrderStatuses/Default.aspx\">Click here</a> to check the order status configuration for your store.");
                }
                //CHECK FOR A STATUS ATTACHED TO THE ORDER CANCELLED EVENT
                status = OrderStatusTriggerDataSource.LoadForStoreEvent(StoreEvent.OrderCancelled);
                if (status == null)
                {
                    status             = new OrderStatus();
                    status.Name        = "Cancelled";
                    status.DisplayName = "Cancelled";
                    status.IsActive    = false;
                    status.IsValid     = false;
                    status.Triggers.Add(new OrderStatusTrigger(StoreEvent.OrderCancelled, status));
                    status.Save();
                    alertList.Add("You did not have an order status assigned to the 'Order Cancelled' event, so one was created for you.  <a href=\"Store/OrderStatuses/Default.aspx\">Click here</a> to check the order status configuration for your store.");
                }

                //MAKE SURE AT LEAST ONE PRODUCT EXISTS
                int productCount = ProductDataSource.CountAll();
                if (productCount == 0)
                {
                    alertList.Add("You have not yet added any products in your store.  <a href=\"Catalog/Browse.aspx\">Click here</a> to manage your catalog now.");
                }

                //MAKE SURE AT LEAST ONE SHIPPING METHOD EXISTS
                int shipMethodCount = ShipMethodDataSource.CountAll();
                if (shipMethodCount == 0)
                {
                    alertList.Add("You do not have any shipping methods configured.  Your customers will not be able to complete checkout if the order contains any shippable products.  <a href=\"Shipping/Methods/Default.aspx\">Click here</a> to manage shipping methods now.");
                }

                //CHECK FOR LOW INVENTORY PRODUCTS
                int lowInventoryProducts = ProductInventoryDataSource.GetLowProductInventoryCount();
                if (lowInventoryProducts > 0)
                {
                    alertList.Add("One or more products are at or below their low inventory warning level.  You can view these products <a href=\"Reports/LowInventory.aspx\">here</a>.");
                }

                //CHECK FOR PRESENCE OF ERRORS
                int errorCount = ErrorMessageDataSource.CountAll();
                if (errorCount > 0)
                {
                    string errorAlert = string.Format("There are {0} messages in your <a href=\"Help/ErrorLog.aspx\">error log</a>.  You should review these messages and take corrective action if necessary.", errorCount);
                    alertList.Add(errorAlert);
                }

                //Check of SSL is not enabled
                StoreSettingsManager storeSettings = AbleContext.Current.Store.Settings;
                if (!storeSettings.SSLEnabled)
                {
                    string alertText = "SSL is not enabled. Your store is currently being accessed over an insecure connection. <a href=\"Store/Security/Default.aspx\">Click Here</a> to change SSL settings.";
                    alertList.Add(alertText);
                }

                //MAKE SURE ORDER NUMBER INCREMENT IS VALID
                if (store.OrderIdIncrement < 1)
                {
                    string alertText = "The order number increment for your store was " + store.OrderIdIncrement + " (invalid).  The increment has been updated to 1.  <a href=\"Store/StoreSettings.aspx\">Click Here</a> to review this setting.";
                    alertList.Add(alertText);
                    store.OrderIdIncrement = 1;
                    store.Save();
                }

                //ALERT FOR ORDER NUMBER PROBLEM
                int maxOrderNumber  = StoreDataSource.GetMaxOrderNumber();
                int nextOrderNumber = StoreDataSource.GetNextOrderNumber(false);
                if (maxOrderNumber >= nextOrderNumber)
                {
                    int newOrderNumber = maxOrderNumber + store.OrderIdIncrement;
                    StoreDataSource.SetNextOrderNumber(newOrderNumber);
                    string alertText = "The next order number of {0} is less than the highest assigned order number of {1}.  We have automatically increased your next order number to {2} to prevent errors.  <a href=\"Store/StoreSettings.aspx\">Click Here</a> to review this setting.";
                    alertList.Add(string.Format(alertText, nextOrderNumber, maxOrderNumber, newOrderNumber));
                }

                //MAKE SURE A VALID ENCRYPTION KEY IS PRESENT
                bool encryptionKeyValid;
                try
                {
                    encryptionKeyValid = EncryptionKeyManager.IsKeyValid(EncryptionKeyManager.Instance.CurrentKey.KeyData);
                }
                catch
                {
                    encryptionKeyValid = false;
                }
                if (!encryptionKeyValid)
                {
                    //ENCRYPTION KEY IS MISSING OR INVALID, SEE WHETHER WE ARE STORING CARD DATA
                    if (storeSettings.EnableCreditCardStorage)
                    {
                        string alertText = "Your store encryption key is missing or invalid, and you have not disabled storage of card data.  You should either <a href=\"Store/Security/EncryptionKey.aspx\">set the encryption key</a> or <a href=\"Store/Security/Default.aspx\">disable credit card storage</a>.";
                        alertList.Add(alertText);
                    }
                }

                // ALERT FOR PRODUCT IMAGE LOOKUP BY SKU
                if (storeSettings.ImageSkuLookupEnabled)
                {
                    // SEARCH FOR PRODUCTS MISSING SKU AND MISSING IMAGE URLs
                    ICriteria productCriteria = NHibernateHelper.CreateCriteria <Product>()
                                                .Add(new Disjunction()
                                                     .Add(Restrictions.IsNull("Sku"))
                                                     .Add(Restrictions.Eq("Sku", string.Empty)))
                                                .Add(new Disjunction()
                                                     .Add(Restrictions.IsNull("ImageUrl"))
                                                     .Add(Restrictions.IsNull("IconUrl"))
                                                     .Add(Restrictions.IsNull("ThumbnailUrl")))
                                                .Add(Restrictions.Eq("VisibilityId", (byte)CatalogVisibility.Public));

                    IList <Product> products = ProductDataSource.LoadForCriteria(productCriteria);
                    if (products != null && products.Count > 0)
                    {
                        StringBuilder textBuilder = new StringBuilder();
                        textBuilder.Append("Following product(s) are missing SKU, and also do not have image paths provided:<br/>");
                        textBuilder.Append("<ul>");

                        int counter = 0; // PRODUCT COUNTER, SHOW ONLY FIRST FIVE PRODUCTS
                        foreach (Product product in products)
                        {
                            counter++;
                            textBuilder.Append("<li><a href=\"products/EditProduct.aspx?ProductId=" + product.Id + "\">" + product.Name + "</a>.</li>");
                            if (counter >= 5)
                            {
                                break;
                            }
                        }
                        textBuilder.Append("<ul>");
                        alertList.Add(textBuilder.ToString());
                    }
                }

                // LOOK FOR UNREAD NOTES
                ICriteria orderNoteCriteria = NHibernateHelper.CreateCriteria <OrderNote>()
                                              .Add(Restrictions.Eq("IsRead", false))
                                              .Add(Restrictions.Not(Restrictions.Eq("NoteTypeId", (byte)NoteType.SystemPublic)))
                                              .Add(Restrictions.Not(Restrictions.Eq("NoteTypeId", (byte)NoteType.SystemPrivate)));
                int unreadNoteCount = OrderNoteDataSource.CountForCriteria(orderNoteCriteria);
                if (unreadNoteCount > 0)
                {
                    string alertText = "There are {0} unread order note(s).  <a href=\"Orders/OrderNotesManager.aspx\">review now</a>";
                    alertList.Add(string.Format(alertText, unreadNoteCount));
                }

                // CHECK ANON USER MAINTENANCE SETTINGS
                if (store.Settings.AnonymousUserLifespan < 1 || store.Settings.AnonymousAffiliateUserLifespan < 1)
                {
                    alertList.Add("You have not configured the number of days to save anonymous user records.  You should visit the <a href=\"Store/Maintenance.aspx\">Configure > Maintenance</a> menu, view the status of the anonymous user database, and update your anonymous user maintenance settings.");
                }

                // ALERT FOR DUPLICATE COUPON CODES
                IList <Coupon> duplicateCoupons = NHibernateHelper.CreateSQLQuery("SELECT * FROM ac_Coupons WHERE CouponCode IN (SELECT LOWER(CouponCode) FROM ac_Coupons GROUP BY CouponCode HAVING COUNT(*) > 1)").AddEntity(typeof(Coupon)).List <Coupon>();
                if (duplicateCoupons.Count > 0)
                {
                    Dictionary <string, List <Coupon> > codeCounts = new Dictionary <string, List <Coupon> >();
                    foreach (Coupon coupon in duplicateCoupons)
                    {
                        string normalizedKey = coupon.CouponCode.ToUpperInvariant();
                        if (!codeCounts.ContainsKey(normalizedKey))
                        {
                            codeCounts[normalizedKey] = new List <Coupon>();
                        }
                        codeCounts[normalizedKey].Add(coupon);
                    }
                    StringBuilder alertText = new StringBuilder();
                    alertText.Append("<p>You have coupons that have duplicate codes.  Duplicates should be eliminated as a unique constraint will be applied in a future release:</p>");
                    foreach (string couponCode in codeCounts.Keys)
                    {
                        alertText.Append("<p><b>" + couponCode + ":</b> ");
                        string delimiter = string.Empty;
                        foreach (Coupon coupon in codeCounts[couponCode])
                        {
                            alertText.Append(delimiter);
                            alertText.Append("<a href=\"Marketing/Coupons/EditCoupon.aspx?CouponId=" + coupon.Id + "\">" + coupon.Name + "</a>");
                            delimiter = ", ";
                        }
                        alertText.Append("</p>");
                    }
                    alertList.Add(alertText.ToString());
                }

                //UPDATE CACHE
                alertWrapper = new CacheWrapper(alertList);
                Cache.Remove("AdminAlerts");
                Cache.Add("AdminAlerts", alertWrapper, null, DateTime.UtcNow.AddMinutes(15), Cache.NoSlidingExpiration, CacheItemPriority.Normal, null);
            }
            else
            {
                alertList = (List <string>)alertWrapper.CacheValue;
            }
            cacheDate = alertWrapper.CacheDate;

            if (alertList.Count == 0)
            {
                alertList.Add("no action items available");
            }
            AlertList.DataSource = alertList;
            AlertList.DataBind();
            CachedAt.Text = string.Format("{0:g}", cacheDate);
        }
예제 #20
0
        protected int SaveCoupon()
        {
            if (Page.IsValid)
            {
                // VALIDATE IF A PROPER END DATE IS SELECTED
                if (EndDate.SelectedEndDate != DateTime.MinValue && DateTime.Compare(EndDate.SelectedEndDate, StartDate.SelectedEndDate) < 0)
                {
                    CustomValidator dateValidator = new CustomValidator();
                    dateValidator.ControlToValidate = "Name"; // THIS SHOULD BE "EndDate" CONTROL, BUT THAT CANNOT BE VALIDATED
                    dateValidator.Text         = "*";
                    dateValidator.ErrorMessage = "End date can not be earlier than start date.";
                    dateValidator.IsValid      = false;
                    phEndDateValidator.Controls.Add(dateValidator);
                    return(0);
                }

                Coupon existingCoupon = CouponDataSource.LoadForCouponCode(CouponCode.Text);
                if (existingCoupon != null)
                {
                    CustomValidator codeValidator = new CustomValidator();
                    codeValidator.ControlToValidate = "CouponCode";
                    codeValidator.Text         = "*";
                    codeValidator.ErrorMessage = "The coupon code " + CouponCode.Text + " is already in use.";
                    codeValidator.IsValid      = false;
                    phCouponCodeValidator.Controls.Add(codeValidator);
                    return(0);
                }

                Coupon _Coupon = new Coupon();
                _Coupon.CouponType     = this.CouponType;
                _Coupon.Name           = Name.Text;
                _Coupon.CouponCode     = CouponCode.Text;
                _Coupon.DiscountAmount = AlwaysConvert.ToDecimal(DiscountAmount.Text);
                _Coupon.IsPercent      = (DiscountType.SelectedIndex == 0);
                //QUANTITY SETTINGS (PRODUCT COUPON)
                if (_Coupon.CouponType == CouponType.Product)
                {
                    _Coupon.MinQuantity = AlwaysConvert.ToInt16(Quantity.Text);
                    if (RepeatCoupon.Checked)
                    {
                        _Coupon.MaxQuantity      = 0;
                        _Coupon.QuantityInterval = _Coupon.MinQuantity;
                    }
                    else
                    {
                        _Coupon.MaxQuantity      = _Coupon.MinQuantity;
                        _Coupon.QuantityInterval = 0;
                    }
                    _Coupon.MaxValue    = 0;
                    _Coupon.MinPurchase = 0;
                }
                //PURCHASE RESTRICTIONS (ORDER AND SHIPPING COUPONS)
                else
                {
                    _Coupon.MaxValue         = AlwaysConvert.ToDecimal(MaxValue.Text);
                    _Coupon.MinPurchase      = AlwaysConvert.ToDecimal(MinPurchase.Text);
                    _Coupon.MinQuantity      = 0;
                    _Coupon.MaxQuantity      = 0;
                    _Coupon.QuantityInterval = 0;
                }
                //SET START DATE
                _Coupon.StartDate = StartDate.SelectedDate;
                //SET END DATE
                _Coupon.EndDate = EndDate.SelectedEndDate;
                //MAX USES
                _Coupon.MaxUsesPerCustomer = AlwaysConvert.ToInt16(MaximumUsesPerCustomer.Text);
                _Coupon.MaxUses            = AlwaysConvert.ToInt16(MaximumUses.Text);
                //COMBINE RULE
                _Coupon.AllowCombine = AllowCombine.Checked;
                //PRODUCT (OR SHIPPING) RULE
                if (_Coupon.CouponType != CouponType.Shipping)
                {
                    _Coupon.ProductRule = (CouponRule)ProductRule.SelectedIndex;
                }
                else
                {
                    _Coupon.ProductRule = (CouponRule)ShipMethodRule.SelectedIndex;
                    _Coupon.ShipMethods.Clear();
                    _Coupon.Save();
                    if (_Coupon.ProductRule != CouponRule.All)
                    {
                        foreach (ListItem item in ShipMethodList.Items)
                        {
                            ShipMethod shipMethod = ShipMethodDataSource.Load(AlwaysConvert.ToInt(item.Value));
                            if (item.Selected)
                            {
                                _Coupon.ShipMethods.Add(shipMethod);
                            }
                        }
                    }
                }
                //GROUP RESTRICTION
                if (UseGroupRestriction.SelectedIndex > 0)
                {
                    _Coupon.Groups.Clear();
                    _Coupon.Save();
                    foreach (ListItem item in GroupList.Items)
                    {
                        Group group = GroupDataSource.Load(AlwaysConvert.ToInt(item.Value));
                        if (item.Selected)
                        {
                            _Coupon.Groups.Add(group);
                        }
                    }
                }
                _Coupon.Save();
                return(_Coupon.Id);
            }
            return(0);
        }
예제 #21
0
        public static ShipMethod GetShipMethod(Basket basket)
        {
            bool       shipMethodNameFound = false;
            string     shipMethName;
            BasketItem sItem = basket.Items.Find(delegate(BasketItem item) { return(item.OrderItemType == OrderItemType.Shipping); });

            if (sItem == null)
            {
                shipMethName = "Unknown(GoogleCheckout)";
            }
            else
            {
                shipMethName        = sItem.Name;
                shipMethodNameFound = true;
            }

            ShipMethodCollection shipMethods = ShipMethodDataSource.LoadForStore();
            ShipMethod           shipMethod;
            string methodName   = "";
            int    shipMethodId = ExtractShipMethodId(shipMethName, out methodName);

            if (shipMethodId != 0)
            {
                shipMethod = FindShipMethod(shipMethods, shipMethodId);
            }
            else
            {
                shipMethod = FindShipMethod(shipMethods, methodName);
            }

            if (shipMethod == null && !shipMethName.Equals("Unknown(GoogleCheckout)"))
            {
                shipMethod = FindShipMethod(shipMethods, "Unknown(GoogleCheckout)");
            }

            if (shipMethod == null)
            {
                //create a new ship method
                shipMethod                = new ShipMethod();
                shipMethod.Name           = "Unknown(GoogleCheckout)";
                shipMethod.ShipMethodType = ShipMethodType.FlatRate;
                shipMethod.MinPurchase    = 999999;
                shipMethod.Save();
            }

            if (shipMethod.Name.Equals("Unknown(GoogleCheckout)"))
            {
                if (shipMethodNameFound)
                {
                    Logger.Warn(string.Format("Shipping method named '{0}' used by GoogleCheckout could not be matched to any shipping method in the store.", shipMethName));
                    Logger.Warn("Using 'Unknown(GoogleCheckout)' shipping method.");
                }
                else
                {
                    Logger.Warn("No shipping method found in the GoogleCheckout notification.");
                    Logger.Warn("Using 'Unknown(GoogleCheckout)' shipping method.");
                }
            }

            return(shipMethod);
        }