Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Rewritten extension to work correctly with Spree 1.0.x

  • Loading branch information...
commit 84fe05fd3ad4e357f7c28e573cc3a68c2365f0a9 1 parent cfc637f
Roman Smirnov authored
2  README.md
View
@@ -12,7 +12,7 @@ Installation
Add `gem "spree_advanced_cart", :git => "git://github.com/romul/spree_advanced_cart.git"
Run `bundle install`
- Run `rake spree_advanced_cart:install:assets`
+ Run `rails g spree_advanced_cart:install`
Copyright (c) 2011 Roman Smirnov
4 public/javascripts/advanced_cart.js → app/assets/javascripts/store/advanced_cart.js
View
@@ -10,8 +10,10 @@
$(this).children(".ajax_loader").fadeOut();
$(this).children("input[type=submit]").show();
});
+
+ $("form#update-cart").attr("data-remote", "true");
- $('form#updatecart').live('ajax:before', function() {
+ $('form#update-cart').live('ajax:before', function() {
$("#order_submit").fadeOut();
$("#applying_coupon").children(".ajax_loader").show();
});
17 public/stylesheets/advanced_cart.css → app/assets/stylesheets/store/advanced_cart.scss
View
@@ -1,18 +1,13 @@
-#updatecart #order-charges td {
- text-align: right;
-}
-
-#updatecart #order-charges td.total {
- text-align: left;
- width: 115px;
+#update-cart #order-charges {
+ margin-left: auto;
+ td { text-align: right; padding-right: 1px;}
}
table#shipping_costs {
width: 40%;
-}
-
-table#shipping_costs th.price {
- width: 70px;
+ margin-top: 2em;
+ th { text-align: left; }
+ th.price { width: 70px; }
}
div#estimate_shipping_costs {
20 app/controllers/orders_controller_decorator.rb
View
@@ -2,16 +2,22 @@
require 'zip-code-info'
def update
- @order = current_order(true)
+ @order = current_order
if @order.update_attributes(params[:order])
@order.line_items = @order.line_items.select {|li| li.quantity > 0 }
+ fire_event('spree.order.contents_changed')
+ if @order.coupon_code.present?
+ if Spree::Promotion.exists?(:code => @order.coupon_code)
+ fire_event('spree.checkout.coupon_code_added', :coupon_code => @order.coupon_code)
+ end
+ end
if request.xhr?
@order.update!
else
- redirect_to cart_path
+ respond_with(@order) { |format| format.html { redirect_to cart_path } }
end
else
- render :edit unless request.xhr?
+ respond_with(@order)
end
end
@@ -28,15 +34,15 @@ def estimate_shipping_cost
state = state_id_by_zip(params[:zipcode])
address_attrs.merge!(:state_id => state.try(:id))
elsif params[:zipcode] =~ /[a-z]\d[a-z]\s?\d[a-z]\d/i # Canadian zipcode
- address_attrs.merge!(:country_id => Country.find_by_iso('CA').try(:id))
+ address_attrs.merge!(:country_id => Spree::Country.find_by_iso('CA').try(:id))
else
zipcode_is_valid = false
end
end
if zipcode_is_valid
- @order.ship_address = Address.new(address_attrs)
- @shipping_methods = ShippingMethod.all_available(@order)
+ @order.ship_address = Spree::Address.new(address_attrs)
+ @shipping_methods = Spree::ShippingMethod.all_available(@order)
@esc_values = @shipping_methods.
map {|sm| [sm.name, sm.calculator.compute(@order)]}.
select{|sm| sm[1]}. #Can a shipping calculator return nil for the price?
@@ -58,7 +64,7 @@ def estimate_shipping_cost
end
def state_id_by_zip(zip_code)
- State.find_by_abbr(ZipCodeInfo.instance.state_for(zip_code))
+ Spree::State.find_by_abbr(ZipCodeInfo.instance.state_for(zip_code))
end
end
7 app/models/spree/advanced_cart_configuration.rb
View
@@ -0,0 +1,7 @@
+module Spree
+ class AdvancedCartConfiguration < Preferences::Configuration
+ preference :enable_coupon_applying, :boolean, :default => true
+ preference :enable_shipping_cost_calculation, :boolean, :default => true
+ preference :skip_zipcode_validation, :boolean, :default => false
+ end
+end
5 app/overrides/advanced_cart_cart_buttons.rb
View
@@ -0,0 +1,5 @@
+Deface::Override.new(:virtual_path => "spree/orders/edit",
+ :name => "advanced_cart_cart_buttons",
+ :insert_before => "[data-hook='cart_buttons']",
+ :partial => "spree/orders/apply_coupon")
+
5 app/overrides/advanced_cart_outside_cart_form.rb
View
@@ -0,0 +1,5 @@
+Deface::Override.new(:virtual_path => "spree/orders/edit",
+ :name => "advanced_cart_outside_cart_form",
+ :insert_after => "[data-hook='outside_cart_form']",
+ :partial => "spree/orders/shipping_cost_calculation")
+
7 app/overrides/advanced_cart_subtotal.rb
View
@@ -0,0 +1,7 @@
+=begin
+Deface::Override.new(:virtual_path => "spree/orders/edit",
+ :name => "advanced_cart_subtotals",
+ :insert_bottom => "div#subtotal",
+ :text => %(<h5><%= t(:total) %>: <span class="order-total"><%= number_to_currency @order.total %></span></h5>)
+ ) if Spree::AdvancedCart::Config[:enable_coupon_applying]
+=end
41 app/views/spree/orders/_advanced_cart.html.erb
View
@@ -1,41 +0,0 @@
-<%= form_for(@order, :url => update_cart_path, :html=>{:id=>'updatecart'}, :remote => true) do |order_form| %>
-
- <div data-hook="cart_items">
- <%= render :partial => 'form', :locals => {:order_form => order_form} %>
- </div>
-
- <% if Spree::AdvancedCart::Config[:enable_coupon_applying] %>
- <table id="order-charges">
- <tbody>
- <% @order.adjustments.each do |adjustment| %>
- <tr>
- <td><strong><%= adjustment.label %></strong></td>
- <td class="total"><span><%= number_to_currency adjustment.amount %></span></td>
- </tr>
- <% end %>
- </tbody>
- </table>
-
- <div id="applying_coupon">
- <h3><%= t(:apply_coupon) %></h3>
- <label><%= t(:coupon_code) %></label>
- <%= order_form.text_field :coupon_code, :size => 19 %>
- <span class="ajax_loader"><%= image_tag 'ajax_loader.gif', :alt => t('loading') %></span>
- <%= order_form.submit t("apply") %>
- </div>
- <% end %>
-
- <div id="subtotal">
- <div data-hook="advanced_cart_subtotal">
- <h3><%= "#{t("subtotal")}: #{order_price(@order)}" %></h3>
- <% if Spree::AdvancedCart::Config[:enable_coupon_applying] %>
- <h3><%= "#{t("total")}: #{number_to_currency @order.total}" %></h3>
- <% end %>
- </div>
- <div class="links" data-hook="advanced_cart_subtotal_links">
- <%= link_to image_tag('/images/update.png') + t("update"), '#', :class => 'button checkout primary', :onclick => "$('form#updatecart').submit(); return false;" %>
- <%= link_to image_tag('/images/checkout.png') + t("checkout"), checkout_path, :class => 'button checkout primary' %>
- </div>
- </div>
-
-<% end %>
21 app/views/spree/orders/_apply_coupon.html.erb
View
@@ -0,0 +1,21 @@
+<% if Spree::AdvancedCart::Config[:enable_coupon_applying] %>
+ <div id="applying_coupon" class="links columns ten alpha">
+ <h3><%= t(:apply_coupon) %></h3>
+ <label><%= t(:coupon_code) %></label>
+ <%= order_form.text_field :coupon_code, :size => 19 %>
+ <span class="ajax_loader"><%= image_tag 'spinner.gif', :alt => t('loading') %></span>
+ <%= order_form.submit t("apply") %>
+ </div>
+ <div class="columns six omega">
+ <table id="order-charges">
+ <tbody>
+ <% @order.adjustments.each do |adjustment| %>
+ <tr>
+ <td class="adjustment_label"><strong><%= adjustment.label %></strong></td>
+ <td><span class="price"><%= number_to_currency adjustment.amount %></span></td>
+ </tr>
+ <% end %>
+ </tbody>
+ </table>
+ </div>
+<% end %>
11 app/views/spree/orders/_shipping_cost_calculation.html.erb
View
@@ -0,0 +1,11 @@
+<% if Spree::AdvancedCart::Config[:enable_shipping_cost_calculation] %>
+ <div id="estimate_shipping_costs" class="links columns ten alpha">
+ <h3><%= t(:calc_estimated_shipping_cost) %></h3>
+ <%= form_tag estimate_shipping_cost_path, :remote => true, :method => :get do %>
+ <%= label_tag t(:enter_zipcode) %>: <%= text_field_tag :zipcode %>
+ <span class="ajax_loader"><%= image_tag 'spinner.gif', :alt => t('loading') %></span>
+ <%= submit_tag t("actions.calc") %>
+ <% end %>
+ <div id="estimate_shipping_cost_table"></div>
+ </div>
+<% end %>
39 app/views/spree/orders/edit.html.erb
View
@@ -1,39 +0,0 @@
-<% @body_id = 'cart' %>
-
-<h1><%= t("shopping_cart")%></h1>
-
-<% if @order.line_items.empty? %>
-
- <div data-hook="empty_cart">
- <p><%= t("your_cart_is_empty.") %></p>
- <p><%= link_to t("continue_shopping"), products_path, :class => 'button continue' %></p>
- </div>
-
-<% else %>
- <div id="advanced_cart">
- <%= render :partial => 'spree/orders/advanced_cart' %>
- </div>
- <div style="clear:both;">
- <% if Spree::AdvancedCart::Config[:enable_shipping_cost_calculation] %>
- <div id="estimate_shipping_costs">
- <h3><%= t(:calc_estimated_shipping_cost) %></h3>
- <%= form_tag estimate_shipping_cost_path, :remote => true, :method => :get do %>
- <%= label_tag t(:enter_zipcode) %>: <%= text_field_tag :zipcode %>
- <span class="ajax_loader"><%= image_tag 'ajax_loader.gif', :alt => t('loading') %></span>
- <%= submit_tag t("actions.calc") %>
- <% end %>
- <div id="estimate_shipping_cost_table"></div>
- </div>
- <% end %>
-
- <div data-hook="continue_shopping_or_empty_cart">
- <%= form_tag empty_cart_path, :method => :put, :id => 'continue_shopping_or_empty_cart' do %>
- <p id="clear_cart_link">
- <%= link_to t("continue_shopping"), products_path, :class => 'button continue' %>
- <%= t(:or) %>
- <input type="submit" value="<%= t('empty_cart') %>" class="button" />
- </p>
- <% end %>
- </div>
- </div>
-<% end %>
6 app/views/spree/orders/update.js.erb
View
@@ -1,5 +1 @@
-<% if @order.line_items.present? %>
- $("#advanced_cart").html("<%= escape_javascript(render('advanced_cart')) %>");
-<% else %>
- window.location.reload(true);
-<% end %>
+$("#content").html("<%= escape_javascript(render(:template => 'spree/orders/edit')) %>");
29 lib/generators/spree_advanced_cart/install_generator.rb
View
@@ -0,0 +1,29 @@
+module SpreeAdvancedCart
+ module Generators
+ class InstallGenerator < Rails::Generators::Base
+
+ def add_javascripts
+ append_file "app/assets/javascripts/store/all.js", "//= require store/advanced_cart\n"
+ end
+
+ def add_stylesheets
+ inject_into_file "app/assets/stylesheets/store/all.css", " *= require store/advanced_cart\n", :before => /\*\//, :verbose => true
+ end
+
+=begin
+ def add_migrations
+ run 'rake railties:install:migrations FROM=spree_advanced_cart'
+ end
+
+ def run_migrations
+ res = ask "Would you like to run the migrations now? [Y/n]"
+ if res == "" || res.downcase == "y"
+ run 'rake db:migrate'
+ else
+ puts "Skiping rake db:migrate, don't forget to run it!"
+ end
+ end
+=end
+ end
+ end
+end
1  lib/spree/advanced_cart/config.rb
View
@@ -1 +0,0 @@
-Spree::AdvancedCart::Config = Spree::AdvancedCartConfiguration.new
26 lib/spree/advanced_cart/engine.rb
View
@@ -0,0 +1,26 @@
+module Spree
+ module AdvancedCart
+ class Engine < Rails::Engine
+ isolate_namespace Spree
+ engine_name 'spree_advanced_cart'
+
+ initializer "spree.advanced_cart.environment", :before => :load_config_initializers do |app|
+ Spree::AdvancedCart::Config = Spree::AdvancedCartConfiguration.new
+ end
+
+ config.autoload_paths += %W(#{config.root}/lib)
+
+ def self.activate
+ Dir.glob(File.join(File.dirname(__FILE__), "../../../app/**/*_decorator*.rb")) do |c|
+ Rails.configuration.cache_classes ? require(c) : load(c)
+ end
+
+ Dir.glob(File.join(File.dirname(__FILE__), "../../../app/overrides/*.rb")) do |c|
+ Rails.configuration.cache_classes ? require(c) : load(c)
+ end
+ end
+
+ config.to_prepare &method(:activate).to_proc
+ end
+ end
+end
5 lib/spree/advanced_cart_configuration.rb
View
@@ -1,5 +0,0 @@
-class Spree::AdvancedCartConfiguration < Spree::Preferences::Configuration
- preference :enable_coupon_applying, :boolean, :default => true
- preference :enable_shipping_cost_calculation, :boolean, :default => true
- preference :skip_zipcode_validation, :boolean, :default => false
-end
19 lib/spree_advanced_cart.rb
View
@@ -1,17 +1,2 @@
-require 'spree_core'
-require 'spree_advanced_cart_hooks'
-
-module SpreeAdvancedCart
- class Engine < Rails::Engine
-
- config.autoload_paths += %W(#{config.root}/lib)
-
- def self.activate
- Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|
- Rails.env.production? ? require(c) : load(c)
- end
- end
-
- config.to_prepare &method(:activate).to_proc
- end
-end
+require 'spree/core'
+require 'spree/advanced_cart/engine'
5 lib/spree_advanced_cart_hooks.rb
View
@@ -1,5 +0,0 @@
-Deface::Override.new(:virtual_path => "layouts/spree_application",
- :name => "advanced_cart_assets",
- :insert_bottom => "head",
- :text => "<%= stylesheet_link_tag 'advanced_cart' %><%= javascript_include_tag 'advanced_cart' %>")
-
25 lib/tasks/install.rake
View
@@ -1,25 +0,0 @@
-namespace :spree_advanced_cart do
- desc "Copies all migrations and assets (NOTE: This will be obsolete with Rails 3.1)"
- task :install do
- Rake::Task['spree_advanced_cart:install:migrations'].invoke
- Rake::Task['spree_advanced_cart:install:assets'].invoke
- end
-
- namespace :install do
- desc "Copies all migrations (NOTE: This will be obsolete with Rails 3.1)"
- task :migrations do
- source = File.join(File.dirname(__FILE__), '..', '..', 'db')
- destination = File.join(Rails.root, 'db')
- Spree::FileUtilz.mirror_files(source, destination)
- end
-
- desc "Copies all assets (NOTE: This will be obsolete with Rails 3.1)"
- task :assets do
- source = File.join(File.dirname(__FILE__), '..', '..', 'public')
- destination = File.join(Rails.root, 'public')
- puts "INFO: Mirroring assets from #{source} to #{destination}"
- Spree::FileUtilz.mirror_files(source, destination)
- end
- end
-
-end
1  lib/tasks/spree_advanced_cart.rake
View
@@ -1 +0,0 @@
-# add custom rake tasks here
Please sign in to comment.
Something went wrong with that request. Please try again.