Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ProductAttribute.ts throws "TypeError: parsedValues.split is not a function" #2107

Closed
phoenixdev-kl opened this issue Dec 21, 2018 · 8 comments

Comments

@phoenixdev-kl
Copy link
Contributor

Current behavior

When product attribute value is of type Number, we get the following error in browser console

Error in render: "TypeError: parsedValues.split is not a function"

Expected behavior

No error message should occur :)

Steps to reproduce the issue

As it would be a pain to setup your system with according product data you might want to set a breakpoint in core/modules/catalog/components/ProductAttribute.ts at or after line 22

let parsedValues = this.product[this.attribute.attribute_code]

and while debugging set the value of parsedValues to lets say 37 or whatever number.

Repository

https://github.com/DivanteLtd/vue-storefront/blob/master/core/modules/catalog/components/ProductAttribute.ts

Can you handle fixing this bug by yourself?

MAYBE, depends if the following is a suitable approach. I would change

let parsedValues = this.product[this.attribute.attribute_code]

to

let parsedValues = this.product[this.attribute.attribute_code].toString()

Environment details

  • Browser: Google Chrome 71.0.3578.98
  • OS: macOS 10.14.2 (18C54) Mojave
  • Node: 5.6.0

Additional information

  • VSF connected to Magento 1
  • Dockerized
@pkarw
Copy link
Collaborator

pkarw commented Dec 21, 2018

Thanks! This should work, maybe we could just add type checking. Running this split makes sense just when the value is a string

@phoenixdev-kl
Copy link
Contributor Author

So, we could change line 27

parsedValues = parsedValues.split(',')

to

parsedValues = typeof parsedValues === 'string' ? parsedValues.split(',') : parsedValues

@pkarw
Copy link
Collaborator

pkarw commented Dec 21, 2018

Correct. Please do!

@phoenixdev-kl
Copy link
Contributor Author

phoenixdev-kl commented Jan 2, 2019

@pkarw Sorry I didn't manage to create a pull request last year. Thank you so much for fixing! 🙏

@phoenixdev-kl
Copy link
Contributor Author

phoenixdev-kl commented Jan 3, 2019

@pkarw I've just noticed an unwanted side effect to this fix: Now another JavaScript error occurs in src/themes/default/components/core/ProductAttribute.vue, line 4:

<span class="weight-700">{{ value|htmlDecode }}</span>

In case value is of type number, htmlDecode fails, as it tries to execute replace() on a number ("TypeError: html.replace is not a function").

We could either add .toString() in src/themes/default/components/core/ProductAttribute.vue or in core/modules/catalog/components/ProductAttribute.ts (to variable parsedValues - as mentioned in initial idea in issue description above)?

@pkarw
Copy link
Collaborator

pkarw commented Jan 3, 2019

Ok! I think we should add it in *.ts - previously (before this fix you’ve applied) the values were always of type string. So they should keep to this type

@pkarw
Copy link
Collaborator

pkarw commented Jan 5, 2019

OK I've added this as I wass fixing some other bug related to ProductAttribute

@phoenixdev-kl
Copy link
Contributor Author

phoenixdev-kl commented Jan 14, 2019

IMHO we have to change

parsedValues = typeof parsedValues === 'string' ? parsedValues.split(',') : parsedValues

to

parsedValues = typeof parsedValues === 'string' ? parsedValues.split(',') : [ parsedValues ]

(return parsedValues as an array) as otherwise computed function value will return an empty string for select attributes. Because for loop two lines later has nothing to loop through:

        let results = []
        for (let parsedVal of parsedValues) {
            ...
        }
        return results.join(', ')

phoenixdev-kl added a commit to phoenixdev-kl/vue-storefront that referenced this issue Jan 14, 2019
pkarw added a commit that referenced this issue Jan 14, 2019
…bute-parsing

#2107 fixed parsing of attributes of type "select"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants