I create a Checkbox in the Checkout Flow, CheckoutPane. How i can send the Value of the Checkbox to a Entity in the User-Profile or the Order.
Description: I need a Checkbox in the CheckoutPane, when the Customer select the Checkbox and click submit i must save the value in a Field in the Order or Profile of the specific user with the date. When the customer select the checkbox first time, its hidden for future orders.
The checkbox is correctly printed, but cannot submit the value of the checkbox to a entity in order, or better a entity in the user-profile. I create the Field field_customer_check in the Order and try it same as in the Drupal Commerce Checkout Flow Example with comments. https://docs.drupalcommerce.org/commerce2/developer-guide/checkout/create-custom-checkout-pane
public function submitPaneForm(array &$pane_form, FormStateInterface $form_state, array &$complete_form) {
$values = $form_state->getValue($pane_form['#parents']);
$this->order->setData('order_comment', $values['comment']);
}
Here is my previous Code for the CheckoutPane:
<?php
namespace Drupal\mymodule_checkout\Plugin\Commerce\CheckoutPane;
use Drupal\commerce_checkout\Plugin\Commerce\CheckoutPane\CheckoutPaneBase;
use Drupal\commerce_checkout\Plugin\Commerce\CheckoutPane\CheckoutPaneInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\commerce\InlineFormManager;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\commerce_checkout\Plugin\Commerce\CheckoutFlow\CheckoutFlowInterface;
/**
* Provides the completion message pane.
*
* @CommerceCheckoutPane(
* id = "agree_terms",
* label = @Translation("Permanent agree"),
* )
*/
class AgreeTerms extends CheckoutPaneBase implements CheckoutPaneInterface {
public function buildPaneForm(array $pane_form, FormStateInterface $form_state, array &$complete_form) {
$order_id = $this->order->id();
$pane_form['user_check_accept'] = [
'#type' => 'checkbox',
'#default_value' => FALSE,
'#title' =>$this->t('My Checkbox Title'),
'#required' => FALSE,
'#weight' => $this->getWeight(),
];
return $pane_form;
}
public function submitPaneForm(array &$pane_form, FormStateInterface $form_state, array &$complete_form) {
$values = $form_state->getValue($pane_form['#parents']);
// How to submit the value from a Checkbox in a Boolean Field in the Order
// Problem, field_customer_check not get any data
$this->order->setData('field_customer_check', $values['user_check_accept']);
}
}