Commerce core isn't going to provide a trait for cost fields on products anymore. See #2935956: Create trait for cost field.

Since none of this module is going to be added to commerce core, this module needs some polish. See #2935956: Create trait for cost field for adding fields with traits. We should do that on products and order items. Then any other code needs to be extra sure whether it's working on a product/order item that has the field (in case we're assuming the field is there right meow).

Comments

tbradbury created an issue. See original summary.

travis-bradbury’s picture

Status: Active » Needs work
StatusFileSize
new1011 bytes

Work in progress. This adds a cost trait. It's using the name "cost" instead of "field_cost". I'll need to change existing field_cost fields to cost. We probably either want this in the base module since order items must have a field even if products resolve theirs another way, but maybe order items could have the trait in the main module and products in the submodule?

travis-bradbury’s picture

Work in progress. Working on moving the trait to commerce_cost itself and setting the trait on types that already have field_cost, then moving the data over.

Also needs to change anywhere `field_cost` is used to `cost` but that should be the easy part.

travis-bradbury’s picture

StatusFileSize
new3.43 KB
travis-bradbury’s picture

StatusFileSize
new3.2 KB

Not a lot to show for the next patch but it represents some progress that's pretty cool.

I threw out most of the update hook because I saw how to use the entity trait manager to load the cost trait and install it rather than trying to install the field manually.

Though untested, this should add the trait to any product variation or order item type that has field_cost. It still needs to migrate data and I have to decide what to do about the old field_cost (probably leave it for manual deletion). And then things have to start using cost instead of field_cost.

travis-bradbury’s picture

Status: Needs work » Needs review
StatusFileSize
new6.15 KB

This should create the traits and migrate the data to the new field. Needs testing on sample data.

travis-bradbury’s picture

Status: Needs review » Needs work

$entity_trait_manager->installTrait($trait, 'commerce_product_variation', $type); should use $entity_type, not hard-coded commerce_product_variation.

travis-bradbury’s picture

#2971216-2: Move PriceWithCostWidget to the main module: shouldn't this trait be in the fields submodule so an a field-less implementation of costs you wouldn't have the trait field?