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 (标签-STM32|关键词-智能小车)
  • ¥20 关于#stm32#的问题,请各位专家解答!
  • ¥15 (标签-python)
  • ¥20 搭建awx,试了很多版本都有错
  • ¥15 java corba的客户端该如何指定使用本地某个固定IP去连接服务端?
  • ¥15 activiti工作流问题,求解答
  • ¥15 有人写过RPA后台管理系统么?
  • ¥15 Bioage计算生物学年龄
  • ¥20 如何将FPGA Alveo U50恢复原来出厂设置哇?
  • ¥50 cocos2d-x lua 在mac上接入lua protobuf?