spree_zone_pricing 0.1.69 → 0.1.70

Sign up to get free protection for your applications and to get access to all the features.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_zone_pricing
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.69
4
+ version: 0.1.70
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -40,18 +40,6 @@ files:
40
40
  - db/seeds.rb
41
41
  - lib/spree_zone_pricing.rb
42
42
  - lib/spree_zone_pricing_hooks.rb
43
- - lib/spree/zone_pricing/checkouts_controller.rb
44
- - lib/spree/zone_pricing/countries_controller.rb
45
- - lib/spree/zone_pricing/get_country.rb
46
- - lib/spree/zone_pricing/order.rb
47
- - lib/spree/zone_pricing/orders_controller.rb
48
- - lib/spree/zone_pricing/products_helper.rb
49
- - lib/spree/zone_pricing/variant.rb
50
- - lib/spree/zone_pricing/zone.rb
51
- - lib/spree/zone_pricing/admin/variants_controller.rb
52
- - lib/tasks/zone_pricing_extension_tasks.rake
53
- - spec/spec.opts
54
- - spec/spec_helper.rb
55
43
  homepage: https://github.com/henriquebf/spree-zone-pricing
56
44
  licenses: []
57
45
  post_install_message:
@@ -1,30 +0,0 @@
1
- module Spree::ZonePricing::Admin::VariantsController
2
-
3
- def self.included(target)
4
- target.class_eval do
5
-
6
- create.before do
7
- # Set zone product to default if they exist
8
- object.set_default_zone_prices(get_user_country_id)
9
- # Make sure to call original code to save
10
- create_before
11
- end
12
-
13
- update.response do |wants|
14
- wants.html do
15
- redirect_to object.is_master ? zone_prices_admin_product_variant_url(object.product, object) : collection_url
16
- end
17
- end
18
-
19
- def object
20
- @object ||= Variant.find(params[:id])
21
- end
22
-
23
- def zone_prices
24
- @variant = object
25
- @product = @variant.product
26
- end
27
- end
28
- end
29
-
30
- end
@@ -1,21 +0,0 @@
1
- module Spree::ZonePricing::CheckoutsController
2
- def self.included(target)
3
- target.class_eval do
4
- address.update_hook :update_zone_prices
5
- end
6
- end
7
-
8
- private
9
-
10
- # Check the ship country and compare against the currently selected country,
11
- # if different update the order line items with the prices from the ship country
12
- def update_zone_prices
13
- # Same country do not update prices
14
- return if get_user_country_id == object.ship_address.country.id
15
- # Update the order prices using the ship to country
16
- @order.update_zone_prices(object.ship_address.country.id)
17
- # Update selected country with ship to country
18
- session[:zone_pricing_country] = object.ship_address.country.id
19
- end
20
-
21
- end
@@ -1,30 +0,0 @@
1
- module Spree::ZonePricing::CountriesController
2
-
3
- def self.included(target)
4
- target.class_eval do
5
-
6
- # Change the currently selected country
7
- def set
8
- country = Country.find(params[:id])
9
- if request.referer && request.referer.starts_with?("http://" + request.host)
10
- session[:return_to] = request.referer
11
- end
12
- if country
13
- # Store country in the session
14
- session[:zone_pricing_country] = country.id
15
- # Update prices for the current order
16
- if session[:order_id]
17
- order = Order.find(session[:order_id])
18
- order.update_zone_prices(get_user_country_id)
19
- end
20
- flash[:notice] = t("country_changed")
21
- else
22
- flash[:error] = t("country_not_changed")
23
- end
24
- redirect_back_or_default(root_path)
25
- end
26
-
27
- end
28
- end
29
-
30
- end
@@ -1,17 +0,0 @@
1
- module Spree::ZonePricing::GetCountry
2
- def self.included(base)
3
- base.class_eval do
4
- # This method will retrieve the users country
5
- def get_user_country_id
6
- # Check if set in session
7
- country = session[:zone_pricing_country] if session.has_key?(:zone_pricing_country)
8
- # If no country in session, check if user has a bill address, if so use
9
- # the country from the address
10
- country ||= (current_user && current_user.respond_to?('ship_address') &&
11
- current_user.ship_address) ? current_user.ship_address.country.id : nil
12
- # If no bill address country use default country
13
- country ||= Spree::Config[:default_country_id]
14
- end
15
- end
16
- end
17
- end
@@ -1,65 +0,0 @@
1
- module Spree::ZonePricing::Order
2
-
3
- def self.included(target)
4
- target.class_eval do
5
- # Override add_variant method so that we can use zone pricing
6
- alias :spree_add_variant :add_variant unless method_defined?(:spree_add_variant)
7
- alias :add_variant :site_add_variant
8
-
9
- # Method to update prices in the current order when country changes
10
- def update_zone_prices(country_id); order_update_zone_prices(country_id); end
11
-
12
- # We need to know what the currently selected country is so that we can
13
- # determine the zone price
14
- attr_accessor :country_id
15
- end
16
- end
17
-
18
- # Override the add_variant functionality so that we can adjust the price based on
19
- # the country and therefore zone selected
20
- def site_add_variant(variant, quantity=1)
21
- current_item = contains?(variant)
22
- # Added: Check if country specified, if so check if zone price defined,
23
- # if no country specified use normal price
24
- if @country_id
25
- price = variant.zone_price(@country_id)
26
- else
27
- price = variant.price
28
- end
29
- if current_item
30
- current_item.increment_quantity unless quantity > 1
31
- current_item.quantity = (current_item.quantity + quantity) if quantity > 1
32
- current_item.price = price # Added
33
- current_item.save
34
- else
35
- current_item = LineItem.new(:quantity => quantity)
36
- current_item.variant = variant
37
- current_item.price = price
38
- self.line_items << current_item
39
- end
40
-
41
- # populate line_items attributes for additional_fields entries
42
- # that have populate => [:line_item]
43
- Variant.additional_fields.select{|f| !f[:populate].nil? && f[:populate].include?(:line_item) }.each do |field|
44
- value = ""
45
-
46
- if field[:only].nil? || field[:only].include?(:variant)
47
- value = variant.send(field[:name].gsub(" ", "_").downcase)
48
- elsif field[:only].include?(:product)
49
- value = variant.product.send(field[:name].gsub(" ", "_").downcase)
50
- end
51
- current_item.update_attribute(field[:name].gsub(" ", "_").downcase, value)
52
- end
53
-
54
- current_item
55
- end
56
-
57
- private
58
-
59
- # Update price of line items in current order on change
60
- # of country
61
- def order_update_zone_prices(country_id)
62
- self.line_items.each {|li| li.update_attribute(:price, li.variant.zone_price(country_id))}
63
- update_totals!
64
- end
65
- end
@@ -1,19 +0,0 @@
1
- module Spree::ZonePricing::OrdersController
2
- def self.included(target)
3
- target.class_eval do
4
- alias_method :spree_create_before, :create_before unless method_defined?(:spree_create_before)
5
- alias_method :create_before, :site_create_before
6
- end
7
- end
8
-
9
- # The order object needs to know which country has been selected
10
- # by the user so that we can calculate the zone prices. This informations
11
- # may be stored in the session which we do not have access to in the model
12
- # so this method will get the currently selected country and provide it to
13
- # the Order model
14
- def site_create_before
15
- @order.country_id = get_user_country_id if @order
16
- spree_create_before
17
- end
18
-
19
- end
@@ -1,30 +0,0 @@
1
- module Spree::ZonePricing::ProductsHelper
2
- def self.included(base)
3
- base.class_eval do
4
- alias_method :spree_product_price, :product_price unless method_defined?(:spree_product_price)
5
- alias_method :product_price, :site_product_price
6
- end
7
- end
8
-
9
- # returns the price of the product to show for display purposes
10
- def site_product_price(product_or_variant, options={})
11
- options.assert_valid_keys(:format_as_currency, :show_vat_text)
12
- options.reverse_merge! :format_as_currency => true, :show_vat_text => Spree::Config[:show_price_inc_vat]
13
-
14
- # Check if this object is a product, if so then access the master variant
15
- # record for the product to get the zone pricing
16
- object = product_or_variant.is_a?(Product) ? product_or_variant.master : product_or_variant
17
-
18
- # Get the zone price for this variant/product if one is defined
19
- # otherwise use the normal price
20
- if object.respond_to?(:zone_price)
21
- amount = object.zone_price(get_user_country_id)
22
- else
23
- amount = object.price
24
- end
25
-
26
- amount += Calculator::Vat.calculate_tax_on(product_or_variant) if Spree::Config[:show_price_inc_vat]
27
- options.delete(:format_as_currency) ? format_price(amount, options) : ("%0.2f" % amount).to_f
28
- end
29
-
30
- end
@@ -1,52 +0,0 @@
1
- module Spree::ZonePricing::Variant
2
-
3
- def self.included(target)
4
- target.class_eval do
5
- has_many :zone_prices, :dependent => :destroy
6
- has_many :zones, :through => :zone_prices
7
-
8
- # Update zone prices for variant from attributes
9
- # passed to us from the form
10
- def zone_price_attributes=(price_attributes)
11
- price_attributes.each do |key, value|
12
- # Check if record exists, if so update. If value of price
13
- # is blank or 0 then delete record
14
- zone_price = ZonePrice.first(:conditions => {:zone_id => key, :variant_id => self.id})
15
- if zone_price
16
- # Record exists, update or delete if no price specified
17
- if value['price'].to_f != 0
18
- zone_price.update_attribute(:price, value['price'].to_f)
19
- else
20
- zone_price.destroy
21
- end
22
- elsif value['price'].to_f != 0
23
- # Record does not exist, create
24
- ZonePrice.create(:zone_id => key, :variant => self, :price => value['price'].to_f)
25
- end
26
- end
27
- end
28
-
29
- # Return zone price if defined otherwise return normal price
30
- def zone_price(country_id)
31
- # Find zone and check if zone price set for the product/variant
32
- zone = Country.find(country_id).zone
33
- zone_price = self.zone_prices.find_by_zone_id(zone.id) if zone && self.respond_to?('zone_prices')
34
- if zone_price
35
- # Zone price set us it
36
- amount = zone_price.price
37
- else
38
- amount = self.price
39
- end
40
- end
41
-
42
- # Method to default variant zone prices to the product zone prices
43
- def set_default_zone_prices(country_id)
44
- return if self.product.master.zone_prices.size <= 0 # No zone prices specified for product
45
- # Assign product zone prices as defaults
46
- self.product.master.zone_prices.each {|zp| self.zone_prices.build(zp.attributes)}
47
- end
48
-
49
- end
50
- end
51
-
52
- end
@@ -1,10 +0,0 @@
1
- module Spree::ZonePricing::Zone
2
-
3
- def self.included(target)
4
- target.class_eval do
5
- has_many :zone_prices, :dependent => :destroy
6
- has_many :variants, :through => :zone_prices
7
- end
8
- end
9
-
10
- end
@@ -1,17 +0,0 @@
1
- namespace :spree do
2
- namespace :extensions do
3
- namespace :zone_pricing do
4
- desc "Copies public assets of the Zone Pricing to the instance public/ directory."
5
- task :update => :environment do
6
- is_svn_git_or_dir = proc {|path| path =~ /\.svn/ || path =~ /\.git/ || File.directory?(path) }
7
- Dir[ZonePricingExtension.root + "/public/**/*"].reject(&is_svn_git_or_dir).each do |file|
8
- path = file.sub(ZonePricingExtension.root, '')
9
- directory = File.dirname(path)
10
- puts "Copying #{path}..."
11
- mkdir_p RAILS_ROOT + directory
12
- cp file, RAILS_ROOT + path
13
- end
14
- end
15
- end
16
- end
17
- end
data/spec/spec.opts DELETED
@@ -1,6 +0,0 @@
1
- --colour
2
- --format
3
- progress
4
- --loadby
5
- mtime
6
- --reverse
data/spec/spec_helper.rb DELETED
@@ -1,37 +0,0 @@
1
- unless defined? SPREE_ROOT
2
- ENV["RAILS_ENV"] = "test"
3
- case
4
- when ENV["SPREE_ENV_FILE"]
5
- require ENV["SPREE_ENV_FILE"]
6
- when File.dirname(__FILE__) =~ %r{vendor/SPREE/vendor/extensions}
7
- require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../../../")}/config/environment"
8
- else
9
- require "#{File.expand_path(File.dirname(__FILE__) + "/../../../../")}/config/environment"
10
- end
11
- end
12
- require "#{SPREE_ROOT}/spec/spec_helper"
13
-
14
- if File.directory?(File.dirname(__FILE__) + "/scenarios")
15
- Scenario.load_paths.unshift File.dirname(__FILE__) + "/scenarios"
16
- end
17
- if File.directory?(File.dirname(__FILE__) + "/matchers")
18
- Dir[File.dirname(__FILE__) + "/matchers/*.rb"].each {|file| require file }
19
- end
20
-
21
- Spec::Runner.configure do |config|
22
- # config.use_transactional_fixtures = true
23
- # config.use_instantiated_fixtures = false
24
- # config.fixture_path = RAILS_ROOT + '/spec/fixtures'
25
-
26
- # You can declare fixtures for each behaviour like this:
27
- # describe "...." do
28
- # fixtures :table_a, :table_b
29
- #
30
- # Alternatively, if you prefer to declare them only once, you can
31
- # do so here, like so ...
32
- #
33
- # config.global_fixtures = :table_a, :table_b
34
- #
35
- # If you declare global fixtures, be aware that they will be declared
36
- # for all of your examples, even those that don't use them.
37
- end