【问题标题】:Opencart Session Variable ErrorsOpencart 会话变量错误
【发布时间】:2013-07-27 18:31:03
【问题描述】:

我在通过会话发送数据时遇到问题,因为我在 validate() 函数下定义 controller/checkout/shipping_address.php 中的变量时遇到了未定义变量的错误。 (结帐/送货地址/验证)。

$this->session->data['ship_date'] = $this->request->post['ship_date']; //<- line 102

在控制器/结帐/运输方法中

$ship_date = $this->session->data['ship_date'];
if(empty($ship_date)) echo "var empty";
$ship_date = explode("-", $ship_date);
$ship_date = $ship_date[0] . "/" . $ship_date[1] . "/" . $ship_date[2];

然后我做

$quote = $this->{'model_shipping_' . $result['code']}->getQuote($shipping_address, $ship_date); 

也可以,在 model/shipping/fedex.php 中我允许使用 $ship_date 参数。然而在那之后我得到了。

无效 JSON:通知:未定义索引:ship_date in /var/www/catalog/controller/checkout/shipping_address.php line 102[] parsererror 注意:未定义索引: 发货日期 /var/www/catalog/controller/checkout/shipping_address.php102 行[]

【问题讨论】:

  • 所以它告诉你所有你需要知道的。这两个数组中的任何一个都不存在“ship_date”。
  • @TobiasKun 你能补充一下吗?

标签: php session variables opencart


【解决方案1】:

您应该调试数组$this->session->data$this->request->post

您看到这些错误的原因是在$this->session->data$this->request->post 中没有索引ship_date。所以你会得到一个Notice: Undefined index:

由于打印的通知,您之后输出的 json 变得无效。

【讨论】:

    【解决方案2】:

    实际上,OpenCart 只通过 JSON 进行对话。所以添加它会有所帮助。

    $JSONarray = array("date" => $this->request->post['ship_date']);
    $this->session->data['ship_date'] = json_encode($JSONarray);
    

    当你想使用它时,

    $JSONarray = $this->session->data['ship_date'];
    $arr = json_decode($JSONarray, TRUE);
    $Value = $arr['ship_date'];
    

    我们必须把数据做成 JSON 然后发送出去

    【讨论】:

      猜你喜欢
      • 2013-04-13
      • 2013-09-17
      • 1970-01-01
      • 2011-10-27
      • 2014-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多