You are here

public function BuyXGetY::submitConfigurationForm in Commerce Core 8.2

Form submission handler.

Parameters

array $form: An associative array containing the structure of the plugin form as built by static::buildConfigurationForm().

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form. Calling code should pass on a subform state created through \Drupal\Core\Form\SubformState::createForSubform().

Overrides PromotionOfferBase::submitConfigurationForm

File

modules/promotion/src/Plugin/Commerce/PromotionOffer/BuyXGetY.php, line 315

Class

BuyXGetY
Provides the "Buy X Get Y" offer for orders.

Namespace

Drupal\commerce_promotion\Plugin\Commerce\PromotionOffer

Code

public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
  parent::submitConfigurationForm($form, $form_state);
  if (!$form_state
    ->getErrors()) {
    $values = $form_state
      ->getValue($form['#parents']);
    $this->configuration['buy_quantity'] = $values['buy']['quantity'];
    $this->configuration['buy_conditions'] = $values['buy']['conditions'];
    $this->configuration['get_quantity'] = $values['get']['quantity'];
    $this->configuration['get_conditions'] = $values['get']['conditions'];
    $this->configuration['get_auto_add'] = $values['get']['auto_add'];
    $this->configuration['offer_type'] = $values['offer']['type'];
    if ($this->configuration['offer_type'] == 'percentage') {
      $this->configuration['offer_percentage'] = Calculator::divide((string) $values['offer']['percentage'], '100');
      $this->configuration['offer_amount'] = NULL;
    }
    else {
      $this->configuration['offer_percentage'] = NULL;
      $this->configuration['offer_amount'] = $values['offer']['amount'];
    }
    $this->configuration['offer_limit'] = $values['limit']['amount'] == 0 ? 0 : $values['limit']['offer_limit'];
  }
}