diff --git a/CHANGELOG.md b/CHANGELOG.md index 743fb6a7f5..e30e7b0361 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - take control over default broswer behavior and use saved category page size to load prev products - @gibkigonzo (#4201) - update getCurrentCartHash after add/remove coupon - @gibkigonzo (#4220) - update replaceNumberToString, so it will change ONLY numbers to string - @gibkigonzo (#4217) +- allow empty shipping methods in checkout - @gibkigozno (#4192) ## [1.11.2] - 2020.03.10 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 }) + }) });