dsdeeaquu38538545 2018-08-25 10:19 采纳率: 100%
浏览 63
已采纳

如何通过在shopping-cart.tpl中创建变量来修改PaymentModule.php中$ order-> id_customer的值?

I have the following code in shopping-cart.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) {
              }
        });

    });

how can i modify the value of $order->id_customer in PaymentModule.php by creating a variable in shopping-cart.tpl?

$order->id_customer = (int)$this->context->cart->id_customer;
  • 写回答

1条回答 默认 最新

  • doutang8098 2018-08-26 19:56
    关注

    you can't change it from a simple assignement in a template. The customer id is retrieved from the context (Cookie / Session) in the validateOrder() function...

    Assign an order to a different customer is quite dangerous, but if you really need this, I see 2 workarounds :

    • Override the PaymentModule::validateOrder() function to set the customer id you want instead of using the one of the context, assuming you stored it somewhere else before in your process: Cookie, db table
    • Use a hook (actionObjectOrderAddBefore, actionValidateOrder, ...) to set or modify all the order related data in database after validation (be careful to subprocesses like email confirmation that could be sent to the previous customer according to the hook you use), and also assuming you stored the good customer id somewhere before

    Good luck

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)