diff --git a/CHANGELOG.md b/CHANGELOG.md index c03bb78..66e4b2c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +### Fixed + +- Assembly options will now be correctly added to the cart when `initiallyOpened` prop is set to `always` + ## [2.11.3] - 2022-07-19 ### Fixed diff --git a/react/ProductAssemblyOptions.tsx b/react/ProductAssemblyOptions.tsx index 8074b3e..c83803e 100644 --- a/react/ProductAssemblyOptions.tsx +++ b/react/ProductAssemblyOptions.tsx @@ -8,7 +8,10 @@ interface Props { initiallyOpened?: 'always' | 'required' } -const ProductAssemblyOptions: FC = ({ children, initiallyOpened }) => { +const ProductAssemblyOptions: FC = ({ + children, + initiallyOpened = 'required', +}) => { const assemblyOptions = useAssemblyOptions() if (!assemblyOptions) { @@ -20,6 +23,7 @@ const ProductAssemblyOptions: FC = ({ children, initiallyOpened }) => { {Object.keys(assemblyOptions).map((assemblyOptionId) => ( diff --git a/react/components/ProductAssemblyContext/Group.tsx b/react/components/ProductAssemblyContext/Group.tsx index 0f30e3f..b90474d 100644 --- a/react/components/ProductAssemblyContext/Group.tsx +++ b/react/components/ProductAssemblyContext/Group.tsx @@ -106,7 +106,12 @@ const useRecursiveDispatch = ({ export const ProductAssemblyGroupContextProvider: FC = ({ assemblyOption, children, + initiallyOpened = 'required', }) => { + if (initiallyOpened === 'always') { + assemblyOption.optin = true + } + const [state, dispatch] = useReducer(reducer, assemblyOption, initState) const recursiveDispatch = useRecursiveDispatch({ @@ -141,6 +146,7 @@ function getGroupPath(assemblyTreePath?: TreePath[]) { interface ProductAssemblyGroupContextProviderProps { assemblyOption: AssemblyOptionGroupState + initiallyOpened?: string } export const useProductAssemblyGroupDispatch = () => diff --git a/react/components/ProductAssemblyOptions/ProductAssemblyOptionsGroup.tsx b/react/components/ProductAssemblyOptions/ProductAssemblyOptionsGroup.tsx index ccb7a55..40d3443 100644 --- a/react/components/ProductAssemblyOptions/ProductAssemblyOptionsGroup.tsx +++ b/react/components/ProductAssemblyOptions/ProductAssemblyOptionsGroup.tsx @@ -26,10 +26,7 @@ interface Props { initiallyOpened?: 'always' | 'required' } -const ProductAssemblyOptionsGroup: FC = ({ - children, - initiallyOpened = 'required', -}) => { +const ProductAssemblyOptionsGroup: FC = ({ children }) => { const intl = useIntl() const handles = useCssHandles(CSS_HANDLES) const assemblyOptionGroup = useProductAssemblyGroupState() as AssemblyOptionGroupState @@ -52,7 +49,7 @@ const ProductAssemblyOptionsGroup: FC = ({ return ( - {assemblyOptionGroup.optin === false && initiallyOpened === 'required' ? ( + {assemblyOptionGroup.optin === false ? (