首页 > 解决方案 > 如何找回下单的店铺ID?

问题描述

我有一个带有市场(几家商店)的 Drupal 8 站点。

我想在“结帐窗格”的“审查”步骤中显示一个带有销售条款的复选框。

目前,如果我在 2 家商店订购,这将创建 2 个购物车(每家商店 1 个)。

每个商店的销售条款都可以通过 url 访问:

/store/ID/cgv

下面的代码有效,但我需要['commerce_store' => 3]用当前商店(下订单的商店)的 Id 替换。

这个怎么做 ?

例子 :

如果我在商店 A 订购产品,它将创建一个购物车。

如果我在 B 商店订购产品,它将创建第二个购物车。

每个购物车必须在“查看”步骤显示该购物车所属商店的一般销售条件。

<?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;
  }

}

标签: phpformsdrupal-modulesdrupal-8drupal-commerce

解决方案


推荐阅读