【问题标题】:How to pass custom variable in cart?如何在购物车中传递自定义变量?
【发布时间】:2016-07-29 12:36:31
【问题描述】:

我正在使用Opencart 2.0.1.1。我想在购物车页面上发布的产品页面上有隐藏的文本字段。我关注this tutorial,但收到Undefined index 问题。

<input type="hidden" name="design" value="12">

我已经完成了以下编码:

在目录/controller/checkout/cart.php 中

$option['design']=$this->request->post['design'];
$this->cart->add($this->request->post['product_id'],$quantity,$option);

然后在$data['products'][] = array( 中添加'design' =&gt; $product['design'],

然后在system/library/cart.php中

$this-&gt;data[$key] = array( 中添加了'design' =&gt; $options['design'],

然后在cart.tpl in view\theme\template-name\template\checkout\cart.tpl

echo $product['design'];

谁能帮我解决这个问题?

【问题讨论】:

  • 我认为,您需要在问题中指定代码以获得更好的问题。你试过什么?
  • @HarnishDesign 现在编辑了问题。
  • 我们能看到实际代码吗,tpl 文件/生成的 html 将有助于确定页面和表单是否正确呈现。
  • 伙计,不要编辑它......如果这是问题的原因,让我们找出并指出它
  • @CarlosCarucce 感谢您的指点,但这只是写作问题。在实际代码中是design

标签: php product cart opencart2.x


【解决方案1】:

如果你得到一个空或无效的索引,你的变量没有被传递,我会确保你的输入在提交的表单中,并确保你的拼写正确以防万一。也可以使用 php

打印_r($_POST);

验证其是否发布数据。如果您看到它列出,请仔细检查您的类方法。

您需要向我们提供更多内容,以便我们更准确地解决问题。

【讨论】:

  • 价值即将到来$_POST
猜你喜欢
  • 2017-12-17
  • 1970-01-01
  • 1970-01-01
  • 2013-03-25
  • 1970-01-01
  • 2019-06-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-10
相关资源
最近更新 更多