From efbf2c7ffaa9dbe438939b87b807d63ee4eb7039 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Fri, 13 Mar 2015 12:58:53 +1100 Subject: [PATCH 1/5] Display extended variant name in quick cart --- .../darkswarm/services/cart.js.coffee | 11 +++++++- app/serializers/api/variant_serializer.rb | 7 ++++- app/views/shared/menu/_cart.html.haml | 2 +- .../darkswarm/services/cart_spec.js.coffee | 28 ++++++++++++++++++- 4 files changed, 44 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/darkswarm/services/cart.js.coffee b/app/assets/javascripts/darkswarm/services/cart.js.coffee index c519d22fdd..0135416ac4 100644 --- a/app/assets/javascripts/darkswarm/services/cart.js.coffee +++ b/app/assets/javascripts/darkswarm/services/cart.js.coffee @@ -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 \ No newline at end of file + @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 diff --git a/app/serializers/api/variant_serializer.rb b/app/serializers/api/variant_serializer.rb index 5871d6def4..f995fa4345 100644 --- a/app/serializers/api/variant_serializer.rb +++ b/app/serializers/api/variant_serializer.rb @@ -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 diff --git a/app/views/shared/menu/_cart.html.haml b/app/views/shared/menu/_cart.html.haml index b0e44f3bad..716d198f67 100644 --- a/app/views/shared/menu/_cart.html.haml +++ b/app/views/shared/menu/_cart.html.haml @@ -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 diff --git a/spec/javascripts/unit/darkswarm/services/cart_spec.js.coffee b/spec/javascripts/unit/darkswarm/services/cart_spec.js.coffee index 4d13ccc8b5..4be1a13dd8 100644 --- a/spec/javascripts/unit/darkswarm/services/cart_spec.js.coffee +++ b/spec/javascripts/unit/darkswarm/services/cart_spec.js.coffee @@ -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)" From b0cfa6a17c391c2f6261bf8cd2943700e98314b9 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Fri, 13 Mar 2015 16:18:49 +1100 Subject: [PATCH 2/5] Shipping method prices displayed next to options in checkout --- app/views/checkout/_shipping.html.haml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/views/checkout/_shipping.html.haml b/app/views/checkout/_shipping.html.haml index d06da7931e..a1c6e5ba9c 100644 --- a/app/views/checkout/_shipping.html.haml +++ b/app/views/checkout/_shipping.html.haml @@ -21,10 +21,10 @@ "ng-value" => "method.id", "ng-model" => "order.shipping_method_id"} {{ method.name }} - // TODO: Laura - this is not working correctly, need to show shipping price regardless of if selected!? - %em.light{"ng-show" => "!Checkout.shippingPrice()"} (Free) - %em.light{"ng-show" => "order.shipping_method.andand.require_ship_address"} - {{ Checkout.shippingPrice() | localizeCurrency }} + %em.light{"ng-show" => "!method.price || method.price == 0"} + (Free) + %em.light{"ng-hide" => "!method.price || method.price == 0"} + ({{ method.price | localizeCurrency }}) %small.error.medium.input-text{"ng-show" => "!fieldValid('order.shipping_method_id')"} = "{{ fieldErrors('order.shipping_method_id') }}" From dd8c769ea9781835fe7591946742225654814068 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Fri, 13 Mar 2015 16:50:57 +1100 Subject: [PATCH 3/5] Hiding fee breakdown on cart page for now --- .../javascripts/darkswarm/cart.js.coffee | 6 +++--- app/views/spree/orders/_adjustments.html.haml | 18 ++++++++---------- app/views/spree/orders/_form.html.haml | 15 +++++++-------- app/views/spree/orders/_line_item.html.haml | 12 ++++++------ 4 files changed, 24 insertions(+), 27 deletions(-) diff --git a/app/assets/javascripts/darkswarm/cart.js.coffee b/app/assets/javascripts/darkswarm/cart.js.coffee index cd12c67c4a..471991143a 100644 --- a/app/assets/javascripts/darkswarm/cart.js.coffee +++ b/app/assets/javascripts/darkswarm/cart.js.coffee @@ -11,9 +11,9 @@ $ -> # Temporarily handles the cart showing stuff $(document).ready -> - $('#cart_adjustments').hide() + $('.cart_adjustment').hide() - $('th.cart-adjustment-header a').click -> - $('#cart_adjustments').toggle() + $('td.cart-adjustments a').click -> + $('.cart_adjustment').toggle() $(this).html('Item Handling Fees (included in item totals)') false diff --git a/app/views/spree/orders/_adjustments.html.haml b/app/views/spree/orders/_adjustments.html.haml index b5956ba2cc..12b16375ec 100644 --- a/app/views/spree/orders/_adjustments.html.haml +++ b/app/views/spree/orders/_adjustments.html.haml @@ -1,11 +1,9 @@ -%thead - %tr{"data-hook" => "cart_adjustments_headers"} - %th.cart-adjustment-header{colspan: "5"} - %a{ href: "#" } Fees... +%tr{"data-hook" => "cart_adjustments_headers"} + %td.cart-adjustments{colspan: "5"} + %a{ href: "#" } Fees... -%tbody#cart_adjustments{"data-hook" => ""} - - checkout_line_item_adjustments(@order).each do |adjustment| - %tr - %td{colspan: "3"}= adjustment.label - %td.text-right= adjustment.display_amount.to_html - %td +- checkout_line_item_adjustments(@order).each do |adjustment| + %tr.cart_adjustment + %td{colspan: "3"}= adjustment.label + %td.text-right= adjustment.display_amount.to_html + %td diff --git a/app/views/spree/orders/_form.html.haml b/app/views/spree/orders/_form.html.haml index 6d43e97a92..bba45a53c8 100644 --- a/app/views/spree/orders/_form.html.haml +++ b/app/views/spree/orders/_form.html.haml @@ -19,7 +19,7 @@ %tbody#line_items{"data-hook" => ""} = order_form.fields_for :line_items do |item_form| = render :partial => 'line_item', :locals => { :variant => item_form.object.variant, :line_item => item_form.object, :item_form => item_form } - + %tfoot#edit-cart %tr %td{colspan:"2"} @@ -32,7 +32,12 @@ %span#clear_cart_link{"data-hook" => ""} = link_to "Empty cart", empty_cart_path, method: :put, :class => 'not-bold small' -#= form_tag empty_cart_path, :method => :put do - -#= submit_tag t(:empty_cart), :class => 'button alert expand small' + -#= submit_tag t(:empty_cart), :class => 'button alert expand small' + + / This is the fees row which we want to replace with the pop-over + -# - unless @order.adjustments.eligible.blank? + -# = render "spree/orders/adjustments" + %tr %td.text-right{colspan:"3"} Produce subtotal %td.text-right @@ -44,11 +49,6 @@ %td.text-right %span.order-total.distribution-total= display_checkout_admin_and_handling_adjustments_total_for(@order) %td - - / This is the fees row which we want to replace with the pop-over - / %tr - / %td{colspan:"5"} - / = render "spree/orders/adjustments" unless @order.adjustments.eligible.blank? %tr %td.text-right{colspan:"3"} @@ -56,4 +56,3 @@ %td.text-right %h5.order-total.grand-total= @order.display_total %td - diff --git a/app/views/spree/orders/_line_item.html.haml b/app/views/spree/orders/_line_item.html.haml index 53eb254812..d687290561 100644 --- a/app/views/spree/orders/_line_item.html.haml +++ b/app/views/spree/orders/_line_item.html.haml @@ -1,5 +1,5 @@ %tr.line-item{class: "variant-#{variant.id}"} - + / removed image thumbnail on shopping cart & checkout to simplify / %td.cart-item-image{"data-hook" => "cart_item_image"} / - if variant.images.length == 0 @@ -24,7 +24,7 @@ %span= variant.product.name %span= "- " + variant.name_to_display %span.text-small.text-skinny= " (" + variant.options_text + ")" unless variant.options_text.empty? - + - if @order.insufficient_stock_lines.include? line_item %span.out-of-stock = variant.in_stock? ? t(:insufficient_stock, :on_hand => variant.on_hand) : t(:out_of_stock) @@ -33,10 +33,10 @@ %td.text-right.cart-item-price{"data-hook" => "cart_item_price"} = line_item.single_display_amount_with_adjustments.to_html -# Now in a template in app/assets/javascripts/templates ! - %price-breakdown{"price-breakdown" => "_", variant: "variant", - "price-breakdown-append-to-body" => "true", - "price-breakdown-placement" => "left", - "price-breakdown-animation" => true} + -# %price-breakdown{"price-breakdown" => "_", variant: "variant", + -# "price-breakdown-append-to-body" => "true", + -# "price-breakdown-placement" => "left", + -# "price-breakdown-animation" => true} %td.text-center.cart-item-quantity{"data-hook" => "cart_item_quantity"} = item_form.number_field :quantity, :min => 0, :class => "line_item_quantity", :size => 5 %td.cart-item-total.text-right{"data-hook" => "cart_item_total"} From d2fbf9f14d402879a0b040544d02908e77625f83 Mon Sep 17 00:00:00 2001 From: summerscope Date: Fri, 13 Mar 2015 18:00:30 +1100 Subject: [PATCH 4/5] Fixing logic for instance where collection instructions are not entered --- .../confirm_email_for_customer.html.haml | 6 ++-- .../confirm_email_for_shop.html.haml | 6 ++-- .../spree/shared/_order_details.html.haml | 29 ++++++++++--------- 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/app/views/spree/order_mailer/confirm_email_for_customer.html.haml b/app/views/spree/order_mailer/confirm_email_for_customer.html.haml index c769615b0b..4488c76edb 100644 --- a/app/views/spree/order_mailer/confirm_email_for_customer.html.haml +++ b/app/views/spree/order_mailer/confirm_email_for_customer.html.haml @@ -123,12 +123,12 @@ - else Collection details - - if @order.order_cycle.andand.pickup_time_for(@order.distributor) + - if @order.order_cycle.andand.pickup_time_for(@order.distributor).present? %h4 Ready for collection: %strong #{@order.order_cycle.pickup_time_for(@order.distributor)} - - if @order.shipping_method.andand.description + - if @order.shipping_method.andand.description.present? %p %em #{@order.shipping_method.description.html_safe} %br   @@ -139,7 +139,7 @@ %br #{@order.ship_address.full_address} - - if @order.order_cycle.andand.pickup_instructions_for(@order.distributor) + - if @order.order_cycle.andand.pickup_instructions_for(@order.distributor).present? %p %strong Collection instructions: %br diff --git a/app/views/spree/order_mailer/confirm_email_for_shop.html.haml b/app/views/spree/order_mailer/confirm_email_for_shop.html.haml index a99c448c6f..fe48c1c6d1 100644 --- a/app/views/spree/order_mailer/confirm_email_for_shop.html.haml +++ b/app/views/spree/order_mailer/confirm_email_for_shop.html.haml @@ -122,12 +122,12 @@ - else Collection details - - if @order.order_cycle.andand.pickup_time_for(@order.distributor) + - if @order.order_cycle.andand.pickup_time_for(@order.distributor).present? %h4 Ready for collection: %strong #{@order.order_cycle.pickup_time_for(@order.distributor)} - - if @order.shipping_method.andand.description + - if @order.shipping_method.andand.description.present? %p %em #{@order.shipping_method.description.html_safe} %br   @@ -138,7 +138,7 @@ %br #{@order.ship_address.full_address} - - if @order.order_cycle.andand.pickup_instructions_for(@order.distributor) + - if @order.order_cycle.andand.pickup_instructions_for(@order.distributor).present? %p %strong Collection instructions: %br diff --git a/app/views/spree/shared/_order_details.html.haml b/app/views/spree/shared/_order_details.html.haml index 0fdcf33a82..da7bc84ca1 100644 --- a/app/views/spree/shared/_order_details.html.haml +++ b/app/views/spree/shared/_order_details.html.haml @@ -2,7 +2,7 @@ .columns.large-6 .order-summary.text-small .right - - if @order.paid? + - if order.paid? PAID - else NOT PAID @@ -13,7 +13,7 @@ .pad .text-big Paying via: - %strong= @order.payments.first.andand.payment_method.andand.name.andand.html_safe + %strong= order.payments.first.andand.payment_method.andand.name.andand.html_safe %p.text-small.text-skinny.pre-line %em= order.payments.first.andand.payment_method.andand.description.andand.html_safe @@ -29,14 +29,14 @@ = order.bill_address.phone .columns.large-6 - - if @order.shipping_method.andand.require_ship_address + - if order.shipping_method.andand.require_ship_address // Delivery option .order-summary.text-small %strong= order.shipping_method.name .pad .text-big Delivery on - %strong #{@order.order_cycle.pickup_time_for(@order.distributor)} + %strong #{order.order_cycle.pickup_time_for(order.distributor)} %p.text-small.text-skinny.pre-line %em= order.shipping_method.description.andand.html_safe || "" .order-summary.text-small @@ -49,7 +49,7 @@ = order.ship_address.full_address %br = order.ship_address.phone - - if order.special_instructions + - if order.special_instructions.present? %br %p.light.small %strong Your notes: @@ -62,7 +62,7 @@ .pad .text-big Ready for collection - %strong #{@order.order_cycle.pickup_time_for(@order.distributor)} + %strong #{order.order_cycle.pickup_time_for(order.distributor)} %p.text-small.text-skinny.pre-line %em= order.shipping_method.description.andand.html_safe || "" .order-summary.text-small @@ -72,14 +72,15 @@ %p.text-small = order.ship_address.full_address - - if @order.order_cycle.pickup_instructions_for(@order.distributor) + - if order.order_cycle.pickup_instructions_for(order.distributor).present? %br %p.text-small %strong Collection Instructions %br - #{@order.order_cycle.pickup_instructions_for(@order.distributor)} - - if order.special_instructions + #{order.order_cycle.pickup_instructions_for(order.distributor)} + + - if order.special_instructions.present? %br %p.light.small %strong Your notes: @@ -102,7 +103,7 @@ %th.text-right.total %span= t(:total) %tbody{"data-hook" => ""} - - @order.line_items.each do |item| + - order.line_items.each do |item| %tr{"data-hook" => "order_details_line_item_row"} %td(data-hook = "order_item_description") @@ -135,11 +136,11 @@ %h5 Total %td.text-right.total - %h5#order_total= @order.display_total.to_html + %h5#order_total= order.display_total.to_html - if order.price_adjustment_totals.present? %tfoot#price-adjustments{"data-hook" => "order_details_price_adjustments"} - - @order.price_adjustment_totals.each do |key, total| + - order.price_adjustment_totals.each do |key, total| %tr.total %td.text-right{colspan: "3"} %strong @@ -153,10 +154,10 @@ %strong Produce %td.text-right.total - %span= display_checkout_subtotal(@order) + %span= display_checkout_subtotal(order) %tfoot#order-charges{"data-hook" => "order_details_adjustments"} - - checkout_adjustments_for(@order, exclude: [:line_item]).reject{ |a| a.amount == 0 }.reverse_each do |adjustment| + - checkout_adjustments_for(order, exclude: [:line_item]).reject{ |a| a.amount == 0 }.reverse_each do |adjustment| %tr.total %td.text-right{:colspan => "3"} %strong From d0f66a6053fb36c1bfc648ac384362d3f5f79c1c Mon Sep 17 00:00:00 2001 From: summerscope Date: Fri, 13 Mar 2015 18:10:59 +1100 Subject: [PATCH 5/5] Fixing label for cart popover to make it write name of product variant without page load --- app/assets/javascripts/darkswarm/services/cart.js.coffee | 1 + 1 file changed, 1 insertion(+) diff --git a/app/assets/javascripts/darkswarm/services/cart.js.coffee b/app/assets/javascripts/darkswarm/services/cart.js.coffee index 0135416ac4..bbb0b5fab4 100644 --- a/app/assets/javascripts/darkswarm/services/cart.js.coffee +++ b/app/assets/javascripts/darkswarm/services/cart.js.coffee @@ -64,6 +64,7 @@ Darkswarm.factory 'Cart', (CurrentOrder, Variants, $timeout, $http)-> @create_line_item(variant) unless exists create_line_item: (variant)-> + variant.extended_name = @extendedVariantName(variant) variant.line_item = variant: variant quantity: null