-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Attributes combinations price #47
Conversation
Variants builded from attributes combinations (now we can build only from text attributes with predefined values).
Thanks for the contribution. This is a great start. I have a few demands however, to bring it more inline with the rest of the module and with what I had in mind for this feature.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my comment for details.
…ardCore.Commerce into triv/attributesPrice
This reverts commit 9a6a3c4.
Moved all logic to separate part: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the changes. I have a few additional requests, but this is getting very close. Cheers!
{ | ||
public interface IPriceVariantsService | ||
{ | ||
Dictionary<string, decimal> GetPriceVariants(ContentItem product); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should those be amounts rather than decimals?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think better to have decimal here b/c currency must be defined in base price. Variant just have other price value, not currency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, about the base price, see my other comment... I think each variant should stand on its own and not rely on the base price.
Models/PriceVariantsPart.cs
Outdated
/// </summary> | ||
public class PriceVariantsPart : ContentPart | ||
{ | ||
public Amount BasePrice { get; set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this has BasePrice, do you envision people using PricePart or this one, or both at the same time? If both at the same time, why is BasePrice necessary here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
People must use only one PricePart
or PriceVariantsPart
. Otherwise we PriceVariantsPart
will depend on PricePart
. Let me know you thoughts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is problematic.
One scenario is a business that starts with simple price. Then they add attributes to their existing products, that they want to individually price. If you have to choose between those two parts, you have no migration path, and you'll have to enter all those prices again.
Another scenario is one where you don't have a base price at all, only mandatory attributes with each a different price.
For at least those two reasons, but also for separation of concerns, I think the base price should be removed (and clearly, prices per attribute can't depend on the simple price part).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All clear. So let me know best way to save variants:
- Currency + Dictionary<string, decimal> properties.
- Dictionary<string, Amount> property.
As for me first one is better b/c all variants must have same currency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure why all variants should have the same currency actually. I could see a scenario where variants are geographically based, like a bookseller who sells translations of the same item. Just to be safe, I'd go for #2 because it offers that flexibility at a low cost (unless I'm missing something).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree! Will do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the new changes. We're getting super-close. I think the last thing is to get rid of the base price (see my comment about why).
Variants changed to dictionary 'Amount'.
Thanks for all your efforts! |
Hey @TRiV07 Alexandr! I've been playing with your work today, and one thing felt a little off: if I add the new part to an existing product, all the variant prices are initially zero. I think the initial value should be unspecified (and when that's the case, the variants price provider would not add a price to the product variant), which should be enough for the simple price provider to take over and apply the simple price (or whatever other price provider exists). Is this something you'd be willing to add? Thanks! |
In fact I've found a couple bugs that I'm fixing now, one of which is the variants price provider adding a 0 price when an attribute value is not found. The other is generating the variant key for text attributes not set to a predefined value. |
Another question: when we are generating the Cartesian product key for a specific combination of attribute values, I'm wondering if we don't have a nondeterminism in the order of the attributes that ould lead to problems, potentially. What do you think? |
Thank you for bug fixing! I believe every variant must have price, that's why used
Correct, this is potentially problem, and we need to sort somehow attributes, maybe attributes can be sorted by Id, and predefined values of attribute just by name. |
So if you look at my latest changes, I added priorities on prices. This way, the simple price part's provider can add its price at the lowest zero priority, and variants are added at priority 1. This makes it possible for the simple price strategy to select the variant price even when it's higher than the variant price (which wasn't the case before). Another consequence is that the simple price (or whatever other price you may have at priority zero) can act as a fallback when variants provide no price. I really think by default, variant prices should be unspecified. This way, the default is whatever other price the product has. It's the right default. Let's sort by attribute name (which should be of the form |
Oh, and one last thing: if the site administrator didn't configure the type to have some base price, and then doesn't specify a variant price for all variants, then the product variant has no price and can't be bought. I think that's a better outcome for what is likely a mistake than giving away the product for free. I need to check exactly what happens in this case, and that the product can't be added, not that we get some sort of exception... |
Hahaha. Of course it crashes :) |
There, I fixed it. Now if you attempt to add to the cart a product without a price, you get an error message and the product isn't added. |
Will do :) |
PricePart have prices for product variants.
Variants builded from attributes combinations (now we can build only from text attributes with predefined values).