created nominative terms in pricing checkout flow
This commit is contained in:
		@@ -35,31 +35,41 @@ configuration:
 | 
			
		||||
      step: order_information
 | 
			
		||||
      weight: 2
 | 
			
		||||
      nid: '1'
 | 
			
		||||
    materio_commerce_agree_nominative:
 | 
			
		||||
      path: /pricing/multijoueur
 | 
			
		||||
      text: "I have taken note that the membership of materialO 'is exclusively nominative. \r\nThe use of an account by more than one person is not allowed.\r\nI can fill the %multi form for multi user order."
 | 
			
		||||
      link_text: Multi-Joueur
 | 
			
		||||
      invalid_text: 'You must agree with the nominative terms before continuing'
 | 
			
		||||
      step: order_information
 | 
			
		||||
      weight: 3
 | 
			
		||||
      prefix_text: 'I agree with the %terms'
 | 
			
		||||
      new_window: '1'
 | 
			
		||||
      nid: '1'
 | 
			
		||||
    review:
 | 
			
		||||
      step: review
 | 
			
		||||
      weight: 3
 | 
			
		||||
      weight: 4
 | 
			
		||||
    stripe_review:
 | 
			
		||||
      button_id: edit-actions-next
 | 
			
		||||
      step: review
 | 
			
		||||
      weight: 4
 | 
			
		||||
      weight: 5
 | 
			
		||||
    payment_process:
 | 
			
		||||
      capture: true
 | 
			
		||||
      step: payment
 | 
			
		||||
      weight: 5
 | 
			
		||||
      weight: 6
 | 
			
		||||
    completion_message:
 | 
			
		||||
      message:
 | 
			
		||||
        value: "<p class=\"welcom\">[current-user:customer:address:given_name] [current-user:customer:address:family_name] thank you and welcome to <strong>[site:name]</strong>!</p>\r\n\r\n<p class=\"base\">Once your order is confirmed, immediatly in case of credit card payment, you will have full access to our <a href=\"/base\">8000+ materials</a></p>\r\n\r\n<p class=\"order\"> </p>\r\n"
 | 
			
		||||
        format: wysiwyg
 | 
			
		||||
      step: complete
 | 
			
		||||
      weight: 6
 | 
			
		||||
      weight: 7
 | 
			
		||||
    order_summary:
 | 
			
		||||
      view: commerce_checkout_order_summary
 | 
			
		||||
      step: _sidebar
 | 
			
		||||
      weight: 7
 | 
			
		||||
      weight: 8
 | 
			
		||||
    coupon_redemption:
 | 
			
		||||
      allow_multiple: false
 | 
			
		||||
      step: _sidebar
 | 
			
		||||
      weight: 8
 | 
			
		||||
      weight: 9
 | 
			
		||||
    email_registration_login:
 | 
			
		||||
      allow_guest_checkout: true
 | 
			
		||||
      allow_registration: false
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,161 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace Drupal\materio_commerce\Plugin\Commerce\CheckoutPane;
 | 
			
		||||
 | 
			
		||||
use Drupal\Core\Form\FormStateInterface;
 | 
			
		||||
use Drupal\commerce_checkout\Plugin\Commerce\CheckoutPane\CheckoutPaneBase;
 | 
			
		||||
use Drupal\commerce_checkout\Plugin\Commerce\CheckoutPane\CheckoutPaneInterface;
 | 
			
		||||
use Drupal\node\Entity\Node;
 | 
			
		||||
use Drupal\Core\Url;
 | 
			
		||||
use Drupal\Core\Link;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Provides the completion message pane.
 | 
			
		||||
 *
 | 
			
		||||
 * @CommerceCheckoutPane(
 | 
			
		||||
 *   id = "materio_commerce_agree_nominative",
 | 
			
		||||
 *   label = @Translation("Agree to Nominative"),
 | 
			
		||||
 *   default_step = "review",
 | 
			
		||||
 * )
 | 
			
		||||
 */
 | 
			
		||||
class MaterioCommerceAgreeNominative extends CheckoutPaneBase implements CheckoutPaneInterface {
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * {@inheritdoc}
 | 
			
		||||
   */
 | 
			
		||||
  public function defaultConfiguration() {
 | 
			
		||||
    return [
 | 
			
		||||
        'path' => NULL,
 | 
			
		||||
        'text' => Null,
 | 
			
		||||
        'link_text' => NULL,
 | 
			
		||||
        'invalid_text' => 'You must agree with the nominative terms before continuing'
 | 
			
		||||
      ] + parent::defaultConfiguration();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * {@inheritdoc}
 | 
			
		||||
   */
 | 
			
		||||
  public function buildConfigurationSummary() {
 | 
			
		||||
    $text = $this->configuration['text'];
 | 
			
		||||
    $invalid_text = $this->configuration['invalid_text'];
 | 
			
		||||
    $link_text = $this->configuration['link_text'];
 | 
			
		||||
    $path = $this->configuration['path'];
 | 
			
		||||
    $summary = '';
 | 
			
		||||
    if (!empty($text)) {
 | 
			
		||||
      $summary .= $this->t('Text: @text', ['@text' => $text]) . '<br/>';
 | 
			
		||||
    }
 | 
			
		||||
    if (!empty($link_text)) {
 | 
			
		||||
      $summary .= $this->t('Link text: @text', ['@text' => $link_text]) . '<br/>';
 | 
			
		||||
    }
 | 
			
		||||
    if (!empty($invalid_text)) {
 | 
			
		||||
      $summary .= $this->t('Error text: @text', ['@text' => $invalid_text]) . '<br/>';
 | 
			
		||||
    }
 | 
			
		||||
    if (!empty($path)) {
 | 
			
		||||
      $summary .= $this->t('Multi page: @path', ['@path' => $path['route_name']]);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return $summary;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * {@inheritdoc}
 | 
			
		||||
   */
 | 
			
		||||
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
 | 
			
		||||
    $form = parent::buildConfigurationForm($form, $form_state);
 | 
			
		||||
    $form['nom_text'] = [
 | 
			
		||||
      '#type' => 'textarea',
 | 
			
		||||
      '#title' => $this->t('Text'),
 | 
			
		||||
      '#default_value' => $this->configuration['text'],
 | 
			
		||||
    ];
 | 
			
		||||
    $form['nom_invalid_text'] = [
 | 
			
		||||
      '#type' => 'textfield',
 | 
			
		||||
      '#title' => $this->t('Invalid text'),
 | 
			
		||||
      '#default_value' => $this->configuration['invalid_text'],
 | 
			
		||||
    ];
 | 
			
		||||
    $form['nom_link_text'] = [
 | 
			
		||||
      '#type' => 'textfield',
 | 
			
		||||
      '#title' => $this->t('Link text'),
 | 
			
		||||
      '#default_value' => $this->configuration['link_text'],
 | 
			
		||||
      '#required' => TRUE,
 | 
			
		||||
    ];
 | 
			
		||||
 | 
			
		||||
    if ($this->configuration['path']) {
 | 
			
		||||
      $path = $this->configuration['path'];
 | 
			
		||||
    }
 | 
			
		||||
    else {
 | 
			
		||||
      $path = NULL;
 | 
			
		||||
    }
 | 
			
		||||
    $form['nom_path'] = [
 | 
			
		||||
      '#title' => 'path',
 | 
			
		||||
      '#type' => 'textfield',
 | 
			
		||||
      '#default_value' => $path,
 | 
			
		||||
      '#required' => TRUE
 | 
			
		||||
    ];
 | 
			
		||||
 | 
			
		||||
    return $form;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * {@inheritdoc}
 | 
			
		||||
   */
 | 
			
		||||
  public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
 | 
			
		||||
    parent::submitConfigurationForm($form, $form_state);
 | 
			
		||||
    // Todo  validate existing path
 | 
			
		||||
    // Get route name and parameters from path.
 | 
			
		||||
    // $url_object = \Drupal::service('path.validator')->getUrlIfValid($path);
 | 
			
		||||
    // $route_name = $url_object->getRouteName();
 | 
			
		||||
    // $route_parameters = $url_object->getrouteParameters();
 | 
			
		||||
    
 | 
			
		||||
    if (!$form_state->getErrors()) {
 | 
			
		||||
      $values = $form_state->getValue($form['#parents']);
 | 
			
		||||
      $this->configuration['text'] = $values['nom_text'];
 | 
			
		||||
      $this->configuration['invalid_text'] = $values['nom_invalid_text'];
 | 
			
		||||
      $this->configuration['link_text'] = $values['nom_link_text'];
 | 
			
		||||
      $this->configuration['path'] = $values['nom_path'];
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * {@inheritdoc}
 | 
			
		||||
   */
 | 
			
		||||
  public function buildPaneForm(array $pane_form, FormStateInterface $form_state, array &$complete_form) {
 | 
			
		||||
    $text = $this->configuration['text'];
 | 
			
		||||
    $link_text = $this->configuration['link_text'];
 | 
			
		||||
    $path = $this->configuration['path'];
 | 
			
		||||
    // $attributes = [];
 | 
			
		||||
    // if ($this->configuration['new_window']) {
 | 
			
		||||
    //   $attributes = ['attributes' => ['target' => '_blank']];
 | 
			
		||||
    // }
 | 
			
		||||
    // $link = Link::createFromRoute(
 | 
			
		||||
    //   $this->t($link_text),
 | 
			
		||||
    //   $path['route_name'],
 | 
			
		||||
    //   $path['route_parameters'],
 | 
			
		||||
    //   $attributes
 | 
			
		||||
    // )->toString();
 | 
			
		||||
 | 
			
		||||
    $url = Url::fromUserInput($path);
 | 
			
		||||
    $link = Link::fromTextAndUrl($link_text, $url)->toString();
 | 
			
		||||
    // $link = '<a href="'.$path.'">'.$this->t($link_text).'</a>';
 | 
			
		||||
 | 
			
		||||
    $pane_form['nominative_terms'] = [
 | 
			
		||||
      '#type' => 'checkbox',
 | 
			
		||||
      '#default_value' => FALSE,
 | 
			
		||||
      '#title' => $this->t($text, ['%multi' => $link]),
 | 
			
		||||
      '#required' => TRUE,
 | 
			
		||||
      '#weight' => $this->getWeight(),
 | 
			
		||||
    ];
 | 
			
		||||
 | 
			
		||||
    return $pane_form;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * {@inheritdoc}
 | 
			
		||||
   */
 | 
			
		||||
  public function validatePaneForm(array &$pane_form, FormStateInterface $form_state, array &$complete_form) {
 | 
			
		||||
    $values = $form_state->getValue($pane_form['#parents']);
 | 
			
		||||
    if (!$values['nominative_terms']) {
 | 
			
		||||
      $form_state->setError($pane_form, $this->configuration['invalid_text']);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
										
											Binary file not shown.
										
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							@@ -2648,6 +2648,12 @@ article.card{
 | 
			
		||||
      background-color: $color-showrooms;
 | 
			
		||||
      padding:1em;
 | 
			
		||||
    }
 | 
			
		||||
    .form-item-materio-commerce-agree-nominative-nominative-terms{
 | 
			
		||||
      label{
 | 
			
		||||
        max-width: 95%;
 | 
			
		||||
        vertical-align: top;
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user