带有id_product的prestashop自定义模块钩子

时间:2015-08-05 13:41:24

标签: hook prestashop

我正在开发一个自定义模块,用于在产品缺货时添加“通知我”按钮。 这个按钮应该只是调用一个动作并写入一个自定义表(由这个模块创建)

我的问题是将id_product传递给钩子

public function install() {

    $sql= "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."fasys_notify`(
    `id` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
    `title` VARCHAR(256) NOT NULL )";


    if (parent::install() == false ||  
            !$this->registerHook('notify') ||
            !$this->registerHook('displayHeader') ||
            !Db::getInstance()->Execute($sql)
        )
        return false;
        return true;
}



public function hookFasysNotify($params) {

    //NEED ID_PRODUCT HERE

    //var_dump(Tools::getValue('id_product')); //doesen't works

    $html ='<button type="button" class="notifyme_btn btn btn-info btn-default">Notify Me</button>';

    return $html ;  

}

在我的.tpl文件中我添加了这个:

{hook h='fasysNotify' product=$product}

如何检索产品?

2 个答案:

答案 0 :(得分:1)

.tpl

protected void pg3button_Click(object sender, EventArgs e)
{            
    try
    {
        //Create the msg object to be sent
        MailMessage msg = new MailMessage();

        //Add your email address to the recipients
        msg.To.Add("test@test.co.uk");

        //Configure the address we are sending the mail from
        MailAddress address = new MailAddress("test@test.co.uk");
        msg.From = address;

        //Append their name in the beginning of the subject
        msg.Subject = "Enquiry";

        msg.Body = Label1.Text + " " + Session["pg1input"].ToString()
                    + Environment.NewLine.ToString() +
                    Label2.Text + " " + Session["pg1dd"].ToString()
                    + Environment.NewLine.ToString() +
                    Label3.Text + " " + Session["pg2"].ToString();

        //Configure an SmtpClient to send the mail.
        SmtpClient client = new SmtpClient("smtp.live.com", 587);
        client.EnableSsl = true; //only enable this if your provider requires it

        //Setup credentials to login to our sender email address ("UserName", "Password")
        NetworkCredential credentials = new NetworkCredential("test@test.co.uk", "Password10");
        client.Credentials = credentials;

        //Send the msg
        client.Send(msg);

        Response.Redirect("/Session/pg4.aspx");
    }
    catch
    {
        //If the message failed at some point, let the user know
        lblResult.Text = "<div class=\"form-group\">" + "<div class=\"col-xs-12\">" + "There was a problem sending your request. Please try again." + "</div>" + "</div>" + "<div class=\"form-group\">" + "<div class=\"col-xs-12\">" + "If the error persists, please contact us." + "</div>" + "</div>";
    }
}

模块:

{hook h='fasysNotify' product=$product}

答案 1 :(得分:0)

在tpl:

{hook h='fasysNotify' product=$product}

{hook h='fasysNotify' product=$id_product}
模块中的

$id_product = $param['id_product'];

$id_product = $param;