Display extended variant name in quick cart

This commit is contained in:
Rohan Mitchell
2015-03-13 12:58:53 +11:00
parent 44511b8b61
commit efbf2c7ffa
4 changed files with 44 additions and 4 deletions

View File

@@ -8,6 +8,7 @@ Darkswarm.factory 'Cart', (CurrentOrder, Variants, $timeout, $http)->
for line_item in @line_items
line_item.variant.line_item = line_item
Variants.register line_item.variant
line_item.variant.extended_name = @extendedVariantName(line_item.variant)
orderChanged: =>
@unsaved()
@@ -67,4 +68,12 @@ Darkswarm.factory 'Cart', (CurrentOrder, Variants, $timeout, $http)->
variant: variant
quantity: null
max_quantity: null
@line_items.push variant.line_item
@line_items.push variant.line_item
extendedVariantName: (variant) =>
if variant.product_name == variant.name_to_display
variant.product_name
else
name = "#{variant.product_name} - #{variant.name_to_display}"
name += " (#{variant.options_text})" if variant.options_text
name

View File

@@ -1,6 +1,6 @@
class Api::VariantSerializer < ActiveModel::Serializer
attributes :id, :is_master, :count_on_hand, :name_to_display, :unit_to_display,
:on_demand, :price, :fees, :price_with_fees
:options_text, :on_demand, :price, :fees, :price_with_fees, :product_name
def price_with_fees
object.price_with_fees(options[:current_distributor], options[:current_order_cycle])
@@ -13,4 +13,9 @@ class Api::VariantSerializer < ActiveModel::Serializer
def fees
object.fees_by_type_for(options[:current_distributor], options[:current_order_cycle])
end
def product_name
object.product.name
end
end

View File

@@ -20,7 +20,7 @@
/ %em {{ line_item.variant.unit_to_display }}
/ - if {{ line_item.product.name }} == {{ line_item.variant.name_to_display }}
%strong
{{ line_item.variant.name_to_display }}
{{ line_item.variant.extended_name }}
.columns.small-3.text-right
%small

View File

@@ -6,7 +6,10 @@ describe 'Cart service', ->
beforeEach ->
module 'Darkswarm'
variant = {id: 1}
variant =
id: 1
name_to_display: 'name'
product_name: 'name'
order = {
line_items: [
variant: variant
@@ -23,6 +26,9 @@ describe 'Cart service', ->
it "registers variants with the Variants service", ->
expect(Variants.variants[1]).toBe variant
it "generates extended variant names", ->
expect(Cart.line_items[0].variant.extended_name).toEqual "name"
it "creates and backreferences new line items if necessary", ->
Cart.register_variant(v2 = {id: 2})
expect(Cart.line_items[1].variant).toBe v2
@@ -37,3 +43,23 @@ describe 'Cart service', ->
expect(Cart.line_items_present()).toEqual []
order.line_items[0].quantity = 2
expect(Cart.total_item_count()).toEqual 2
describe "generating an extended variant name", ->
it "returns the product name when it is the same as the variant name", ->
variant = {product_name: 'product_name', name_to_display: 'product_name'}
expect(Cart.extendedVariantName(variant)).toEqual "product_name"
describe "when the product name and the variant name differ", ->
it "returns a combined name when there is no options text", ->
variant =
product_name: 'product_name'
name_to_display: 'name_to_display'
expect(Cart.extendedVariantName(variant)).toEqual "product_name - name_to_display"
it "returns a combined name when there is some options text", ->
variant =
product_name: 'product_name'
name_to_display: 'name_to_display'
options_text: 'options_text'
expect(Cart.extendedVariantName(variant)).toEqual "product_name - name_to_display (options_text)"