vuestorefront / vue-storefront

Alokai is a Frontend as a Service solution that simplifies composable commerce. It connects all the technologies needed to build and deploy fast & scalable ecommerce frontends. It guides merchants to deliver exceptional customer experiences quickly and easily.
https://www.alokai.com
MIT License
10.58k stars 2.08k forks source link

Cash on Delivery appears on storefront after page reload while disabled in magento #2983

Closed Cheeerd closed 5 years ago

Cheeerd commented 5 years ago

Current behavior

At first Cash on Delivery is not shown at payment methods in checkout, but after page reload it does.

Expected behavior

After page reload payment methods should stay same.

Steps to reproduce the issue

Cash on Delivery disabled in magento. 1) Open vue storefront in new browser/private window/after clearing local storage. 2) Add product to cart and go to checkout. 3) See that there are no Cash on Delivery in payment methods. 4) Reload page. 5) Go to checkout. 6) See Cash on Delivery in payment methods.

Additional details

How cashondelivery appears there: it is predefined in core/modules/checkout/store/payment/index.ts:9 and in function getPaymentMethods (core/modules/cart/store/actions.ts:337) backendmethods are added to this array, but this code does not delete cashondelivery if it not present in backend methods. Why it is not shown at first time: if cart is empty getter paymentMethods (core/modules/checkout/store/payment/index.ts:28) removes cashondelivery from resulting array (!isVirtualCart || method.code !== 'cashondelivery').

Can you handle fixing this bug by yourself?

If remove cashondelivery from initial array (core/modules/checkout/store/payment/index.ts:9) the issue disappears. And if after that enable cashondelivery in magento, checkout with cashondelivery method is still working. Also it is possible to remove payment methods which are not presented in backend methods in function getPaymentMethods from core/modules/cart/store/actions.ts. But this behavior looks quite strange for me and I don't know which of that may cause another issues with cashondelivery or another custom payment method.

Environment details

pkarw commented 5 years ago

Hi there! This is de-facto not an issue but ... a feature :) we’ll not well documented at last. I mean there is a module “payment-cash-on-delivery” that adds this method for the offline mode purposes and it’s solely independent from the Magento payment methods. Please disable this module by commenting it in the src/modules/index.js.

@kkdg can You please add a note on that in the recipes section in the docs?

danielmaier42 commented 5 years ago

@pkarw - Hi Piotr, we have the same or very similar issue so i would like to reopen that one please.

We have two custom payment methods defined in magento (invoice + debit) which are both offline methods and are correctly returned by the payment-methods api and therefore added to the checkout.

But now the existing cashondelivery method is still present - even when disabling the module payment-cash-on-delivery in src/modules/index.js. The only thing that helps is to remove the predefined method in core/modules/checkout/store/payment/index.ts

pkarw commented 5 years ago

Hi @danielmaier42 OK! we should remove it from the core/modules/checkout/store/payment/index.ts. Can You please remove it within a Pull Request (good first contribution :-)). Please just make sure that the cash-on-delivery module registers it dynamically when enabled. As for short overlook it does: https://github.com/DivanteLtd/vue-storefront/blob/4c150446cbb66f87d353495bb4cbe41c6dc7d611/src/modules/payment-cash-on-delivery/hooks/afterRegistration.ts#L15 - so we just need to remove this static entry

kkdg commented 5 years ago

Hi there! This is de-facto not an issue but ... a feature :) we’ll not well documented at last. I mean there is a module “payment-cash-on-delivery” that adds this method for the offline mode purposes and it’s solely independent from the Magento payment methods. Please disable this module by commenting it in the src/modules/index.js.

@kkdg can You please add a note on that in the recipes section in the docs?

Yep @pkarw , this will be quoted in Chapter 5. Extending a module, which I believe will roll out in July. Thanks.