我正在为magento编写自定义订单处理脚本。如果脚本通过cron获取新订单,则应创建发票并通知用户并发送评论。我为此目的使用SOAP api。
这在发送电子邮件时有效,但如何在前端对用户显示评论?
如果我手动登录Magento admin,我可以在订单中添加注释,然后选中Visible on Frontend
。
我希望我添加sales_order_invoice.create
和sales_order_shipment.create
的评论以同样的方式对前端的客户可见。我知道后端默认设置是不可能的,但我想这样做。
如果这真的很难做到,我至少会喜欢用sales_order.addComment
添加的评论在前端对客户可见,就像我手动评论并检查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。堆栈溢出对我在途中遇到的所有问题的旅程有很大的帮助;我有很多,我的意思是通过在过去使用堆栈溢出的搜索功能提供很多帮助。感谢那! 当然我和大朋友谷歌一起再次使用它,但第一次没有运气。这就是为什么这是我的第一个问题。 我真的希望你们能帮助我,提前谢谢!
答案 0 :(得分:1)
好的我发现了怎么做,不得不改变一些代码:
/app/code/core/Mage/Sales/Model/Order/Api.php
改为/app/code/local/Mage/Sales/Model/Order/Api.php
我更改了方法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;
}
然后在我班上:
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文件中做同样的事情。