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 $store_id = 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\Component\Serialization\Json;
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) {
    $store_id = 3;
    $pane_form['#attached']['library'][] = 'core/drupal.dialog.ajax';
    $attributes = [
      'attributes' => [
        'class' => 'use-ajax',
        'data-dialog-type' => 'modal',
        'data-dialog-options' => Json::encode([
          'width' => 800,
        ]),
      ],
    ];
    $link = Link::createFromRoute(
      $this->t('the general terms and conditions of business'),
      'entity.commerce_store.canonical',
      ['commerce_store' => $store_id],
      $attributes
    )->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;
  }

}

Comments

zenimagine created an issue. See original summary.

bojanz’s picture

Status: Active » Fixed

$this->order->getStoreId()

zenimagine’s picture

@bojanz Perfect thank you

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.