Add property to ProductVariationType via hook_entity_type_build() Hy guys,

I'm trying to implement a simple stock management in my e-commerce. The ProductVariation will have a stock_quantity field used to track product availability.

I would like that stock_quantity field is shown only if user checks an enable_stock_management checkbox on ProductVariation bundle edit page. I.e. /admin/commerce/config/product-variation-types/default/edit

In other words I would like to mimic Submission form settings, Menu settings, Display settings functionalities of Node's bundles.

By Google-ing a bit I think that hook_entity_type_build() is the hook to use. But, once I'm in the hook what I'm supposed to do in order to add the property I need and display it in the edit form?

 /**
  * Implements hook_entity_type_build().
  */
 function commerce_warehouse_entity_type_build(array &amp;$entity_types) {
     /** @var \Drupal\Core\Entity\EntityTypeInterface[] $entity_types */
     $entity_types['commerce_product_variation_type']-&gt; # ... And now?;
 }
Ends up that hook_entity_type_build() is not the right way to implement what I want. I found a solution usign ThirdPartySettingsInterface, which every ConfigEntityBase implements.

First I've altered ProductVariationType form via hook_form_alter() in order to add a checkbox to the form and register a new #enity_builder.

/**
 * Implements hook_form_BASE_FORM_ID_alter().
 */
function MY_MODULE_form_BASE_FORM_ID_alter(&amp;$form, FormStateInterface $form_state, $form_id) {
  /** @var ProductVariationTypeInterface $entity */
  $entity = $form_state-&gt;getFormObject()-&gt;getEntity();

  $form['warehouse_management'] = [
    '#type' =&gt; 'checkbox',
    '#title' =&gt; t('Enable warehouse management'),
    '#default_value' =&gt; $entity-&gt;getThirdPartySetting('commerce_warehouse', 'warehouse_management'),
  ];

  $form['#entity_builders'][] = 'MY_MODULE_entity_ENTITY_ID_builder';
}


Then I've defined my custom entity builder function where I register my third party setting. Pretty simple! This article helps me out a lot.

/**
 * Entity builder for commerce_product_variation_type entity.
 */
function MY_MODULE_entity_ENTITY_ID_builder($entity_type, ProductVariationTypeInterface $entity, &amp;$form, FormStateInterface $form_state) {
  $entity-&gt;setThirdPartySetting('commerce_warehouse', 'warehouse_management', $form_state-&gt;getValue('warehouse_management'));
}