Last active
June 1, 2023 14:36
-
-
Save junaidpv/fb577b891f3873e693041865c181e5f5 to your computer and use it in GitHub Desktop.
Modified patch of https://www.drupal.org/project/commerce/issues/3082613#comment-14787941 to apply over already applied other patches.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/modules/checkout/config/install/commerce_checkout.commerce_checkout_flow.default.yml b/modules/checkout/config/install/commerce_checkout.commerce_checkout_flow.default.yml | |
| index c350ab28..630c7852 100644 | |
| --- a/modules/checkout/config/install/commerce_checkout.commerce_checkout_flow.default.yml | |
| +++ b/modules/checkout/config/install/commerce_checkout.commerce_checkout_flow.default.yml | |
| @@ -11,6 +11,7 @@ configuration: | |
| login: | |
| allow_guest_checkout: true | |
| allow_registration: false | |
| + new_registration_mail: '' | |
| step: login | |
| weight: 0 | |
| contact_information: | |
| @@ -29,7 +30,10 @@ configuration: | |
| format: plain_text | |
| step: complete | |
| weight: 4 | |
| + completion_register: | |
| + new_registration_mail: '' | |
| + weight: 5 | |
| order_summary: | |
| view: null | |
| step: _sidebar | |
| - weight: 5 | |
| + weight: 6 | |
| diff --git a/modules/checkout/config/schema/commerce_checkout.schema.yml b/modules/checkout/config/schema/commerce_checkout.schema.yml | |
| index dffb610d..a323fd8d 100644 | |
| --- a/modules/checkout/config/schema/commerce_checkout.schema.yml | |
| +++ b/modules/checkout/config/schema/commerce_checkout.schema.yml | |
| @@ -78,6 +78,9 @@ commerce_checkout.commerce_checkout_pane.login: | |
| register_form_title: | |
| type: string | |
| label: 'Title For New Customer Form' | |
| + new_registration_mail: | |
| + type: string | |
| + label: 'Send registration email' | |
| commerce_checkout.commerce_checkout_pane.order_summary: | |
| type: commerce_checkout_pane_configuration | |
| @@ -94,6 +97,13 @@ commerce_checkout.commerce_checkout_pane.completion_message: | |
| label: 'message' | |
| translatable: true | |
| +commerce_checkout.commerce_checkout_pane.completion_register: | |
| + type: commerce_checkout_pane_configuration | |
| + mapping: | |
| + new_registration_mail: | |
| + type: string | |
| + label: 'Send registration email' | |
| + | |
| commerce_checkout_pane_configuration: | |
| type: mapping | |
| mapping: | |
| diff --git a/modules/checkout/src/Plugin/Commerce/CheckoutPane/CompletionRegister.php b/modules/checkout/src/Plugin/Commerce/CheckoutPane/CompletionRegister.php | |
| index 3fe770ff..180c5c0b 100644 | |
| --- a/modules/checkout/src/Plugin/Commerce/CheckoutPane/CompletionRegister.php | |
| +++ b/modules/checkout/src/Plugin/Commerce/CheckoutPane/CompletionRegister.php | |
| @@ -136,6 +136,63 @@ class CompletionRegister extends CheckoutPaneBase implements CheckoutPaneInterfa | |
| ); | |
| } | |
| + | |
| + /** | |
| + * {@inheritdoc} | |
| + */ | |
| + public function defaultConfiguration() { | |
| + return [ | |
| + 'new_registration_mail' => '', | |
| + ] + parent::defaultConfiguration(); | |
| + } | |
| + | |
| + /** | |
| + * {@inheritdoc} | |
| + */ | |
| + public function buildConfigurationSummary() { | |
| + if (!empty($this->configuration['new_registration_mail'])) { | |
| + $summary = '<br>' . $this->t('Registration: Send new account email (' . $this->configuration['new_registration_mail'] . ')'); | |
| + } | |
| + else { | |
| + $summary = '<br>' . $this->t('Registration: Do not send new account email'); | |
| + } | |
| + | |
| + return $summary; | |
| + } | |
| + | |
| + /** | |
| + * {@inheritdoc} | |
| + */ | |
| + public function buildConfigurationForm(array $form, FormStateInterface $form_state) { | |
| + $form = parent::buildConfigurationForm($form, $form_state); | |
| + $config_notify = \Drupal::configFactory()->get('user.settings')->get('notify'); | |
| + $form['new_registration_mail'] = [ | |
| + '#type' => 'select', | |
| + '#title' => $this->t('Send email after registration?'), | |
| + '#options' => array_merge(['' => 'Do not send'], array_combine(array_keys($config_notify), array_keys($config_notify))), | |
| + '#default_value' => $this->configuration['new_registration_mail'], | |
| + '#states' => [ | |
| + 'visible' => [ | |
| + ':input[name="configuration[panes][login][configuration][allow_registration]"]' => ['checked' => TRUE], | |
| + ], | |
| + ], | |
| + ]; | |
| + | |
| + return $form; | |
| + } | |
| + | |
| + /** | |
| + * {@inheritdoc} | |
| + */ | |
| + 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['new_registration_mail'] = $values['new_registration_mail']; | |
| + } | |
| + } | |
| + | |
| /** | |
| * {@inheritdoc} | |
| */ | |
| @@ -263,6 +320,9 @@ class CompletionRegister extends CheckoutPaneBase implements CheckoutPaneInterfa | |
| $form_state->setRedirectUrl($url); | |
| } | |
| $this->messenger()->addStatus($this->t('Registration successful. You are now logged in.')); | |
| + if (!empty($this->configuration['new_registration_mail'])) { | |
| + _user_mail_notify($this->configuration['new_registration_mail'], $account); | |
| + } | |
| } | |
| } | |
| diff --git a/modules/checkout/src/Plugin/Commerce/CheckoutPane/Login.php b/modules/checkout/src/Plugin/Commerce/CheckoutPane/Login.php | |
| index aecb96a6..3fcc7bd3 100644 | |
| --- a/modules/checkout/src/Plugin/Commerce/CheckoutPane/Login.php | |
| +++ b/modules/checkout/src/Plugin/Commerce/CheckoutPane/Login.php | |
| @@ -144,6 +144,7 @@ class Login extends CheckoutPaneBase implements CheckoutPaneInterface, Container | |
| 'registration_form_mode' => 'register', | |
| 'returning_customer_form_title' => '', | |
| 'register_form_title' => '', | |
| + 'new_registration_mail' => '', | |
| ] + parent::defaultConfiguration(); | |
| } | |
| @@ -173,6 +174,13 @@ class Login extends CheckoutPaneBase implements CheckoutPaneInterface, Container | |
| $summary .= $this->t('Title For New Customer Form: ') . $this->configuration['register_form_title'] . '<br>'; | |
| } | |
| + if (!empty($this->configuration['new_registration_mail'])) { | |
| + $summary .= '<br>' . $this->t('Registration: Send new account email (' . $this->configuration['new_registration_mail'] . ')'); | |
| + } | |
| + else { | |
| + $summary .= '<br>' . $this->t('Registration: Do not send new account email'); | |
| + } | |
| + | |
| return $summary; | |
| } | |
| @@ -212,6 +220,18 @@ class Login extends CheckoutPaneBase implements CheckoutPaneInterface, Container | |
| '#title' => $this->t('Title For New Customer Form'), | |
| '#default_value' => $this->configuration['register_form_title'], | |
| ]; | |
| + $config_notify = \Drupal::configFactory()->get('user.settings')->get('notify'); | |
| + $form['new_registration_mail'] = [ | |
| + '#type' => 'select', | |
| + '#title' => $this->t('Send email after registration?'), | |
| + '#options' => array_merge(['' => 'Do not send'], array_combine(array_keys($config_notify), array_keys($config_notify))), | |
| + '#default_value' => $this->configuration['new_registration_mail'], | |
| + '#states' => [ | |
| + 'visible' => [ | |
| + ':input[name="configuration[panes][login][configuration][allow_registration]"]' => ['checked' => TRUE], | |
| + ], | |
| + ], | |
| + ]; | |
| return $form; | |
| } | |
| @@ -229,6 +249,7 @@ class Login extends CheckoutPaneBase implements CheckoutPaneInterface, Container | |
| $this->configuration['registration_form_mode'] = $values['registration_form_mode']; | |
| $this->configuration['returning_customer_form_title'] = $values['returning_customer_form_title']; | |
| $this->configuration['register_form_title'] = $values['register_form_title']; | |
| + $this->configuration['new_registration_mail'] = $values['new_registration_mail']; | |
| } | |
| } | |
| @@ -461,6 +482,9 @@ class Login extends CheckoutPaneBase implements CheckoutPaneInterface, Container | |
| if (!$form_state->hasAnyErrors()) { | |
| $account->save(); | |
| $form_state->set('logged_in_uid', $account->id()); | |
| + if ($this->configuration['allow_registration'] && !empty($this->configuration['new_registration_mail'])) { | |
| + _user_mail_notify($this->configuration['new_registration_mail'], $account); | |
| + } | |
| } | |
| break; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment