产品选项不同的定价域设计

时间:2011-10-26 09:25:19

标签: c# sql-server domain-driven-design

我的问题是我应该如何为具有不同价格的产品选项设计我的课程?

想象一下“漂亮的T恤”,一般期权的价格是10美元。 但如果“颜色”是“蓝色”而“尺寸”是“XL”则需要12美元。 如果“颜色”为“红色”且“尺寸”为“M”则为8美元。

我计划了这样的事情......

        ProductOptionGroup pogSize = new ProductOptionGroup() { Name = "Size" };
        ProductOptionGroup pogColor = new ProductOptionGroup() { Name = "Color" };

        ProductOptions poSize = new ProductOptions();
        poSize.Add(new ProductOption() { Name = "XL", ProductOptionGroup = pogSize });
        poSize.Add(new ProductOption() { Name = "L", ProductOptionGroup = pogSize });
        poSize.Add(new ProductOption() { Name = "M", ProductOptionGroup = pogSize });

        ProductOptions poColor = new ProductOptions();
        poColor.Add(new ProductOption() { Name = "Blue", ProductOptionGroup = pogColor });
        poColor.Add(new ProductOption() { Name = "Red", ProductOptionGroup = pogColor });

        ProductOptions poBlueXL = new ProductOptions();
        poColor.Add(poColor.First(x => x.Name == "Blue"));
        poColor.Add(poSize.First(x => x.Name == "XL"));

        ProductOptions poRedM = new ProductOptions();
        poRedM.Add(poColor.First(x => x.Name == "Red"));
        poRedM.Add(poSize.First(x => x.Name == "M"));

        ProductOptionPrice popBlueXL = new ProductOptionPrice() { ProductOptionsForDifferentPrices = poBlueXL, Price = 12 };
        ProductOptionPrice popRedM = new ProductOptionPrice() { ProductOptionsForDifferentPrices = poRedM, Price = 8 };

        ProductOptionPrices pop = new ProductOptionPrices();
        pop.Add(popBlueXL);
        pop.Add(popRedM);

        Product p = new Product()
        {
            Name = "Nice T-Shirt",
            Price = 10,
            HasDifferentPriceOptions = true,
            ProductOptionPrices = pop
        };

我很困惑的一点是应该将ProductOptionPrice保留为产品属性吗? 任何其他改进的评论都会很好:)

另一方面,我计划将产品保留在DB中,就像这个架构一样 http://www.ecommerce-database.com/ecommerce-database-design/how-to-keep-products-on-ecommerce.htm

0 个答案:

没有答案