-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Closed
Labels
Milestone
Description
Current behavior
When having a checkbox custom option and not selecting any option, the value is null, but:
const replaceNumberToString = obj => {
Object.keys(obj).forEach(key => {
if (typeof obj[key] === 'object') {
return replaceNumberToString(obj[key]);
}
obj[key] = String(obj[key]);
});
return obj;
}
fails because obj[key] == null and typeof null = 'object'. A simple fix would be to do:
if (obj[key] && typeof obj[key] === 'object') {
However the return under it makes no sense either.
I can't find what the original intent was of the code, but if it's to turn all integer keys in the object into a string recursively then something like:
const replaceNumberToString = obj => {
Object.keys(obj).forEach(key => {
if (obj[key]) {
if (typeof obj[key] === 'object') {
obj[key] = replaceNumberToString(obj[key]);
} else
obj[key] = String(obj[key]);
}
});
return obj;
}
would work a lot better.
Expected behavior
No exception due to a null.
Steps to reproduce the issue
Create a product custom options, use option type "checkbox" and add 1 or more values. Open the product page, add it to the cart without checking any boxes.
Repository
Can you handle fixing this bug by yourself?
- YES
- [ x] NO
Which Release Cycle state this refers to? Info for developer.
Pick one option.
- This is a bug report for test version on https://test.storefrontcloud.io - In this case Developer should create branch from
developbranch and create Pull Request2. Feature / Improvementback todevelop. - This is a bug report for current Release Candidate version on https://next.storefrontcloud.io - In this case Developer should create branch from
releasebranch and create Pull Request3. Stabilisation fixback torelease. - This is a bug report for current Stable version on https://demo.storefrontcloud.io and should be placed in next stable version hotfix - In this case Developer should create branch from
hotfixormasterbranch and create Pull Request4. Hotfixback tohotfix.
Environment details
- Browser: Chrome
- OS: Windows 10
- Node: v13.7.0
- Code Version: HEAD of develop