如何在购物车中传递自定义变量?

时间:2016-07-29 12:36:31

标签: php product cart opencart2.x

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

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

我已经完成了以下编码:

在catalog / controller / checkout / cart.php中

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

然后在$data['products'][] = array(添加'design' => $product['design'],

然后在system / library / cart.php

$this->data[$key] = array(添加了'design' => $options['design'],

然后在cart.tpl中查看\ theme \ template-name \ template \ checkout \ cart.tpl

echo $product['design'];

有人可以帮我解决这个问题吗?

1 个答案:

答案 0 :(得分:1)

如果您获得的索引为空或无效,则您的变量未被传递,我会确保您的输入位于正在提交的表单中,并确保您拼写正确以防万一。也使用php

print _r($ _ POST);

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

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