Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hgati/35c5e0f8df5b5e3230466397d6f771bf to your computer and use it in GitHub Desktop.
Save hgati/35c5e0f8df5b5e3230466397d6f771bf to your computer and use it in GitHub Desktop.
Magento2 DeleteOrders Patch #4
From 80066770da67f5710c02ea8f65533a69b0a55917 Mon Sep 17 00:00:00 2001
From: Dennis <cobays@gmail.com>
Date: Wed, 25 Oct 2023 15:24:59 +0900
Subject: [PATCH] Fixed an error in system.log: Areacode is already set
---
Console/Command/DeleteOrdersCommand.php | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/Console/Command/DeleteOrdersCommand.php b/Console/Command/DeleteOrdersCommand.php
index 793bfd9..34dae80 100644
--- a/Console/Command/DeleteOrdersCommand.php
+++ b/Console/Command/DeleteOrdersCommand.php
@@ -40,6 +40,11 @@ class DeleteOrdersCommand extends Command
*/
protected $registry;
+ /**
+ * @var \Magento\Framework\App\State
+ */
+ protected $state;
+
/**
* Init constructor
*
@@ -57,8 +62,7 @@ class DeleteOrdersCommand extends Command
\Magenizr\DeleteOrders\Helper\Data $helper,
\Magento\Framework\Registry $registry
) {
- $state->setAreaCode(\Magento\Framework\App\Area::AREA_ADMINHTML);
-
+ $this->state = $state;
$this->orderFactory = $orderFactory;
$this->order = $order;
$this->helper = $helper;
@@ -97,6 +101,7 @@ class DeleteOrdersCommand extends Command
protected function execute(InputInterface $input, OutputInterface $output)
{
$exitCode = 0;
+ $this->state->setAreaCode(\Magento\Framework\App\Area::AREA_ADMINHTML); // AreaCode must be set in execute method not constructor method.
$this->registry->register('isSecureArea', true); // This action (true) must be performed in order to enable the delete action.
try {
--
2.34.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment