[英]Opencart 2.x checkout / Success add tracking code for specific product
I am looking to add a block of JavaScript to the success.tpl file only if a specific product is purchased. 我希望仅在购买了特定产品的情况下,才将一个JavaScript块添加到success.tpl文件中。
I know I have to edit the following file to place the id check. 我知道我必须编辑以下文件来放置ID检查。
template/common/success.tpl
I just need help figuring out how to edit the controller to create or allow the use of the variables needed. 我只需要帮助弄清楚如何编辑控制器即可创建或允许使用所需的变量。
catalog/controller/checkout/success.php
Everyone is talking about getting the order ID but I cant find anything that talks about receiving a list of the products purchased. 每个人都在谈论获取订单ID,但是我找不到任何关于接收已购买产品列表的信息。 Does anyone know how I can manage to get the product IDs so that I can create the check against them. 有谁知道我如何设法获得产品ID,以便我可以对它们进行检查。
Tested on Opencart 2.2.0.0 : 在Opencart 2.2.0.0上测试:
open: 打开:
catalog/controller/checkout/success.php
Find: 找:
if (isset($this->session->data['order_id'])) {
Add after it: 在其后添加:
$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;
Then open tpl
file: 然后打开tpl
文件:
catalog/view/theme/default/template/common/success.tpl
And add this: 并添加以下内容:
<?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 }
} ?>
Hope this help you. 希望这对您有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.