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

  1. Create an order item type in code, e.g. OrderItemType::create(['id' => 'example', 'label' => 'Example', 'purchasableEntityType' => 'commerce_product_variation', 'orderType' => 'default'])->save();
  2. Create a product variation type using that order item type, and a product type using that variation type.
  3. Create a product and view it.
  4. 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

Command icon 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

jsacksick created an issue. See original summary.

  • jsacksick committed 152b69af on 4.x
    fix: #3641835 Hide the unit price on the add to cart form when no form...

  • jsacksick committed 6b2256f7 on 3.x
    fix: #3641835 Hide the unit price on the add to cart form when no form...
jsacksick’s picture

Status: Active » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.