Getting started with Domain Driven Design on an ecommerce site - domain-driven-design

having a tough time figuring out how to model the expected product behavior.
Basically, the customer's inventory is managed along products and skus.
A product has many skus, but a single sku accounts for several product attributes.
Let me give an example.
Let's say i'm selling you a shirt. "Shirt" is the product with some product ID. If it comes in small, medium, large, then each of those sizes would be associated with a sku #.
easy enough so far, but if the shirt also comes in multiple colors, let's say red, yellow, and green, then there will be nine skus (red/small, red/medium, red/large, yellow/small, and so on).
Add to that the challenge that the types of attributes can be different for different products. A shirt might have sizes and colors, a handbag might have different handle styles or patterns, and I won't know ahead of time, these are things that the customer needs to be able to input in an adhoc fashion.
Any ideas on how to approach this from a DDD perspective? I"ve been baking my noodle on it for a few days now.
Thanks.

First of all you have to regard each sku as a single product attribute and not combine them. If a product can have a color and a size, these are two distinct attributes, not one (as in red/small, red/medium, etc). Suppose a product has five attributes, each with 4 possible values. You would then have 4^5=1024 skus. This quickly becomes a maintenance nightmare.
So, the first two objects in your domain model should be ProductDefinition and Attribute. The reason I choose ProductDefinition as a name and not Product is that this is just a label for some product type, a shirt for example. It is not yet a small yellow shirt.
Attributes can have possible values, so this makes for a third domain object: AttributeValue. The relation between Attribute and AttributeValue is 1:n. An attribute has multiple values, a value only belongs to one attribute.
Note that AttributeValue contains all possible values for an attribute, not the actual value for a single product. This actual value becomes a relation between ProductDefinition, Attribute and AttributeValue: ProductAttributeValue. Up for the shirt example in a database model:
ProductDefinition Attribute AttributeValue
1 | Shirt 1 | Color 1 | 1 | Red
2 | Size 2 | 1 | Yellow
3 | 1 | Green
4 | 2 | Small
5 | 2 | Medium
6 | 2 | Large
We have now modeled one product definition, two attributes and three attribute values per attribute. Suppose now we want to model three shirts: a small red one, a small green one and a large yellow one. This results in the following ProductAttributeValue content (ProductId, ProductDefinitionId, AttributeId, AttributeValueId):
ProductAttributeValue
1 | 1 | 1 | 1
1 | 1 | 2 | 4
2 | 1 | 1 | 3
2 | 1 | 2 | 4
3 | 1 | 1 | 2
3 | 1 | 2 | 2

We did a system like this..
ProductDefinition
has Type (Shirt, Handbag)
has many ProductFieldDefinition
ProductFieldDefinition
has Type (Color, size, pattern)
Product
has ProductDefinition
has SKU
has many ProductField
has ProductFieldDefinition
has Value
The one thing I would change in our system is I would use a Document Database to store everything but in our case the graph actually went much deeper with each level having it's own fields.

Related

How do I sum up a score based on 2 values?

I have this excel table
Status | Priority |
-------------------
Yes | High |
No | Medium |
N/A | Medium |
Yes | Low |
A bit | Bonus |
| |
| |
Each priority has a point value. Priority points can change to anything. They aren't in order. Note that lines can also be blank. Assuming that if priority is blank then status is also blank.
High = 3 points
Medium = 2 Points
Low = 1 Point
Bonus = 1 Point
Status's can be blank or any value. However if they are the following then they have coniditions:
Yes = Full point (eg. Yes with High priority gives 3 points) or (eg. Yes with Bonus gives 1 point).
A bit = Half a point (eg. A little with High priortiy gives half 1.5 points) or (eg. A little with Medium gives 1 point). Essentially halving the point.
If the Status is Yes then I want it to count the corresponding point value. So for the table above it should count up 4.5 points.
3 Points for Row 2
1 Point for Row 5
0.5 points for Row 6
I was wondering how I can do this?
I was going to do the following, but it only has one condition.
=COUNTIF(A2:A5, "Yes")
Using Tables and Named Ranges with structured references gives you a great deal of flexibility.
I first set up two tables
priorityTbl
statusTbl
With our Input, I Named the two Ranges Status and Priority
The total is then given by the formula:
=SUMPRODUCT(IFERROR(INDEX(statusTbl,MATCH(Status,statusTbl[Status],0),2),0),
IFERROR(INDEX(priorityTbl,MATCH(Priority,priorityTbl[Priority],0),2),0))
If you want to change the values you assign to the different Priority/Status items, you merely change them in the table.
You could also add new rows to the tables, if that is appropriate.
Note that I did not bother adding to the tables rows where the value might be zero, but you could if you wanted to.

Excel syntax for getting the value in another table based on 2 cells

I would like to know what is the best syntax if i want to get the price of an item depending on the specific product and its unit of measure because a product can be sold per bag or per kilo. Here's a sample content of excel sheet. The only required input for the user is the enter product name and unit of measure in the Orders Sheet.
Orders Sheet
Item Purchased | Unit | Price
-------------------+----------+---------
Product 1 | Bag | 1000
Product 1 | Kilo | 100
~~~~~~~
Price List Sheet
Item | Unit of Measure | Price
----------+---------------------+--------
Product 1 | Bag | 1000
Product 1 | Kilo | 100
Product 2 | Bag | 2000
You can use SUMIFS, which can be used specifically when the result you want is a numeric value:
=SUMIFS(C:C, A:A, E2, B:B, F2)
That's assuming though that your price list is a true price list, meaning no item is duplicated (e.g. Product 1, Bag doesn't appear more than once).

Excel grouping by prioritized ruleset

I wonder why nobody has asked this, but how do I classify (ordinal) entries in a table according to a prioritized ruleset / tree? (possibly with naked excel and not a nested if cascade)
Minimal example (only 3 of 11 or more features shown)
Name | IsCool | IsNerdy | HasChild
Joe | 1 | 1 | 1
Charliese | 1 | 0 | 1
Peter | 1 | 0 | 0
Jonas | 0 | 0 | 0
Rules
Priority | IsCool | IsNerdy | HasChild | => Group
1. | 1 | 1 | ignore | A (at least cool&nerdy)
2. | ignore | ignore | 1 | B (not A, but has a child)
3. | 1 | 0 | 0 | C (only cool)
4. | ignore | ignore | ignore | D (everything else)
stop after first match
yielding:
Name | IsCool | IsNerdy | HasChild | Group
Joe | 1 | 1 | 1 | A
Charliese | 1 | 0 | 1 | B
Peter | 1 | 0 | 0 | C
Jonas | 0 | 0 | 0 | D
You can convert a "ruleset" into all possible combinations of the attributes (IsCool, IsNerdy, HasChild, etc) by treating "Ignore" as 0 (zero) or 1 (unity).
So, the first rule in the questions ruleset would be replaced by two rules.
IsCool ¦ IsNerdy ¦ HasChild¦ Group
1 ¦ 1 ¦ 0 ¦ A
1 ¦ 1 ¦ 1 ¦ A
Although there are only 8 possibilities across the three attributes, this approach can lead to more than 8 rules. For example in the question's ruleset, a person with the data tuple (IsCool, IsNerdy, HasChild) given by (1,1,1) would match to both Group A and Group B when the "ignore"'s in the rulset are expanded in this way. To eliminate the ambiguity this causes, it is also necessary to apply the priorities: the match to Group A has higher priority than that for B so the lookup table would include (1,1,1,A) as a row but exclude (1,1,1,B).
With a larger ruleset involving more attributes, the task of constructing the required VLOOKUPtable from the table of rules will not be without its problems, particularly if a non-manual approach is desired and just Excel is to be used rather Excel in conjunction with VBA.
An alternative approach not involving VBA which treats the ruleset as data is as follows.
Formalising the notation introduced above, a rule involving n attributes can be expressed as
(r[1],r[2],...,r[n],G)
where r[i] (i=1,...,n) can take values of 0, 1 or "ignore" and G represents the group (one of A, B, C or D in the question's example).
An instance of data can similarly be represented as
(d[1],d[2],...,d[n])
where d[i] (i=1,...,n) takes values of 0 or 1 (but not "ignore")
The rule is matched if
r[i] = "ignore" OR "d[i] = r[i]" for each i from 1 to n
There is a pretty obvious way implementing this in Excel as
=AND(OR(r[1]="ignore",d[1]=r[1]),OR(r[2]="ignore",d[2]=r[2]),...,OR(r[n]="ignore",d[n]=r[n]))
where, of course, the relevant cell references are used in place of the d[i] and r[i] placeholders shown above and the appropriate number of OR's are nested inside of the AND to replace the ... shorthand.
The pseudo-formula above has a value of either TRUE or FALSE with the former indicating the data instance matches to the rule and the latter that it does not.
However, this is not the end of the story as the rules still need to be applied in priority order.
So, extending the notation further, assume that the rules are listed in priority order (rule 1 has a higher priority than rule 2, which has a higher priority than rule 3, etc)
If cell C[k] holds the result of the applying the k'th rule to an instance of the data then modifying the above pseudo-formula so that C[k] now has the formula
=IF(OR(C[1],...,C[k-1]),FALSE,AND(...))
ensures that the k'th rule can be matched only if no earlier (and therefore higher priority) rule is matched. (Here the third part of the IF is the AND formula previously noted.)
The screengrab below shows the approach in action for the question's example.
The cells in blue are formulae. Those for TRUE/FALSE values in the second table implement the pseudo-formula discussed above. For example, cellF13 shows the result of applying rule 1 to the data instance (0,0,0) and has the following formula
=AND(OR($C$5="Ignore",$C$5=$C13),OR($D$5="Ignore",$D$5=$D13),OR($E$5="Ignore",$E$5=$E13))
NB: no IF needs to be wrapped around this formula because there is no rule with a higher priority than rule 1.
The formula for cell I13 shows the result of applying rule 4 to the same data instance and needs to take account of the higher priorities accorded to rules 1, 2 and 3. The formula in this cell is
=IF(OR($F13:H13),FALSE,AND(OR($C$8="Ignore",$C$8=$C13),OR($D$8="Ignore",$D$8=$D13),OR($E$8="Ignore",$E$8=$E13)))
The formulae in cells G13 and H13 are similar to that of I13 (left as an exercise).
By design, there can be at most one TRUE value in each row and, if the ruleset is sound, there should be exactly one such value. The formulae in the final column of the second table make this asssumption about the ruleset and simply pick out the relevant value from the final column of the first table corresponding to whichever rule shows as TRUE.
The formula in cell J13 is
=INDEX(F$5:F$8,SUMPRODUCT(1*(F13:I13),F$12:I$12))
The formulae in range F13:J13 were simply copied down the rows of the table to cells F14:J20
You could do this by creating a key in your data (e.g. Joe = "111", Charliese = "101", etc.), and then it's just a vlookup against your ruleset which contains all possible combinations of the key.

How to get two+ rows to link together? Excel 2010 (Example)

I have a parts list with competitor pricing. One part number brings multiple brands up with the location of the company.
As you can see from the picture, I have part numbers for one item with three companies. I want to sort by part type. So for example I want to list only the brake pads. When I do this the blanks get sent to the bottom, but the blanks are not really blanks because they have additional info with them for that part number.
Column 1 | Column 2 | Column 3 | Column 4 | Column 5 | Column 6 | Column 7
Part No | Company A | Price | Company B | Price | Company C | Price
4656546 | Brand A | $5 | Brand A | $5 | Brand A | $5
(BLANK) | Brand b | $8 | Brand b | $8 | Brand b | $8
I have tried to use a helper column, but I have 1,000+ rows.
Does anyone know if you can link or have a relationship between two+ rows?
I hope you understand and if not. I can try to explain better.
I asume that a "blank" in PartNo means "take the PartNo from the cell above" ...
In order to normalize the PartNo (= get rid of the blanks) use another PartNo-Normalized column (e.g. [K:K]) and normalize as following:
K1 ="PartNo-Normalized"
K2:Kxx =IF(A2<>"",A2,K1)
Next convert all formulas in [K:K] into values !!! (Copy / PasteAs - Values) before sorting ... as a sort operation will destroy the calculated values.
After conversion to values it's save to sort, and you may create a filter on that column.
Depending on how well organized your data is, it might be a good idea to add one more column and fill it with 1, 2, 3, 4, 5 ... before any sorting so you can restore the original sort order just in case something nasty happens.

Excel Graph - Category and Subcategory grouping

I seldom if ever use excel and have no deep understanding of graphs and graphing-related functions. Having said that...
I have dozens of rows of data, composed by 4 columns
column 1 = amount/price (in numbers)
column 2 = description (the what
in text)
column 3 = category (in text)
column 4 = subcategory (in
text)
I want to make a bar graph of my rows of data so that, the end result looks like this:
X axis - categories
Y axis - amount/price
The trick here is for categories NOT to repeat themselves. For example, if our data is something like...
100 | boat purchase | boats | 3 engine boat
200 | boat purchase |
boats | 2 engine boat
500 | plane purchase | planes | 4 engine plane
900 | car purchase | cars | 1 engine car
Then there should only be ONE instance of boats, planes and cars in my graph, under which all associated data would be summed up.
Last but not least, I have seen graphs where, these unique-not-repeated categories, instead of just being one single 'bar' so to speak, are composed of smaller bars. In this case, I want these smaller bars to be the sub categories, so that the end result would look like this:
In that sample image, I first present a 'basic, classic' graph where blue, yellow and red each represent a unique, different category. Right below it is what I want, a 'breakdown' of each category by subcategory where blue/yellow/red each represent an imaginary 3 different subcategories per category.
This means subcategories will repeat themselves for each category, but categories themselves will not.
For clarification, I currently only have 3 main categories and 6 or so sub-categories, but this could change in the future, hence the desire to have this in an automatic/dynamic fashion
Kind regards
G.Campos
EDIT: new image:
Here i my take on it. Unfortunately I can't post the screenshots as I don't have enough posts.
One solution is to use pivot charts put Amount in "Values", Category in "Row Lables", and SubCategory in "Column Labels".
I uploaded relevant images on a free image upload service.
This is our source data:
Amount Decription Category SubCategory
100 boat purchase boats 3 engine boat
200 boat purchase boats 2 engine boat
500 plane purchase planes 4 engine plane
900 car purchase cars 1 engine car
450 boat purchase boats 2 engine boat
110 plane purchase planes 4 engine plane
550 car purchase cars 1 engine car
230 car purchase cars 2 engine car
450 car purchase cars 5 engine car
This is the desired graph (Edit: This has ghost bars):
http://imageshack.us/photo/my-images/849/pivot.gif/
I just read the comment about no ghost graphs. This might be what you are looking for:
http://imageshack.us/photo/my-images/266/pivotnoghost.gif/
Just googled and found something very similar here:
peltiertech.com/WordPress/using-pivot-table-data-for-a-chart-with-a-dual-category-axis/
You need to add http:// ( I can't have more than two hyperlinks due to low number of posts)
I am not sure this will get you exactly where you want but I find in general in excel it is easiest to summarize your graph data on a separate tab.
For sample data like this
you would create a 2nd tab in the sheet that appears something like
the totals are calculated by using the sumif formula
=SUMIF(Data!C:C,Summary!A2,Data!A:A)
For the Category totals
and
=SUMIF(Data!D:D,Summary!E2,Data!A:A)
For the sub category totals (Assuming sub-categories are mutally exclusive). Now that that data is summarized, highlight the cells and insert a column chart for the following charts.
Adding new categories and/or sub categories will require you to add lines to the summary data, and then add series to the charts. You could use a vba macro to automate that task but I suspect that is overkill since your dataset is "dozens" rather than "thousands"

Resources