From 3fb0f3160912e30324e2d4e41e6446ca52f2190e Mon Sep 17 00:00:00 2001 From: tkostuch Date: Tue, 7 Apr 2020 10:33:00 +0200 Subject: [PATCH 1/2] allow empty shipping methods --- core/modules/cart/store/actions/methodsActions.ts | 8 ++++---- core/modules/cart/test/unit/store/methodsActions.spec.ts | 6 ++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/core/modules/cart/store/actions/methodsActions.ts b/core/modules/cart/store/actions/methodsActions.ts index b836cdc73e..e839481dd3 100644 --- a/core/modules/cart/store/actions/methodsActions.ts +++ b/core/modules/cart/store/actions/methodsActions.ts @@ -60,10 +60,10 @@ const methodsActions = { } }, async updateShippingMethods ({ dispatch }, { shippingMethods }) { - if (shippingMethods.length > 0) { - const newShippingMethods = shippingMethods.map(method => ({ ...method, is_server_method: true })) - await dispatch('checkout/replaceShippingMethods', newShippingMethods, { root: true }) - } + const newShippingMethods = shippingMethods + .map(method => ({ ...method, is_server_method: true })) + .filter(method => !method.hasOwnProperty('available') || method.available) + await dispatch('checkout/replaceShippingMethods', newShippingMethods, { root: true }) }, async syncShippingMethods ({ getters, rootGetters, dispatch }, { forceServerSync = false }) { if (getters.canUpdateMethods && (getters.isTotalsSyncRequired || forceServerSync)) { diff --git a/core/modules/cart/test/unit/store/methodsActions.spec.ts b/core/modules/cart/test/unit/store/methodsActions.spec.ts index 907410a941..3fa70c4ce4 100644 --- a/core/modules/cart/test/unit/store/methodsActions.spec.ts +++ b/core/modules/cart/test/unit/store/methodsActions.spec.ts @@ -159,4 +159,10 @@ describe('Cart methodsActions', () => { await (cartActions as any).updateShippingMethods(contextMock, { shippingMethods: [{ method: 1 }] }); expect(contextMock.dispatch).toBeCalledWith('checkout/replaceShippingMethods', [{ is_server_method: true, method: 1 }], { root: true }) }) + + it('doesn\'t add not available method', async () => { + const contextMock = createContextMock() + await (cartActions as any).updateShippingMethods(contextMock, { shippingMethods: [{ method: 1, available: false }] }); + expect(contextMock.dispatch).toBeCalledWith('checkout/replaceShippingMethods', [], { root: true }) + }) }); From 5f7207f21ad4fe23f9aa0f79f330b59781678331 Mon Sep 17 00:00:00 2001 From: tkostuch Date: Tue, 7 Apr 2020 10:38:14 +0200 Subject: [PATCH 2/2] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ecd75b769..98619c6546 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - add missing cache tags for category and product - @gibkigonzo (#4173) - add ssrAppId to avoid second meta render on csr - @gibkigonzo (#4203) - take control over default broswer behavior and use saved category page size to load prev products - @gibkigonzo (#4201) +- allow empty shipping methods in checkout - @gibkigozno (#4192) ## [1.11.2] - 2020.03.10