Beispiel #1
0
    private void CreateFile(string filePath, CreateShopVariables newShopVariables)
    {
        if (filePath.LastIndexOf(@"\") > 0) {
            string fileName = filePath.Substring(filePath.LastIndexOf(@"\") + 1);
            fileName = filePath.Substring(filePath.LastIndexOf(@"/") + 1);
            //copy content from resource files
            string fileContent = WAFRuntime.FileSystem.FileReadAllText(filePath);
            //set masterpage
            fileContent = fileContent.Replace("#MASTERPAGEURL#", MasterPagePath.Replace(WAFContext.PathFromRootToAppFolder,"").Replace(@"\", "/"));
            fileContent = fileContent.Replace("#CONTENTPLACEHOLDER#", ContentPlaceHolderId.Replace(WAFContext.PathFromRootToAppFolder,"").Replace(@"\", "/"));
            string newFilePath = "";
            //create template file
            string folderPath = WAFContext.PathFromRootToAppFolder + TemplateFolder.Replace(@"/", @"\");
            if (fileName.EndsWith("_code.txt")) {
                if (AddBasicStyling) {
                    fileContent = fileContent.Replace(@"//#CSS#", "");
                }
                TemplateFolder = TemplateFolder.Replace(@"\", "/");
                if (!TemplateFolder.EndsWith(@"/")) { TemplateFolder = TemplateFolder + "/"; }
                fileContent = fileContent.Replace("#TEMPLATEFOLDER#", TemplateFolder);
                newFilePath = folderPath + fileName.Replace("_code.txt", ".aspx.cs");
                if (!WAFRuntime.FileSystem.DirectoryExists(folderPath)) {
                    WAFRuntime.FileSystem.DirectoryCreate(folderPath);
                }
                WAFRuntime.FileSystem.FileWriteAllText(newFilePath, fileContent);
            } else if (fileName.EndsWith(".txt")) {
                //aspx file
                if (!WAFRuntime.FileSystem.DirectoryExists(folderPath)) {
                    WAFRuntime.FileSystem.DirectoryCreate(folderPath);
                }
                newFilePath = folderPath + fileName.Replace(".txt", ".aspx");
                WAFRuntime.FileSystem.FileWriteAllText(newFilePath, fileContent);
                //create template node
                Template template = WAFContext.Session.NewContent<Template>();
                template.Filepath = newFilePath.Replace(WAFContext.PathFromRootToAppFolder, "");
                if (fileName == "productpage.txt") {
                    template.ContentClasses.SetClassIds(new UniqueList<int>() { ProductBase.ContentClassId });

                    template.Name = Local.Text("Web.WAF.Dialogues.ShopSetupShopWizardProductPage");
                    newShopVariables.ProductTemplateNodeId = template.NodeId;
                } else if (fileName == "productcategorypage.txt") {
                    template.ContentClasses.SetClassIds(new UniqueList<int>() { ProductCategory.ContentClassId });

                    template.Name = Local.Text("Web.WAF.Dialogues.ShopSetupShopWizardPrductCategoryPage");
                    newShopVariables.ProductCategoryTemplateNodeId = template.NodeId;
                } else if (fileName == "shoppingcartpage.txt") {
                    template.ContentClasses.SetClassIds(new UniqueList<int>() { ArticleBase.ContentClassId });

                    template.Name = Local.Text("Web.WAF.Dialogues.ShopSetupShopWizardShoppingCartPage");
                    newShopVariables.ShoppingCartTemplateNodeId = template.NodeId;
                } else if (fileName == "checkoutpage.txt") {
                    template.ContentClasses.SetClassIds(new UniqueList<int>() { ArticleBase.ContentClassId });

                    template.Name = Local.Text("Web.WAF.Dialogues.ShopSetupShopWizardCheckoutPage");
                    newShopVariables.CheckoutTemplateNodeId = template.NodeId;
                } else if (fileName == "paymentandshippingpage.txt") {
                    template.ContentClasses.SetClassIds(new UniqueList<int>() { ArticleBase.ContentClassId });

                    template.Name = Local.Text("Web.WAF.Dialogues.ShopSetupShopWizardPaymentShippingPage");
                    newShopVariables.PaymentAndShippingTemplateNodeId = template.NodeId;
                } else if (fileName == "orderreceivedpage.txt") {
                    template.ContentClasses.SetClassIds(new UniqueList<int>() { ArticleBase.ContentClassId });

                    template.Name = Local.Text("Web.WAF.Dialogues.ShopSetupShopWizardOrderRecivedPage");
                    newShopVariables.OrderReceivedTemplateNodeId = template.NodeId;
                }
                template.UpdateChanges();
            } else {
                if (!WAFRuntime.FileSystem.DirectoryExists(folderPath)) {
                    WAFRuntime.FileSystem.DirectoryCreate(folderPath);
                }
                newFilePath = folderPath + fileName;
                WAFRuntime.FileSystem.FileWriteAllText(newFilePath, fileContent);
            }
        }
    }
Beispiel #2
0
    protected void btnStartAutomaticSetup_Click(object sender, EventArgs e)
    {
        TemplateFolder = txtFolder.Text;
        //create template files
        Shop shop = WAFShopHelper.GetCurrentShop();
        CreateShopVariables newShopVariables = new CreateShopVariables();
        string[] files = WAFRuntime.FileSystem.GetFiles(WAFContext.PathFromRootToAppFolder + "WAF/Edit/Webshop/Resources/");
        foreach (string filePath in files) {
            CreateFile(filePath, newShopVariables);
        }
        //create new nodes for shopping and ordering flow
        //Shopping cart node
        ArticleBase shoppingCartPage = WAFContext.Engine.SystemSession.NewContent<ArticleBase>();
        shoppingCartPage.TemplateId = newShopVariables.ShoppingCartTemplateNodeId;
        shoppingCartPage.Name = Local.Text("Web.WAF.Dialogues.ShopSetupShopWizardShoppingCartName");
        shoppingCartPage.Parent.Set(WAFContext.Session.SiteId);
        shoppingCartPage.UpdateChanges();

        //Checkout node
        ArticleBase checkoutPage = WAFContext.Engine.SystemSession.NewContent<ArticleBase>();
        checkoutPage.TemplateId = newShopVariables.CheckoutTemplateNodeId;
        checkoutPage.Name = Local.Text("Web.WAF.Dialogues.ShopSetupShopWizardCheckOutName");
        checkoutPage.Parent.Set(shoppingCartPage.NodeId);
        checkoutPage.UpdateChanges();
        //Payment and shipping node
        ArticleBase paymentPage = WAFContext.Engine.SystemSession.NewContent<ArticleBase>();
        paymentPage.TemplateId = newShopVariables.PaymentAndShippingTemplateNodeId;
        paymentPage.Name = Local.Text("Web.WAF.Dialogues.ShopSetupShopWizardPaymentAndShippingName");
        paymentPage.Parent.Set(checkoutPage.NodeId);
        paymentPage.UpdateChanges();
        //Order received node
        ArticleBase orderReceivedPage = WAFContext.Engine.SystemSession.NewContent<ArticleBase>();
        orderReceivedPage.TemplateId = newShopVariables.OrderReceivedTemplateNodeId;
        orderReceivedPage.Name = Local.Text("Web.WAF.Dialogues.ShopSetupShopWizardOrderRecivedName");
        orderReceivedPage.Parent.Set(paymentPage.NodeId);
        orderReceivedPage.UpdateChanges();
        //create new dummy products and one product category
        if (CreateProducts) {
            ProductCategory category = WAFContext.Engine.SystemSession.NewContent<ProductCategory>();

            category.Name = Local.Text("Web.WAF.Dialogues.ShopSetupShopWizardTestCategoryName");
            category.Shop.Set(shop.NodeId);
            category.TemplateId = newShopVariables.ProductCategoryTemplateNodeId;
            category.ShowInMenu = true;
            category.ShowInTree = true;
            category.Parent.Set(WAFContext.Session.SiteId);
            category.UpdateChanges();

            CreateProduct(category.NodeId, "1", Local.Text("Web.WAF.Dialogues.ShopSetupShopWizardTestProduct1"), (double)25, newShopVariables.ProductTemplateNodeId);
            CreateProduct(category.NodeId, "2", Local.Text("Web.WAF.Dialogues.ShopSetupShopWizardTestProduct2"), (double)220, newShopVariables.ProductTemplateNodeId);
            CreateProduct(category.NodeId, "3", Local.Text("Web.WAF.Dialogues.ShopSetupShopWizardTestProduct3"), (double)88, newShopVariables.ProductTemplateNodeId);
        }

        //set providers on shop:
        shop.DefaultTaxRate = 20;
        shop.TaxProviderClass = "WAF.Common.Webshop.Providers.TaxProviders.WAFFlatTaxRateCalculationProvider";
        shop.NotificationProviderClass = "WAF.Common.Webshop.Providers.NotificationProviders.DefaultWAFNotificationService";
        shop.InventoryProviderClass = "WAF.Common.Webshop.Providers.InventoryProviders.WAFDefaultInventoryProvider";

        //set order flow relations on shop:
        shop.OrderReceivedPage.Set(orderReceivedPage.NodeId);
        shop.PaymentAndShippingMethodPage.Set(paymentPage.NodeId);
        shop.CheckoutPage.Set(checkoutPage.NodeId);
        shop.ShoppingCartPage.Set(shoppingCartPage.NodeId);
        shop.UpdateChanges();

        //create payment and shipping methods and relate them to the shop
        ItemCostShippingCalculationMethod itemCostShipping = WAFContext.Engine.SystemSession.NewContent<ItemCostShippingCalculationMethod>();
        itemCostShipping.Name = "USPS";
        itemCostShipping.ItemCost = 30;
        itemCostShipping.DisplayName = "USPS";
        itemCostShipping.MaxShipCost = 200;
        itemCostShipping.MinShipCost = 30;
        itemCostShipping.ShippingCalculationProviderClass = "WAF.Common.Webshop.Providers.ShippingProviders.WAFItemCountShippingCalculationProvider";
        itemCostShipping.Shops.Add(shop.NodeId);
        itemCostShipping.UpdateChanges();

        PaymentMethod invoicePaymentMethod = WAFContext.Engine.SystemSession.NewContent<PaymentMethod>();
        invoicePaymentMethod.PaymentMethodProviderClass = "WAF.Common.Webshop.Providers.PaymentMethodProviders.WAFInvoiceProvider";
        invoicePaymentMethod.DisplayName = "Invoice";
        invoicePaymentMethod.TypeOfPayment = TypeOfPayment.OnePhase;
        invoicePaymentMethod.TestModeEnabled = true;
        invoicePaymentMethod.Name = "Invoice";
        invoicePaymentMethod.Shops.Add(shop.NodeId);
        invoicePaymentMethod.UpdateChanges();
        SetPanelVisibility(WizardPanel.SuccessMessage);
    }