[英]Opencart 2.x checkout / Success add tracking code for specific product
我希望仅在购买了特定产品的情况下,才将一个JavaScript块添加到success.tpl文件中。
我知道我必须编辑以下文件来放置ID检查。
template/common/success.tpl
我只需要帮助弄清楚如何编辑控制器即可创建或允许使用所需的变量。
catalog/controller/checkout/success.php
每个人都在谈论获取订单ID,但是我找不到任何关于接收已购买产品列表的信息。 有谁知道我如何设法获得产品ID,以便我可以对它们进行检查。
在Opencart 2.2.0.0上测试:
打开:
catalog/controller/checkout/success.php
找:
if (isset($this->session->data['order_id'])) {
在其后添加:
$order_product_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_product WHERE order_id = '" . (int)$this->session->data['order_id'] . "'");
$order_products_id = array();
foreach ($order_product_query->rows as $product){
$order_products_id[] = $product['product_id'];
}
$data['order_products_id'] = $order_products_id;
然后打开tpl
文件:
catalog/view/theme/default/template/common/success.tpl
并添加以下内容:
<?php if(isset($order_products_id)){
echo '<pre>';
var_dump($order_products_id);
echo '</pre>';
$specific_product_id = 28;
if(in_array($specific_product_id, $order_products_id)){ ?>
<script>alert('Yes, it is');</script>
<?php }
} ?>
希望这对您有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.