Problem/Motivation

ContentEntityStorageInterface defines the 'createWithSampleValues' method, to help tools like layout builder provide sample values while a layout (or anything else using Context) is configured. When this is called to generate an order, it eventually calls
EntityReferenceItem::generateSampleValue() which uses EntityReferenceItem::getRandomBundle() to ascertain which bundle of entity to create. getRandomBundle() returns a random key from $selection_settings['target_bundles'] - it expects target bundles to be of the form

 [
  'bundle1' => 'bundle1',
  'bundle2' => 'bundle2',
]

- the billing profile field is not defined like this. This causes EntityReferenceItem::generateSampleValue() to make a profile entity with bundle '0' and you get an error.

Steps to reproduce

  1. Install commerce and commerce_order
  2. Run
         \Drupal::entityTypeManager()->getStorage('commerce_order')->createWithSampleValues('default');
      
  3. Get the error

Proposed resolution

Update Order::baseFieldDefinitions() to correctly set the target_bundles in the way EntityReferenceItem expects.

  ->setSetting('handler_settings', ['target_bundles' => ['customer' => 'customer']])

Remaining tasks

User interface changes

None

API changes

None

Data model changes

None

Issue fork commerce-3170998

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

rlmumford created an issue. See original summary.

rlmumford’s picture

Issue summary: View changes

rlmumford’s picture

Status: Active » Needs review
rlmumford’s picture

Status: Needs review » Closed (duplicate)

Duplicate of #3137225