Skip to content

Commit

Permalink
Async cart recap enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
vala committed Mar 18, 2013
1 parent 991d20a commit 4086010
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 24 deletions.
10 changes: 5 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ GIT
PATH
remote: .
specs:
glysellin (0.3.alpha)
glysellin (0.3.1)
activemerchant
country_select
money
Expand Down Expand Up @@ -48,7 +48,7 @@ GEM
active_utils (1.0.5)
activesupport (>= 2.3.11)
i18n
activemerchant (1.29.3)
activemerchant (1.31.1)
active_utils (>= 1.0.2)
activesupport (>= 2.3.14)
builder (>= 2.0.0)
Expand Down Expand Up @@ -83,7 +83,7 @@ GEM
coffee-script-source
execjs
coffee-script-source (1.4.0)
country_select (1.0.1)
country_select (1.1.3)
devise (2.1.2)
bcrypt-ruby (~> 3.0)
orm_adapter (~> 0.1)
Expand Down Expand Up @@ -114,7 +114,7 @@ GEM
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.19)
money (5.1.0)
money (5.1.1)
i18n (~> 0.6.0)
multi_json (1.5.0)
mysql2 (0.3.11)
Expand Down Expand Up @@ -162,7 +162,7 @@ GEM
railties (~> 3.2.0)
sass (>= 3.1.10)
tilt (~> 1.3)
simple_form (2.0.4)
simple_form (2.1.0)
actionpack (~> 3.0)
activemodel (~> 3.0)
sprockets (2.2.2)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ end
To display the cart you must render it's partial in your layout :

```erb
<%= render partial: "glysellin/cart/cart", locals: { cart: @cart } %>
<%= render_cart(@cart) %>
```

### Filling the cart
Expand Down
17 changes: 10 additions & 7 deletions app/assets/javascripts/glysellin/cart-recap.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class CartRecap
class AsyncCart
constructor: (@container) ->
@defaultPostOptions = {
_method: @container.find('input[name="_method"]').val(),
Expand Down Expand Up @@ -46,10 +46,10 @@ class CartRecap
@adjustmentRow.find('.remove-discount-btn').on 'click', (e) =>
@resetDiscountCode(); false

@container.on "submit", (e, force = false) ->
false unless force
@container.on "submit", (e, force = false) -> console.log("tuff"); force

@container.find("#submit-order").on "click", (e) =>
@container.find("[name=submit_order]").on "click", (e) =>
console.log(e)
if e.clientX != 0 && e.clientY != 0
@container.trigger("submit", [true])

Expand Down Expand Up @@ -121,6 +121,9 @@ class CartRecap
@totals.eot.text(totals.total_eot_price)
@totals.total.text(totals.total_price)


$ ->
new CartRecap($('.products-recap-form.editable'))
$.fn.glysellinAsyncCart = (options = {})->
@each ->
$cart = $(this)
data = $cart.data('glysellin.async-cart')
unless data
$cart.data('glysellin.async-cart', new AsyncCart($cart, options))
4 changes: 4 additions & 0 deletions app/helpers/glysellin/cart_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,9 @@ def add_to_cart_form product, options = {}
def added_to_cart_warning
render partial: 'glysellin/cart/added_to_cart_warning'
end

def render_cart cart
render partial: "glysellin/cart/cart", locals: { cart: cart }
end
end
end
18 changes: 10 additions & 8 deletions app/views/glysellin/cart/_cart.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<div class="cart-container warn">
<% if cart.empty? %>
<%= t('glysellin.labels.cart.no_products_in_cart') %>
<% else %>
<%= t('glysellin.labels.cart.products_count', count: cart.products_total) %>

<%= link_to t('glysellin.labels.cart.create_order'), cart_path %>
<% end %>
<div class="cart-wrapper">
<div class="cart-container warn">
<% if cart.empty? %>
<%= t('glysellin.labels.cart.no_products_in_cart') %>
<% else %>
<%= t('glysellin.labels.cart.products_count', count: cart.products_total) %>
-
<%= link_to t('glysellin.labels.cart.create_order'), cart_path %>
<% end %>
</div>
</div>
12 changes: 10 additions & 2 deletions app/views/glysellin/cart/_products.html.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<% editable = false unless defined?(editable) && editable == true %>
<% remote = false unless defined?(remote) && remote == true %>
<% remote = Glysellin.async_cart %>

<%= form_tag update_cart_path, method: "put", class: "products-recap-form#{ ' editable' if editable }" do %>
<table id="order_recap_table" class="table">
<table id="order_recap_table" class="table table-bordered table-striped">
<tr>
<th><%= t('glysellin.labels.order.sku') %></th>
<th><%= t('glysellin.labels.order.name') %></th>
Expand Down Expand Up @@ -98,13 +98,21 @@
<td class="total-price">
<%= number_to_currency(cart.total_price) %>
</td>
<% if editable %>
<td></td>
<% end %>
</tr>
</table>

<% if editable %>
<div class="discount-code">
<%= label_tag :discount_code, t('glysellin.labels.order.discount_code') %>
<%= text_field_tag :discount_code, cart.discount_code %>
<% if remote %>
<button class="update-discount-code-btn" type="button">
<%= t('glysellin.labels.cart.update_discount') %>
</button>
<% end %>
</div>
<% unless remote %>
<!-- Update cart contents -->
Expand Down
7 changes: 7 additions & 0 deletions app/views/glysellin/products/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<% if @product.variants.length > 1 %>
<% @product.variants.each do |variant| %>
<%= variant.name(false) %>
<% end %>
<% end %>

<%= add_to_cart_form(@product) %>
3 changes: 2 additions & 1 deletion config/locales/glysellin.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ en:
order_reference: "Order reference"
sku: "SKU"
name: "Product name"
eot_price: "Duty Free Price"
eot_price: "Excluding VAT price"
price: "Price"
subtotal: "Sub-total"
shipping: "Shipping"
Expand Down Expand Up @@ -68,6 +68,7 @@ en:
remove_from_cart: "Delete"
update: "Update cart"
update_discount: "Update discount code"
create_order_form: "Submit order"
orders:
states:
created: "Created"
Expand Down

0 comments on commit 4086010

Please sign in to comment.