Example #1
0
        protected void Page_Load(object sender, System.EventArgs e)
        {
            string keywords = Request.QueryString["k"];

            if (string.IsNullOrEmpty(keywords))
            {
                Response.Redirect(AbleCommerce.Code.NavigationHelper.GetAdminUrl());
            }
            SearchArea searchArea = SearchArea.All;

            if (!string.IsNullOrEmpty(Request.QueryString["a"]))
            {
                searchArea = AlwaysConvert.ToEnum <SearchArea>(Request.QueryString["a"], SearchArea.All);
            }

            Caption.Text                   = String.Format(Caption.Text, keywords);
            _SearchAreaResults             = SearchDataSource.Search(keywords, searchArea, 100);
            ProductUrl                     = Page.ResolveUrl("~/Admin/Products/EditProduct.aspx?ProductId={0}");
            UserUrl                        = Page.ResolveUrl("~/Admin/People/Users/EditUser.aspx?UserId={0}");
            OrderUrl                       = Page.ResolveUrl("~/Admin/Orders/ViewOrder.aspx?OrderNumber={0}");
            CategoryUrl                    = Page.ResolveUrl("~/Admin/Catalog/EditCategory.aspx?CategoryId={0}");
            LinkUrl                        = Page.ResolveUrl("~/Admin/Catalog/EditLink.aspx?LinkId={0}");
            WebpageUrl                     = Page.ResolveUrl("~/Admin/Catalog/EditWebpage.aspx?WebpageId={0}");
            SearchAreasRepeater.DataSource = _SearchAreaResults;
            SearchAreasRepeater.DataBind();
        }
Example #2
0
        private void SaveGateWayProviderDHL()
        {
            DHLInternational provider = (DHLInternational)_ShipGateway.GetProviderInstance();

            provider.UseDebugMode         = UseDebugMode.Checked;
            provider.UseTestMode          = UseTestMode.Checked;
            provider.EnablePackageBreakup = EnablePackaging.Checked;
            provider.ShippingKey          = ShippingKey.Text;
            provider.AccountNumber        = AccountNumber.Text;
            provider.UserID     = UserID.Text;
            provider.Password   = Password.Text;
            provider.DaysToShip = AlwaysConvert.ToInt(DaysToShip.Text, 1);
            if (provider.DaysToShip < 1)
            {
                provider.DaysToShip = 1;
            }
            DaysToShip.Text                 = provider.DaysToShip.ToString();
            provider.LiveModeUrl            = LiveServerURL.Text;
            provider.TestModeUrl            = TestServerURL.Text;
            provider.TrackingUrl            = TrackingURL.Text;
            provider.MaxPackageWeight       = AlwaysConvert.ToDecimal(MaxWeight.Text, (decimal)provider.MaxPackageWeight);
            provider.MinPackageWeight       = AlwaysConvert.ToDecimal(MinWeight.Text, (decimal)provider.MinPackageWeight);
            provider.DutiableFlag           = DutiableFlag.Checked;
            provider.CustomsValueMultiplier = AlwaysConvert.ToDecimal(CustomsValueMultiplier.Text, 1);
            provider.CommerceLicensed       = CommerceLicensed.Checked;
            provider.FilingType             = (DHLInternational.FilingTypeFlags)AlwaysConvert.ToEnum(typeof(DHLInternational.FilingTypeFlags), FilingType.SelectedValue, DHLInternational.FilingTypeFlags.ITN);
            provider.FTRExemptionCode       = FTRExemptionCode.Text;
            provider.ITNNumber              = ITNNumber.Text;
            provider.EINCode                = EINCode.Text;
            _ShipGateway.UpdateConfigData(provider.GetConfigData());
            _ShipGateway.Save();
        }
 protected void SaveButton_Click(object sender, EventArgs e)
 {
     if (Page.IsValid)
     {
         // UPDATE THE SETTINGS
         StoreSettingsManager settings = AbleContext.Current.Store.Settings;
         settings.AffiliateParameterName   = StringHelper.Truncate(AffiliateParameter.Text.Trim(), 200);
         settings.AffiliateTrackerUrl      = StringHelper.Truncate(TrackerUrl.Text.Trim(), 200);
         settings.AffiliateAllowSelfSignup = SelfSignup.Checked;
         settings.AffiliateReferralRule    = AlwaysConvert.ToEnum <ReferralRule>(AffiliateReferralRule.SelectedValue, ReferralRule.NewSignupsOnly);
         settings.AffiliatePersistence     = ((AffiliateReferralPeriod)AlwaysConvert.ToByte(AffiliatePersistence.SelectedValue));
         AffiliateReferralPeriod referralPeriod = ((AffiliateReferralPeriod)AlwaysConvert.ToByte(AffiliatePersistence.SelectedValue));
         if ((referralPeriod != AffiliateReferralPeriod.Persistent && referralPeriod != AffiliateReferralPeriod.FirstOrder))
         {
             settings.AffiliateReferralPeriod = AlwaysConvert.ToInt16(ReferralPeriod.Text);
         }
         else
         {
             settings.AffiliateReferralPeriod = 0;
         }
         settings.AffiliateCommissionRate      = AlwaysConvert.ToDecimal(CommissionRate.Text);
         settings.AffiliateCommissionIsPercent = (CommissionType.SelectedIndex > 0);
         settings.AffiliateCommissionOnTotal   = (CommissionType.SelectedIndex == 2);
         settings.Save();
         AffiliateSettingsMessage.Text    = string.Format(AffiliateSettingsMessage.Text, LocaleHelper.LocalNow);
         AffiliateSettingsMessage.Visible = true;
     }
 }
Example #4
0
        private void SaveEmailTemplate()
        {
            String oldName = _EmailTemplate.Name;

            _EmailTemplate.Name        = Name.Text;
            _EmailTemplate.ToAddress   = ToAddress.Text;
            _EmailTemplate.FromAddress = FromAddress.Text;
            _EmailTemplate.CCList      = CCAddress.Text;
            _EmailTemplate.BCCList     = BCCAddress.Text;
            _EmailTemplate.Subject     = Subject.Text;
            _EmailTemplate.Body        = Message.Text;
            _EmailTemplate.IsHTML      = (MailFormat.SelectedIndex == 0);
            _EmailTemplate.Save();

            // UPDATE TRIGGERS
            _EmailTemplate.Triggers.DeleteAll();
            foreach (GridViewRow row in TriggerGrid.Rows)
            {
                CheckBox selected = row.FindControl("Selected") as CheckBox;
                if (selected.Checked)
                {
                    StoreEvent storeEvent = AlwaysConvert.ToEnum <StoreEvent>(TriggerGrid.DataKeys[row.RowIndex].Value.ToString(), StoreEvent.None);
                    _EmailTemplate.Triggers.Add(new EmailTemplateTrigger(_EmailTemplate, storeEvent));
                }
            }
            _EmailTemplate.Save();


            // SEE IF NAME WAS UPDATED
            if (_EmailTemplate.Name != oldName)
            {
                // SEE IF FILE NAME NEEEDS TO BE CHANGED
                string generatedFileName = Regex.Replace(Name.Text, "[^a-zA-Z0-9 _-]", "") + " ID" + _EmailTemplate.Id + ".html";
                if (_EmailTemplate.ContentFileName != generatedFileName)
                {
                    // INITIATE FILE NAME CHANGE
                    string templatesPath = Path.Combine(FileHelper.ApplicationBasePath, "App_Data\\EmailTemplates\\" + AbleContext.Current.StoreId);
                    string sourceFile    = Path.Combine(templatesPath, _EmailTemplate.ContentFileName);
                    string targetFile    = Path.Combine(templatesPath, generatedFileName);
                    try
                    {
                        if (File.Exists(targetFile))
                        {
                            File.Delete(targetFile);
                        }
                        File.Move(sourceFile, targetFile);
                        _EmailTemplate.ContentFileName = generatedFileName;
                    }
                    catch (Exception ex)
                    {
                        string error = "Could not update the content file name for email template '{0}'.  Failed to rename file from {1} to {2}.";
                        Logger.Warn(string.Format(error, _EmailTemplate.Name, _EmailTemplate.ContentFileName, generatedFileName), ex);
                    }

                    // SAVE IN CASE THE RENAME WAS SUCCESSFUL
                    // (IF RENAME FAILED, ISDIRTY FLAG WILL BE FALSE AND SAVE CALL WILL BE IGNORED)
                    _EmailTemplate.Save();
                }
            }
        }
Example #5
0
 public override void Initialize(int ShipGatewayId, Dictionary <string, string> ConfigurationData)
 {
     base.Initialize(ShipGatewayId, ConfigurationData);
     //INITIALIZE MY FIELDS
     if (ConfigurationData.ContainsKey("AccountNumber"))
     {
         AccountNumber = ConfigurationData["AccountNumber"];
     }
     if (ConfigurationData.ContainsKey("MeterNumber"))
     {
         MeterNumber = ConfigurationData["MeterNumber"];
     }
     if (ConfigurationData.ContainsKey("EnablePackageBreakup"))
     {
         EnablePackageBreakup = AlwaysConvert.ToBool(ConfigurationData["EnablePackageBreakup"], true);
     }
     if (ConfigurationData.ContainsKey("MinPackageWeight"))
     {
         MinPackageWeight = AlwaysConvert.ToDecimal(ConfigurationData["MinPackageWeight"], (decimal)MinPackageWeight);
     }
     if (ConfigurationData.ContainsKey("MaxPackageWeight"))
     {
         MaxPackageWeight = AlwaysConvert.ToDecimal(ConfigurationData["MaxPackageWeight"], (decimal)MaxPackageWeight);
     }
     if (ConfigurationData.ContainsKey("IncludeDeclaredValue"))
     {
         IncludeDeclaredValue = AlwaysConvert.ToBool(ConfigurationData["IncludeDeclaredValue"], true);
     }
     if (ConfigurationData.ContainsKey("UseTestMode"))
     {
         UseTestMode = AlwaysConvert.ToBool(ConfigurationData["UseTestMode"], false);
     }
     if (ConfigurationData.ContainsKey("AccountActive"))
     {
         AccountActive = AlwaysConvert.ToBool(ConfigurationData["AccountActive"], false);
     }
     if (ConfigurationData.ContainsKey("DropOffType"))
     {
         DropOffType = (FDXDropOffType)AlwaysConvert.ToEnum(typeof(FDXDropOffType), ConfigurationData["DropOffType"], FDXDropOffType.REGULARPICKUP, true);
     }
     if (ConfigurationData.ContainsKey("PackagingType"))
     {
         PackagingType = (FDXPackagingType)AlwaysConvert.ToEnum(typeof(FDXPackagingType), ConfigurationData["PackagingType"], FDXPackagingType.YOURPACKAGING, true);
     }
     if (ConfigurationData.ContainsKey("TestModeUrl"))
     {
         TestModeUrl = ConfigurationData["TestModeUrl"];
     }
     if (ConfigurationData.ContainsKey("LiveModeUrl"))
     {
         LiveModeUrl = ConfigurationData["LiveModeUrl"];
     }
     if (ConfigurationData.ContainsKey("TrackingUrl"))
     {
         TrackingUrl = ConfigurationData["TrackingUrl"];
     }
 }
Example #6
0
        protected void SaveButton_Click(object sender, EventArgs e)
        {
            if (!Page.IsValid)
            {
                return;
            }
            EmailTemplate template = new EmailTemplate();

            template.Name        = Name.Text;
            template.ToAddress   = ToAddress.Text;
            template.FromAddress = FromAddress.Text;
            template.CCList      = CCAddress.Text;
            template.BCCList     = BCCAddress.Text;
            template.Subject     = Subject.Text;
            string temporaryFileName = Guid.NewGuid().ToString();

            template.ContentFileName = temporaryFileName;
            template.IsHTML          = (MailFormat.SelectedIndex == 0);
            foreach (GridViewRow row in TriggerGrid.Rows)
            {
                CheckBox selected = row.FindControl("Selected") as CheckBox;
                if (selected.Checked)
                {
                    StoreEvent storeEvent = AlwaysConvert.ToEnum <StoreEvent>(TriggerGrid.DataKeys[row.RowIndex].Value.ToString(), StoreEvent.None);
                    template.Triggers.Add(new EmailTemplateTrigger(template, storeEvent));
                }
            }
            template.Save();

            // RENAME THE FILE AND SAVE
            template.Body            = Message.Text;
            template.ContentFileName = Regex.Replace(Name.Text, "[^a-zA-Z0-9 _-]", "") + " ID" + template.Id + ".html";
            template.Save();

            // DELETE TEMPORARY CONTENT FILE
            string templatesPath = "App_Data\\EmailTemplates\\" + AbleContext.Current.StoreId;

            templatesPath = Path.Combine(FileHelper.ApplicationBasePath, templatesPath);
            string tempFilePath = Path.Combine(templatesPath, temporaryFileName);

            try
            {
                if (File.Exists(tempFilePath))
                {
                    File.Delete(tempFilePath);
                }
            }
            catch (Exception ex)
            {
                Logger.Warn("Error deleting temporary email template content file '" + tempFilePath + "'.", ex);
            }

            Response.Redirect("Default.aspx");
        }
        private void SaveOrderStatuses()
        {
            _OrderStatus.Name        = Name.Text;
            _OrderStatus.DisplayName = DisplayName.Text;
            //ACTIVE FLAG IS USED TO DETERMINE VALID SALES FOR REPORTING
            _OrderStatus.IsActive = Report.Checked;
            //VALID FLAG IS USED TO DERMINE WHICH ORDERS ARE BAD
            _OrderStatus.IsValid         = (!Cancelled.Checked);
            _OrderStatus.InventoryAction = (CommerceBuilder.Orders.InventoryAction)InventoryAction.SelectedIndex;
            _OrderStatus.Triggers.DeleteAll();
            foreach (ListItem item in Triggers.Items)
            {
                if (item.Selected)
                {
                    StoreEvent  thisEvent      = AlwaysConvert.ToEnum <StoreEvent>(item.Value, StoreEvent.None);
                    OrderStatus oldOrderStatus = OrderStatusTriggerDataSource.LoadForStoreEvent(thisEvent);
                    if (oldOrderStatus != null)
                    {
                        List <OrderStatusTrigger> triggers = (from t in oldOrderStatus.Triggers
                                                              where t.StoreEvent == thisEvent
                                                              select t).ToList <OrderStatusTrigger>();
                        triggers.DeleteAll <OrderStatusTrigger>();
                    }

                    // DROP EXISTING TRIGGERS FOR THIS EVENT
                    (from t in _OrderStatus.Triggers where t.StoreEvent == thisEvent select t).ToList <OrderStatusTrigger>().DeleteAll <OrderStatusTrigger>();
                    _OrderStatus.Triggers.Add(new OrderStatusTrigger(thisEvent, _OrderStatus));
                }
            }
            _OrderStatus.EmailTemplates.Clear();
            _OrderStatus.Save();

            foreach (ListItem item in EmailTemplates.Items)
            {
                var tempalte = EntityLoader.Load <EmailTemplate>(AlwaysConvert.ToInt(item.Value));
                int index    = tempalte.OrderStatuses.IndexOf(_OrderStatus.Id);
                if (item.Selected)
                {
                    if (index < 0)
                    {
                        tempalte.OrderStatuses.Add(_OrderStatus);
                    }
                }
                else
                {
                    if (index >= 0)
                    {
                        tempalte.OrderStatuses.RemoveAt(index);
                    }
                }

                tempalte.Save();
            }
        }
        public void Load(ISiteMapOptionKeys settingKeys)
        {
            StoreSettingCollection settings = Token.Instance.Store.Settings;

            _CompressedSiteMapFileName = settings.GetValueByKey(settingKeys.CompressedSiteMapFileName);
            _SiteMapDataPath           = settings.GetValueByKey(settingKeys.SiteMapDataPath);
            _SiteMapFileName           = settings.GetValueByKey(settingKeys.SiteMapFileName);
            _IncludeProducts           = AlwaysConvert.ToBool(settings.GetValueByKey(settingKeys.IncludeProducts), true);
            _IncludeCategories         = AlwaysConvert.ToBool(settings.GetValueByKey(settingKeys.IncludeCategories), true);
            _IncludeWebpages           = AlwaysConvert.ToBool(settings.GetValueByKey(settingKeys.IncludeWebpages), true);
            _OverwriteCompressedFile   = AlwaysConvert.ToBool(settings.GetValueByKey(settingKeys.OverwriteCompressedFile), true);
            _OverwriteSiteMapFile      = AlwaysConvert.ToBool(settings.GetValueByKey(settingKeys.OverwriteSiteMapFile), true);
            _DefaultChangeFrequency    = (changefreq)AlwaysConvert.ToEnum(typeof(changefreq), settings.GetValueByKey(settingKeys.DefaultChangeFrequency), changefreq.weekly);
            _DefaultUrlPriority        = AlwaysConvert.ToDecimal(settings.GetValueByKey(settingKeys.DefaultUrlPriority), 0.5M);
            IsDirty = false;
        }
Example #9
0
        public ActionResult Config(int?id)
        {
            int            gatewayId = id ?? 0;
            PaymentGateway gateway   = _gatewayRepo.Load(gatewayId);

            var    aName        = GetType().Assembly.GetName();
            string assemblyInfo = aName.Name.ToString() + "&nbsp;(v" + aName.Version.ToString() + ")";

            var model = new ConfigModel();

            model.AssemblyInfo   = assemblyInfo;
            model.ExecutionModes = Enum.GetNames(typeof(EPProvider.GatewayExecutionMode))
                                   .Select(name => new SelectListItem()
            {
                Text = name, Value = name
            })
                                   .ToList();
            model.PaymentMethods = _methodRepo.LoadPaymentMethods(_hiddenMethods).Select(method => new PaymentMethodModel()
            {
                Id   = method.Id,
                Name = method.Name
            }
                                                                                         ).ToList();

            if (gateway != null)
            {
                model.GatewayId = gateway.Id;
                model.PaymentMethods.ForEach(method => method.IsSelected = gateway.PaymentMethods.Any(pm => pm.Id == method.Id));

                var configurationData = gateway.ParseConfigData();
                if (configurationData.ContainsKey("UseDebugMode"))
                {
                    model.UseDebugMode = AlwaysConvert.ToBool(configurationData["UseDebugMode"], false);
                }
                if (configurationData.ContainsKey("ExecutionMode"))
                {
                    model.ExecutionMode = AlwaysConvert.ToEnum <EPProvider.GatewayExecutionMode>(configurationData["ExecutionMode"], EPProvider.GatewayExecutionMode.AlwaysAccept);
                }
                if (configurationData.ContainsKey("UseAuthCapture"))
                {
                    model.UseAuthCapture = AlwaysConvert.ToBool(configurationData["UseAuthCapture"], true);
                }
            }

            return(View("~/Plugins/ExamplePaymentPlugin/Views/Config.cshtml", model));
        }
        protected void SaveButton_Click(object sender, EventArgs e)
        {
            OrderStatus _OrderStatus = new OrderStatus();

            _OrderStatus.Name        = Name.Text;
            _OrderStatus.DisplayName = DisplayName.Text;
            //ACTIVE FLAG IS USED TO DETERMINE VALID SALES FOR REPORTING
            _OrderStatus.IsActive = Report.Checked;
            //VALID FLAG IS USED TO DERMINE WHICH ORDERS ARE BAD
            _OrderStatus.IsValid         = (!Cancelled.Checked);
            _OrderStatus.InventoryAction = (CommerceBuilder.Orders.InventoryAction)InventoryAction.SelectedIndex;
            foreach (ListItem item in Triggers.Items)
            {
                if (item.Selected)
                {
                    StoreEvent  thisEvent      = AlwaysConvert.ToEnum <StoreEvent>(item.Value, StoreEvent.None);
                    OrderStatus oldOrderStatus = OrderStatusTriggerDataSource.LoadForStoreEvent(thisEvent);
                    if (oldOrderStatus != null)
                    {
                        List <OrderStatusTrigger> triggers = (from t in oldOrderStatus.Triggers
                                                              where t.StoreEvent == thisEvent
                                                              select t).ToList <OrderStatusTrigger>();
                        triggers.DeleteAll <OrderStatusTrigger>();
                    }

                    // DROP EXISTING TRIGGERS FOR THIS EVENT
                    (from t in _OrderStatus.Triggers where t.StoreEvent == thisEvent select t).ToList <OrderStatusTrigger>().DeleteAll <OrderStatusTrigger>();
                    _OrderStatus.Triggers.Add(new OrderStatusTrigger(thisEvent, _OrderStatus));
                }
            }
            _OrderStatus.Save();

            foreach (ListItem item in EmailTemplates.Items)
            {
                var tempalte = EntityLoader.Load <EmailTemplate>(AlwaysConvert.ToInt(item.Value));
                if (item.Selected)
                {
                    tempalte.OrderStatuses.Add(_OrderStatus);
                }

                tempalte.Save();
            }
            Response.Redirect("Default.aspx");
        }
        public override void Initialize(int ShipGatewayId, Dictionary <string, string> ConfigurationData)
        {
            base.Initialize(ShipGatewayId, ConfigurationData);
            //INITIALIZE MY FIELDS
            if (ConfigurationData.ContainsKey("UserID"))
            {
                UserID = ConfigurationData["UserID"];
            }
            if (ConfigurationData.ContainsKey("Password"))
            {
                Password = ConfigurationData["Password"];
            }
            if (ConfigurationData.ContainsKey("EnablePackageBreakup"))
            {
                EnablePackageBreakup = AlwaysConvert.ToBool(ConfigurationData["EnablePackageBreakup"], true);
            }
            if (ConfigurationData.ContainsKey("AccountNumber"))
            {
                AccountNumber = ConfigurationData["AccountNumber"];
            }
            if (ConfigurationData.ContainsKey("ShippingKey"))
            {
                ShippingKey = ConfigurationData["ShippingKey"];
            }
            if (ConfigurationData.ContainsKey("DaysToShip"))
            {
                DaysToShip = AlwaysConvert.ToInt(ConfigurationData["DaysToShip"], 0);
            }
            if (ConfigurationData.ContainsKey("UseTestMode"))
            {
                UseTestMode = AlwaysConvert.ToBool(ConfigurationData["UseTestMode"], false);
            }
            if (ConfigurationData.ContainsKey("AccountActive"))
            {
                AccountActive = AlwaysConvert.ToBool(ConfigurationData["AccountActive"], false);
            }
            if (ConfigurationData.ContainsKey("TestModeUrl"))
            {
                TestModeUrl = ConfigurationData["TestModeUrl"];
            }
            if (ConfigurationData.ContainsKey("LiveModeUrl"))
            {
                LiveModeUrl = ConfigurationData["LiveModeUrl"];
            }
            if (ConfigurationData.ContainsKey("TrackingUrl"))
            {
                TrackingUrl = ConfigurationData["TrackingUrl"];
            }

            if (ConfigurationData.ContainsKey("DOSFlag"))
            {
                DOSFlag = AlwaysConvert.ToBool(ConfigurationData["DOSFlag"], false);
            }
            if (ConfigurationData.ContainsKey("DutiableFlag"))
            {
                DutiableFlag = AlwaysConvert.ToBool(ConfigurationData["DutiableFlag"], false);
            }
            if (ConfigurationData.ContainsKey("CustomsValueMultiplier"))
            {
                CustomsValueMultiplier = AlwaysConvert.ToDecimal(ConfigurationData["CustomsValueMultiplier"], 1);
            }
            if (ConfigurationData.ContainsKey("CommerceLicensed"))
            {
                CommerceLicensed = AlwaysConvert.ToBool(ConfigurationData["CommerceLicensed"], false);
            }
            if (ConfigurationData.ContainsKey("FilingType"))
            {
                FilingType = (FilingTypeFlags)AlwaysConvert.ToEnum(typeof(FilingTypeFlags), ConfigurationData["FilingType"], FilingTypeFlags.ITN, true);
            }
            if (ConfigurationData.ContainsKey("FTRExemptionCode"))
            {
                FTRExemptionCode = ConfigurationData["FTRExemptionCode"];
            }
            if (ConfigurationData.ContainsKey("ITNNumber"))
            {
                ITNNumber = ConfigurationData["ITNNumber"];
            }
            if (ConfigurationData.ContainsKey("EINCode"))
            {
                EINCode = ConfigurationData["EINCode"];
            }

            if (ConfigurationData.ContainsKey("MinPackageWeight"))
            {
                MinPackageWeight = AlwaysConvert.ToDecimal(ConfigurationData["MinPackageWeight"], (decimal)MinPackageWeight);
            }
            if (ConfigurationData.ContainsKey("MaxPackageWeight"))
            {
                MaxPackageWeight = AlwaysConvert.ToDecimal(ConfigurationData["MaxPackageWeight"], (decimal)MaxPackageWeight);
            }
        }
Example #12
0
 protected void SearchButton_Click(object sender, EventArgs e)
 {
     CouponGrid.DataBind();
     Session["CouponSearchFilter"] = new SearchFilter(CouponCode.Text.Trim(), AlwaysConvert.ToEnum<CouponUsageFilter>(UsageFilter.SelectedValue, CouponUsageFilter.Any));
 }
Example #13
0
        public static Basket GetAcBasket(AutoGen.ShoppingCart shoppingcart, bool clearShipNTax)
        {
            TraceContext trace    = WebTrace.GetTraceContext();
            string       traceKey = "GoogleCheckout.AC.AcHelper";

            trace.Write(traceKey, "Begin AcHelper.GetAcBasket");

            int basketId = AcHelper.GetAcBasketId(shoppingcart);

            trace.Write(traceKey, "Look for basket ID " + basketId.ToString());
            Basket basket = BasketDataSource.Load(basketId, false);

            if (basket == null)
            {
                trace.Write(traceKey, "Basket not found. Creating New Basket.");
                basket = new Basket();
            }
            else
            {
                //basket found. check if content hash matches
                string contentHash = GetReportedBasketHash(shoppingcart);
                if (contentHash.Equals(GetAcBasketHash(basket)))
                {
                    //hash matched. basket has not changed.
                    if (clearShipNTax)
                    {
                        ClearShippingAndTaxes(basket);
                    }
                    return(basket);
                }
            }

            trace.Write(traceKey, "Clear existing Basket contents and populate with Google Input.");
            basket.Clear();

            if (shoppingcart.items != null)
            {
                trace.Write(traceKey, "Looping " + shoppingcart.items.Length.ToString() + " items in Google cart");
            }
            foreach (Item thisItem in shoppingcart.items)
            {
                trace.Write(traceKey, "itemName: " + thisItem.itemname);
                BasketItem basketItem = new BasketItem();
                basketItem.Name     = thisItem.itemname;
                basketItem.Quantity = (short)thisItem.quantity;
                basketItem.Price    = thisItem.unitprice.Value;

                XmlNode[] privateNodes = thisItem.merchantprivateitemdata.Any;
                foreach (XmlNode privateNode in privateNodes)
                {
                    trace.Write(traceKey, "privateNode.Name: " + privateNode.Name);
                    switch (privateNode.Name)
                    {
                    case "productId":
                        basketItem.ProductId = AlwaysConvert.ToInt(privateNode.InnerText);
                        break;

                    case "orderItemType":
                        basketItem.OrderItemType = (OrderItemType)AlwaysConvert.ToEnum(typeof(OrderItemType), privateNode.InnerText, OrderItemType.Product, true);
                        break;

                    case "shippable":
                        basketItem.Shippable = (Shippable)AlwaysConvert.ToEnum(typeof(Shippable), privateNode.InnerText, Shippable.Yes, true);
                        break;

                    case "taxCodeId":
                        basketItem.TaxCodeId = AlwaysConvert.ToInt(privateNode.InnerText);
                        break;

                    case "weight":
                        basketItem.Weight = AlwaysConvert.ToDecimal(privateNode.InnerText);
                        break;

                    case "wrapStyleId":
                        basketItem.WrapStyleId = AlwaysConvert.ToInt(privateNode.InnerText);
                        break;

                    case "optionList":
                        basketItem.OptionList = privateNode.InnerText;
                        break;

                    case "giftMessage":
                        basketItem.GiftMessage = privateNode.InnerText;
                        break;

                    case "lineMessage":
                        basketItem.LineMessage = privateNode.InnerText;
                        break;

                    case "lastModifiedDate":
                        basketItem.LastModifiedDate = AlwaysConvert.ToDateTime(privateNode.InnerText, LocaleHelper.LocalNow);
                        break;

                    case "orderBy":
                        basketItem.OrderBy = AlwaysConvert.ToInt16(privateNode.InnerText);
                        break;

                    case "parentItemId":
                        basketItem.ParentItemId = AlwaysConvert.ToInt(privateNode.InnerText);
                        break;

                    case "sku":
                        basketItem.Sku = privateNode.InnerText;
                        break;

                    case "wishlistItemId":
                        basketItem.WishlistItemId = AlwaysConvert.ToInt(privateNode.InnerText);
                        break;

                    case "basketItemKitProducts":
                        List <string> kitList = new List <string>();
                        foreach (XmlNode subNode in privateNode.ChildNodes)
                        {
                            if (subNode.Name.Equals("kitProductId"))
                            {
                                int        kitProductId = AlwaysConvert.ToInt(subNode.InnerText);
                                KitProduct kitProd      = KitProductDataSource.Load(kitProductId);
                                if (kitProd != null)
                                {
                                    kitList.Add(kitProductId.ToString());
                                }
                            }
                        }
                        if (kitList.Count > 0)
                        {
                            basketItem.KitList = string.Join(",", kitList.ToArray());
                        }
                        break;

                    case "inputs":
                        foreach (XmlNode subNode in privateNode.ChildNodes)
                        {
                            if (subNode.Name.Equals("itemInput"))
                            {
                                int inputFieldId = 0;
                                foreach (XmlAttribute attr in subNode.Attributes)
                                {
                                    if (attr.Name.Equals("inputFieldId"))
                                    {
                                        inputFieldId = AlwaysConvert.ToInt(attr.InnerText);
                                        break;
                                    }
                                }
                                InputField inputField = InputFieldDataSource.Load(inputFieldId);
                                if (inputField != null)
                                {
                                    BasketItemInput bInput = new BasketItemInput();
                                    bInput.InputFieldId = inputFieldId;
                                    bInput.InputValue   = subNode.InnerText;
                                    basketItem.Inputs.Add(bInput);
                                }
                            }
                        }
                        break;

                    case "couponCode":
                        basketItem.Sku = privateNode.InnerText;
                        break;
                    }
                }
                basket.Items.Add(basketItem);
            }
            trace.Write(traceKey, "Saving basket");
            basket.Save();

            string key = "Basket_" + basket.BasketId.ToString();

            ContextCache.SetObject(key, basket);

            trace.Write(traceKey, "Basket created, returning to caller (End GetAcBasket)");
            return(basket);
        }