After enabling Google Tag Manager, Paypal Express checkout breaks
-
06-10-2020 - |
Pregunta
When going through the one step checkout process, Paypal Express is encountering an error where the page is not being properly redirected.
By debugging into opcheckout.js, in the function setStepResponse
, this line was stopping execution of all JS:
$('checkout-'+response.update_section.name+'-load').update(response.update_section.html);
Some additional debugging showed that response.update_section.name
was undefined.
By adding a custom observer to the hook controller_action_postdispatch_checkout
and ensuring a name is set, I was able to fix this problem.
The Enterprise extension GoogleAnalyticsUniversal
has an observer tied to the same event that calls the function setGoogleAnalyticsOnCheckout
. It appears that this function is causing the problem.
Is this a bug in Enterprise? Or is it possible the data is "corrupted" upstream by a custom extension?
Solución
After contacting Magento's Enterprise support, it was confirmed this is a bug between GTM and Paypal Express.
I was able to fix this problem by creating an observer on setGoogleAnalyticsOnCheckout
in Enterprise_GoogleAnalyticsUniversal_Model_Observer
. The saveBilling
function has this line:
$body['update_section']['name'] = 'shipping';
My observer uses the same logic as this line to add a name to savePayment
which fixes the broken javascript and allows the checkout process to continue.
I did receive a patch from Magento that resolves the problem in a similar fashion (it modifies core code instead of creating an observer), but I'm unsure if I'm allowed to share it. The name of the patch is "PATCH_SUPEE-6717_EE_1.14.2.0_v1.sh".