mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Line items were initialised with undefined quantities which makes it impossible to distinguish between the initial unset quantity and a user entering an invalid quantity. When a user changed order cycles, all quantities are reset and the UI displayed the quantity modifier buttons instead of the Add button. Initialising with the valid quantity 0 helps us to display the Add button in that situation.
28 lines
799 B
CoffeeScript
28 lines
799 B
CoffeeScript
Darkswarm.factory 'Variants', ->
|
|
new class Variants
|
|
variants: {}
|
|
|
|
clear: ->
|
|
@variants = {}
|
|
|
|
register: (variant)->
|
|
@variants[variant.id] ||= @extend variant
|
|
|
|
extend: (variant)->
|
|
variant.extended_name = @extendedVariantName(variant)
|
|
variant.line_item ||= @lineItemFor(variant) # line_item may have been initialised in Cart#constructor
|
|
variant.line_item.total_price = variant.price_with_fees * variant.line_item.quantity
|
|
variant
|
|
|
|
extendedVariantName: (variant) =>
|
|
if variant.product_name == variant.name_to_display
|
|
name = variant.product_name
|
|
else
|
|
name = "#{variant.product_name} - #{variant.name_to_display}"
|
|
name
|
|
|
|
lineItemFor: (variant) ->
|
|
variant: variant
|
|
quantity: 0
|
|
max_quantity: 0
|