Problem/Motivation
The unit_price field is supposed to be hidden on the add to cart form unless an add_to_cart form display was explicitly saved for the order item type with that field enabled.
The check in CommerceCartHooks::entityFormDisplayAlter() only removes the component when the display returned for the add_to_cart form mode is a different mode (e.g. the default fallback). When the order item type has no stored form display at all (types created in code, by migrations, recipes, or shipped in module config without displays), core returns a new runtime display whose mode is already add_to_cart, so the check passes and the "Override the unit price" checkbox is shown on the add to cart form.
Order item types created through the admin UI aren't affected, since an add_to_cart form display without unit_price is saved when the type is created.
Steps to reproduce
- Create an order item type in code, e.g.
OrderItemType::create(['id' => 'example', 'label' => 'Example', 'purchasableEntityType' => 'commerce_product_variation', 'orderType' => 'default'])->save(); - Create a product variation type using that order item type, and a product type using that variation type.
- Create a product and view it.
- The add to cart form shows the "Override the unit price" checkbox.
Proposed resolution
Also remove the unit_price component when the add_to_cart form display is new (i.e. not stored).
Remaining tasks
- Review the MR.
Issue fork commerce-3641835
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #6
jsacksick commented