Skip to content

Commit

Permalink
Merge pull request #18 from mageplaza/2.4-develop
Browse files Browse the repository at this point in the history
merge branch 2.4 develop intp 2.4
  • Loading branch information
phamcuongmp authored Aug 16, 2021
2 parents ca5983e + 238017b commit 44bc6c2
Show file tree
Hide file tree
Showing 8 changed files with 316 additions and 231 deletions.
19 changes: 8 additions & 11 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

/**
* Class Data
*
* @package Mageplaza\DeleteOrders\Helper
*/
class Data extends AbstractData
Expand All @@ -51,11 +50,10 @@ class Data extends AbstractData
/**
* Data constructor.
*
* @param Context $context
* @param Context $context
* @param ObjectManagerInterface $objectManager
* @param StoreManagerInterface $storeManager
* @param CollectionFactory $orderCollectionFactory
* @param OrderFactory $orderResourceFactory
* @param StoreManagerInterface $storeManager
* @param OrderFactory $orderResourceFactory
*/
public function __construct(
Context $context,
Expand All @@ -74,7 +72,7 @@ public function __construct(
* Get order collection which matching the delete config condition
*
* @param null $storeId
* @param int $limit
* @param int $limit
*
* @return Collection
*/
Expand All @@ -85,12 +83,12 @@ public function getMatchingOrders($storeId = null, $limit = 1000)
->addFieldToFilter('customer_group_id', ['in' => $this->getOrderCustomerGroupConfig($storeId)]);

$storeIds = $this->getStoreViewConfig($storeId);
if (!in_array(Store::DEFAULT_STORE_ID, $storeIds)) {
if (!in_array(Store::DEFAULT_STORE_ID, $storeIds, true)) {
$orderCollection->addFieldToFilter('store_id', ['in' => $storeIds]);
}

if ($total = $this->getOrderTotalConfig($storeId)) {
$orderCollection->addFieldToFilter('grand_total', ['lteq' => $total]);
$orderCollection->addFieldToFilter('base_grand_total', ['lteq' => $total]);
}

if ($dayBefore = $this->getPeriodConfig($storeId)) {
Expand All @@ -108,8 +106,7 @@ public function getMatchingOrders($storeId = null, $limit = 1000)
'main_table.entity_id = soa.parent_id',
[]
)
->where('soa.country_id IN (?)', $this->getCountriesConfig($storeId))
->where('soa.address_type IN (?)', 'shipping');
->where('soa.country_id IN (?)', $this->getCountriesConfig($storeId));
}

return $orderCollection;
Expand Down Expand Up @@ -225,7 +222,7 @@ public function getPeriodConfig($storeId = null)

/**
* @param $code
* @param null $storeId
* @param null $storeId
*
* @return mixed
*/
Expand Down
30 changes: 13 additions & 17 deletions Model/Config/Backend/Order/Frequency.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,16 @@ class Frequency extends Value
/**
* Frequency constructor.
*
* @param Context $context
* @param Registry $registry
* @param ScopeConfigInterface $config
* @param TypeListInterface $cacheTypeList
* @param ValueFactory $configValueFactory
* @param ManagerInterface $messageManager
* @param Context $context
* @param Registry $registry
* @param ScopeConfigInterface $config
* @param TypeListInterface $cacheTypeList
* @param ValueFactory $configValueFactory
* @param ManagerInterface $messageManager
* @param AbstractResource|null $resource
* @param AbstractDb|null $resourceCollection
* @param string $runModelPath
* @param array $data
* @param AbstractDb|null $resourceCollection
* @param string $runModelPath
* @param array $data
*/
public function __construct(
Context $context,
Expand Down Expand Up @@ -111,16 +111,12 @@ public function __construct(
public function afterSave()
{
$time = $this->getData('groups/schedule/fields/time/value');
$frequency = $this->getData('groups/schedule/fields/schedule_for/value');
$frequency = $this->getData('groups/schedule/fields/frequency/value');

if (!$frequency) {
return parent::afterSave();
}

if ($frequency !== ValueConfig::DISABLE) {
if ($frequency != (string)ValueConfig::DISABLE) {
$cronExprArray = [
(int)$time[1], //Minute
(int)$time[0], //Hour
(int) $time[1], //Minute
(int) $time[0], //Hour
$frequency === \Magento\Cron\Model\Config\Source\Frequency::CRON_MONTHLY ? '1' : '*', //Day of the Month
'*', //Month of the Year
$frequency === \Magento\Cron\Model\Config\Source\Frequency::CRON_WEEKLY ? '1' : '*', //Day of the Week
Expand Down
64 changes: 64 additions & 0 deletions Plugin/Model/Order.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php
/**
* Mageplaza
*
* NOTICE OF LICENSE
*
* This source file is subject to the Mageplaza.com license that is
* available through the world-wide-web at this URL:
* https://www.mageplaza.com/LICENSE.txt
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this extension to newer
* version in the future.
*
* @category Mageplaza
* @package Mageplaza_DeleteOrder
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
* @license https://www.mageplaza.com/LICENSE.txt
*/

namespace Mageplaza\DeleteOrders\Plugin\Model;

use Mageplaza\DeleteOrders\Helper\Data;
use Magento\Sales\Model\Order as CoreOrder;

/**
* Class Order
* @package Mageplaza\DeleteOrders\Plugin\Model
*/
class Order
{
/**
* @var Data
*/
protected $helper;

/**
* Order constructor.
* @param Data $helper
*/
public function __construct(
Data $helper
) {
$this->helper = $helper;
}

/**
* @param CoreOrder $order
* @return array
*/
public function beforeUnhold(CoreOrder $order)
{
if (!$this->helper->isEnabled()) {
return [];
}

if ($order->getStatus() !== $order->getState() && $order->getStatus() === CoreOrder::STATE_HOLDED) {
$order->setState(CoreOrder::STATE_HOLDED);
}

return [];
}
}
39 changes: 31 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Magento 2 Delete Orders free by Mageplaza
# Magento 2 Delete Orders extension Free

**Magento 2 Delete Orders** by Mageplaza helps admins completely remove unnecessary orders, invoices, shipments and credit memos which are arised during testing process. This helps simplify order management and get these arranged neater.
**[Magento 2 Delete Orders](https://www.mageplaza.com/magento-2-delete-orders/)** by Mageplaza helps admins completely remove unnecessary orders, invoices, shipments and credit memos which are arised during testing process. This helps simplify order management and get these arranged neater.


## Highlight features
Expand All @@ -13,7 +13,7 @@
[![Latest Stable Version](https://poser.pugx.org/mageplaza/module-delete-orders/v/stable)](https://packagist.org/packages/mageplaza/module-delete-orders)
[![Total Downloads](https://poser.pugx.org/mageplaza/module-delete-orders/downloads)](https://packagist.org/packages/mageplaza/module-delete-orders)

**IMPORTANT NOTE:** This version of Mageplaza Delete Orders extension on Github is free as a contribution to the Magento community from Mageplaza. This package does not include the technical support. Should you need technical support for this extension, you will have to buy a license from Mageplaza. [Click here to buy](https://www.mageplaza.com/magento-2-delete-orders/).
**IMPORTANT NOTE:** This version of Magento 2 Delete Orders extension on Github is free as a contribution to the Magento community from Mageplaza. This package does not include the technical support. Should you need technical support for this extension, you will have to buy a license from Mageplaza. [Click here to buy](https://www.mageplaza.com/magento-2-delete-orders/).

## 1. Documentation

Expand All @@ -31,26 +31,34 @@
A: Read solution: https://github.com/mageplaza/module-core/issues/3


## 3. How to install
## 3. How to install Magento 2 Delete Orders


## ✓ Install via composer (recommend)
Run the following command in Magento 2 root folder:

With Marketing Automation (recommend):
```
composer require mageplaza/module-delete-orders mageplaza/module-smtp
php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy
```

Without Marketing Automation:
```
composer require mageplaza/module-delete-orders
php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy
```


## 4. Problems & Solutions
## 4. Magento 2 Delete Orders: Problems & Solutions

Before applying any new changes in an online store, store admins have to carry quite many tests. This testing process can arise a number of orders, invoices, shipments and credit memos which are obviously unnecessary in long term and they can cause difficulties in management. Unfortunately, default Magento 2 doesn’t support any functionalities to remove them from the backend. This consequently causes frustration and inconvenience in administration.

There should be a way to deal with this problem, Mageplaza Delete Orders extension is developed to help store admins simplify this task. The module helps delete orders, invoices, shipments and credit memos from the backend but keeps the retire data safe. The job can be done in the blink of an eye with mass deleting feature and ability to delete all.

## 5. Why online stores must have Mageplaza Delete Orders
## 5. Why online stores must have Mageplaza's Delete Orders

### To keep the backend well-arranged and neat
The appearance of test orders makes a store’s backend look like a mess. Thus cuts in unnecessary orders, shipments, invoices and credit memos created for testing will make everything neater, easier to follow and less confusing.
Expand All @@ -59,7 +67,7 @@ The appearance of test orders makes a store’s backend look like a mess. Thus c
The large number of test orders can confuse store admins and this can cause inconvenience or mistakes in managing. Having a neater backend will simplify order management.


## 6. Features
## 6. Magento 2 Delete Orders Features

![magento 2 delete orders](https://cdn.mageplaza.com/media/general/GKcj6HQ.png)

Expand All @@ -81,7 +89,7 @@ While deleting orders, invoices, shipments and credit memos, their related data
- The module supports multi stores
- Multiple languages are supported
- It’s easy to customize
- Mageplaza provides a well-documented user guide for Delete Orders extension
- Mageplaza provides a well-documented user guide for Magento 2 Delete Orders extension

**People also search:**
- magento 2 delete order
Expand All @@ -104,3 +112,18 @@ While deleting orders, invoices, shipments and credit memos, their related data
- [Magento 2 blog extension](https://github.com/mageplaza/magento-2-blog)
- [Magento 2 Ajax Layered Navigation](https://github.com/mageplaza/magento-2-ajax-layered-navigation)
- [Magento 2 security](https://github.com/mageplaza/magento-2-security)


**Get more [Magento 2 extension on Marketplace](https://marketplace.magento.com/partner/Mageplaza):**
- [Magento 2 OneStepCheckout](https://marketplace.magento.com/mageplaza-magento-2-one-step-checkout-extension.html)
- [Magento 2 Payment Restriction](https://marketplace.magento.com/mageplaza-module-payment-restriction.html)
- [Magento 2 Frequently Bought Together](https://marketplace.magento.com/mageplaza-module-frequently-bought-together.html)
- [Magento 2 Shipping Rules](https://marketplace.magento.com/mageplaza-module-shipping-rules.html)
- [Magento 2 Abandoned Cart Email](https://marketplace.magento.com/mageplaza-module-abandoned-cart-email.html)
- [Magento 2 SMTP](https://marketplace.magento.com/mageplaza-module-smtp.html)
- [Magento 2 Shipping Restrictions](https://marketplace.magento.com/mageplaza-module-shipping-restriction.html)
- [Magento 2 Gift Card](https://marketplace.magento.com/mageplaza-module-gift-card.html)
- [Magento 2 Order Attributes](https://marketplace.magento.com/mageplaza-module-order-attributes.html)
- [Magento 2 Layer Navitaion](https://marketplace.magento.com/mageplaza-layered-navigation-m2.html)
- [Magento 2 SEO All-in-one](https://marketplace.magento.com/mageplaza-magento-2-seo-extension.html)

2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"mageplaza/module-core": "^1.4.5"
},
"type": "magento2-module",
"version": "4.0.0",
"version": "4.0.1",
"license": "proprietary",
"authors": [
{
Expand Down
63 changes: 33 additions & 30 deletions etc/adminhtml/di.xml
Original file line number Diff line number Diff line change
@@ -1,30 +1,33 @@
<?xml version="1.0"?>
<!--
/**
* Mageplaza
*
* NOTICE OF LICENSE
*
* This source file is subject to the Mageplaza.com license that is
* available through the world-wide-web at this URL:
* https://www.mageplaza.com/LICENSE.txt
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this extension to newer
* version in the future.
*
* @category Mageplaza
* @package Mageplaza_DeleteOrders
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
* @license https://www.mageplaza.com/LICENSE.txt
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Sales\Block\Adminhtml\Order\View">
<plugin name="delete_order_add_button_delete" type="Mageplaza\DeleteOrders\Plugin\Order\AddDeleteButton"/>
</type>
<type name="Magento\Ui\Component\MassAction">
<plugin name="delete_order_add_massaction_delete" type="Mageplaza\DeleteOrders\Plugin\Order\AddDeleteAction"/>
</type>
</config>
<?xml version="1.0"?>
<!--
/**
* Mageplaza
*
* NOTICE OF LICENSE
*
* This source file is subject to the Mageplaza.com license that is
* available through the world-wide-web at this URL:
* https://www.mageplaza.com/LICENSE.txt
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this extension to newer
* version in the future.
*
* @category Mageplaza
* @package Mageplaza_DeleteOrders
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
* @license https://www.mageplaza.com/LICENSE.txt
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Sales\Block\Adminhtml\Order\View">
<plugin name="delete_order_add_button_delete" type="Mageplaza\DeleteOrders\Plugin\Order\AddDeleteButton"/>
</type>
<type name="Magento\Ui\Component\MassAction">
<plugin name="delete_order_add_massaction_delete" type="Mageplaza\DeleteOrders\Plugin\Order\AddDeleteAction"/>
</type>
<type name="Magento\Sales\Model\Order">
<plugin name="delete_order_hold_on" type="Mageplaza\DeleteOrders\Plugin\Model\Order"/>
</type>
</config>
Loading

0 comments on commit 44bc6c2

Please sign in to comment.