我正在研究opencart 2.0.1.1,在这里,我将数据从模型中获取到控制器。在此之后,我需要传递带有th script标记的数据视图页面。我已经这样做了,但它显示了洋娃娃的问题。
(注意: C:\xampp\www\htdocs\abc\catalog\view\theme\default\template\common\success.tpl中数组到字符串的在线转换)
如能在这方面提供任何帮助,我们将不胜感激。
控制器码
success.php
$this->load->model('checkout/order');
$data['orderDetails'] = $this->model_checkout_order->getOrder($this->session->data['order_id']);
$data['ordertax'] = $this->model_checkout_order->gettax($this->session->data['order_id']);
$data['orderProduct'] = $this->model_checkout_order->getOrderProduct($this->session->data['order_id']);
$this->response->setOutput($this->load->view('default/template/common/success.tpl', $data));查看代码
success.tpl
<script type="text/javascript">
ga('require', 'ecommerce');
ga('ecommerce:addTransaction', {
'id': "<?php $orderDetails['order_id'];?>", // Transaction ID. Required. dynamic variable of order id
'affiliation': "<?php $orderDetails['store_name'];?>", // Affiliation or store name. Kuberan Silks
'revenue': "<?php $orderDetails['total'];?>", // Grand Total. grand total dynamic variable of the price
'shipping':"<?php $ordertax['value'];?>" , // Shipping. dynamic variable of shipping
'tax': "<?php $orderProduct['tax'];?>" // Tax. dynamic tax variable
});
ga('ecommerce:addItem', {
'id': "<?php $orderProduct['order_id'];?>", // Transaction ID. Required.
'name': "<?php $orderProduct['name'];?>", // Product name. Required.
'sku': "<?php $orderProduct['model'];?>", // SKU/code.
//'category': 'Party Toys', // Category or variation.
'price': "<?php $orderProduct['price'];?>", // Unit price.
'quantity':"<?php $orderProduct['quantity'];?>" // Quantity.
});
ga('ecommerce:send');
</script>
<?php echo $footer; ?>当我检查被检查的元素时,它显示如下:
<script type="text/javascript">
ga('require', 'ecommerce');
ga('ecommerce:addTransaction', {
'id': "<b>Notice</b>: Undefined variable: orderDetails in <b>C:\xampp\www\htdocs\kuberan\catalog\view\theme\default\template\common\success.tpl</b> on line <b>41</b>",
'affiliation': "<b>Notice</b>: Undefined variable: orderDetails in <b>C:\xampp\www\htdocs\kuberan\catalog\view\theme\default\template\common\success.tpl</b> on line <b>42</b>",
});
ga('ecommerce:addItem', {
'id': "<b>Notice</b>: Undefined variable: orderProduct in <b>C:\xampp\www\htdocs\kuberan\catalog\view\theme\default\template\common\success.tpl</b> on line <b>49</b>",
'sku': "<b>Notice</b>: Undefined variable: orderProduct in <b>C:\xampp\www\htdocs\kuberan\catalog\view\theme\default\template\common\success.tpl</b> on line <b>51</b>",
});
ga('ecommerce:send');
</script>发布于 2018-03-19 06:05:36
数组到字符串的转换。
当您试图在PHP中回显数组值时,会出现此错误。不能将数组用作字符串!!
若要克服此问题,可以向要打印的数组中添加键。
例如。
<?php $orderDetails[0]['order_id'];?>这将返回键为0的$orderDetails数组中的$orderDetails值。建议您使用for循环从数组中获取值,因为您无法确定其中有多少个键。
好运!!
https://stackoverflow.com/questions/49356653
复制相似问题