Score:0

Customer profiles cannot hold more than 1 values, even when allowing multiple profiles per user

in flag

I have custom API that creates new Customer profiles with different addresses / emails:

$profileStorage->create([
        'type' => 'customer',
        'uid' => $this->currentUser->id(),
        'status'=> 1,
        'address' => $addressData
])
$profile->setDefault(true);
$profile->save();

It works creating those profiles and attaching them to the current user. However, then after whenever I try to edit the user's account fields or just use $user->validate() I get this error:

"customer_profiles: Customer profiles: this field cannot hold more than 1 values."

However Customer Profile Type has both "Allow multiple profiles per user" and "Profiles of this type represent Commerce customer profiles" selected.

This has been the case in Drupal 8 and 9.

enter image description here

UPDATE:

It seems this error actually occurs at $entity->validate(), not on save()

enter image description here

This is the contents of core.entity_form_display.profile.customer.default.yml

uuid: xxx7f0e2-d809-4d2b-9388-af399c98xxxx
langcode: en
status: true
dependencies:
  config:
    - field.field.profile.customer.address
    - field.field.profile.customer.field_email
    - profile.type.customer
  module:
    - address
  enforced:
    module:
      - commerce_order
_core:
  default_config_hash: xxxxVkJkUSPhil9xxxxdTivMqxCUloT_71AHWxxxx
id: profile.customer.default
targetEntityType: profile
bundle: customer
mode: default
content:
  address:
    type: address_default
    weight: 0
    region: content
    settings: {  }
    third_party_settings: {  }
  field_email:
    type: email_default
    weight: 1
    region: content
    settings:
      placeholder: ''
      size: 60
    third_party_settings: {  }
hidden: {  }

and the contents of profile.type.customer.yml

uuid: xxxx4f32-xxxx-xxxx-xxxx-bd10470bxxxx
langcode: en
status: true
dependencies:
  enforced:
    module:
      - commerce_order
third_party_settings:
  commerce_order:
    customer_profile_type: true
_core:
  default_config_hash: xxxxAQDUxxxxwavxxxxlcbJx9xxxxFtCq8l73Axxxx
id: customer
label: Customer
display_label: 'Customer information'
multiple: true
registration: false
roles:
  authenticated: authenticated
  verified_email: verified_email
  verified_cc: verified_cc
allow_revisions: false
new_revision: false
Score:0
it flag

That setting means the customer may have multiple profiles of that type assigned to their uid, not that every profile reference field can itself be used for multiple value references. That said, I'm not aware of a field in Commerce Core called customer_profiles. Is this something custom? You might just need to update its definition to be able to put multiple references in it.

in flag
so am I creating / attaching the Profile incorrectly? My goal is that "the customer may have multiple profiles of that type assigned to their uid".
in flag
Also, I think "customer_profiles" is just the machine name from creating a Profile Type called "Customers". What are you exactly suggesting I update?
it flag
You have a field on your site called "Customer profiles". Where did that come from?
in flag
I posted my yml files if that might help. Also discovered the error occurs on `$user->validate()` not `$user->save()`
in flag
Also the `Customer Profiles` is a `Profile Type` not a field, provided by Commerce: https://docs.drupalcommerce.org/commerce2/developer-guide/customers/profiles/profile-configuration - along with its `field_address`. I added a`field_email`.
it flag
Ok. In that case, I don't understand the error message, which indicates a field is not validating properly. I'm not sure there's much more I can do to help.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.