Javascript 如何修改$order->;的值;通过在shopping-cart.tpl中创建一个变量在PaymentModule.php中标识客户?

Javascript 如何修改$order->;的值;通过在shopping-cart.tpl中创建一个变量在PaymentModule.php中标识客户?,javascript,php,prestashop,smarty,Javascript,Php,Prestashop,Smarty,我在购物车.tpl中有以下代码: $(document).ready(function(){ $.ajax({ url: document.location.origin+"/univers/themes/leostyl/shopping-cart.php", type: 'get', success: function(data){ var array = $.par

我在
购物车.tpl中有以下代码:

    $(document).ready(function(){
        $.ajax({
            url: document.location.origin+"/univers/themes/leostyl/shopping-cart.php",
            type: 'get',
            success: function(data){
                var array = $.parseJSON(data);
               ch='<select class="form-control" id="customer-id" onchange="myFunction()">';
               for (var i=0;i<array['results'].length;i++) {
                if(array['results'][i].id_default_group== 3)
                  ch=ch+'<option id='+array['results'][i].id_customer+'> '+array['results'][i].firstname+' '+array['results'][i].lastname+'</option>';
                  }
                  ch=ch+'</select>';
                  $( ".customer" ).append(ch);                    
            },
            error: function (xhr, ajaxOptions, thrownError) {
              }
        });

    });

不能从模板中的简单赋值更改它。客户id是从validateOrder()函数中的上下文(Cookie/Session)中检索的

将订单分配给其他客户是非常危险的,但如果您真的需要,我认为有两种解决方法:

  • 覆盖PaymentModule::validateOrder()函数来设置您想要的客户id,而不是使用上下文中的一个,假设您在流程中之前将其存储在其他位置:Cookie,db table
  • 使用钩子(actionObjectOrderAddBefore,actionValidateOrder,…)在验证后设置或修改数据库中与订单相关的所有数据(请注意,根据您使用的钩子,可以将电子邮件确认等子流程发送给以前的客户),并且假设您以前在某个地方存储了良好的客户id

祝你好运

为什么要更改与购物车相同的变量?我需要修改客户id你不能这样做,或者我只能说,你不应该这样做。该变量用于许多流程、验证等。
$order->id_customer = (int)$this->context->cart->id_customer;