You are here

public function MailchimpEcommerceAdminSettings::_submitForm in Mailchimp E-Commerce 8

1 call to MailchimpEcommerceAdminSettings::_submitForm()
MailchimpEcommerceAdminSettings::submitForm in src/Form/MailchimpEcommerceAdminSettings.php
Form submission handler.

File

src/Form/MailchimpEcommerceAdminSettings.php, line 208

Class

MailchimpEcommerceAdminSettings

Namespace

Drupal\mailchimp_ecommerce\Form

Code

public function _submitForm(array &$form, \Drupal\Core\Form\FormStateInterface $form_state) {
  $store_id = \Drupal::config('mailchimp_ecommerce.settings')
    ->get('mailchimp_ecommerce_store_id');
  if (\Drupal::config('mailchimp_ecommerce.settings')
    ->get('mailchimp_ecommerce_store_id') == NULL) {
    $store_id = mailchimp_ecommerce_generate_store_id();
    \Drupal::configFactory()
      ->getEditable('mailchimp_ecommerce.settings')
      ->set('mailchimp_ecommerce_store_id', $store_id)
      ->save();
  }
  if ($store_id != NULL) {
    $currency = $form_state
      ->getValue([
      'mailchimp_ecommerce_currency',
    ]);
    $platform = !empty($form_state
      ->getValue('platform')) ? $form_state
      ->getValue('platform') : '';

    // Determine if a store is being created or updated.
    $existing_store = $this->store_handler
      ->getStore($store_id);
    if (empty($existing_store)) {
      $store = [
        'list_id' => !$form_state
          ->getValue([
          'mailchimp_ecommerce_list_id',
        ]) ? $form_state
          ->getValue([
          'mailchimp_ecommerce_list_id',
        ]) : \Drupal::config('mailchimp_ecommerce.settings')
          ->get('mailchimp_ecommerce_list_id'),
        'name' => $form_state
          ->getValue([
          'mailchimp_ecommerce_store_name',
        ]),
        'currency_code' => $currency,
      ];
      $this->store_handler
        ->addStore($store_id, $store, $platform);
    }
    else {
      $this->store_handler
        ->updateStore($store_id, $form_state
        ->getValue([
        'mailchimp_ecommerce_store_name',
      ]), $currency, $platform);
    }
  }
}