Beispiel #1
0
        public bool SaveData()
        {
            if (SettingsSEO.GoogleAnalyticsNumber != txtGoogleAnalytics.Text && chbGoogleAnalytics.Checked)
            {
                TrialService.TrackEvent(TrialEvents.SetUpGoogleAnalytics, string.Empty);
            }

            SettingsSEO.GoogleAnalyticsNumber = txtGoogleAnalytics.Text;
            SettingsSEO.GoogleAnalyticsEnableDemogrReports = chkGaUseDemografic.Checked;
            SettingsSEO.GoogleAnalyticsEnabled             = chbGoogleAnalytics.Checked;

            SettingsSEO.GoogleAnalyticsApiEnabled = chbGoogleAnalyticsApi.Checked;
            SettingsSEO.GoogleAnalyticsAccountID  = txtGoogleAnalyticsAccountID.Text;
            SettingsSEO.GoogleAnalyticsUserName   = txtGoogleAnalyticsUserName.Text;
            SettingsSEO.GoogleAnalyticsPassword   = txtGoogleAnalyticsPassword.Text;
            SettingsSEO.GoogleAnalyticsAPIKey     = txtGoogleAnalyticsAPIKey.Text;

            SettingsSEO.UseGTM         = chbUseGTM.Checked;
            SettingsSEO.GTMContainerID = txtGTMContainerID.Text;

            SettingsOrderConfirmation.SuccessOrderScript = txtOrderSuccessScript.Text;

            LoadData();

            return(true);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            SetMeta(string.Format("{0} - {1}", SettingsMain.ShopName, Resource.Admin_ExportFeed_Yandex_aspx));

            if (!(CommonStatistic.IsRun))
            {
                TrialService.TrackEvent(TrialEvents.ExportProductsToFeed, "");
                CommonStatistic.Init();
            }
            if (!CommonStatistic.IsRun && string.IsNullOrEmpty(ModuleName))
            {
                Response.Redirect("ExportFeed.aspx?ModuleId=YandexMarket");
                return;
            }

            PageSubheader.Visible  = true;
            ModuleNameLiteral.Text = ModuleName;

            OutDiv.Visible  = Start;
            PhysicalAppPath = Request.PhysicalApplicationPath;

            if ((SaasDataService.IsSaasEnabled) && (!SaasDataService.CurrentSaasData.HaveExportFeeds))
            {
                mainDiv.Visible     = false;
                notInTariff.Visible = true;
            }
        }
        protected void btnOk_Click(object sender, EventArgs e)
        {
            var type   = (PaymentType)int.Parse(ddlType.SelectedValue);
            var method = PaymentMethod.Create(type);

            method.Name        = txtName.Text;
            method.Description = txtDescription.Text;
            if (!string.IsNullOrEmpty(txtSortOrder.Text))
            {
                method.SortOrder = int.Parse(txtSortOrder.Text);
            }
            method.Enabled = type == PaymentType.Cash;
            //Some dirty magic
            if (method.Parameters.ContainsKey(AssistTemplate.CurrencyValue))
            {
                var parameters = method.Parameters;
                parameters[AssistTemplate.CurrencyValue] = "1";
                method.Parameters = parameters;
            }
            //End of dirty magic
            TrialService.TrackEvent(TrialEvents.AddPaymentMethod, method.Type.ToString());
            var id = PaymentService.AddPaymentMethod(method);

            if (id != 0)
            {
                Response.Redirect("~/Admin/PaymentMethod.aspx?PaymentMethodID=" + id);
            }
        }
        protected void btnSendMail_Click(object sender, EventArgs e)
        {
            if ((!ValidateData() || !ValidateData_TestMailForm()))
            {
                MsgErr(Resource.Admin_CommonSettings_TestEmail_NotValid, false);
                return;
            }

            System.Threading.Thread.Sleep(1200); // To show progress...

            int ti;

            if (!int.TryParse(txtEmailPort.Text, out ti))
            {
                ti = 25;
            }

            //        lblDegub.Text = string.Format(@"Text: {0}<br>txtSubject: {1}<br> txtMessage: {2}<br>
            //        iSHtml: {3}<br> txtEmailSMTP: {4}<br> txtEmailLogin: {5}<br> txtEmailPassword: {6}<br>
            //        ti: {7}<br> txtEmail: {8}<br> chkEnableSSL: {9}<br>",
            //            txtTo.Text,
            //            txtSubject.Text,
            //            txtMessage.Text,Fpfn
            //            false,
            //            txtEmailSMTP.Text,
            //            txtEmailLogin.Text,
            //            txtEmailPassword.Text,
            //            ti,
            //            txtEmail.Text,
            //            chkEnableSSL.Checked);

            //        string strResult = "True";

            string strResult = AdvantShop.Mails.SendMail.SendMailThreadStringResult(txtTo.Text,
                                                                                    txtSubject.Text,
                                                                                    txtMessage.Text,
                                                                                    false,
                                                                                    txtEmailSMTP.Text,
                                                                                    txtEmailLogin.Text,
                                                                                    txtEmailPassword.Text,
                                                                                    ti,
                                                                                    txtEmail.Text,
                                                                                    chkEnableSSL.Checked);

            if (strResult.Equals("True"))
            {
                if (!txtEmail.Text.Contains("advantshop"))
                {
                    TrialService.TrackEvent(TrialEvents.SendTestEmail, string.Empty);
                }
                MsgErr(Resource.Admin_CommonSettings_TestEmail_Success, true);
            }
            else
            {
                MsgErr(strResult, false);
            }
        }
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);

            if (!Request.Browser.Crawler && CommonHelper.GetCookieString(TrialEvents.VisitAdminSide.ToString()).IsNullOrEmpty())
            {
                TrialService.TrackEvent(TrialEvents.VisitAdminSide, "IP:" + Request.UserHostAddress + " User-Agent: " + Request.UserAgent);
                CommonHelper.SetCookie(TrialEvents.VisitAdminSide.ToString(), DateTime.Now.ToString(), new TimeSpan(0, 20, 0), true);
            }
        }
Beispiel #6
0
        protected void bntClearShop_OnClick(object sender, EventArgs e)
        {
            if (TrialService.IsTrialEnabled)
            {
                foreach (var category in CategoryService.GetCategories().Where(category => category.ID != 0))
                {
                    CategoryService.DeleteCategoryAndPhotos(category.ID);
                }

                foreach (var productId in ProductService.GetAllProductIDs())
                {
                    ProductService.DeleteProduct(productId, false);
                }

                foreach (var property in PropertyService.GetAllProperties())
                {
                    PropertyService.DeleteProperty(property.PropertyId);
                }

                foreach (var brand in BrandService.GetBrands())
                {
                    BrandService.DeleteBrand(brand.ID);
                }


                foreach (var paymentId in PaymentService.GetAllPaymentMethodIDs())
                {
                    PaymentService.DeletePaymentMethod(paymentId);
                }

                foreach (var shippingId in ShippingMethodService.GetAllShippingMethodIds())
                {
                    ShippingMethodService.DeleteShippingMethod(shippingId);
                }

                foreach (var news in NewsService.GetNews())
                {
                    NewsService.DeleteNews(news.ID);
                }

                foreach (var newsCstegory in NewsService.GetNewsCategories())
                {
                    NewsService.DeleteNewsCategory(newsCstegory.NewsCategoryID);
                }

                CategoryService.RecalculateProductsCountManual();
                CategoryService.SetCategoryHierarchicallyEnabled(0);
                CacheManager.Clean();

                TrialService.TrackEvent(TrialEvents.DeleteTestData, string.Empty);
            }
        }
Beispiel #7
0
        protected void bthAddCarousel_Click(object sender, EventArgs e)
        {
            lblErrorImage.Text = string.Empty;
            int sort;

            if (CarouselLoad.HasFile && !FileHelpers.CheckFileExtension(CarouselLoad.FileName, FileHelpers.eAdvantShopFileTypes.Image))
            {
                lblErrorImage.Text = Resource.Admin_ErrorMessage_WrongImageExtension;
                return;
            }

            int.TryParse(txtSortedCarousel.Text, out sort);

            if (string.IsNullOrEmpty(txtURL.Text))
            {
                txtURL.Text = "#";
            }

            var carousel = new Carousel {
                URL = txtURL.Text, SortOrder = sort, Enabled = true
            };
            int id = CarouselService.AddCarousel(carousel);

            try
            {
                if (CarouselLoad.HasFile)
                {
                    var tempName = PhotoService.AddPhoto(new Photo(0, id, PhotoType.Carousel)
                    {
                        OriginName = CarouselLoad.FileName
                    });
                    if (!string.IsNullOrWhiteSpace(tempName))
                    {
                        using (System.Drawing.Image image = System.Drawing.Image.FromStream(CarouselLoad.PostedFile.InputStream))
                        {
                            FileHelpers.SaveResizePhotoFile(FoldersHelper.GetPathAbsolut(FolderType.Carousel, tempName), SettingsPictureSize.CarouselBigWidth, SettingsPictureSize.CarouselBigHeight, image);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.LogError(ex, "Attempt to load not image file");
            }

            txtURL.Text            = string.Empty;
            txtSortedCarousel.Text = string.Empty;
            TrialService.TrackEvent(TrialEvents.AddCarousel, "");
            Response.Redirect(UrlService.GetAdminAbsoluteLink("Carousel.aspx"));
        }
Beispiel #8
0
        private int CreateProduct()
        {
            int  id         = 0;
            var  artNo      = txtStockNumber.Text;
            bool validArtNo = true;

            try
            {
                // проверяем свободен ли артикул
                if (ProductService.GetProductId(artNo) != 0)
                {
                    validArtNo = false;
                    Msg(Resource.Admin_Product_Duplicate);
                }

                Validate();
                //проверяем свободен ли урл
                if (!UrlService.IsAvailableUrl(ParamType.Product, txtSynonym.Text))
                {
                    validArtNo = false;
                    Msg(Resource.Admin_SynonymExist);
                }

                imgExcl1.Visible = !IsValidTab(1) || !validArtNo;
                imgExcl2.Visible = !IsValidTab(2);
                if (IsValid && validArtNo)
                {
                    ProductService.EnableDynamicProductLinkRecalc();
                    var productToCreate = GetProductFromForm();
                    if (productToCreate == null)
                    {
                        return(0);
                    }

                    productToCreate.AddManually = true;

                    id = ProductService.AddProduct(productToCreate, true);
                    ProductService.DisableDynamicProductLinkRecalc();
                }
            }
            catch (Exception ex)
            {
                Debug.LogError(ex);
                Msg("Erorr at create product");
                return(0);
            }
            TrialService.TrackEvent(TrialEvents.AddProduct, "");
            return(id);
        }
Beispiel #9
0
        protected void btnDownload_Click(object sender, EventArgs e)
        {
            if (lError.Visible)
            {
                return;
            }
            if (CommonStatistic.IsRun)
            {
                return;
            }

            //delete old
            foreach (var item in Directory.GetFiles(_strFilePath).Where(f => f.Contains(StrFileName)))
            {
                FileHelpers.DeleteFile(item);
            }

            divAction.Visible    = false;
            divbtnAction.Visible = false;
            choseDiv.Visible     = false;

            CsvSettings.CsvEnconing  = ddlEncoding.SelectedValue;
            CsvSettings.CsvSeparator = ddlSeparetors.SelectedValue == SeparatorsEnum.Custom.StrName() ? txtCustomSeparator.Text : ddlSeparetors.SelectedValue;

            CsvSettings.CsvColumSeparator     = txtColumSeparator.Text;
            CsvSettings.CsvPropertySeparator  = txtPropertySeparator.Text;
            CsvSettings.CsvExportNoInCategory = chbCsvExportNoInCategory.Checked;

            CommonStatistic.Init();
            CommonStatistic.CurrentProcess     = Request.Url.PathAndQuery;
            CommonStatistic.CurrentProcessName = Resource.Admin_ExportExcel_CatalogDownload;
            linkCancel.Visible  = true;
            OutDiv.Visible      = true;
            btnDownload.Visible = false;

            // Directory
            foreach (var file in Directory.GetFiles(_strFilePath).Where(f => f.Contains(StrFileName)).ToList())
            {
                FileHelpers.DeleteFile(file);
            }

            ExtStrFileName = (StrFileName + StrFileExt).FileNamePlusDate();
            _strFullPath   = _strFilePath + ExtStrFileName;
            FileHelpers.CreateDirectory(_strFilePath);
            CsvExport.Factory(_strFullPath, CsvSettings.CsvEnconing, CsvSettings.CsvSeparator, CsvSettings.CsvColumSeparator, CsvSettings.CsvPropertySeparator, FieldMapping, CsvSettings.CsvExportNoInCategory).Process();

            TrialService.TrackEvent(TrialEvents.MakeCSVExport, "");
        }
Beispiel #10
0
        public static Dictionary <DateTime, GoogleAnalyticsData> GetData()
        {
            if (!SettingsSEO.GoogleAnalyticsApiEnabled || SettingsSEO.GoogleAnalyticsUserName.IsNullOrEmpty() ||
                SettingsSEO.GoogleAnalyticsPassword.IsNullOrEmpty() || SettingsSEO.GoogleAnalyticsAPIKey.IsNullOrEmpty())
            {
                return(null);
            }

            if (SettingsSEO.GoogleAnalyticsCachedDate == DateTime.MinValue || SettingsSEO.GoogleAnalyticsCachedDate.AddHours(1) <= DateTime.Now)
            {
                var service = new AnalyticsService("WebApp");
                service.setUserCredentials(SettingsSEO.GoogleAnalyticsUserName, SettingsSEO.GoogleAnalyticsPassword);

                if (TrialService.IsTrialEnabled || SaasDataService.IsSaasEnabled)
                {
                    if (GetTotalVisitors(service) > 100)
                    {
                        TrialService.TrackEvent(TrialEvents.GetFirstThouthandVisitors, string.Empty);
                    }
                }

                var data = GetVisitsData(service);
                if (data != null)
                {
                    return(data);
                }
            }


            // if something is wrong return cached data
            if (SettingsSEO.GoogleAnalyticsCachedData.IsNullOrEmpty())
            {
                return(null);
            }

            try
            {
                var cachedData = Newtonsoft.Json.JsonConvert.DeserializeObject <Dictionary <DateTime, GoogleAnalyticsData> >(SettingsSEO.GoogleAnalyticsCachedData);
                return(cachedData);
            }
            catch (Exception ex)
            {
                Debug.LogError(ex, false);
                return(null); // if there is no any data
            }
        }
Beispiel #11
0
        protected bool ValidateInput()
        {
            string synonym = txtSynonym.Text;

            if (string.IsNullOrEmpty(synonym))
            {
                MsgErr(Resource.Admin_StaticPage_URLIsRequired);
                return(false);
            }
            var r = new Regex("^[a-zA-Z0-9_-]*$");

            if (!r.IsMatch(synonym))
            {
                MsgErr(Resource.Admin_m_Category_SynonymInfo);
                return(false);
            }
            if (StaticPageId == 0 ? !UrlService.IsAvailableUrl(ParamType.StaticPage, synonym) : !UrlService.IsAvailableUrl(StaticPageId, ParamType.StaticPage, synonym))
            {
                MsgErr(Resource.Admin_SynonymExist);
                return(false);
            }

            if (string.IsNullOrEmpty(txtPageName.Text))
            {
                MsgErr(Resource.Client_AuxView_EnterTitle);
                return(false);
            }

            if (string.IsNullOrEmpty(fckPageText.Text))
            {
                MsgErr(Resource.Client_AuxView_EnterText);
                return(false);
            }

            int ti;

            if (!Int32.TryParse(txtSortOrder.Text, out ti))
            {
                txtSortOrder.Text = "0";
            }
            if (StaticPageId == 132)
            {
                TrialService.TrackEvent(TrialEvents.ChangeContactPage, "");
            }
            return(true);
        }
Beispiel #12
0
        protected void btnOk_Click(object sender, EventArgs e)
        {
            var type   = (ShippingType)int.Parse(ddlType.SelectedValue);
            var method = new ShippingMethod
            {
                Type                = type,
                Name                = txtName.Text,
                Description         = txtDescription.Text,
                Enabled             = type == ShippingType.FreeShipping,
                DisplayCustomFields = true,
                SortOrder           = txtSortOrder.Text.TryParseInt(),
                ZeroPriceMessage    = Resources.Resource.Admin_ShippingMethod_ZeroPriceMessage
            };

            TrialService.TrackEvent(TrialEvents.AddShippingMethod, method.Type.ToString());
            var id = ShippingMethodService.InsertShippingMethod(method);

            if (id != 0)
            {
                Response.Redirect("~/Admin/ShippingMethod.aspx?ShippingMethodID=" + id);
            }
        }
Beispiel #13
0
        protected void btnAction_Click(object sender, EventArgs e)
        {
            if (!String.IsNullOrEmpty(lblError.Text))
            {
                return;
            }


            if (!_fieldMapping.ContainsKey(ProductFields.Sku.StrName()) && !_fieldMapping.ContainsKey(ProductFields.Name.StrName()))
            {
                MsgErr(Resource.Admin_ImportCsv_SelectNameOrSKU);
                return;
            }

            divAction.Visible = false;
            choseDiv.Visible  = false;
            if (!File.Exists(_fullPath))
            {
                return;
            }

            if (CommonStatistic.IsRun)
            {
                return;
            }
            _hasHeadrs = Request["hasheadrs"] == "true";
            CommonStatistic.Init();
            CommonStatistic.CurrentProcess     = Request.Url.PathAndQuery;
            CommonStatistic.CurrentProcessName = Resource.Admin_ImportXLS_CatalogUpload;
            linkCancel.Visible = true;
            MsgErr(true);
            lblRes.Text = string.Empty;
            CsvImport.Factory(_fullPath, _hasHeadrs, chboxDisableProducts.Checked, CsvSettings.CsvSeparator, CsvSettings.CsvEnconing, _fieldMapping, CsvSettings.CsvColumSeparator, CsvSettings.CsvPropertySeparator).Process();
            OutDiv.Visible = true;
            TrialService.TrackEvent(TrialEvents.MakeCSVImport, "");
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack || OrderID == 0 || (Order = OrderService.GetOrder(OrderID)) == null)
            {
                return;
            }

            var sb = StaticBlockService.GetPagePartByKeyWithCache("OrderSuccessTop");

            if (sb == null || (!CustomerContext.CurrentCustomer.IsAdmin && !sb.Enabled))
            {
                SbOrderSuccessTopText = string.Empty;
            }
            else
            {
                SbOrderSuccessTopId   = sb.StaticBlockId;
                SbOrderSuccessTopText = sb.Content ?? string.Empty;

                SbOrderSuccessTopText = SbOrderSuccessTopText.Replace("#ORDER_ID#", OrderID.ToString());
            }

            if (SettingsOrderConfirmation.SuccessOrderScript.IsNotEmpty())
            {
                string orderScript = SettingsOrderConfirmation.SuccessOrderScript
                                     .Replace("#ORDER_ID#", Order.OrderID.ToString())
                                     .Replace("#ORDER_SUM#", Order.Sum.ToString("#.##"))
                                     .Replace("#CUSTOMER_EMAIL#", HttpUtility.HtmlEncode(Order.OrderCustomer.Email))
                                     .Replace("#CUSTOMER_FIRSTNAME#", HttpUtility.HtmlEncode(Order.OrderCustomer.FirstName))
                                     .Replace("#CUSTOMER_LASTNAME#", HttpUtility.HtmlEncode(Order.OrderCustomer.LastName))
                                     .Replace("#CUSTOMER_PHONE#", HttpUtility.HtmlEncode(Order.OrderCustomer.MobilePhone))
                                     .Replace("#CUSTOMER_ID#", Order.OrderCustomer.CustomerID.ToString());

                var regex    = new Regex("<<(.*)>>");
                var match    = regex.Match(orderScript);
                var products = new StringBuilder();

                if (match.Groups.Count > 0 && match.Groups[1].Value.IsNotEmpty())
                {
                    var productLine = match.Groups[1].Value;
                    foreach (var item in Order.OrderItems)
                    {
                        products.Append(
                            productLine.Replace("#PRODUCT_ARTNO#", HttpUtility.HtmlEncode(item.ArtNo))
                            .Replace("#PRODUCT_NAME#", HttpUtility.HtmlEncode(item.Name))
                            .Replace("#PRODUCT_PRICE#", item.Price.ToString("#.##"))
                            .Replace("#PRODUCT_AMOUNT#", item.Amount.ToString("#.##")));
                    }

                    orderScript = orderScript.Replace("<<" + productLine + ">>", products.ToString());
                }

                lSuccessScript.Text = orderScript;
            }

            LoadGoogleAnalytics(Order);

            if (GoogleTagManager.Enabled)
            {
                TagManager.PageType   = GoogleTagManager.ePageType.purchase;
                TagManager.TotalValue = Order.OrderItems.Sum(item => item.Price * item.Amount);

                TagManager.Transaction = new Transaction()
                {
                    TransactionAffiliation = SettingsMain.ShopName,
                    TransactionId          = Order.OrderID,
                    TransactionTotal       = Order.Sum - Order.ShippingCost,
                    TransactionShipping    = Order.ShippingCost,
                    TransactionProducts    =
                        new List <TransactionProduct>(
                            Order.OrderItems.Select(
                                item =>
                                new TransactionProduct()
                    {
                        Name     = item.Name,
                        Price    = item.Price,
                        Quantity = item.Amount,
                        SKU      = item.ArtNo,
                        Category =
                            CategoryService.GetCategory(
                                ProductService.GetFirstCategoryIdByProductId((int)item.ProductID)).Name
                    }))
                };
            }
            TrialService.TrackEvent(TrialEvents.CheckoutOrder, OrderID.ToString());
        }
        public bool SaveData()
        {
            if (!ValidateData())
            {
                return(false);
            }

            if (SettingsMain.ShopName != txtShopName.Text)
            {
                TrialService.TrackEvent(TrialEvents.ChangeShopName, "");
            }

            if (SettingsMain.Phone != txtPhone.Text)
            {
                TrialService.TrackEvent(TrialEvents.ChangePhoneNumber, "");
            }

            if (SettingsMain.SiteUrl != txtShopURL.Text)
            {
                TrialService.TrackEvent(TrialEvents.ChangeDomain, "");
            }

            SettingsMain.SiteUrl         = txtShopURL.Text.StartsWith("http://") || txtShopURL.Text.StartsWith("https://") ? txtShopURL.Text : "http://" + txtShopURL.Text;
            SettingsMain.ShopName        = txtShopName.Text;
            SettingsMain.LogoImageAlt    = txtImageAlt.Text;
            SettingsMain.AdminDateFormat = txtFormat.Text;
            SettingsMain.ShortDateFormat = txtShortFormat.Text;
            SettingsMain.SellerCountryId = ddlCountry.SelectedValue != string.Empty ? SQLDataHelper.GetInt(ddlCountry.SelectedValue) : 0;
            SettingsMain.Phone           = txtPhone.Text;
            SettingsMain.City            = txtCity.Text;
            SettingsMain.EnableCaptcha   = ckbEnableCheckConfirmCode.Checked;
            SettingsMain.EnableInplace   = ckbEnableInplaceEditor.Checked;

            SettingsDesign.DisplayToolBarBottom = ckbDisplayToolBarBottom.Checked;

            SettingsDesign.DisplayCityInTopPanel = ckbDisplayCityInTopPanel.Checked;
            SettingsDesign.DisplayCityBubble     = ckbDisplayCityBubble.Checked;

            SettingsMain.EnablePhoneMask = ckbEnablePhoneMask.Checked;

            if (ddlRegion.Enabled)
            {
                SettingsMain.SellerRegionId = ddlRegion.SelectedValue != string.Empty ? SQLDataHelper.GetInt(ddlRegion.SelectedValue) : 0;
            }

            if (fuLogoImage.HasFile)
            {
                if (FileHelpers.CheckFileExtension(fuLogoImage.FileName, FileHelpers.eAdvantShopFileTypes.Image))
                {
                    FileHelpers.CreateDirectory(FoldersHelper.GetPathAbsolut(FolderType.ImageTemp));
                    FileHelpers.DeleteFile(FoldersHelper.GetPathAbsolut(FolderType.Pictures, SettingsMain.LogoImageName));
                    var newFile = fuLogoImage.FileName.FileNamePlusDate("logo");
                    SettingsMain.LogoImageName = newFile;
                    fuLogoImage.SaveAs(FoldersHelper.GetPathAbsolut(FolderType.Pictures, newFile));
                    TrialService.TrackEvent(TrialEvents.ChangeLogo, "");
                }
                else
                {
                    ErrMessage = Resource.Admin_CommonSettings_InvalidLogoFormat;
                    return(false);
                }
            }

            if (fuFaviconImage.HasFile)
            {
                FileHelpers.CreateDirectory(FoldersHelper.GetPathAbsolut(FolderType.ImageTemp));

                if (FileHelpers.CheckFileExtension(fuFaviconImage.FileName, FileHelpers.eAdvantShopFileTypes.Favicon))
                {
                    FileHelpers.DeleteFile(FoldersHelper.GetPathAbsolut(FolderType.Pictures, SettingsMain.FaviconImageName));
                    var newFile = fuFaviconImage.FileName.FileNamePlusDate("favicon");
                    SettingsMain.FaviconImageName = newFile;
                    fuFaviconImage.SaveAs(FoldersHelper.GetPathAbsolut(FolderType.Pictures, newFile));
                }
                else
                {
                    ErrMessage = Resource.Admin_CommonSettings_InvalidFaviconFormat;
                    return(false);
                }
            }

            LoadData();
            return(true);
        }
Beispiel #16
0
        private int CreateCategory()
        {
            // Validation
            MsgErr(true);

            if (string.IsNullOrEmpty(txtName.Text))
            {
                MsgErr(Resource.Admin_m_Category_NoName);
                return(0);
            }
            if (string.IsNullOrEmpty(txtSynonym.Text))
            {
                MsgErr(Resource.Admin_m_Category_NoSynonym);
                return(0);
            }
            var reg = new Regex("^[a-zA-Z0-9_-]*$");

            if (!reg.IsMatch(txtSynonym.Text))
            {
                MsgErr(Resource.Admin_m_Category_SynonymInfo);
                return(0);
            }

            if (!UrlService.IsAvailableUrl(ParamType.Category, txtSynonym.Text))
            {
                MsgErr(Resource.Admin_SynonymExist);
                return(0);
            }

            if ((PictureFileUpload.HasFile && !FileHelpers.CheckFileExtension(PictureFileUpload.FileName, FileHelpers.eAdvantShopFileTypes.Image)) ||
                (MiniPictureFileUpload.HasFile && !FileHelpers.CheckFileExtension(MiniPictureFileUpload.FileName, FileHelpers.eAdvantShopFileTypes.Image)))
            {
                MsgErr(Resource.Admin_ErrorMessage_WrongImageExtension);
                return(0);
            }

            var myCat = new Category
            {
                Name                 = txtName.Text,
                ParentCategoryId     = tree.SelectedValue.TryParseInt(),
                Description          = fckDescription.Text,
                BriefDescription     = fckBriefDescription.Text,
                SortOrder            = txtSortIndex.Text.TryParseInt(),
                Enabled              = ChkEnableCategory.Checked,
                DisplayChildProducts = false,     //ChkDisplayChildProducts.Checked,
                DisplayStyle         = SubCategoryDisplayStyle.SelectedValue,
                UrlPath              = txtSynonym.Text,
                Meta                 = new MetaInfo(0, 0, MetaType.Category, txtTitle.Text, txtMetaKeywords.Text, txtMetaDescription.Text, txtH1.Text),
                Sorting              = (ESortOrder)ddlSorting.SelectedValue.TryParseInt()
            };

            try
            {
                myCat.CategoryId = CategoryService.AddCategory(myCat, true);
                if (myCat.CategoryId == 0)
                {
                    return(0);
                }

                if (PictureFileUpload.HasFile)
                {
                    var tempName = PhotoService.AddPhoto(new Photo(0, myCat.CategoryId, PhotoType.CategoryBig)
                    {
                        OriginName = PictureFileUpload.FileName
                    });
                    if (!string.IsNullOrWhiteSpace(tempName))
                    {
                        using (Image image = Image.FromStream(PictureFileUpload.FileContent))
                            FileHelpers.SaveResizePhotoFile(FoldersHelper.GetImageCategoryPathAbsolut(CategoryImageType.Big, tempName), SettingsPictureSize.BigCategoryImageWidth, SettingsPictureSize.BigCategoryImageHeight, image);
                    }
                }


                if (MiniPictureFileUpload.HasFile)
                {
                    var tempName = PhotoService.AddPhoto(new Photo(0, myCat.CategoryId, PhotoType.CategorySmall)
                    {
                        OriginName = MiniPictureFileUpload.FileName
                    });
                    if (!string.IsNullOrWhiteSpace(tempName))
                    {
                        using (Image image = Image.FromStream(MiniPictureFileUpload.FileContent))
                            FileHelpers.SaveResizePhotoFile(FoldersHelper.GetImageCategoryPathAbsolut(CategoryImageType.Small, tempName), SettingsPictureSize.SmallCategoryImageWidth, SettingsPictureSize.SmallCategoryImageHeight, image);
                    }
                }

                TrialService.TrackEvent(TrialEvents.AddCategory, "");
                return(myCat.CategoryId);
            }
            catch (Exception ex)
            {
                MsgErr(ex.Message + "at CreateCategory");
                Debug.LogError(ex, false);
            }
            return(0);
        }
        private Order CreateOrder(ShoppingCart shoppingCart)
        {
            var orderConfirmData = PageData.OrderConfirmationData;
            var customerGroup    = CustomerContext.CurrentCustomer.CustomerGroup;

            var baseCurrency = CurrencyService.BaseCurrency;

            var ord = new Order
            {
                OrderCustomer = new OrderCustomer
                {
                    CustomerIP  = Request.UserHostAddress,
                    CustomerID  = orderConfirmData.Customer.Id,
                    FirstName   = orderConfirmData.Customer.FirstName,
                    LastName    = orderConfirmData.Customer.LastName,
                    Patronymic  = orderConfirmData.Customer.Patronymic,
                    Email       = orderConfirmData.Customer.EMail,
                    MobilePhone = orderConfirmData.Customer.Phone,
                },
                OrderCurrency = new OrderCurrency
                {
                    //CurrencyCode = CurrencyService.CurrentCurrency.Iso3,
                    //CurrencyValue = CurrencyService.CurrentCurrency.Value,
                    //CurrencySymbol = CurrencyService.CurrentCurrency.Symbol,
                    //CurrencyNumCode = CurrencyService.CurrentCurrency.NumIso3,
                    //IsCodeBefore = CurrencyService.CurrentCurrency.IsCodeBefore
                    CurrencyCode    = baseCurrency.Iso3,
                    CurrencyValue   = baseCurrency.Value,
                    CurrencySymbol  = baseCurrency.Symbol,
                    CurrencyNumCode = baseCurrency.NumIso3,
                    IsCodeBefore    = baseCurrency.IsCodeBefore
                },
                OrderStatusId   = OrderService.DefaultOrderStatus,
                AffiliateID     = 0,
                OrderDate       = DateTime.Now,
                CustomerComment = orderConfirmData.CustomerComment,
                ShippingContact = new OrderContact
                {
                    Name         = orderConfirmData.ShippingContact.Name,
                    Country      = orderConfirmData.ShippingContact.Country,
                    Zone         = orderConfirmData.ShippingContact.RegionName,
                    City         = orderConfirmData.ShippingContact.City,
                    Zip          = orderConfirmData.ShippingContact.Zip,
                    Address      = orderConfirmData.ShippingContact.Address,
                    CustomField1 = orderConfirmData.ShippingContact.CustomField1,
                    CustomField2 = orderConfirmData.ShippingContact.CustomField2,
                    CustomField3 = orderConfirmData.ShippingContact.CustomField3
                },

                GroupName     = customerGroup.GroupName,
                GroupDiscount = customerGroup.GroupDiscount,
                OrderDiscount = shoppingCart.DiscountPercentOnTotalPrice
            };

            foreach (var orderItem in shoppingCart.Select(item => (OrderItem)item))
            {
                ord.OrderItems.Add(orderItem);
            }

            if (!orderConfirmData.BillingIsShipping)
            {
                ord.BillingContact = new OrderContact
                {
                    Name         = orderConfirmData.BillingContact.Name,
                    Country      = orderConfirmData.BillingContact.Country,
                    Zone         = orderConfirmData.BillingContact.RegionName,
                    City         = orderConfirmData.BillingContact.City,
                    Zip          = orderConfirmData.BillingContact.Zip,
                    Address      = orderConfirmData.BillingContact.Address,
                    CustomField1 = orderConfirmData.BillingContact.CustomField1,
                    CustomField2 = orderConfirmData.BillingContact.CustomField2,
                    CustomField3 = orderConfirmData.BillingContact.CustomField3
                };
            }

            ord.ShippingMethodId = orderConfirmData.SelectedShippingItem.MethodId;
            ord.PaymentMethodId  = orderConfirmData.SelectedPaymentItem.PaymenMethodtId;

            ord.ArchivedShippingName = orderConfirmData.SelectedShippingItem.MethodNameRate;
            ord.ArchivedPaymentName  = orderConfirmData.SelectedPaymentItem.Name;

            ord.PaymentDetails = orderConfirmData.PaymentDetails;

            if (orderConfirmData.SelectedShippingItem.Ext != null &&
                orderConfirmData.SelectedShippingItem.Ext.PickpointAddress.IsNotEmpty())
            {
                ord.OrderPickPoint = new OrderPickPoint
                {
                    PickPointId      = orderConfirmData.SelectedShippingItem.Ext.PickpointId,
                    PickPointAddress = orderConfirmData.SelectedShippingItem.Ext.PickpointAddress,
                    AdditionalData   = orderConfirmData.SelectedShippingItem.Ext.AdditionalData
                };
            }
            else if (orderConfirmData.SelectedShippingItem.Ext != null &&
                     orderConfirmData.SelectedShippingItem.Ext.Type == ExtendedType.Cdek &&
                     orderConfirmData.SelectedShippingItem.Ext.PickpointAddress.IsNullOrEmpty())
            {
                ord.OrderPickPoint = new OrderPickPoint
                {
                    PickPointId      = orderConfirmData.SelectedShippingItem.Ext.PickpointId,
                    PickPointAddress = ord.ShippingContact.Address,
                    AdditionalData   = orderConfirmData.SelectedShippingItem.Ext.AdditionalData
                };
            }
            else if (orderConfirmData.SelectedShippingItem.Type == ShippingType.CheckoutRu &&
                     orderConfirmData.SelectedShippingItem.Ext != null)
            {
                ord.OrderPickPoint = new OrderPickPoint
                {
                    PickPointId      = orderConfirmData.SelectedShippingItem.Ext.PickpointId,
                    PickPointAddress = orderConfirmData.SelectedShippingItem.Ext.Type != ExtendedType.CashOnDelivery
                        ? ord.ShippingContact.Address
                        : string.Empty,
                    AdditionalData = orderConfirmData.SelectedShippingItem.Ext.AdditionalData
                };
            }

            var certificate = shoppingCart.Certificate;
            var coupon      = shoppingCart.Coupon;

            if (certificate != null)
            {
                ord.Certificate = new OrderCertificate()
                {
                    Code  = certificate.CertificateCode,
                    Price = certificate.Sum
                };
            }
            if (coupon != null && shoppingCart.TotalPrice >= coupon.MinimalOrderPrice)
            {
                ord.Coupon = new OrderCoupon()
                {
                    Code  = coupon.Code,
                    Type  = coupon.Type,
                    Value = coupon.Value
                };
            }

            var shippingPrice = orderConfirmData.SelectedPaymentItem.Type == PaymentType.CashOnDelivery && (orderConfirmData.SelectedShippingItem.Type != ShippingType.Cdek || orderConfirmData.SelectedShippingItem.Type != ShippingType.CheckoutRu)
                                ? orderConfirmData.SelectedShippingItem.Ext != null
                                      ? orderConfirmData.SelectedShippingItem.Ext.PriceCash
                                      : 0
                                : orderConfirmData.SelectedShippingItem.Rate;

            BonusCard bonusCard = null;

            if (BonusSystem.IsActive)
            {
                bonusCard = BonusSystemService.GetCard(orderConfirmData.Customer.BonusCardNumber);
                if (bonusCard != null && orderConfirmData.UseBonuses && bonusCard.BonusAmount > 0)
                {
                    ord.BonusCost =
                        BonusSystemService.GetBonusCost(
                            shoppingCart.TotalPrice - shoppingCart.TotalDiscount + shippingPrice,
                            shoppingCart.TotalPrice - shoppingCart.TotalDiscount, bonusCard.BonusAmount);
                }
            }

            var taxTotal =
                AdvantShop.Taxes.TaxServices.CalculateTaxes(shoppingCart.TotalPrice - shoppingCart.TotalDiscount +
                                                            shippingPrice - ord.BonusCost).Where(tax => !tax.Key.ShowInPrice).Sum(tax => tax.Value);

            var paymentPrice = orderConfirmData.SelectedPaymentItem.ExtrachargeType == ExtrachargeType.Percent
                                    ? (shoppingCart.TotalPrice - shoppingCart.TotalDiscount + shippingPrice - ord.BonusCost + taxTotal) * orderConfirmData.SelectedPaymentItem.Extracharge / 100
                                    : orderConfirmData.SelectedPaymentItem.Extracharge;

            ord.ShippingCost = shippingPrice;
            ord.PaymentCost  = paymentPrice;


            ord.Number = OrderService.GenerateNumber(1); // For crash protection

            ord.OrderID = OrderService.AddOrder(ord);
            ord.Number  = OrderService.GenerateNumber(ord.OrderID); // new number
            OrderService.UpdateNumber(ord.OrderID, ord.Number);

            ModulesRenderer.OrderAdded(ord.OrderID);

            OrderService.ChangeOrderStatus(ord.OrderID, OrderService.DefaultOrderStatus);

            if (BonusSystem.IsActive && bonusCard != null)
            {
                var sumPrice = BonusSystem.BonusType == BonusSystem.EBonusType.ByProductsCostWithShipping
                       ? shoppingCart.TotalPrice - shoppingCart.TotalDiscount + shippingPrice
                       : shoppingCart.TotalPrice - shoppingCart.TotalDiscount;

                BonusSystemService.MakeBonusPurchase(bonusCard.CardNumber, sumPrice, ord.BonusCost, ord.Number, ord.OrderID);
            }



            TrialService.TrackEvent(
                ord.OrderItems.Any(item => item.Name.Contains("SM-G900F"))
                    ? TrialEvents.BuyTheProduct
                    : TrialEvents.CheckoutOrder, string.Empty);

            return(ord);
        }