When looking deeply at the line item, I found out that the price of a line item need not be the price of its variant. A number of things can come inbetween: Currencies, Price modifiers from the variant, or hard-setting a line item's price. In a large way, that's also how the test suite is structured: The line item factory makes line items worth 10, while the associated variant is 19.99.
That's very flexible, but a little unfortunate for the upcoming MOSS refactoring. For MOSS, prices have to change depending on the order's tax address. Previously, we helped ourselves by using the variant's price as the single source of truth. However, the variant's price is not necessarily the right price for your already price-adjusted line item.
What do you think about the following idea: We introduce price modifier adjustments. They can be added to a line item the same way a promotion or tax adjustment is added, and their sum is then added to the line item's price. I'll try to illustrate this in pseudo-ruby:
class Adjustment
scope :price_modifier, -> { where(price_modifier: true) }
end
class LineItem
def price
super + price_modifier_total
end
end
VAT rates will have to make price modifications, so they can be the adjustment's source. I think the model would also quite nicely fit the existing, variant-based price modifiers: The source is the variant, and the tax stuff just wouldn't touch those adjustments.
I hope I've explained myself well here. The nice thing about it would be that we could adjust and re-adjust line item prices in a transparent, reproducible way. The not-so-nice-thing is that it would introduce yet another complex moving piece, but if we have to do it, let's at least do it in a way that mirrors other complex moving pieces.
What do you think?
When looking deeply at the line item, I found out that the price of a line item need not be the price of its variant. A number of things can come inbetween: Currencies, Price modifiers from the variant, or hard-setting a line item's price. In a large way, that's also how the test suite is structured: The line item factory makes line items worth 10, while the associated variant is 19.99.
That's very flexible, but a little unfortunate for the upcoming MOSS refactoring. For MOSS, prices have to change depending on the order's tax address. Previously, we helped ourselves by using the variant's price as the single source of truth. However, the variant's price is not necessarily the right price for your already price-adjusted line item.
What do you think about the following idea: We introduce price modifier adjustments. They can be added to a line item the same way a promotion or tax adjustment is added, and their sum is then added to the line item's price. I'll try to illustrate this in pseudo-ruby:
VAT rates will have to make price modifications, so they can be the adjustment's source. I think the model would also quite nicely fit the existing, variant-based price modifiers: The source is the variant, and the tax stuff just wouldn't touch those adjustments.
I hope I've explained myself well here. The nice thing about it would be that we could adjust and re-adjust line item prices in a transparent, reproducible way. The not-so-nice-thing is that it would introduce yet another complex moving piece, but if we have to do it, let's at least do it in a way that mirrors other complex moving pieces.
What do you think?