在hookActionOrderStatusUpdate中无法获取发送电子邮件的客户电子邮件

时间:2019-04-10 19:34:52

标签: prestashop-1.6

我正在编写一个模块,以便在客户购买特定产品时向其发送邮件。如果我设置了固定的电子邮件地址,则该模块可以正常工作,但是当我尝试使用客户电子邮件变量时,该模块不能正常工作。

这是钩子hookActionOrderStatusUpdate的代码

有什么想法吗?谢谢

public function hookActionOrderStatusUpdate($params)
{
    $cart = $params['cart'];

    if($params['newOrderStatus']->id == 3) // cancelado
    {
        $prods = $cart->getProducts(true);
        $customer = $params['customer'];

        error_log("Test");
        error_log(' $customer->email');
        error_log($customer->email);

        foreach($prods as $prod)
        {
            if($prod['id_product'] == 1054)  //your category ID
            {
                Mail::Send(
                    (int)(Configuration::get('PS_LANG_DEFAULT')), // defaut language id
                    'bolsones', // email template file to be use
                    'Te queremos contar acerca de nuestros Bolsones', // email subject
                    array(
                       '{firstname}' => $customer->firstname,
                    ),
                    $customer->email, // receiver email address 
                    $customer->firstname, //receiver name
                    NULL, //from email address
                    NULL  //from name
                );
            }
        }
    }
}

1 个答案:

答案 0 :(得分:0)

这是因为customer数组中的$params索引不存在。

您必须从cart索引实例化您的客户对象。

这是您的钩子的外观:

public function hookActionOrderStatusUpdate($params)
{
    $cart     = $params['cart'];
    $customer = new Customer($cart->id_customer);

    if($params['newOrderStatus']->id == 3 && Validate::isLoadedObject($customer)) // cancelado
    {
        $prods = $cart->getProducts(true);

        foreach($prods as $prod)
        {
            if($prod['id_product'] == 1054)  //your category ID
            {
                Mail::Send(
                    (int)(Configuration::get('PS_LANG_DEFAULT')), // defaut language id
                    'bolsones', // email template file to be use
                    'Te queremos contar acerca de nuestros Bolsones', // email subject
                    array(
                        '{firstname}' => $customer->firstname,
                    ),
                    $customer->email, // receiver email address 
                    $customer->firstname, //receiver name
                    NULL, //from email address
                    NULL  //from name
                );
            }
        }
    }
}
相关问题