MultiSafepay / magento2

MultiSafepay plugin for Magento 2
Open Software License 3.0
19 stars 8 forks source link

Explode on NULL -> EinvoicingConfigProvider->getCheckoutFields() #38

Closed xgerhard closed 1 year ago

xgerhard commented 1 year ago

Describe the bug Cart / checkout error after updating plugin v2.5 -> 2.21

Cart just shows blank screen Checkout shows: An error has happened during application run. See exception log for details.

[2022-10-11 09:00:37] main.CRITICAL: TypeError: explode() expects parameter 2 to be string, null given in /var/domains/X.com/application/vendor/multisafepay/magento2-core/Model/Ui/Gateway/EinvoicingConfigProvider.php:57
Stack trace:
#0 /var/domains/X.com/application/vendor/multisafepay/magento2-core/Model/Ui/Gateway/EinvoicingConfigProvider.php(57): explode(',', NULL)
#1 /var/domains/X.com/application/vendor/multisafepay/magento2-core/Model/Ui/Gateway/EinvoicingConfigProvider.php(42): MultiSafepay\ConnectCore\Model\Ui\Gateway\EinvoicingConfigProvider->getCheckoutFields()
#2 /var/domains/X.com/application/vendor/multisafepay/magento2-frontend/Plugin/Checkout/Model/CompositeConfigProvider.php(51): MultiSafepay\ConnectCore\Model\Ui\Gateway\EinvoicingConfigProvider->getConfig()
#3 /var/domains/X.com/application/vendor/magento/framework/Interception/Interceptor.php(146): MultiSafepay\ConnectFrontend\Plugin\Checkout\Model\CompositeConfigProvider->afterGetConfig(Object(Magento\Checkout\Model\CompositeConfigProvider\Interceptor), Array)
#4 /var/domains/X.com/application/vendor/magento/framework/Interception/Interceptor.php(153): Magento\Checkout\Model\CompositeConfigProvider\Interceptor->Magento\Framework\Interception\{closure}()
#5 /var/domains/X.com/application/generated/code/Magento/Checkout/Model/CompositeConfigProvider/Interceptor.php(23): Magento\Checkout\Model\CompositeConfigProvider\Interceptor->___callPlugins('getConfig', Array, Array)
#6 /var/domains/X.com/application/vendor/magento/module-checkout/Block/Onepage.php(106): Magento\Checkout\Model\CompositeConfigProvider\Interceptor->getConfig()
#7 /var/domains/X.com/application/vendor/magento/module-checkout/Block/Onepage.php(128): Magento\Checkout\Block\Onepage->getCheckoutConfig()
#8 /var/domains/X.com/application/vendor/magento/module-checkout/view/frontend/templates/onepage.phtml(27): Magento\Checkout\Block\Onepage->getSerializedCheckoutConfig()

To Reproduce Steps to reproduce the behavior:

  1. Magento 2.4.2, MSP plugin v2.5
  2. Update to v2.2.1
  3. Visit cart or checkout page

Additional context Updated the plugin on a system with an old version of the plugin 2.5: composer update multisafepay/magento2 --with-dependencies Updated without any errors.

xgerhard commented 1 year ago

By adding a null check on the getCheckoutFields function the cart & checkout works. However I'm not sure if this 'checkout_fields' field should ever be null, or if that's a different problem.

    /**
     * Returns the selected checkout fields from the config
     *
     * @return array
     */
    private function getCheckoutFields(): array
    {
        $checkoutFields = $this->getPaymentConfig($this->getStoreIdFromCheckoutSession())[Config::CHECKOUT_FIELDS];

        if ($checkoutFields && $checkoutFieldsArray = explode(',', $checkoutFields)) {
            return $checkoutFieldsArray;
        }

        return [];
    }
vinodsowdagar commented 1 year ago

Hi @xgerhard ,

First of all, thank you for the report.

In the config.xml we have added a default value for the checkout_fields, so if a setup:upgrade was done after installation, the default value should have been picked up in that piece of code. The default value is a string, so that is why we did not account for it being NULL. Can you confirm that you are still seeing this issue, even after a setup:upgrade?

If so, then we will have to look into what is happening and indeed, maybe account for it being NULL, or find another way to populate the checkout_fields config field after installation/upgrade.

xgerhard commented 1 year ago

Hi @Vinod-MultiSafepay thanks for the info. I've looked into a bit after your comment, yes we did do a setup:upgrade.

What I've found is.. on the MSP 'payment gateways' settings page, at the 'E-invoicing' tab, the 'use default' checkbox for the 'select checkout fields' wasn't selected, and no options were selected.

So when I changed one the other paymethod settings (E-invoicing wasn't even enabled) the payment/multisafepay_einvoicing/checkout_fields setting got saved as null.

This is on a store level, they were selected at the default config, however the 'select checkout fields' options wasn't even in the older version of the plugin, so I would assumed it had the use default option on.

Since you can deselect all the 'checkout fields' in the backend, a null check might work for that setting.

vinodsowdagar commented 1 year ago

@xgerhard ,

We expected the default value in the config.xml to automatically be picked up. Apparently this is not the case in all Magento instances. We have modified the code to also account for the default config to be null.

The fix is available in the latest release: https://github.com/MultiSafepay/magento2/releases/tag/2.21.1

If there are more questions, please feel free to reopen this issue or create a new one.

xgerhard commented 1 year ago

Thanks for the update! :)