Skip to content

Commit 2c6a95a

Browse files
committed
ACP2E-1120: extend new statuses that can apply for new placed order with free payment
1 parent c7d99dc commit 2c6a95a

File tree

1 file changed

+24
-3
lines changed
  • app/code/Magento/Payment/Model/Method

1 file changed

+24
-3
lines changed

app/code/Magento/Payment/Model/Method/Free.php

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,18 @@
55
*/
66
namespace Magento\Payment\Model\Method;
77

8+
use Magento\Framework\Api\AttributeValueFactory;
9+
use Magento\Framework\Api\ExtensionAttributesFactory;
10+
use Magento\Framework\App\Config\ScopeConfigInterface;
11+
use Magento\Framework\App\ObjectManager;
12+
use Magento\Framework\Data\Collection\AbstractDb;
13+
use Magento\Framework\Model\Context;
14+
use Magento\Framework\Model\ResourceModel\AbstractResource;
815
use Magento\Framework\Pricing\PriceCurrencyInterface;
16+
use Magento\Framework\Registry;
17+
use Magento\Payment\Helper\Data;
18+
use Magento\Sales\Model\Order\Config;
19+
use Magento\Sales\Model\Order\Status;
920

1021
/**
1122
* Free payment method
@@ -50,6 +61,11 @@ class Free extends \Magento\Payment\Model\Method\AbstractMethod
5061
*/
5162
protected $priceCurrency;
5263

64+
/**
65+
* @var Config|null
66+
*/
67+
private $config;
68+
5369
/**
5470
* @param \Magento\Framework\Model\Context $context
5571
* @param \Magento\Framework\Registry $registry
@@ -62,6 +78,7 @@ class Free extends \Magento\Payment\Model\Method\AbstractMethod
6278
* @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
6379
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
6480
* @param array $data
81+
* @param Config|null $config
6582
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
6683
*/
6784
public function __construct(
@@ -75,7 +92,8 @@ public function __construct(
7592
PriceCurrencyInterface $priceCurrency,
7693
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
7794
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
78-
array $data = []
95+
array $data = [],
96+
Config $config = null
7997
) {
8098
parent::__construct(
8199
$context,
@@ -90,6 +108,7 @@ public function __construct(
90108
$data
91109
);
92110
$this->priceCurrency = $priceCurrency;
111+
$this->config = $config ?: ObjectManager::getInstance()->create(Config::class);
93112
}
94113

95114
/**
@@ -119,12 +138,14 @@ public function isAvailableInConfig($quote = null)
119138
}
120139

121140
/**
122-
* Get config payment action, do nothing if status is pending
141+
* Get config payment action, do nothing if status is pending or status is assigned to new[Pending] state
123142
*
124143
* @return string|null
125144
*/
126145
public function getConfigPaymentAction()
127146
{
128-
return $this->getConfigData('order_status') == 'pending' ? null : parent::getConfigPaymentAction();
147+
$newStateStatuses = $this->config->getStateStatuses('new');
148+
$configNewOrderStatus = $this->getConfigData('order_status');
149+
return $configNewOrderStatus == 'pending' || array_key_exists($configNewOrderStatus, $newStateStatuses) ? null : parent::getConfigPaymentAction();
129150
}
130151
}

0 commit comments

Comments
 (0)