diff --git a/app/assets/javascripts/darkswarm/cart.js.coffee b/app/assets/javascripts/darkswarm/cart.js.coffee new file mode 100644 index 0000000000..1d3e76290f --- /dev/null +++ b/app/assets/javascripts/darkswarm/cart.js.coffee @@ -0,0 +1,14 @@ +window.Cart = angular.module("Cart", ["ngResource"]).config ($httpProvider) -> + $httpProvider.defaults.headers.post['X-CSRF-Token'] = $('meta[name="csrf-token"]').attr('content') + + +# TEMPORARILY handles the deletetion +$ -> + if ($ 'form#update-cart').is('*') + ($ 'form#update-cart a.delete').show().one 'click', -> + ($ this).parents('.line-item').first().find('input.line_item_quantity').val 0 + ($ this).parents('form').first().submit() + false + + ($ 'form#update-cart').submit -> + ($ 'form#update-cart #update-button').attr('disabled', true) diff --git a/app/overrides/rearrange_empty_cart_form.rb b/app/overrides/rearrange_empty_cart_form.rb deleted file mode 100644 index 813173f489..0000000000 --- a/app/overrides/rearrange_empty_cart_form.rb +++ /dev/null @@ -1,6 +0,0 @@ -# Remove column layout from cart form items so we can style it with CSS -Deface::Override.new(:virtual_path => "spree/orders/edit", - :replace => "#empty-cart[data-hook]", - :partial => "spree/orders/empty_cart_form", - :name => "rearrange_empty_cart_form", - :original => 'b5a751777e66ccbd45d7f1b980ecd201af94cb5b') \ No newline at end of file diff --git a/app/overrides/rearrange_inside_cart_form.rb b/app/overrides/rearrange_inside_cart_form.rb deleted file mode 100644 index fd4f873ad5..0000000000 --- a/app/overrides/rearrange_inside_cart_form.rb +++ /dev/null @@ -1,6 +0,0 @@ -# Remove column layout from cart form items so we can style it with CSS -Deface::Override.new(:virtual_path => "spree/orders/edit", - :replace => "[data-hook='inside_cart_form']", - :partial => "spree/orders/inside_cart_form", - :name => "rearrange_inside_cart_form", - :original => 'e30b0e749869c51f004242b0cb7be582b45e044e') diff --git a/app/overrides/spree/orders/edit/list_view.html.haml.deface b/app/overrides/spree/orders/edit/list_view.html.haml.deface deleted file mode 100644 index 86f90c6c8e..0000000000 --- a/app/overrides/spree/orders/edit/list_view.html.haml.deface +++ /dev/null @@ -1,6 +0,0 @@ -/ replace_contents "[id='clear_cart_link']" - -%p - = link_to "Continue Shopping", main_app.shop_path, class: "button primary checkout" - = t(:or) - = submit_tag t(:empty_cart), :class => 'button gray' diff --git a/app/overrides/spree/orders/edit/quick_checkout.html.haml.deface b/app/overrides/spree/orders/edit/quick_checkout.html.haml.deface deleted file mode 100644 index ea21298832..0000000000 --- a/app/overrides/spree/orders/edit/quick_checkout.html.haml.deface +++ /dev/null @@ -1,9 +0,0 @@ -/ replace_contents "[data-hook='cart_buttons']" - -= button_tag :class => 'primary', :id => 'update-button' do - = t(:update) -  -= link_to "Checkout", main_app.shop_checkout_path, class: "button checkout primary" - -%div - = link_to "Old Checkout", "/checkout", :id => 'checkout-link' diff --git a/app/views/spree/orders/_empty_cart_form.html.haml b/app/views/spree/orders/_empty_cart_form.html.haml deleted file mode 100644 index 1e9a792eec..0000000000 --- a/app/views/spree/orders/_empty_cart_form.html.haml +++ /dev/null @@ -1,6 +0,0 @@ -#empty-cart{'data-hook' => ""} - = form_tag empty_cart_path, :method => :put do - %p#clear_cart_link{'data-hook' => ""} - = link_to t(:continue_shopping), products_path, :class => 'continue button' - = t(:or) - = submit_tag t(:empty_cart), :class => 'button' diff --git a/app/views/spree/orders/_form.html.haml b/app/views/spree/orders/_form.html.haml new file mode 100644 index 0000000000..ae2e392872 --- /dev/null +++ b/app/views/spree/orders/_form.html.haml @@ -0,0 +1,20 @@ += render :partial => 'spree/shared/error_messages', :locals => { :target => @order } + +%table#cart-detail{"data-hook" => ""} + %col{halign: "center", valign: "middle", width: "30%"}/ + %col{valign: "middle", width: "25%"}/ + %col{halign: "center", valign: "middle", width: "15%"}/ + %col{halign: "center", valign: "middle", width: "15%"}/ + %col{halign: "center", valign: "middle", width: "10%"}/ + %col{halign: "center", valign: "middle", width: "5%"}/ + %thead + %tr{"data-hook" => "cart_items_headers"} + %th.cart-item-description-header{colspan: "2"}= t(:item) + %th.cart-item-price-header= t(:price) + %th.cart-item-quantity-header= t(:qty) + %th.cart-item-total-header= t(:total) + %th.cart-item-delete-header + %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 } + = render "spree/orders/adjustments" unless @order.adjustments.eligible.blank? diff --git a/app/views/spree/orders/_inside_cart_form.html.haml b/app/views/spree/orders/_inside_cart_form.html.haml deleted file mode 100644 index 502546113f..0000000000 --- a/app/views/spree/orders/_inside_cart_form.html.haml +++ /dev/null @@ -1,22 +0,0 @@ -%div{'data-hook' => "inside_cart_form"} - %div{'data-hook' => "cart_items"} - = render :partial => 'form', :locals => { :order_form => order_form } - - #subtotal{'data-hook' => ""} - %h5 - Item total - \: - %span.order-total.item-total= number_to_currency @order.item_total - %h5 - Distribution total - \: - %span.order-total.distribution-total= order_distribution_subtotal(@order) - %h4 - Total - \: - %span.order-total.grand-total= @order.display_total - - .links{'data-hook' => "cart_buttons"} - = button_tag :class => 'primary', :id => 'update-button' do - = t(:update) - = link_to t(:checkout), checkout_path, :class => 'button checkout primary', :id => 'checkout-link' diff --git a/app/views/spree/orders/_line_item.html.haml b/app/views/spree/orders/_line_item.html.haml new file mode 100644 index 0000000000..bb7054655f --- /dev/null +++ b/app/views/spree/orders/_line_item.html.haml @@ -0,0 +1,27 @@ +%tr.line-item + %td.cart-item-image{"data-hook" => "cart_item_image"} + - if variant.images.length == 0 + = link_to small_image(variant.product), variant.product + - else + = link_to image_tag(variant.images.first.attachment.url(:small)), variant.product + + %td.cart-item-description{"data-hook" => "cart_item_description"} + %h4= link_to variant.product.name, product_path(variant.product) + = variant.options_text + - 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) + %br + = line_item_description(variant) + + %td.cart-item-price{"data-hook" => "cart_item_price"} + = line_item.single_money.to_html + %td.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{"data-hook" => "cart_item_total"} + = line_item.display_amount.to_html unless line_item.quantity.nil? + + %td.cart-item-delete{"data-hook" => "cart_item_delete"} + {{ quantity }} + = link_to image_tag('icons/delete.png'), '#', :class => 'delete', + :id => "delete_#{dom_id(line_item)}" diff --git a/app/views/spree/orders/edit.html.haml b/app/views/spree/orders/edit.html.haml new file mode 100644 index 0000000000..3038412438 --- /dev/null +++ b/app/views/spree/orders/edit.html.haml @@ -0,0 +1,57 @@ +- @body_id = 'cart' +.darkswarm + - content_for :order_cycle_form do + %strong.avenir + Order ready on + - if @order.order_cycle + = pickup_time @order.order_cycle + - else + = @order.distributor.next_collection_at + + = render partial: "shop/details" + + %fieldset{"ng-app" => "Cart"} + - if @order.line_items.empty? + %div.row{"data-hook" => "empty_cart"} + %p= t(:your_cart_is_empty) + %p= link_to t(:continue_shopping), main_app.shop_path, :class => 'button continue' + + - else + %div{"data-hook" => "outside_cart_form"} + = form_for @order, :url => update_cart_path, :html => {:id => 'update-cart'} do |order_form| + %div{"data-hook" => "inside_cart_form"} + %div{"data-hook" => "cart_items"} + .row + = render :partial => 'form', :locals => { :order_form => order_form } + + #subtotal.row{'data-hook' => ""} + .columns.large-5 + %h5 + Item total + \: + %span.order-total.item-total= number_to_currency @order.item_total + .columns.large-5 + %h5 + Distribution total + \: + %span.order-total.distribution-total= order_distribution_subtotal(@order) + .columns.large-2 + %h4 + Total + \: + %span.order-total.grand-total= @order.display_total + + .links{'data-hook' => "cart_buttons"} + .row + .columns.large-1 + = button_tag :class => 'primary', :id => 'update-button' do + = t(:update) + .columns.large-2 + = link_to "Checkout", main_app.shop_checkout_path, class: "button checkout primary", id: "checkout-link" + + #empty-cart.columns.large-4{"data-hook" => ""} + = form_tag empty_cart_path, :method => :put do + #clear_cart_link{"data-hook" => ""} + = link_to "Continue Shopping", main_app.shop_path, class: "button primary checkout" + = t(:or) + = submit_tag t(:empty_cart), :class => 'button gray' diff --git a/spec/features/chili/enterprises_distributor_info_rich_text_feature_spec.rb b/spec/features/chili/enterprises_distributor_info_rich_text_feature_spec.rb index 887dd1188d..19ee905ae2 100644 --- a/spec/features/chili/enterprises_distributor_info_rich_text_feature_spec.rb +++ b/spec/features/chili/enterprises_distributor_info_rich_text_feature_spec.rb @@ -78,6 +78,7 @@ feature "enterprises distributor info as rich text" do # -- Checkout click_button 'Add To Cart' find('#checkout-link').click + visit "/checkout" within 'fieldset#shipping' do page.should have_content 'Chu ge sai yubi dan bisento tobi ashi yubi ge omote.' page.should have_content 'Thursday 2nd May' @@ -123,6 +124,7 @@ feature "enterprises distributor info as rich text" do # -- Checkout click_button 'Add To Cart' find('#checkout-link').click + visit "/checkout" within 'fieldset#shipping' do page.should have_content 'Chu ge sai yubi dan bisento tobi ashi yubi ge omote.' page.should have_content 'Friday 4th May' diff --git a/spec/features/consumer/checkout_spec.rb b/spec/features/consumer/checkout_spec.rb index ddb42d2214..c150582ae9 100644 --- a/spec/features/consumer/checkout_spec.rb +++ b/spec/features/consumer/checkout_spec.rb @@ -365,6 +365,9 @@ feature %q{ click_link 'Zucchini' click_button 'Add To Cart' find('#checkout-link').click + + # And manually visit the old checkout + visit "/checkout" # -- Checkout: Address fill_in_fields('order_bill_address_attributes_firstname' => 'Joe', @@ -451,9 +454,11 @@ feature %q{ # We perform login inline because: # a) It's a common user flow # b) It has been known to trigger errors with spree_last_address - fill_in 'spree_user_email', :with => 'someone@ofn.org' - fill_in 'spree_user_password', :with => 'passw0rd' - click_button 'Login' + within "#checkout_login" do + fill_in 'login_spree_user_email', :with => 'someone@ofn.org' + fill_in 'login_spree_user_password', :with => 'passw0rd' + click_button 'Login' + end # -- Checkout: Address page.should have_field 'order_bill_address_attributes_firstname', with: 'Joe' @@ -464,44 +469,6 @@ feature %q{ page.should have_field 'order_bill_address_attributes_phone', with: '12999911111' page.should have_select 'order_bill_address_attributes_state_id', selected: 'Victoria' page.should have_select 'order_bill_address_attributes_country_id', selected: 'Australia' - - # Distributor details should be displayed - within('fieldset#shipping') do - [@distributor_oc.name, - @distributor_oc.distributor_info, - @distributor_oc.next_collection_at - ].each do |value| - - page.should have_content value - end - end - - # Disabled until this form takes order cycles into account - # page.should have_selector "select#order_distributor_id option[value='#{@distributor_alternative.id}']" - - click_checkout_continue_button - - # -- Checkout: Delivery - order_charges = page.all("tbody#summary-order-charges tr").map {|row| row.all('td').map(&:text)}.take(2) - order_charges.should == [["Distribution:", "$51.00"]] - click_checkout_continue_button - - # -- Checkout: Payment - # Given the distributor I have selected for my order, I should only see payment methods valid for that distributor - page.should have_selector 'label', :text => @payment_method_distributor_oc.name - page.should_not have_selector 'label', :text => @payment_method_alternative.name - click_checkout_continue_button - - # -- Checkout: Order complete - page.should have_content 'Your order has been processed successfully' - page.should have_content @payment_method_distributor_oc.description - - page.should have_selector 'tfoot#order-charges tr.total td', text: 'Distribution' - page.should have_selector 'tfoot#order-charges tr.total td', text: '51.00' - - # -- Checkout: Email - email = ActionMailer::Base.deliveries.last - email.body.should =~ /Distribution[\s+]\$51.00/ end