This issue is related to #1124144: how to setup drupal for a school scenario?.

In the issue that I linked to above, Ryan has made a very good fix to the whole problem, that if you change a price field in the UI the price component won't get update. Since a lot of stuff is going on with the price you usually want to change: the line item unit price, a lot of special care is needed for price field, since we might have taxes, discounts etc, that could get effected by the price change.

The problem is that every price field that is added by the users won't have these price components. This is especially needed when people start making custom line items, that should be added to orders. Right now we require that they know a lot about how the internal price handling is done for commerce. I have done a lot experience in this area since the early alpha of commerce, and I think we could help developers a lot by adding some default price handling.

Another benefit of this, is less code to maintain. To set a value on an empty price field, you would simply set the amount and currency code. To change a price, you would change the amount and let the price field handle the rest. This simple approach can't handle all cases, as we've seen in the above issue, but providing a default handling that just works for most cases, seems like a good addition to me.

Comments

googletorp’s picture

Status: Needs review » Active

The issue I wanted to link to above is #1124414: Changing a unit price on a non-cart order preserves stale price data

I've added a patch that relies on the patch made for #1192200: commerce_price_component_add always adds a base price component to the price components., since I added support for using different price components than the base_price (very handy for the shipping module). The patch consist of two parts.

1. I've added a setting on price fields, where you can select the default price component type for the field.
2. I've added price handling in the presave that will, 1. Add a price component if none is there, update the "main" price component if needed.

I've also made it possible to turn this default price handling of via the API when creating the price field, to make this as helpful and less intrusive as possible.

I've tested this patch with a single VAT item, to make sure that this doesn't conflict with patch made by Ryan to fix the original issue. I couldn't find any bugs, and setting /changing the price via code or UI works great.

I've committed this to my sandbox

googletorp’s picture

Status: Active » Needs review

And set status

googletorp’s picture

Status: Active » Needs review
Issue tags: +1.3 review

Ryan could you look at this.

I'm not sure this is needed anymore or if you managed to fix it somewhere else in the process, but would be nice to either get this in or close this issue if we don't want to go this route.

joelpittet’s picture

Issue summary: View changes
Status: Needs review » Active

There is no patch, this issue is active. @see https://www.drupal.org/node/156119#needs-review