簡體   English   中英

Opencart 2.x結帳/成功添加特定產品的跟蹤代碼

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM