1

I've created a custom checkout pane for commerce 2.x, Drupal version 8.7.x. I've added a textfield called field_order_notes on the order entity. The pane works, and I can run $this->order->set('field_order_notes', $values) in my pane's submit handler, and I can debug the order object and see the value's set. But when i finish the order, field_order_notes is empty on the order. Not sure what I'm missing here.

 /**
 * Adds a section for order notes.
 *
 * @CommerceCheckoutPane(
 *   id = "order_notes",
 *   label = @Translation("Order notes"),
 *   default_step = "order_information",
 * )
 */
class OrderNotes extends CheckoutPaneBase implements CheckoutPaneInterface {
  /**
   * The inline form manager.
   *
   * @var \Drupal\commerce\InlineFormManager
   */
  protected $inlineFormManager;
  /**
   * {@inheritdoc}
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, CheckoutFlowInterface $checkout_flow, EntityTypeManagerInterface $entity_type_manager) {
    parent::__construct($configuration, $plugin_id, $plugin_definition, $checkout_flow, $entity_type_manager);
  }
  /**
   * {@inheritdoc}
   */
  public function buildPaneForm(array $pane_form, FormStateInterface $form_state, array &$complete_form) {
    $pane_form['order_notes'] = [
      '#type' => 'textarea',
      '#title' => $this->t('Order notes'),
      '#default_value' => $this->order->get('field_order_notes')->getString(),
      '#required' => FALSE,
    ];
    return $pane_form;
  }
  /**
   * {@inheritdoc}
   */
  public function submitPaneForm(array &$pane_form, FormStateInterface $form_state, array &$complete_form) {
    $values = $form_state->getValue($pane_form['#parents']);
    $this->order->set('field_order_notes', $values);
  }
}
1
  • What happens if you just put a $this->order->save(); to the submit? It looks like other panes rely on the CheckoutFlowBase to save the order on "submitForm" and "redirectToStep".
    – Dylan
    Commented Jun 19, 2019 at 6:08

1 Answer 1

1

This was fixed by passing ['order_notes'] into $values.

 /**
   * {@inheritdoc}
   */
  public function submitPaneForm(array &$pane_form, FormStateInterface $form_state, array &$complete_form) {
    $values = $form_state->getValue($pane_form['#parents']);
    $this->order->set('field_order_notes', $values['order_notes']);
  }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.