Skip to content

Commit

Permalink
Merge pull request #8 from mageplaza/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
haitv282 authored Feb 24, 2020
2 parents af68cab + 855ccc3 commit 94f4003
Show file tree
Hide file tree
Showing 30 changed files with 928 additions and 821 deletions.
26 changes: 13 additions & 13 deletions .github/no-response.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Configuration for probot-no-response - https://github.com/probot/no-response

# Number of days of inactivity before an Issue is closed for lack of response
daysUntilClose: 7
# Label requiring a response
responseRequiredLabel: waiting-customer-response
# Comment to post when closing an Issue for lack of response. Set to `false` to disable
closeComment: >
This issue has been automatically closed because there has been no response
to our request for more information from the original author. With only the
information that is currently in the issue, we don't have enough information
to take action. Please reach out if you have or find the answers we need so
that we can investigate further.
# Configuration for probot-no-response - https://github.com/probot/no-response

# Number of days of inactivity before an Issue is closed for lack of response
daysUntilClose: 7
# Label requiring a response
responseRequiredLabel: waiting-customer-response
# Comment to post when closing an Issue for lack of response. Set to `false` to disable
closeComment: >
This issue has been automatically closed because there has been no response
to our request for more information from the original author. With only the
information that is currently in the issue, we don't have enough information
to take action. Please reach out if you have or find the answers we need so
that we can investigate further.
136 changes: 68 additions & 68 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,68 +1,68 @@
language: php
php:
- 7.0
- 7.1
sudo: required
dist: trusty
env:
global:
- COMPOSER_BIN_DIR=~/bin
- INTEGRATION_SETS=3
- NODE_JS_VERSION=6
- MAGENTO_HOST_NAME="magento2.travis"
- COMPOSER_MODULE=mageplaza/module-delete-orders
matrix:
- MAGENTO_VERSION=2.2.1 TEST_SUITE=integration INTEGRATION_INDEX=1
- MAGENTO_VERSION=2.2.1 TEST_SUITE=integration INTEGRATION_INDEX=2
- MAGENTO_VERSION=2.2.1 TEST_SUITE=integration INTEGRATION_INDEX=3
- MAGENTO_VERSION=2.2.2 TEST_SUITE=static
- MAGENTO_VERSION=2.2.2 TEST_SUITE=js GRUNT_COMMAND=static
- MAGENTO_VERSION=2.2.2 TEST_SUITE=integration INTEGRATION_INDEX=1
- MAGENTO_VERSION=2.2.2 TEST_SUITE=integration INTEGRATION_INDEX=2
- MAGENTO_VERSION=2.2.2 TEST_SUITE=integration INTEGRATION_INDEX=3
- MAGENTO_VERSION=2.2.5 TEST_SUITE=integration INTEGRATION_INDEX=1
- MAGENTO_VERSION=2.2.5 TEST_SUITE=integration INTEGRATION_INDEX=2
- MAGENTO_VERSION=2.2.5 TEST_SUITE=integration INTEGRATION_INDEX=3
- MAGENTO_VERSION=2.2.6 TEST_SUITE=integration INTEGRATION_INDEX=1
- MAGENTO_VERSION=2.2.6 TEST_SUITE=integration INTEGRATION_INDEX=2
- MAGENTO_VERSION=2.2.6 TEST_SUITE=integration INTEGRATION_INDEX=3

matrix:
exclude:
- php: 7.0
env: MAGENTO_VERSION=2.2.2 TEST_SUITE=js GRUNT_COMMAND=static
- php: 7.0
env: MAGENTO_VERSION=2.2.2 TEST_SUITE=static
cache:
apt: true
directories:
- "$HOME/.composer/cache"
- "$HOME/.nvm"
addons:
apt:
packages:
- mysql-server-5.6
- mysql-client-core-5.6
- mysql-client-5.6
- postfix
firefox: '46.0'
hosts:
- magento2.travis
before_install:
- git clone https://github.com/magento/magento2 --branch $MAGENTO_VERSION
- cd magento2
- bash ./dev/travis/before_install.sh
install:
- composer install --no-interaction --prefer-dist
- composer require $COMPOSER_MODULE
before_script:
#- cp -f ${TRAVIS_BUILD_DIR}/dev/tests/integration/phpunit.xml.dist dev/tests/integration/
- echo "vendor/$COMPOSER_MODULE" > dev/tests/static/testsuite/Magento/Test/Less/_files/whitelist/common.txt
- echo "vendor/$COMPOSER_MODULE" > dev/tests/static/testsuite/Magento/Test/Php/_files/whitelist/common.txt
- echo "vendor/$COMPOSER_MODULE/**/*.js" > dev/tests/static/testsuite/Magento/Test/Js/_files/whitelist/magento.txt
- bash ./dev/travis/before_script.sh
script:
- test $TEST_SUITE = "static" && TEST_FILTER='--filter "Magento\\Test\\Php\\LiveCodeTest"' || true
- test $TEST_SUITE = "functional" && TEST_FILTER='dev/tests/functional/testsuites/Magento/Mtf/TestSuite/InjectableTests.php' || true


language: php
php:
- 7.0
- 7.1
sudo: required
dist: trusty
env:
global:
- COMPOSER_BIN_DIR=~/bin
- INTEGRATION_SETS=3
- NODE_JS_VERSION=6
- MAGENTO_HOST_NAME="magento2.travis"
- COMPOSER_MODULE=mageplaza/module-delete-orders
matrix:
- MAGENTO_VERSION=2.2.1 TEST_SUITE=integration INTEGRATION_INDEX=1
- MAGENTO_VERSION=2.2.1 TEST_SUITE=integration INTEGRATION_INDEX=2
- MAGENTO_VERSION=2.2.1 TEST_SUITE=integration INTEGRATION_INDEX=3
- MAGENTO_VERSION=2.2.2 TEST_SUITE=static
- MAGENTO_VERSION=2.2.2 TEST_SUITE=js GRUNT_COMMAND=static
- MAGENTO_VERSION=2.2.2 TEST_SUITE=integration INTEGRATION_INDEX=1
- MAGENTO_VERSION=2.2.2 TEST_SUITE=integration INTEGRATION_INDEX=2
- MAGENTO_VERSION=2.2.2 TEST_SUITE=integration INTEGRATION_INDEX=3
- MAGENTO_VERSION=2.2.5 TEST_SUITE=integration INTEGRATION_INDEX=1
- MAGENTO_VERSION=2.2.5 TEST_SUITE=integration INTEGRATION_INDEX=2
- MAGENTO_VERSION=2.2.5 TEST_SUITE=integration INTEGRATION_INDEX=3
- MAGENTO_VERSION=2.2.6 TEST_SUITE=integration INTEGRATION_INDEX=1
- MAGENTO_VERSION=2.2.6 TEST_SUITE=integration INTEGRATION_INDEX=2
- MAGENTO_VERSION=2.2.6 TEST_SUITE=integration INTEGRATION_INDEX=3

matrix:
exclude:
- php: 7.0
env: MAGENTO_VERSION=2.2.2 TEST_SUITE=js GRUNT_COMMAND=static
- php: 7.0
env: MAGENTO_VERSION=2.2.2 TEST_SUITE=static
cache:
apt: true
directories:
- "$HOME/.composer/cache"
- "$HOME/.nvm"
addons:
apt:
packages:
- mysql-server-5.6
- mysql-client-core-5.6
- mysql-client-5.6
- postfix
firefox: '46.0'
hosts:
- magento2.travis
before_install:
- git clone https://github.com/magento/magento2 --branch $MAGENTO_VERSION
- cd magento2
- bash ./dev/travis/before_install.sh
install:
- composer install --no-interaction --prefer-dist
- composer require $COMPOSER_MODULE
before_script:
#- cp -f ${TRAVIS_BUILD_DIR}/dev/tests/integration/phpunit.xml.dist dev/tests/integration/
- echo "vendor/$COMPOSER_MODULE" > dev/tests/static/testsuite/Magento/Test/Less/_files/whitelist/common.txt
- echo "vendor/$COMPOSER_MODULE" > dev/tests/static/testsuite/Magento/Test/Php/_files/whitelist/common.txt
- echo "vendor/$COMPOSER_MODULE/**/*.js" > dev/tests/static/testsuite/Magento/Test/Js/_files/whitelist/magento.txt
- bash ./dev/travis/before_script.sh
script:
- test $TEST_SUITE = "static" && TEST_FILTER='--filter "Magento\\Test\\Php\\LiveCodeTest"' || true
- test $TEST_SUITE = "functional" && TEST_FILTER='dev/tests/functional/testsuites/Magento/Mtf/TestSuite/InjectableTests.php' || true


7 changes: 4 additions & 3 deletions Console/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class Delete extends Command

/**
* Delete constructor.
*
* @param HelperData $helperData
* @param OrderRepository $orderRepository
* @param State $state
Expand All @@ -76,10 +77,10 @@ public function __construct(
Registry $registry,
$name = null
) {
$this->_helperData = $helperData;
$this->_helperData = $helperData;
$this->orderRepository = $orderRepository;
$this->state = $state;
$this->registry = $registry;
$this->state = $state;
$this->registry = $registry;

parent::__construct($name);
}
Expand Down
64 changes: 53 additions & 11 deletions Controller/Adminhtml/Delete/Manually.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@
use Magento\Framework\App\ResponseInterface;
use Magento\Framework\Controller\Result\Redirect;
use Magento\Framework\Controller\ResultInterface;
use Magento\Sales\Api\OrderManagementInterface;
use Magento\Sales\Model\OrderRepository;
use Magento\Store\Model\StoreManagerInterface;
use Mageplaza\DeleteOrders\Helper\Data as HelperData;
use Mageplaza\DeleteOrders\Helper\Email;
use Psr\Log\LoggerInterface;

/**
Expand All @@ -53,22 +56,47 @@ class Manually extends Action
*/
protected $logger;

/**
* @var OrderManagementInterface
*/
protected $_orderManagement;

/**
* @var Email
*/
protected $_email;

/**
* @var StoreManagerInterface
*/
protected $_storeManager;

/**
* Manually constructor.
*
* @param Context $context
* @param HelperData $helperData
* @param OrderRepository $orderRepository
* @param LoggerInterface $logger
* @param OrderManagementInterface $orderManagement
* @param Email $email
* @param StoreManagerInterface $storeManager
*/
public function __construct(
Context $context,
HelperData $helperData,
OrderRepository $orderRepository,
LoggerInterface $logger
LoggerInterface $logger,
OrderManagementInterface $orderManagement,
Email $email,
StoreManagerInterface $storeManager
) {
$this->_helperData = $helperData;
$this->orderRepository = $orderRepository;
$this->logger = $logger;
$this->_helperData = $helperData;
$this->orderRepository = $orderRepository;
$this->logger = $logger;
$this->_orderManagement = $orderManagement;
$this->_email = $email;
$this->_storeManager = $storeManager;

parent::__construct($context);
}
Expand All @@ -78,18 +106,29 @@ public function __construct(
*/
public function execute()
{
$resultRedirect = $this->resultRedirectFactory->create();
$storeId = $this->getRequest()->getParam('store');

$resultRedirect = $this->resultRedirectFactory->create();
$storeId = $this->getRequest()->getParam('store');
$status = ['processing', 'pending', 'fraud'];
$orderCollection = $this->_helperData->getMatchingOrders($storeId);

if ($orderCollection->getSize()) {
$successDelete = 0;
$errorOrders = [];
$errorOrders = [];

foreach ($orderCollection->getItems() as $order) {
try {
$this->orderRepository->delete($order);
$this->_helperData->deleteRecord(reset($orderIds));
if ($this->_helperData->versionCompare('2.3.0')) {
if (in_array($order->getStatus(), $status, true)) {
$this->_orderManagement->cancel($order->getId());
}
if ($order->getStatus() === 'holded') {
$this->_orderManagement->unHold($order->getId());
$this->_orderManagement->cancel($order->getId());
}
}

$this->orderRepository->delete($order);
$this->_helperData->deleteRecord($order->getId());
$successDelete++;
} catch (Exception $e) {
$errorOrders[$order->getId()] = $order->getIncrementId();
Expand All @@ -102,7 +141,10 @@ public function execute()
}

if (count($errorOrders)) {
$this->messageManager->addSuccessMessage(__('The following orders cannot being deleted. %1', implode(', ', $errorOrders)));
$this->messageManager->addErrorMessage(__(
'The following orders cannot being deleted. %1',
implode(', ', $errorOrders)
));
}
} else {
$this->messageManager->addNoticeMessage(__('No order has been deleted!'));
Expand Down
21 changes: 17 additions & 4 deletions Controller/Adminhtml/Order/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
namespace Mageplaza\DeleteOrders\Controller\Adminhtml\Order;

use Exception;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\App\ResponseInterface;
use Magento\Framework\Controller\Result\Redirect;
use Magento\Framework\Controller\ResultInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\Sales\Controller\Adminhtml\Order;
Expand All @@ -42,13 +44,15 @@ class Delete extends Order
const ADMIN_RESOURCE = 'Magento_Sales::delete';

/**
* @return $this|ResponseInterface|ResultInterface
* @return ResponseInterface|Redirect|ResultInterface
*/
public function execute()
{
$resultRedirect = $this->resultRedirectFactory->create();

$helper = $this->_objectManager->get(Data::class);
$resultRedirect = $this->resultRedirectFactory->create();
$objectManager = ObjectManager::getInstance();
$orderManagement = $objectManager->create('Magento\Sales\Api\OrderManagementInterface');
$status = ['processing', 'pending', 'fraud'];
$helper = $this->_objectManager->get(Data::class);
if (!$helper->isEnabled()) {
$this->messageManager->addError(__('Cannot delete the order.'));

Expand All @@ -60,6 +64,15 @@ public function execute()
$order = $this->_initOrder();
if ($order) {
try {
if ($helper->versionCompare('2.3.0')) {
if (in_array($order->getStatus(), $status)) {
$orderManagement->cancel($order->getId());
}
if ($order->getStatus() === 'holded') {
$orderManagement->unHold($order->getId());
$orderManagement->cancel($order->getId());
}
}
/** delete order*/
$this->orderRepository->delete($order);
/** delete order data on grid report data related*/
Expand Down
Loading

0 comments on commit 94f4003

Please sign in to comment.