mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Merge branch 'order-confirmation' into ready-to-merge
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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()
|
||||
@@ -63,8 +64,17 @@ 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
|
||||
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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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') }}"
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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"}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)"
|
||||
|
||||
Reference in New Issue
Block a user