【发布时间】:2014-08-02 05:01:32
【问题描述】:
我正在为 magento 编写自定义订单处理脚本。如果脚本通过 cron 收到新订单,它应该创建发票并通知用户并发送评论。为此,我使用 SOAP api。
这在发送电子邮件时有效,但是如何使评论在前端对用户可见?
如果我手动登录到 Magento 管理员,我可以在订单中添加评论,然后检查 Visible on Frontend。
我希望我用sales_order_invoice.create 和sales_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。堆栈溢出对于我在旅途中遇到的所有问题都有很大的帮助;我有很多,我的意思是过去只使用堆栈溢出的搜索功能就得到了很多帮助。感谢那! 当然我和大朋友谷歌一起再次使用它,但第一次没有运气。这就是为什么这是我在这里的第一个问题。 我真的希望你们能帮助我,提前谢谢!
【问题讨论】: