Is it possible to get the order items fields in a price resolver using Drupal 8 and Commerce 2.x?
Indeed, the resolve method in a price resolver only allow to access the purchased entity, quantity and context.
public function resolve(PurchasableEntityInterface $entity, $quantity, Context $contex) {}
I would like to:
- Define some custom fields in an "Order Item Type" (In my case the fields are dates.)
- Expose those fields in the add-to-cart form
- Define product variation and product that uses that custom order item type, to have my custom add-to-cart form
- Compute the purchased product price (in a custom Price resolver) according to field values provided in the add-to-cart form
I could use product attributes to achieve that, but unfortunately the values entered in the order item fields are not finite.
Notes
- This looks similar to https://www.drupal.org/project/commerce/issues/2836221, but I additionally need the entered field values to compute the final price
- The answer in Update commerce price field with another custom field in Drupal 8 does not apply because I cannot define a finite set of values and create variations
How do I implement this in Commerce 2.x? Did I misunderstand something?
thanks in advance