Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport: #2315 #2746

Merged
merged 3 commits into from
Nov 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -5050,6 +5050,16 @@ parameters:
count: 1
path: ../app/code/core/Mage/Sales/Block/Recurring/Profiles.php

-
message: "#^Variable \\$oldArea might not be defined\\.$#"
count: 1
path: ../app/code/core/Mage/Sales/Model/Api2/Order/Comment/Rest/Admin/V1.php

-
message: "#^Variable \\$oldStore might not be defined\\.$#"
count: 1
path: ../app/code/core/Mage/Sales/Model/Api2/Order/Comment/Rest/Admin/V1.php

-
message: "#^Call to an undefined method Varien_Simplexml_Element\\:\\:getClassName\\(\\)\\.$#"
count: 1
Expand Down
1 change: 1 addition & 0 deletions app/code/core/Mage/Sales/Model/Api2/Order/Comment/Rest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,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)
*/
public const PARAM_ORDER_ID = 'id';
public const PARAM_COMMENT_ID = 'comment_id';
/**#@-*/

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,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);
elidrissidev marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* 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();
}
}
5 changes: 5 additions & 0 deletions app/code/core/Mage/Sales/etc/api2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@
<title>Order Comments</title>
<privileges>
<admin>
<create>1</create>
<retrieve>1</retrieve>
</admin>
<customer>
Expand All @@ -323,6 +324,10 @@
</customer>
</force_attributes>
<routes>
<route_entity>
<route>/orders/comments/:comment_id</route>
<action_type>entity</action_type>
</route_entity>
<route_collection>
<route>/orders/:id/comments</route>
<action_type>collection</action_type>
Expand Down