예제 #1
0
 protected void BindShipMethods()
 {
     ShipMethodList.Visible = (ShipMethodRule.SelectedIndex > 0);
     if (ShipMethodList.Visible)
     {
         ShipMethodList.DataSource = ShipMethodDataSource.LoadAll("Name");
         ShipMethodList.DataBind();
     }
 }
예제 #2
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;
             }
         }
     }
 }
예제 #3
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();
                }
            }
        }
예제 #5
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();
                }
            }
        }