protected override void OnInit(System.EventArgs e)
        {
            base.OnInit(e);

            choiceid     = Request.QueryString["cid"];
            productBvin  = Request.QueryString["id"];
            localProduct = MTApp.CatalogServices.Products.Find(productBvin);
            choice       = (Option)localProduct.Options.Where(y => y.Bvin == choiceid).FirstOrDefault();
            //choice = MTApp.CatalogServices.ProductOptions.Find(choiceid);
            if (choice.OptionType == OptionTypes.DropDownList)
            {
                this.ItemsEditor.AllowLabels = true;
            }
            else
            {
                this.ItemsEditor.AllowLabels = false;
            }
            this.ItemsEditor.OptionId = choice.Bvin;

            if (choice.OptionType == OptionTypes.DropDownList | choice.OptionType == OptionTypes.RadioButtonList)
            {
                trVariant.Visible = true;
            }

            this.PageTitle  = "Edit Product Choice";
            this.CurrentTab = AdminTabType.Catalog;
            ValidateCurrentUserHasPermission(SystemPermissions.CatalogView);
        }
        private void RenderSingleItem(StringBuilder sb, Option o, bool isAlternate)
        {

            string destinationLink = "ProductSharedChoices_Edit.aspx?id=" + o.Bvin;

            sb.Append("<tr id=\"" + o.Bvin + "\"");
            if ((isAlternate))
            {
                sb.Append(" class=\"alternaterow-padded\"");
            }
            else
            {
                sb.Append(" class=\"row-padded\"");
            }
            sb.Append("><td><a href=\"" + destinationLink + "\">");
            sb.Append(o.Name);
            sb.Append("</a></td>");
            sb.Append("<td>");
            sb.Append(o.Render());
            sb.Append("</td>");
            sb.Append("<td>");
            sb.Append("<a id=\"rem" + o.Bvin + "\" class=\"trash\" href=\"ProductSharedChoices_Delete.aspx?redirect=y&id=");
            sb.Append(o.Bvin);
            sb.Append("\" >");
            sb.Append("<img src=\"../images/buttons/delete.png\" alt=\"delete\" />");
            sb.Append("</a></td>");
            sb.Append("<td><a href=\"" + destinationLink + "\">");
            sb.Append("<img src=\"../images/buttons/edit.png\" alt=\"Edit\" />");
            sb.Append("</a></td>");
            sb.Append("</tr>");
        }
        protected override void OnInit(System.EventArgs e)
        {

            base.OnInit(e);

            choiceid = Request.QueryString["cid"];
            productBvin = Request.QueryString["id"];
            localProduct = MTApp.CatalogServices.Products.Find(productBvin);
            choice = (Option)localProduct.Options.Where(y => y.Bvin == choiceid).FirstOrDefault();
            //choice = MTApp.CatalogServices.ProductOptions.Find(choiceid);
            if (choice.OptionType == OptionTypes.DropDownList)
            {
                this.ItemsEditor.AllowLabels = true;
            }
            else
            {
                this.ItemsEditor.AllowLabels = false;
            }
            this.ItemsEditor.OptionId = choice.Bvin;

            if (choice.OptionType == OptionTypes.DropDownList | choice.OptionType == OptionTypes.RadioButtonList)
            {
                trVariant.Visible = true;
            }

            this.PageTitle = "Edit Product Choice";
            this.CurrentTab = AdminTabType.Catalog;
            ValidateCurrentUserHasPermission(SystemPermissions.CatalogView);
        }
        protected override void OnPreLoad(System.EventArgs e)
        {
            base.OnPreLoad(e);
            choiceid = Request.QueryString["id"];
            choice = MTApp.CatalogServices.ProductOptions.Find(choiceid);
            if (choice.OptionType == OptionTypes.DropDownList)
            {
                this.ItemsEditor.AllowLabels = true;
            }
            else
            {
                this.ItemsEditor.AllowLabels = false;
            }
            this.ItemsEditor.OptionId = choice.Bvin;

            if (choice.OptionType == OptionTypes.DropDownList | choice.OptionType == OptionTypes.RadioButtonList)
            {
                trVariant.Visible = true;
            }
        }
Ejemplo n.º 5
0
        private OptionList GetSampleOptions()
        {
            OptionList result = new OptionList();

            MerchantTribe.Commerce.Catalog.Option option1 = Option.Factory(OptionTypes.DropDownList);
            option1.Name      = "Color";
            option1.Bvin      = "1";
            option1.IsShared  = false;
            option1.IsVariant = true;
            option1.Items.Add(new OptionItem()
            {
                Bvin = "101", Name = "Red", OptionBvin = "1", SortOrder = 1, IsLabel = false
            });
            option1.Items.Add(new OptionItem()
            {
                Bvin = "102", Name = "Green", OptionBvin = "1", SortOrder = 2, IsLabel = false
            });
            result.Add(option1);

            MerchantTribe.Commerce.Catalog.Option option2 = Option.Factory(OptionTypes.RadioButtonList);
            option2.Name      = "Size";
            option2.Bvin      = "2";
            option2.IsShared  = false;
            option2.IsVariant = true;
            option2.Items.Add(new OptionItem()
            {
                Bvin = "201", Name = "S", OptionBvin = "2", SortOrder = 1, IsLabel = false
            });
            option2.Items.Add(new OptionItem()
            {
                Bvin = "202", Name = "M", OptionBvin = "2", SortOrder = 2, IsLabel = false
            });
            option2.Items.Add(new OptionItem()
            {
                Bvin = "203", Name = "L", OptionBvin = "2", SortOrder = 3, IsLabel = false
            });
            result.Add(option2);

            return(result);
        }
Ejemplo n.º 6
0
        protected void NewChoiceButton_Click(object sender, System.Web.UI.ImageClickEventArgs e)
        {
            this.MessageBox1.ClearMessage();

            Option opt = new Option();
            opt.SetProcessor(OptionTypes.DropDownList);

            int typeCode = 100;
            if ((int.TryParse(this.ChoiceTypes.SelectedItem.Value, out typeCode)))
            {
                opt.SetProcessor((OptionTypes)typeCode);
            }

            opt.IsShared = false;
            opt.IsVariant = false;
            opt.Name = "New Choice";

            switch (opt.OptionType)
            {
                case OptionTypes.CheckBoxes:
                    opt.Name = "New Checkboxes";
                    break;
                case OptionTypes.DropDownList:
                    opt.Name = "New Drop Down List";
                    break;
                case OptionTypes.FileUpload:
                    opt.Name = "New File Upload";
                    break;
                case OptionTypes.Html:
                    opt.Name = "New Html Description";
                    break;
                case OptionTypes.RadioButtonList:
                    opt.Name = "New Radio Button List";
                    break;
                case OptionTypes.TextInput:
                    opt.Name = "New Text Input";
                    break;
            }
            opt.StoreId = MTApp.CurrentStore.Id;

            // Trick the new option to be an already existing option if shared
            if ((this.ChoiceTypes.SelectedItem.Value.Trim().Length > 30))
            {
                opt.Bvin = this.ChoiceTypes.SelectedItem.Value;
                opt.IsShared = true;
                opt.Name = this.ChoiceTypes.SelectedItem.Text;
            }

            // Create Choice
            bool created = false;

            if ((opt.IsShared))
            {
                created = true;
            }
            else
            {
                localProduct.Options.Add(opt);
                MTApp.CatalogServices.Products.Update(localProduct);
                created = true;
            }

            // Associate Choice with Product
            if ((created))
            {
                if ((localProduct != null))
                {
                    MTApp.CatalogServices.ProductsAddOption(localProduct, opt.Bvin);                    
                    if ((opt.IsShared == false))
                    {
                        Response.Redirect("ProductChoices_Edit.aspx?cid=" + opt.Bvin + "&id=" + localProduct.Bvin);
                    }
                }
                else
                {
                    this.MessageBox1.ShowError("Unable to associate choice with product. An Administrator has been alerted to the issue.");
                    EventLog.LogEvent("ProductChoices.aspx", "Could not associate choice " + opt.Bvin + " with product " + productBvin, EventLogSeverity.Error);
                }
            }

            MTApp.CatalogServices.ProductsReloadOptions(localProduct);            
            LoadItems();
        }
Ejemplo n.º 7
0
        private void RenderSingleItem(StringBuilder sb, Option o)
        {

            string destinationLink = "ProductChoices_Edit.aspx?cid=" + o.Bvin + "&id=" + productBvin;

            sb.Append("<div class=\"dragitem\" id=\"item_" + o.Bvin + "\"><table class=\"formtable\" width=\"100%\"><tr>");
            sb.Append("<td width=\"25%\"><a href=\"" + destinationLink + "\">");
            sb.Append(o.Name);
            sb.Append("</a></td>");
            sb.Append("<td>");
            sb.Append(o.Render());
            sb.Append("</td>");

            sb.Append("<td width=\"75\">");
            if ((o.IsVariant))
            {
                sb.Append("VARIANT");
            }
            sb.Append("</td>");

            if ((o.IsShared))
            {
                sb.Append("<td width=\"75\">SHARED</td>");
            }
            else
            {
                sb.Append("<td width=\"75\"><a href=\"" + destinationLink + "\"><img src=\"../images/buttons/edit.png\" alt=\"edit\" /></a></td>");
            }

            sb.Append("<td width=\"30\"><a href=\"#\" class=\"trash\" id=\"rem" + o.Bvin + "\"");
            if ((o.IsVariant))
            {
                sb.Append("  title=\"variant\" ");
            }
            sb.Append("><img src=\"../../images/system/trashcan.png\" alt=\"Delete\" /></a></td>");
            sb.Append("<td width=\"30\"><a href=\"#\" class=\"handle\"><img src=\"../../images/system/draghandle.png\" alt=\"Move\" /></a></td>");

            sb.Append("</tr></table></div>");
        }
Ejemplo n.º 8
0
        public void ValidateVariantsForSharedOption(Option o)
        {
            if (o.IsShared)
            {
                List<Product> productsUsing = ProductsFindByOption(o.Bvin);

                foreach (Product p in productsUsing)
                {
                    ProductsReloadOptions(p);
                    VariantsReloadForProduct(p);
                    VariantsValidate(p);
                }
            }
        }
Ejemplo n.º 9
0
        public void CanAddOptionsToProductInCorrectOrder()
        {
            RequestContext c = new RequestContext();
            c.CurrentStore = new Accounts.Store();
            c.CurrentStore.Id = 342;

            MerchantTribeApplication app = MerchantTribeApplication.InstantiateForMemory(c);

            Product p = new Product();
            p.Sku = "TESTABC";
            p.ProductName = "Test Product ABC";


            Option opt = new Option();
            opt.SetProcessor(OptionTypes.CheckBoxes);
            opt.Name = "Test Option A";
            opt.Items.Add(new OptionItem() { Name = "Item A" });
            opt.Items.Add(new OptionItem() { Name = "Item B" });

            Option opt2 = new Option();
            opt.SetProcessor(OptionTypes.DropDownList);
            opt.Items.Add(new OptionItem() { Name = "Choice One" });
            opt.Items.Add(new OptionItem() { Name = "Choice Two" });

            Option opt3 = Option.Factory(OptionTypes.Html);
            opt3.Name = "Option 3";

            Option opt4 = Option.Factory(OptionTypes.Html);
            opt3.Name = "Option 4";

            Option opt5 = Option.Factory(OptionTypes.Html);
            opt3.Name = "Option 5";

            Option opt6 = Option.Factory(OptionTypes.Html);
            opt3.Name = "Option 6";

            Option opt7 = Option.Factory(OptionTypes.Html);
            opt3.Name = "Option 7";


            // Add the option
            p.Options.Add(opt);
            p.Options.Add(opt2);
            p.Options.Add(opt3);
            p.Options.Add(opt4);
            p.Options.Add(opt5);
            p.Options.Add(opt6);
            p.Options.Add(opt7);            

            Assert.IsTrue(app.CatalogServices.Products.Create(p));

            Product actual = app.CatalogServices.Products.Find(p.Bvin);
            Assert.IsNotNull(actual, "Actual product should not be null");

            Assert.AreEqual(7, actual.Options.Count, "There should be one option on the product");
            
            Assert.AreEqual(opt.Name, actual.Options[0].Name, "Option name didn't match");
            Assert.AreEqual(opt2.Name, actual.Options[1].Name, "Option2 name didn't match");
            Assert.AreEqual(opt3.Name, actual.Options[2].Name, "Option3 name didn't match");
            Assert.AreEqual(opt4.Name, actual.Options[3].Name, "Option4 name didn't match");
            Assert.AreEqual(opt5.Name, actual.Options[4].Name, "Option5 name didn't match");
            Assert.AreEqual(opt6.Name, actual.Options[5].Name, "Option6 name didn't match");
            Assert.AreEqual(opt7.Name, actual.Options[6].Name, "Option7 name didn't match");                        
        }
Ejemplo n.º 10
0
        public void CanAddOptionsToProductWithItemsInCorrectOrder()
        {
            RequestContext c = new RequestContext();
            c.CurrentStore = new Accounts.Store();
            c.CurrentStore.Id = 342;

            MerchantTribeApplication app = MerchantTribeApplication.InstantiateForMemory(c);

            Product p = new Product();
            p.Sku = "TESTABC";
            p.ProductName = "Test Product ABC";

            Option opt = new Option();
            opt.SetProcessor(OptionTypes.CheckBoxes);
            opt.Name = "Test Option";
            opt.Items.Add(new OptionItem() { Name = "Item A" });
            opt.Items.Add(new OptionItem() { Name = "Item B" });
            opt.Items.Add(new OptionItem() { Name = "Alphabet City" });
            
            // Add the option
            p.Options.Add(opt);

            Assert.IsTrue(app.CatalogServices.Products.Create(p));

            Product actual = app.CatalogServices.Products.Find(p.Bvin);
            Assert.IsNotNull(actual, "Actual product should not be null");
            
            Assert.AreEqual(1, actual.Options.Count, "There should be one option on the product");
            Assert.AreEqual(opt.Name, actual.Options[0].Name, "Option name didn't match");
            Assert.AreEqual(opt.OptionType, actual.Options[0].OptionType, "Option type was incorrect");
            
            Assert.AreEqual(3, actual.Options[0].Items.Count, "Item count on option should be 3");

            Assert.AreEqual(1, actual.Options[0].Items[0].SortOrder, "First sort order should be zero");
            Assert.AreEqual("Item A", actual.Options[0].Items[0].Name, "First Name Didn't Match");

            Assert.AreEqual(2, actual.Options[0].Items[1].SortOrder, "Second sort order should be zero");
            Assert.AreEqual("Item B", actual.Options[0].Items[1].Name, "Second Name Didn't Match");

            Assert.AreEqual(3, actual.Options[0].Items[2].SortOrder, "Third sort order should be zero");
            Assert.AreEqual("Alphabet City", actual.Options[0].Items[2].Name, "Third Name Didn't Match");
        }
        // Create or Update
        public override string PostAction(string parameters, System.Collections.Specialized.NameValueCollection querystring, string postdata)
        {
            string data = string.Empty;
            string bvin = FirstParameter(parameters);

            string isProducts = GetParameterByIndex(1, parameters);
            string productBvin = GetParameterByIndex(2, parameters);

            if (isProducts.Trim().ToLower() == "generateonly")
            {
                // Generate Variants Only
                ApiResponse<bool> response = new ApiResponse<bool>();
                Product p = MTApp.CatalogServices.Products.Find(productBvin);
                if (p == null | p.Bvin == string.Empty)
                {
                    data = MerchantTribe.Web.Json.ObjectToJson(response);
                    return data;
                }
                MTApp.CatalogServices.VariantsGenerateAllPossible(p);
                response.Content = true;
                data = MerchantTribe.Web.Json.ObjectToJson(response);
            }
            else if (isProducts.Trim().ToLower() == "products")
            {

                string generatevariants = querystring["generatevariants"];

                // Assign to Products
                ApiResponse<bool> response = new ApiResponse<bool>();
                Product p = MTApp.CatalogServices.Products.Find(productBvin);
                if (p == null || p.Bvin == string.Empty)
                {
                    data = MerchantTribe.Web.Json.ObjectToJson(response);
                    return data;
                }
                MTApp.CatalogServices.ProductsAddOption(p, bvin);
                if (generatevariants.Trim() == "1")
                {
                    MTApp.CatalogServices.VariantsGenerateAllPossible(p);
                }
                response.Content = true;
                data = MerchantTribe.Web.Json.ObjectToJson(response);
            }
            else
            {
                ApiResponse<OptionDTO> response = new ApiResponse<OptionDTO>();

                OptionDTO postedItem = null;
                try
                {
                    postedItem = MerchantTribe.Web.Json.ObjectFromJson<OptionDTO>(postdata);
                }
                catch (Exception ex)
                {
                    response.Errors.Add(new ApiError("EXCEPTION", ex.Message));
                    return MerchantTribe.Web.Json.ObjectToJson(response);
                }

                Option existing = MTApp.CatalogServices.ProductOptions.Find(postedItem.Bvin);

                if (existing == null || existing.Bvin == string.Empty)
                {
                    postedItem.StoreId = MTApp.CurrentStore.Id;

                    // Create
                    Option op = new Option();
                    if (op == null)
                    {
                        response.Errors.Add(new ApiError("NULL FACTORY", "Option Factory returned a null object"));
                        return MerchantTribe.Web.Json.ObjectToJson(response);
                    }

                    op.FromDto(postedItem);

                    bool createResult = MTApp.CatalogServices.ProductOptions.Create(op);

                    Option created = MTApp.CatalogServices.ProductOptions.Find(postedItem.Bvin);
                    if (postedItem.Items != null)
                    {
                        foreach (OptionItemDTO oi in postedItem.Items)
                        {
                            OptionItem i = new OptionItem();
                            oi.OptionBvin = created.Bvin;
                            i.FromDto(oi);
                            created.Items.Add(i);
                        }
                        MTApp.CatalogServices.ProductOptions.Update(created);
                    }
                    response.Content = ((Option)created).ToDto();
                }
                else
                {
                    response.Content = ((Option)existing).ToDto();
                }

                data = MerchantTribe.Web.Json.ObjectToJson(response);
            }

            return data;
        }
Ejemplo n.º 12
0
 public static Option Factory(OptionTypes type)
 {
     Option result = new Option();
     result.SetProcessor(type);
     return result;
 }