我希望只在购买特定产品时才向success.tpl文件添加一个JavaScript块。
我知道我必须编辑以下文件来进行ID检查。
template/common/success.tpl
我只需要帮助弄清楚如何编辑控制器以创建或允许使用所需的变量。
catalog/controller/checkout/success.php
每个人都在谈论获取订单ID但我无法找到任何有关收到所购产品清单的内容。有谁知道如何设法获取产品ID,以便我可以创建对他们的检查。
答案 0 :(得分:0)
在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 }
} ?>
希望这对你有所帮助。