【问题标题】:Prestashop function query to the templatePrestashop 功能查询到模板
【发布时间】:2020-09-17 11:20:35
【问题描述】:

我在 prestashop 1.6 和 classes/Cart.php 中测试过,我可以与模板文件进行通信。 在我为返回预期结果所做的查询中,在 phpmyadmin 上工作,并且在 cart.php 中工作到 tpl 文件调用,但只有当我写客户的 id 号,并且我想使用变量 id customer 时(具有 THIS 或类似 prestashop 工作方式的东西 - (int)$id_customer - )。 请大家帮忙!!!!!!

//cart.php 代码

public static function payLater($id_customer)
{
    $sql =  "SELECT ps_customer.pay_later
            FROM ps_customer
            LEFT JOIN ps_cart ON ps_customer.id_customer = ps_cart.id_customer
            ORDER BY ps_cart.id_cart DESC LIMIT 1
            WHERE ps_cart.id_customer =".(int)$id_customer;
    //if i change (int)$id_customer for a real id number like 43 it shows correct info
    $result = Db::getInstance()->getValue($sql);
    return $result;
}

//模板文件代码

{Cart::payLater(Tools::getvalue('pay_later'))}

【问题讨论】:

    标签: sql variables prestashop smarty


    【解决方案1】:

    {Cart::payLater($customer.id)} 在 tpl 文件中。我也编辑了你的功能。请检查下方是否有空的客户 ID。

    public static function payLater($id_customer)
    {
       if((int)$id_customer == 0){ return; } // check if customer id is blank
        $sql =  "SELECT ps_customer.pay_later
                FROM ps_customer
                LEFT JOIN ps_cart ON ps_customer.id_customer = ps_cart.id_customer
                ORDER BY ps_cart.id_cart DESC LIMIT 1
                WHERE ps_cart.id_customer =".(int)$id_customer;
        //if i change (int)$id_customer for a real id number like 43 it shows correct info
        $result = Db::getInstance()->getValue($sql);
        return $result;
    }
    

    【讨论】:

    • 您是否在 tpl 文件中打印了 $customer.id?你得到了什么?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-09-02
    • 2022-06-17
    • 2016-10-21
    • 1970-01-01
    • 2020-06-26
    • 2015-06-22
    • 1970-01-01
    相关资源
    最近更新 更多