Feature: Get the value of product options by title
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 11.9k
- Forks
- 1.5k
- Avg merge
- 17h 55m
- Merged PRs (30d)
- 3
Description
Some time ago, I was asked by Stan Kostadinov to create an issue here.
Feature:
- At the moment it is not possible to get a list of all the values per option. EG:
Getting all the values for the option 'color' would have to be done like this:
{% for product_option in product.options_with_values %}
{% if product_option == 'color' %}
{% for value in product_option.values %}
{{ value }}
{% endfor %}
{% endif %}
{% endfor %}
Would it be possible to have something like this instead?:
{% for value in product.options_with_values['color'] %}
{{ value }}
{% endfor %}
- Get the value of a variant option by title. EG:
On some products we have the following options: Size, Color, Length. Respectively, these would be variant.option 1, 2 and 3. However, on some other products we have the options: Size and Pattern (Again, variant.option 1 and 2).
If we want to get the color option of a product variant, whether it's there or not, whether the store admin or whoever we build the theme for has size before color, or the other way around. As a developer, you cannot know for sure whether the option 'color' will always be 'variant.option2'.
So, what do you do?
{% for product_option in product.options %}
{% if product_option == 'color' or product_option == 'colour' %}
{% assign has_color = true %}
{% assign color_index = 'option' | append: forloop.index %}
{% endif %}
{% endfor %}
{% if has_color %}
{% for variant in product.variants %}
{{ variant[color_index] }}
{% endfor %}
{% endif %}
Could we use something like variant.option['color'] or be able to get the title as well, instead of only the value? (variant.option1.title , variant.option1.value)
This could save a lot of lines of code and unnecesarry looping through tons of products/variants.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the existing product.options_with_values, product.options, product.variants, and variant.option access patterns shown in the issue. Determine how title-based option lookup should behave for missing options and whether both option titles and values are required; completion would need an agreed API and corresponding tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- web-dev
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100