【问题标题】:How to get Magento Invoice & shipment comment visible on frontend through SOAP API?如何通过 SOAP API 在前端显示 Magento 发票和发货评论?
【发布时间】:2014-08-02 05:01:32
【问题描述】:

我正在为 magento 编写自定义订单处理脚本。如果脚本通过 cron 收到新订单,它应该创建发票并通知用户并发送评论。为此,我使用 SOAP api。 这在发送电子邮件时有效,但是如何使评论在前端对用户可见? 如果我手动登录到 Magento 管理员,我可以在订单中添加评论,然后检查 Visible on Frontend。 我希望我用sales_order_invoice.createsales_order_shipment.create 添加的cmets 以同样的方式在前端对客户可见。我知道使用后端的默认设置是不可能的,但我想这样做。 如果这真的很难做到,我至少希望添加 sales_order.addComment 的 cmets 在前端对客户可见,就像我手动评论和检查 Visible on Frontend 时一样。

这是我的 SOAP 代理代码:

class magentoProxyHandler{

    protected $proxy;
    protected $session;

    function __construct(){

        $this->proxy = new SoapClient('http://www.magento.nl/index.php/api/soap/?wsdl');
        $this->session = $this->proxy->login('change_order', 'password');
    }

    function __destruct(){

        $this->proxy->endSession($this->session);

    }

    function addComment($orderId, $status, $comment = '', $notifyCustomer = true){

        $orderId = ($orderId > 100000000 ? $orderId : $orderId + 100000000);
        $notify = $notifyCustomer ? true : false;

        $changeOrder = array('orderIncrementId' => $orderId, 'status' => $status, 'comment'=> $comment, 'notify'=> $notify);

        return $this->proxy->call($this->session, 'sales_order.addComment', $changeOrder);

    }


    function createInvoice($orderId, $status, $comment = 'Invoice ready', $notifyCustomer = true){

        $orderId = ($orderId > 100000000 ? $orderId : $orderId + 100000000);
        $notify = $notifyCustomer ? true : false;
        return $this->proxy->call($this->session, 'sales_order_invoice.create', array($orderId, array(), $comment, true, true));

    }

    function shipOrder($orderId, $status, $comment = 'Order shipped', $notifyCustomer = true){

        $orderId = ($orderId > 100000000 ? $orderId : $orderId + 100000000);
        $notify = $notifyCustomer ? true : false;
        return $this->proxy->call($this->session, 'sales_order_shipment.create', array($orderId, array(), $comment, true, true));

    }


} //end of class

我知道我可以对这段代码做一些小改进,这只是为了测试soap API。

我只是通过阅读互联网上的指南并开始尝试来学习编写 PHP。堆栈溢出对于我在旅途中遇到的所有问题都有很大的帮助;我有很多,我的意思是过去只使用堆栈溢出的搜索功能就得到了很多帮助。感谢那! 当然我和大朋友谷歌一起再次使用它,但第一次没有运气。这就是为什么这是我在这里的第一个问题。 我真的希望你们能帮助我,提前谢谢!

【问题讨论】:

    标签: php magento soap


    【解决方案1】:

    好的,我知道怎么做,只好修改一点代码:

    1. 我将/app/code/core/Mage/Sales/Model/Order/Api.php 复制到/app/code/local/Mage/Sales/Model/Order/Api.php
    2. 我改变了addComment的方法:

      public function addComment($orderIncrementId, $status, $comment = '', $notify = false, $showOnFront = true)
      {
          $order = $this->_initOrder($orderIncrementId);
      
          $historyItem = $order->addStatusHistoryComment($comment, $status);
          $historyItem->setIsVisibleOnFront($showOnFront);
          $historyItem->setIsCustomerNotified($notify)->save();
      
      
          try {
              if ($notify && $comment) {
                  $oldStore = Mage::getDesign()->getStore();
                  $oldArea = Mage::getDesign()->getArea();
                  Mage::getDesign()->setStore($order->getStoreId());
                  Mage::getDesign()->setArea('frontend');
              }
      
              $order->save();
              $order->sendOrderUpdateEmail($notify, $comment);
              if ($notify && $comment) {
                  Mage::getDesign()->setStore($oldStore);
                  Mage::getDesign()->setArea($oldArea);
              }
      
          } catch (Mage_Core_Exception $e) {
              $this->_fault('status_not_changed', $e->getMessage());
          }
      
          return true;
      }
      
    3. 然后在我的课堂上:

      function addComment($orderId, $status, $comment = '', $notifyCustomer = true, $showOnFront = true){
      
          $orderId = ($orderId > 100000000 ? $orderId : $orderId + 100000000);
          $notify = $notifyCustomer ? true : false;
      
          $changeOrder = array('orderIncrementId' => $orderId, 'status' => $status, 'comment'=> $comment, 'notify'=> $notify, 'showOnFront' =>  $showOnFront);
      
          return $this->proxy->call($this->session, 'sales_order.addComment', $changeOrder);
      
      }
      

    像魅力一样工作! 据我所知,我可以在货件和发票 api 文件中做同样的事情。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多