verbb / snipcart

A Craft CMS plugin to integrate with Snipcart.
Other
21 stars 9 forks source link

Improvement: Custom option prices #6

Closed ghost closed 5 years ago

ghost commented 5 years ago

Hello Matt,

in your buy-now.twig template, you loop over the prices of each custom option. There I see a hard-coded "+".

data-item-custom{{ loop.index }}-options="{% for option in customOption.options -%}
        {{ option.name }}[+{{ option.price }}]
        {%- if loop.last != true %}|{% endif %}{% endfor %}"
    {%- endfor -%}

I wonder if it would make more sense to delete the + from the template and make it a part of the price itself? Isn't there also a chance to decrease the price?

You can see an example here in the Snipcart docs:

https://docs.snipcart.com/configuration/custom-fields#altering-item-prices

Best regards

Mike

mattstein commented 5 years ago

You're right, the current template prevents using negative price adjustments. Instead of removing the + from the template I'll only add it if the price adjustment is positive and a + is not already passed in. This should make it slightly more forgiving since it may seem unintuitive to require the + symbol for positive numbers.

data-item-custom{{ loop.index }}-options="{% for option in customOption.options -%}
    {{ option.name }}[{{ '+' not in option.price and option.price >= 0 ? '+' : '' }}{{ option.price }}]
    {%- if not loop.last %}|{% endif %}{% endfor %}"
mattstein commented 5 years ago

Improved in 1.0.4.

ghost commented 5 years ago

Thank you, Matt. 🏆