在 Stripe 定期支付模块控制器中以编程方式将用户添加到自定义组时出现内部服务器错误

问题描述

大家好,感谢您花时间阅读我的帖子。

我是 Prestashop 的新手。我从 Prestashop 插件添加了条纹定期付款模块。效果很好。

但我的目标是根据他在模块的 addStripeSubscription() 函数订阅的产品的 id 将用户添加一个组中,就像开发人员建议的那样。我无法读取错误,因为模块只返回服务器出现错误,因此我无法获得更多信息。

这是我实际在做的事情:

    $customer = new customer(6); //This is my customer id
    if ($id_product == 27) {
        // On ajoute l'user au groupe champion
        $new_id_group = 4; // This is an existing group's id
        if ($customer->id_default_group!=$new_id_group) {
            $customer->cleangroups();
            $customer->addGroups([(int)$new_id_group]);
            $customer->id_default_group = (int)$new_id_group;
            $customer->update(); // It fails here
        }
    }

    // if ($id_product == 28) {
    //     // Groupe chevalier
    //     $new_id_group = 5;
    //      if ($customer->id_default_group!=$new_id_group) {
    //         $customer->cleangroups();
    //         $customer->addGroups(array((int)$new_id_group));
    //         $customer->id_default_group = (int)$new_id_group;
    //         $customer->update();
    //     }
    // }

它在 $customer->update(); 处失败,但前提是 $customer->addGroups($new_id_group) 没有被注释。所以它与这个 addGroups() 函数有关。即使我直接在 addGroups() 函数的参数中传递 3(Prestashop 中的认客户组),它也会失败。

这让我发疯。

为什么会这样?我错过了什么?

感谢您的帮助!

解决方法

我找到了原因。循环条带支付模块或条带模块正在传递到生产模式,而另一个没有,而且随机地,这是造成内部服务器错误的原因,我认为它与组有关。

我还发现了一个免费模块,它允许在发生其他事情时做一些事情,所以现在我使用这个模块在他购买作为特定 ID 的产品时自动添加一个用户,并且这个客户被添加到我的组中与产品相关联。疯狂的模块。

又是一个很酷的模块,可以自动做很多事情。

https://store.getdatakick.com/en/modules/conseqs-free

希望这对一些人有所帮助!