mollie / magento2

Mollie Payments for Magento 2
https://www.mollie.com
Other
101 stars 53 forks source link

getMethod() on null #37

Closed pascal08 closed 6 years ago

pascal08 commented 6 years ago

This error occurs around these lines of code in /vendor/mollie/magento2/Controller/Checkout/Redirect.php

$order = $this->checkoutSession->getLastRealOrder();
$method = $order->getPayment()->getMethod();
$methodInstance = $this->paymentHelper->getMethodInstance($method);

Stack trace:


( ! ) Fatal error: Uncaught Error: Call to a member function getMethod() on null in /data/magento2/vendor/mollie/magento2/Controller/Checkout/Redirect.php on line 54
--

1 | 0.0002 | 396584 | {main}( ) | .../index.php:0
2 | 3.3563 | 27800824 | Magento\Framework\App\Bootstrap->run( ) | .../index.php:39
3 | 3.3572 | 27827344 | Magento\Framework\App\Http->launch( ) | .../Bootstrap.php:258
4 | 6.0866 | 35369864 | Magento\Framework\App\FrontController\Interceptor->dispatch( ) | .../Http.php:135
5 | 6.1644 | 35653392 | Magento\Framework\App\FrontController\Interceptor->___callPlugins( ) | .../Interceptor.php:26
6 | 6.1679 | 35779168 | TemplateMonster\SiteMaintenance\Model\PageCache\App\FrontController\BuiltinPlugin->aroundDispatch( ) | .../Interceptor.php:142
7 | 6.1679 | 35779168 | TemplateMonster\SiteMaintenance\Model\PageCache\App\FrontController\BuiltinPlugin->aroundDispatch( ) | .../BuiltinPlugin.php:30
8 | 6.1681 | 35784032 | Magento\Framework\App\FrontController\Interceptor->Magento\Framework\Interception\{closure}( ) | .../BuiltinPlugin.php:68
9 | 6.1681 | 35784408 | Magento\Framework\Interception\Chain\Chain->invokeNext( ) | .../Interceptor.php:138
10 | 6.1682 | 35786936 | Magento\PageCache\Model\App\FrontController\VarnishPlugin->aroundDispatch( ) | .../Chain.php:67
11 | 6.1682 | 35786936 | Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain\{closure}( ) | .../VarnishPlugin.php:55
12 | 6.1682 | 35787312 | Magento\Framework\Interception\Chain\Chain->invokeNext( ) | .../Chain.php:63
13 | 6.1683 | 35789304 | TemplateMonster\LayoutSwitcher\Model\App\Action\ContextPlugin->aroundDispatch( ) | .../Chain.php:67
14 | 6.1884 | 36375464 | Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain\{closure}( ) | .../ContextPlugin.php:40
15 | 6.1884 | 36375840 | Magento\Framework\Interception\Chain\Chain->invokeNext( ) | .../Chain.php:63
16 | 6.1902 | 36420368 | Magento\Framework\Module\Plugin\DbStatusValidator->aroundDispatch( ) | .../Chain.php:67
17 | 6.2542 | 36594504 | Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain\{closure}( ) | .../DbStatusValidator.php:69
18 | 6.2542 | 36594880 | Magento\Framework\Interception\Chain\Chain->invokeNext( ) | .../Chain.php:63
19 | 6.2547 | 36601672 | Magento\Store\App\FrontController\Plugin\RequestPreprocessor->aroundDispatch( ) | .../Chain.php:67
20 | 6.2569 | 36632256 | Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain\{closure}( ) | .../RequestPreprocessor.php:94
21 | 6.2569 | 36632632 | Magento\Framework\Interception\Chain\Chain->invokeNext( ) | .../Chain.php:63
22 | 6.2569 | 36632672 | Magento\Framework\App\FrontController\Interceptor->___callParent( ) | .../Chain.php:70
23 | 6.2569 | 36632672 | Magento\Framework\App\FrontController\Interceptor->dispatch( ) | .../Interceptor.php:74
24 | 8.1442 | 43901488 | Mollie\Payment\Controller\Checkout\Redirect\Interceptor->dispatch( ) | .../FrontController.php:55
25 | 8.1464 | 43983272 | Mollie\Payment\Controller\Checkout\Redirect\Interceptor->___callPlugins( ) | .../Interceptor.php:39
26 | 8.1820 | 46337872 | Magento\Tax\Model\App\Action\ContextPlugin->aroundDispatch( ) | .../Interceptor.php:142
27 | 8.1821 | 46337872 | Mollie\Payment\Controller\Checkout\Redirect\Interceptor->Magento\Framework\Interception\{closure}( ) | .../ContextPlugin.php:91
28 | 8.1821 | 46338248 | Magento\Framework\Interception\Chain\Chain->invokeNext( ) | .../Interceptor.php:138
29 | 8.1964 | 47592096 | Magento\Weee\Model\App\Action\ContextPlugin->aroundDispatch( ) | .../Chain.php:67
30 | 8.1964 | 47592096 | Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain\{closure}( ) | .../ContextPlugin.php:112
31 | 8.1964 | 47592472 | Magento\Framework\Interception\Chain\Chain->invokeNext( ) | .../Chain.php:63
32 | 8.1966 | 47594472 | Magento\Store\App\Action\Plugin\StoreCheck->aroundDispatch( ) | .../Chain.php:67
33 | 8.1966 | 47594472 | Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain\{closure}( ) | .../StoreCheck.php:44
34 | 8.1966 | 47594848 | Magento\Framework\Interception\Chain\Chain->invokeNext( ) | .../Chain.php:63
35 | 8.1968 | 47597288 | Magento\Customer\Model\App\Action\ContextPlugin->aroundDispatch( ) | .../Chain.php:67
36 | 8.1973 | 47620160 | Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain\{closure}( ) | .../ContextPlugin.php:61
37 | 8.1973 | 47620536 | Magento\Framework\Interception\Chain\Chain->invokeNext( ) | .../Chain.php:63
38 | 8.1975 | 47624272 | Magento\Store\App\Action\Plugin\Context->aroundDispatch( ) | .../Chain.php:67
39 | 8.2232 | 48049776 | Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain\{closure}( ) | .../Context.php:106
40 | 8.2232 | 48050152 | Magento\Framework\Interception\Chain\Chain->invokeNext( ) | .../Chain.php:63
41 | 8.4004 | 49935288 | Mollie\Payment\Controller\Checkout\Redirect\Interceptor->___callParent( ) | .../Chain.php:70
42 | 8.4004 | 49935288 | Mollie\Payment\Controller\Checkout\Redirect\Interceptor->dispatch( ) | .../Interceptor.php:74
43 | 8.4130 | 50410296 | Mollie\Payment\Controller\Checkout\Redirect\Interceptor->execute( ) | .../Action.php:102
44 | 8.4130 | 50410296 | Mollie\Payment\Controller\Checkout\Redirect\Interceptor->execute( ) | .../Interceptor.php:24
Marvin-Magmodules commented 6 years ago

Can you contact us through https://www.magmodules.eu/contact-us.html so we can exchange some log files?

pascal08 commented 6 years ago

Sure. I have send a message through the contact form. I referred to this issue.

Marvin-Magmodules commented 6 years ago

Not Mollie issue, but a bug in other module results in missing/incomplete checkout session.

PieterCappelle commented 6 years ago

Any more information about this issue and which checkout session problem? Having same problem in one of our stores. Only with payment method "CreditCard". Using v1.2.1.

Marvin-Magmodules commented 6 years ago

This was a result of a "Split Order"-module overwriting a core class. Are you using other Mollie methods besides CC in the store? Can you contact us thoughhttps://www.magmodules.eu/contact-us.html so we can exchange some log files?

versdivers commented 6 years ago

This is a bug in the Mollie module btw. It is ridiculous to say it is not.

Simple said we have made a module that does a final last check before placing the order if certain conditions are met with an observer on the event (how it should be!). We do a redirect (how you should do it) if not met and add a message to the messagemanager.

Because we do the redirect and do not let Magento create that Order you module doesn't have a payment method.

Our modules has no bugs whats so ever on a blank or luma installation.

Is it so hard to include something like this?

$payment = $order->getPayment();

if(!isset($payment){
//redirect however you want
}

$method = $payment->getMethod();

OR just use Observers or plugins like the rest of us to implement code into Magento to make it compatible. If you would code by Magento standards we would never even reach that part of the code.

Ow and btw. It is return $this->_redirect('checkout/cart');

not just$this->_redirect('checkout/cart');

If you do not return it than it will just continue your code.

versdivers commented 6 years ago

For the onces who wants to fix it.

$payment = $order->getPayment();
           if(!isset($payment)) {
               return $this->_redirect('checkout/cart');
           }

Is how it should be coded. Not including the fact that they should use an Observer on the event before the order is placed and redirect there to the controller that they want to use.

Marvin-Magmodules commented 6 years ago

Hi @versdivers,

I'm not really following you, are you the developer of pascal08, or are you referring to an other case? What event are you observing in your module so we take a look why this problem is occurring?

versdivers commented 6 years ago

@Marvin-Magmodules Like i said we are observing the event before order is placed which is 'sales_order_place_before'. And the reason why your module collides with other modules is because you do not use the event 'sales_order_place_after' like how you should.

As a certificied Magento developer you should know that people are using those 2 events to have their own logics within Magento during order creation. I also already talked to Mollie because instead of waiting until the order is placed you can easily reserve a order number , redirect to mollie and only create the order with that order number until they paid instead of cancelling everything. I know this is another thing but if you use synchronizations between systems like my clients that means they are stuck with a bunch of cancelled orders within each system.

All thing that are not coding to be compatible with anything. Magento is as modular as the developers keep it.

versdivers commented 6 years ago

But if you want to redirect under certain conditions at least return the redirect.... That's not even Magento. That's just PHP.

Frank-Magmodules commented 6 years ago

Hi @versdivers , Thanks for your feedback on this, we are going to take a look into your suggestion based on your point of view but let me please remind that your tone of voice is not really collaborative.

We are open for suggestions and surely we want to make improvements based on your feedback but your comments are not really cooperative from the start.

versdivers commented 6 years ago

@Frank-Magmodules Ok first of all let my apologies if this came over as non-constructive feedback. It was not intended like that but i was nearly trying to point out some facts.

Even though i certainly get that a certain code can have a bug or missing features but in my opinion i feel like this has been looked over way to easily. It was just rejected with the phrase : "This was a result of a "Split Order"-module overwriting a core class.". But the real result here is the fact that this just does not support any kind of cooperation with other modules that are build to do a check before the order has been placed because of the lack of use of the Observers.

Even if someone would interrupt the checkout procedure your code still executes. And like i pointed out before also does not work great with any synchronization module like we do with Exact Online.

Some other remarks that might improve your module

The module also has the usage of Objectmanager in it. This is something we always avoid : https://magento.stackexchange.com/questions/117098/magento-2-to-use-or-not-to-use-the-objectmanager-directly

You have seperate css filles in the header like this

    <head>
        <css src="Mollie_Payment::css/styles.css"/>
    </head>

Which does not work with a merge or minify and loads separately. Read my answer that i gave in this topic. (SwAt is my Magento stackexchange nickname) https://magento.stackexchange.com/questions/200087/implement-a-custom-theme-magento-2/200111#200111

Check my answer there.

Observers and plugins are used to extend the Code of Magento (or preferences but only if there is not another way).

These are some important things in Magento 2 to improve loading time and also to improve collaboration between modules.

But do not get me wrong. The overall quality of the module is better then a lot of modules out there. But realize that these things make it that we need to put time into developing workarounds or adjust the module and have a reminder every time when we do an update.

I believe as Dutch developers we should set higher quality code then our competitors in less expensive countries and these things is what separates us from other company's i believe. The only reason why i might come over somewhat harsh is because we do set the bar really high as it should be.

Again my apologies.

WalterSmulders commented 5 years ago

Seems that I am experiencing the same problem as stated above. Although the code is changed now as suggested by versdivers on Jul 6, 2018 it seems that this is still an ongoing issue and results in customers of the webshop being redirected to the cart without any warning or anything logged, it's by change that I stumbled on this and it is resulting in non-paid orders for the merchant since the customers wont be redirected to Mollie and there is no transaction ID written to the database. This happens quite a lot in this webshop and I kindly request to make some changes to this.

Frank-Magmodules commented 5 years ago

Hi @WalterSmulders, can you drop us an e-mail through our contact form so we can exchange some logs and login details and take a better look into this issue?

Thanks!