php - 如何找回下单的店铺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;
}
}
解决方案
推荐阅读
- python - 将用户输入拆分为越来越大的列表 [python]
- sql-server - 无法在 SQL Select 中向 DATEOFFSET(2) 添加时间
- bash - 在 Docker 构建期间从文本文件中提取变量
- amazon-web-services - 在 terraform(aws 提供程序)中创建接口类型 vpc 端点时出错
- firebase - 如何告诉 Firestore 使用 Node Admin SDK 返回 Timestamp 对象?
- android - 将 firebase 库更新到 16.0.0 会引发 google play services 依赖问题
- c++ - Libnoise 不想编译:找不到 -lnoise
- java - Grails 默认应用程序未部署到 tomcat
- vb.net - 更改数据集访问数据库 Visual Studio
- ember.js - Ember CLI + Watchman 未检测到插件更改