Skip to content

Commit

Permalink
Merge pull request #15 from mageplaza/2.4-develop
Browse files Browse the repository at this point in the history
v4.0.0
  • Loading branch information
phamcuongmp authored Apr 2, 2021
2 parents 7c51f1c + 88e4889 commit ca5983e
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 47 deletions.
17 changes: 10 additions & 7 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

/**
* Class Data
*
* @package Mageplaza\DeleteOrders\Helper
*/
class Data extends AbstractData
Expand All @@ -50,10 +51,11 @@ class Data extends AbstractData
/**
* Data constructor.
*
* @param Context $context
* @param Context $context
* @param ObjectManagerInterface $objectManager
* @param StoreManagerInterface $storeManager
* @param OrderFactory $orderResourceFactory
* @param StoreManagerInterface $storeManager
* @param CollectionFactory $orderCollectionFactory
* @param OrderFactory $orderResourceFactory
*/
public function __construct(
Context $context,
Expand All @@ -72,7 +74,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 @@ -83,7 +85,7 @@ 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, true)) {
if (!in_array(Store::DEFAULT_STORE_ID, $storeIds)) {
$orderCollection->addFieldToFilter('store_id', ['in' => $storeIds]);
}

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

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

/**
* @param $code
* @param null $storeId
* @param null $storeId
*
* @return mixed
*/
Expand Down
28 changes: 16 additions & 12 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,12 +111,16 @@ public function __construct(
public function afterSave()
{
$time = $this->getData('groups/schedule/fields/time/value');
$frequency = (int) $this->getData('groups/schedule/fields/schedule_for/value');
$frequency = $this->getData('groups/schedule/fields/schedule_for/value');

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

if ($frequency !== 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
90 changes: 90 additions & 0 deletions Model/Config/Source/StoreView.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?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_DeleteOrders
* @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/)
* @license https://www.mageplaza.com/LICENSE.txt
*/

namespace Mageplaza\DeleteOrders\Model\Config\Source;

use Magento\Store\Model\System\Store;
use Magento\Eav\Model\Entity\Attribute\Source\AbstractSource;

/**
* Class StoreView
*
* @package Mageplaza\DeleteOrders\Model\Config\Source
*/
class StoreView extends AbstractSource
{
/**
* @var Store
*/
private $store;

/**
* StoreView constructor.
*
* @param Store $store
*/
public function __construct(Store $store)
{
$this->store = $store;
}

/**
* @return array
*/
public function toOptionArray()
{
$this->_options[] = [
'label' => __('All Store Views'),
'value' => 0,
];

foreach ($this->store->toOptionArray() as $item) {
$this->_options[] = [
'label' => __($item['label']),
'value' => $item['value'],
];
}

return $this->_options;
}

/**
* Get all options
*
* @return array
*/
public function getAllOptions()
{
$this->_options[] = [
'label' => __('All Store Views'),
'value' => 0,
];

foreach ($this->store->toOptionArray() as $item) {
$this->_options[] = [
'label' => __($item['label']),
'value' => $item['value'],
];
}

return $this->_options;
}
}
52 changes: 26 additions & 26 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
{
"name": "mageplaza/module-delete-orders",
"description": "Magento 2 Delete Orders extension",
"require": {
"mageplaza/module-core": "^1.4.5"
},
"type": "magento2-module",
"version": "1.2.1",
"license": "proprietary",
"authors": [
{
"name": "Mageplaza",
"email": "[email protected]",
"homepage": "https://www.mageplaza.com",
"role": "Technical Support"
}
],
"autoload": {
"files": [
"registration.php"
],
"psr-4": {
"Mageplaza\\DeleteOrders\\": ""
}
}
}
{
"name": "mageplaza/module-delete-orders",
"description": "Magento 2 Delete Orders extension",
"require": {
"mageplaza/module-core": "^1.4.5"
},
"type": "magento2-module",
"version": "4.0.0",
"license": "proprietary",
"authors": [
{
"name": "Mageplaza",
"email": "[email protected]",
"homepage": "https://www.mageplaza.com",
"role": "Technical Support"
}
],
"autoload": {
"files": [
"registration.php"
],
"psr-4": {
"Mageplaza\\DeleteOrders\\": ""
}
}
}
4 changes: 2 additions & 2 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@
</field>
<field id="order_status" translate="label comment" type="multiselect" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<label>Order Status</label>
<source_model>Magento\Sales\Model\Config\Source\Order\Status</source_model>
<source_model>Magento\Sales\Model\ResourceModel\Order\Status\Collection</source_model>
</field>
<field id="customer_groups" translate="label comment" type="multiselect" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<label>Customer Group(s)</label>
<source_model>Magento\Customer\Model\ResourceModel\Group\Collection</source_model>
</field>
<field id="store_views" translate="label comment" type="multiselect" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<label>Store View(s)</label>
<source_model>Magento\Store\Model\System\Store</source_model>
<source_model>Mageplaza\DeleteOrders\Model\Config\Source\StoreView</source_model>
</field>
<field id="country" translate="label comment" type="select" sortOrder="50" showInDefault="1" showInWebsite="1" showInStore="1" canRestore="1">
<label>Shipping Countries</label>
Expand Down

0 comments on commit ca5983e

Please sign in to comment.