Skip to content

Commit

Permalink
Merge pull request #4 from outeredge/change-order-status
Browse files Browse the repository at this point in the history
Change order status
  • Loading branch information
davidwindell authored Aug 19, 2024
2 parents f5b6a44 + 9c8f390 commit ca26fcf
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Controller/Adminhtml/Order/MassOrderShip.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,6 @@ public function execute()
}
}
}
return $resultRedirect->setPath('sales/order/index', [], ['error' => true]);
return $resultRedirect->setPath('sales/order/index');
}
}
47 changes: 47 additions & 0 deletions Controller/Adminhtml/Order/MassOrderStatus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace OuterEdge\BulkActions\Controller\Adminhtml\Order;

use Magento\Backend\App\Action\Context;
use Psr\Log\LoggerInterface;
use Magento\Framework\App\ResourceConnection;
use Magento\Sales\Model\Order;

class MassOrderStatus extends \Magento\Backend\App\Action
{
public function __construct(
Context $context,
protected LoggerInterface $logger,
protected ResourceConnection $resourceConnection,
) {
parent::__construct($context);
}

public function execute()
{
$resultRedirect = $this->resultRedirectFactory->create();
$ordersId = $this->getRequest()->getParam('selected');

if (!empty($ordersId)) {
foreach ($ordersId as $orderId) {
$tableSalesOrder = $this->resourceConnection->getTableName('sales_order');
$tableSalesOrderGrid = $this->resourceConnection->getTableName('sales_order_grid');

try {
$connection = $this->resourceConnection->getConnection();
$connection->fetchRow(
"UPDATE $tableSalesOrder SET `state` = '".Order::STATE_COMPLETE."', `status` = '".Order::STATE_COMPLETE."' WHERE `entity_id` = $orderId");
$connection->fetchRow(
"UPDATE $tableSalesOrderGrid SET`status` = '".Order::STATE_COMPLETE."' WHERE `entity_id` = $orderId");

$this->messageManager->addSuccessMessage(__("Status was been changed. Order Id: ".$orderId));
} catch (\Exception $e) {
$this->logger->error($e);
$this->messageManager->addExceptionMessage($e, $e->getMessage());
}
}
}

return $resultRedirect->setPath('sales/order/index');
}
}
7 changes: 7 additions & 0 deletions view/adminhtml/ui_component/sales_order_grid.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@
<label translate="true">Ship (don't notify customer)</label>
</settings>
</action>
<action name="change_status_to_complete">
<settings>
<url path="shipbulkactions/order/massorderstatus"/>
<type>change_status_to_complete</type>
<label translate="true">Force Status to Complete</label>
</settings>
</action>
</massaction>
<paging name="listing_paging"/>
</listingToolbar>
Expand Down

0 comments on commit ca26fcf

Please sign in to comment.