2

I have a Drupal 8 site with a marketplace (several stores).

I want to display in the "review" step of the "Checkout Pane" a checkbox with the sales terms.

Currently if I order in 2 stores, this will create 2 shopping cart (1 per store).

The terms of sales are accessible for each store at the url :

/store/ID/cgv

The code below works, but I need to replace the ['commerce_store' => 3] with the Id of the current store (the store where the order is placed).

How to do this ?

EXAMPLE :

If I order a product in store A, it will create a shopping cart.

If I order a product in store B, it will create a second shopping cart.

Each shopping cart must display at the step "review" the general conditions of sale of the store to which the shopping basket belongs.

<?php

namespace Drupal\commerce_agree_cgv\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\Core\Link;

/**
 * Provides the completion message pane.
 *
 * @CommerceCheckoutPane(
 *   id = "agree_cgv",
 *   label = @Translation("Agree CGV"),
 *   default_step = "review",
 * )
 */
class AgreeCGV extends CheckoutPaneBase implements CheckoutPaneInterface {

  /**
   * {@inheritdoc}
   */
  public function buildPaneForm(array $pane_form, FormStateInterface $form_state, array &$complete_form) {
    $link = Link::createFromRoute('the general terms and conditions of business', 'entity.commerce_store.canonical', ['commerce_store' => 3], ['attributes' => ['target' => '_blank']])->toString();
    $pane_form['cgv'] = [
      '#type' => 'checkbox',
      '#default_value' => FALSE,
      '#title' => $this->t('I have read and accept @cgv.', ['@cgv' => $link]),
      '#required' => TRUE,
      '#weight' => $this->getWeight(),
    ];
    return $pane_form;
  }

}
mathieu61
  • 33
  • 1
  • 5

0 Answers0