Magento 在下订单后将客户与订单相关联

标签 magento

我的自定义模块观察到 sales_order_place_after事件,并通过设置 customerId 创建客户并将客户与订单相关联为订单。

什么有效?

  • 下单
  • 创建客户
  • customerId在订单数据库中更新

  • 什么不起作用?
  • customerId立即设置回 NULL由另一个脚本

  • 如何找出更新 customerId 的脚本至NULL再次,在我的观察者完成运行后?

    最佳答案

    我有同样的问题 - 我的假设是调用 save订单上的方法触发了正在监听 sales_order_save_before/after 的任何内容事件,其中之一是将客户 ID 设置回 null .我通过只保存我想要的属性来解决这个问题,而不是触发整个订单的保存:

    $order
        ->setCustomerId($customer->getId())
        ->setCustomerIsGuest(0)
        ->setCustomerGroupId($customer->getGroupId());
    
    $order->getResource()
        ->saveAttribute($order, 'customer_id'      )
        ->saveAttribute($order, 'customer_is_guest')
        ->saveAttribute($order, 'customer_group_id');
    

    这使我能够使用 sales_model_service_quote_submit_success 成功地将客户与 Magento EE 1.14.3.10 中的订单关联起来。事件。

    关于Magento 在下订单后将客户与订单相关联,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50566831/

    相关文章:

    php - 如何重置 Magento 交易电子邮件 ID?

    magento - 如何在 magento 2.0 中获取原始大小的图像 url

    linux - Magento 在实时服务器上移动媒体文件夹后产品图像未显示在前端和后端

    magento - 使用 Magento API 在产品上创建自定义选项

    php - Magento 快速 getResourceModel 问题

    sql - Magento:如何获取产品负载的 SQL 查询?

    php - 使用 Magento 重新索引刚刚以编程方式更改的产品

    magento - 为什么 $address->hasCouponCode() 总是返回 null?

    php - Magento - 将 Cart_sidebar 移动到 top.phtml

    magento - OnepageController 没有用我的自定义 Controller 重载/重写