checkout / checkout-magento2-plugin

Checkout.com Magento 2 official extension
MIT License
32 stars 32 forks source link

order_action_failed_payment is Null if config is default #532

Open kpitn opened 11 months ago

kpitn commented 11 months ago

Hi,

I Controller/Payment/Fail.php File you are using :

$action = $this->config->getValue('order_action_failed_payment', null, $storeCode);

    public function getValue(
        string $field,
        string $methodId = null,
        $storeCode = null,
        string $scope = ScopeInterface::SCOPE_WEBSITE
    ) {
        return $this->loader->getValue($field, $methodId, $storeCode, $scope);
    }

The module is config in defaut vue :

+---------+-------+--------+--------------------------------------------------------------+------+-------------------+
|config_id|scope  |scope_id|path                                                          |value |updated_at         |
+---------+-------+--------+--------------------------------------------------------------+------+-------------------+
|1429     |default|0       |settings/checkoutcom_configuration/order_action_failed_payment|cancel|2022-08-11 08:58:17|
+---------+-------+--------+--------------------------------------------------------------+------+-------------------+

$action is always NULL.

The solution is to use store scope instead of website scope.

Another patch for the module :

--- Controller/Payment/Fail.php
+++ Controller/Payment/Fail.php
@@ -179,7 +179,7 @@
                     ]);

                     $storeCode = $this->storeManager->getStore()->getCode();
-                    $action    = $this->config->getValue('order_action_failed_payment', null, $storeCode);
+                    $action    = $this->config->getValue('order_action_failed_payment', null, $storeCode, ScopeInterface::SCOPE_STORE);
                     $status    = $action === 'cancel' ? 'canceled' : 'false';

                     // Log the payment error