- 🇧🇪Belgium Tom_VDB
I needed the language the user used to create the order.
I resorted to enabling thelangcode
field oncommerce_order
.In a custom module:
function example_entity_type_build(array &$entity_types) { $keys = $entity_types['commerce_order']->getKeys(); $keys['langcode'] = 'langcode'; $entity_types['commerce_order']->set('entity_keys', $keys); }
use Drupal\Core\Field\BaseFieldDefinition; use Drupal\Core\StringTranslation\TranslatableMarkup; /** * Add 'langcode' to 'commerce_order'. */ function example_update_8001() { $storage_definition = BaseFieldDefinition::create('language') ->setLabel(new TranslatableMarkup('Language')) ->setDisplayOptions('view', [ 'region' => 'hidden', ]) ->setDisplayOptions('form', [ 'type' => 'language_select', 'weight' => 2, ]); \Drupal::entityDefinitionUpdateManager()->installFieldStorageDefinition('langcode', 'commerce_order', 'commerce_order', $storage_definition); }
This hold the current langcode when the order is first created.
After which it is accessible with$order->langcode()