diff --git a/app/code/core/Mage/Sales/Model/Api2/Order/Comment/Rest.php b/app/code/core/Mage/Sales/Model/Api2/Order/Comment/Rest.php index 6bdf1316d9b..fa4a216ac74 100644 --- a/app/code/core/Mage/Sales/Model/Api2/Order/Comment/Rest.php +++ b/app/code/core/Mage/Sales/Model/Api2/Order/Comment/Rest.php @@ -37,6 +37,7 @@ abstract class Mage_Sales_Model_Api2_Order_Comment_Rest extends Mage_Sales_Model * Parameters in request used in model (usually specified in route mask) */ const PARAM_ORDER_ID = 'id'; + const PARAM_COMMENT_ID = 'comment_id'; /**#@-*/ /** diff --git a/app/code/core/Mage/Sales/Model/Api2/Order/Comment/Rest/Admin/V1.php b/app/code/core/Mage/Sales/Model/Api2/Order/Comment/Rest/Admin/V1.php index 230b18d8548..275cedb538b 100644 --- a/app/code/core/Mage/Sales/Model/Api2/Order/Comment/Rest/Admin/V1.php +++ b/app/code/core/Mage/Sales/Model/Api2/Order/Comment/Rest/Admin/V1.php @@ -33,4 +33,67 @@ */ class Mage_Sales_Model_Api2_Order_Comment_Rest_Admin_V1 extends Mage_Sales_Model_Api2_Order_Comment_Rest { + /** + * Add comment to order + * + * @param array $data + * @return string + */ + protected function _create(array $data) + { + $orderId = $this->getRequest()->getParam(self::PARAM_ORDER_ID); + $order = $this->_loadOrderById($orderId); + + $status = $data['status'] ?? false; + $comment = $data['comment'] ?? ''; + $visibleOnFront = $data['is_visible_on_front'] ?? 0; + $notifyCustomer = array_key_exists('is_customer_notified', $data) ? $data['is_customer_notified'] : false; + + $historyItem = $order->addStatusHistoryComment($comment, $status); + $historyItem->setIsCustomerNotified($notifyCustomer) + ->setIsVisibleOnFront((int) $visibleOnFront) + ->save(); + + try { + if ($notifyCustomer && $comment) { + $oldStore = Mage::getDesign()->getStore(); + $oldArea = Mage::getDesign()->getArea(); + Mage::getDesign()->setStore($order->getStoreId()); + Mage::getDesign()->setArea('frontend'); + } + + $order->save(); + $order->sendOrderUpdateEmail((bool) $notifyCustomer, $comment); + + if ($notifyCustomer && $comment) { + Mage::getDesign()->setStore($oldStore); + Mage::getDesign()->setArea($oldArea); + } + } catch (Mage_Core_Exception $e) { + $this->_critical($e->getMessage(), self::RESOURCE_INTERNAL_ERROR); + } catch (Throwable $t) { + Mage::logException($t); + $this->_critical($t->getMessage(), self::RESOURCE_UNKNOWN_ERROR); + } + + return $this->_getLocation($historyItem); + } + + /** + * Retrieve order comment by id + * + * @return array + */ + protected function _retrieve() + { + $comment = Mage::getModel('sales/order_status_history')->load( + $this->getRequest()->getParam(self::PARAM_COMMENT_ID) + ); + + if (!$comment->getId()) { + $this->_critical(self::RESOURCE_NOT_FOUND); + } + + return $comment->getData(); + } } diff --git a/app/code/core/Mage/Sales/etc/api2.xml b/app/code/core/Mage/Sales/etc/api2.xml index c5c28ee3681..44ae5a07564 100644 --- a/app/code/core/Mage/Sales/etc/api2.xml +++ b/app/code/core/Mage/Sales/etc/api2.xml @@ -308,6 +308,7 @@