Permalink
Browse files

try to update to spree 2-1-stable

  • Loading branch information...
1 parent 69438db commit 9c35647c4c66cc8b233326025d00e863abf777eb @damjack damjack committed Feb 21, 2014
View
@@ -1,9 +1,6 @@
-# This file is used to designate compatibilty with different versions of Spree
-# Please see http://spreecommerce.com/documentation/extensions.html#versionfile for details
+"2.1.x" => { :branch => "master"}
+"1.3.x" => { :branch => "1-3-stable"}
+"1.1.x" => { :branch => "1-1-stable"}
+"1.0.x" => { :branch => "1-0-stable"}
-# Examples
-#
-# "0.70.x" => { :branch => "master"}
-# "0.60.x" => { :branch => "0-60-stable" }
-# "0.40.x" => { :tag => "v1.0.0", :version => "1.0.0" }
@@ -0,0 +1,111 @@
+//= require jquery.payment
+
+Spree.disableSaveOnClick = ->
+ ($ 'form.edit_order').submit ->
+ ($ this).find(':submit, :image').attr('disabled', true).removeClass('primary').addClass 'disabled'
+
+Spree.ready ($) ->
+ Spree.Checkout = {}
+ $(".cardNumber").payment('formatCardNumber')
+ $(".cardExpiry").payment('formatCardExpiry')
+ $(".cardCode").payment('formatCardCVC')
+
+ $(".cardNumber").change ->
+ $(this).parent().siblings(".ccType").val($.payment.cardType(@value))
+
+ if ($ '#checkout_form_address').is('*')
+ ($ '#checkout_form_address').validate()
+
+ getCountryId = (region) ->
+ $('#' + region + 'country select').val()
+
+ updateState = (region) ->
+ countryId = getCountryId(region)
+ if countryId?
+ unless Spree.Checkout[countryId]?
+ $.get Spree.routes.states_search, {country_id: countryId}, (data) ->
+ Spree.Checkout[countryId] =
+ states: data.states
+ states_required: data.states_required
+ fillStates(Spree.Checkout[countryId], region)
+ else
+ fillStates(Spree.Checkout[countryId], region)
+
+ fillStates = (data, region) ->
+ statesRequired = data.states_required
+ states = data.states
+
+ statePara = ($ '#' + region + 'state')
+ stateSelect = statePara.find('select')
+ stateInput = statePara.find('input')
+ stateSpanRequired = statePara.find('state-required')
+ if states.length > 0
+ selected = parseInt stateSelect.val()
+ stateSelect.html ''
+ statesWithBlank = [{ name: '', id: ''}].concat(states)
+ $.each statesWithBlank, (idx, state) ->
+ opt = ($ document.createElement('option')).attr('value', state.id).html(state.name)
+ opt.prop 'selected', true if selected is state.id
+ stateSelect.append opt
+
+ stateSelect.prop('disabled', false).show()
+ stateInput.hide().prop 'disabled', true
+ statePara.show()
+ stateSpanRequired.show()
+ stateSelect.addClass('required') if statesRequired
+ stateSelect.removeClass('hidden')
+ stateInput.removeClass('required')
+ else
+ stateSelect.hide().prop 'disabled', true
+ stateInput.show()
+ if statesRequired
+ stateSpanRequired.show()
+ stateInput.addClass('required')
+ else
+ stateInput.val ''
+ stateSpanRequired.hide()
+ stateInput.removeClass('required')
+ statePara.toggle(!!statesRequired)
+ stateInput.prop('disabled', !statesRequired)
+ stateInput.removeClass('hidden')
+ stateSelect.removeClass('required')
+
+ ($ '#bcountry select').change ->
+ updateState 'b'
+
+ ($ '#scountry select').change ->
+ updateState 's'
+
+ updateState 'b'
+
+ order_use_shipping = ($ 'input#order_use_shipping ')
+ order_use_shipping .change ->
+ update_billing_form_state order_use_shipping
+
+ update_billing_form_state = (order_use_shipping ) ->
+ if order_use_shipping .is(':checked')
+ ($ '#billing .inner').hide()
+ ($ '#billing .inner input, #billing .inner select').prop 'disabled', true
+ else
+ ($ '#billing .inner').show()
+ ($ '#billing .inner input, #billing .inner select').prop 'disabled', false
+ updateState('s')
+
+ update_billing_form_state order_use_shipping
+
+ if ($ '#checkout_form_payment').is('*')
+ ($ 'input[type="radio"][name="order[payments_attributes][][payment_method_id]"]').click(->
+ ($ '#payment-methods li').hide()
+ ($ '#payment_method_' + @value).show() if @checked
+ )
+
+ ($ document).on('click', '#cvv_link', (event) ->
+ windowName = 'cvv_info'
+ windowOptions = 'left=20,top=20,width=500,height=500,toolbar=0,resizable=0,scrollbars=1'
+ window.open(($ this).attr('href'), windowName, windowOptions)
+ event.preventDefault()
+ )
+
+ # Activate already checked payment method if form is re-rendered
+ # i.e. if user enters invalid data
+ ($ 'input[type="radio"]:checked').click()
@@ -1,3 +1 @@
-//= require store/user_address
-
-
+//= require store/checkout
@@ -1,131 +0,0 @@
-var remove_bill_address = 'Rimuovi indirizzo di fatturazione';
-var remove_ship_address = 'Rimuovi indirizzo di consegna';
-var add_bill_address = 'Aggiungi indirizzo di fatturazione';
-var add_ship_address = 'Aggiungi indirizzo di consegna';
-
-
-(function ($) {
-
- $(document).ready(function () {
- //$('#new-customer #shipping .inner').css('display','initial');
- //$('.edit-user #shipping .inner').css('display','initial');
- // TODO make multilanguage
- $('#add_ship_address').click(function () {
- $('#shipping').toggle();
- if ($('#shipping').css('display') == 'none') {
- $('#add_ship_address').html(add_ship_address);
- $('#delete_ship_address').val('true');
- } else {
- $('#add_ship_address').html(remove_ship_address);
- $('#delete_ship_address').val('false');
- }
- return false;
- });
-
- $('#add_bill_address').click(function () {
- $('#billing').toggle();
- if ($('#billing').css('display') == 'none') {
- $('#add_bill_address').html(add_bill_address);
- $('#delete_bill_address').val('true');
- } else {
- $('#add_bill_address').html(remove_bill_address);
- $('#delete_bill_address').val('false');
- }
- return false;
- });
-
- // need for populate state select
- if ($('#new-customer').is('*') || $('.edit_user').is('*')) {
- var get_states = function (region) {
- country = $('p#' + region + 'country' + ' span#' + region + 'country-selection :only-child').val();
- return state_mapper[country];
- }
-
- var update_state = function (region) {
- states = get_states(region);
-
- state_select = $('p#' + region + 'state select');
- state_input = $('p#' + region + 'state input');
-
- if (states) {
- selected = state_select.val();
- state_select.html('');
- states_with_blank = [
- ["", ""]
- ].concat(states);
- $.each(states_with_blank, function (pos, id_nm) {
- var opt = $(document.createElement('option'))
- .attr('value', id_nm[0])
- .html(id_nm[1]);
- if (selected == id_nm[0]) {
- opt.prop("selected", true);
- }
- state_select.append(opt);
- });
- state_select.prop("disabled", false).show();
- state_input.hide().prop("disabled", true);
-
- } else {
- state_input.prop("disabled", false).show();
- state_select.hide().prop("disabled", true);
- }
-
- };
-
- $('p#bcountry select').change(function () {
- update_state('b');
- });
- $('p#scountry select').change(function () {
- update_state('s');
- });
- update_state('b');
- update_state('s');
- }
-
- // Visible or hide address if is present
- if ($('.edit_user').is('*')) {
- if (!is_present('bill')) {
- $('#billing').toggle();
- } else {
- $('#add_bill_address').html(remove_bill_address);
- }
- if (!is_present('ship')) {
- $('#shipping').toggle();
- } else {
- $('#add_ship_address').html(remove_ship_address);
- }
- }
-
- $('#new-customer #shipping').toggle();
- $('#new-customer #billing').toggle();
- });
-})(jQuery);
-
-function is_present(prefix) {
- var count = 0;
- if ($('#user_' + prefix + '_address_attributes_firstname').val() == '') {
- count++;
- }
- if ($('#user_' + prefix + '_address_attributes_lastname').val() == '') {
- count++;
- }
- if ($('#user_' + prefix + '_address_attributes_address1').val() == '') {
- count++;
- }
- if ($('#user_' + prefix + '_address_attributes_city').val() == '') {
- count++;
- }
- if ($('#user_' + prefix + '_address_attributes_zipcode').val() == '') {
- count++;
- }
- if ($('#user_' + prefix + '_address_attributes_phone').val() == '') {
- count++;
- }
-
- if (count == 6) {
- return false;
- } else {
- return true;
- }
-}
-
@@ -10,8 +10,8 @@ def registration
def before_address
if current_user
- @order.bill_address ||= current_user.bill_address || Spree::Address.default
- @order.ship_address ||= current_user.ship_address || Spree::Address.default
+ @order.bill_address ||= (!current_user.bill_address.blank? && current_user.bill_address.valid?) ? current_user.bill_address : Spree::Address.default
+ @order.ship_address ||= (!current_user.ship_address.blank? && current_user.ship_address.valid?) ? current_user.ship_address : Spree::Address.default
else
@order.bill_address ||= Spree::Address.default
@order.ship_address ||= Spree::Address.default
@@ -1,17 +0,0 @@
-Spree::UserRegistrationsController.class_eval do
- include Spree::AddressHelper
-
- def new
- resource = build_resource({})
- country = Spree::Country.find(Spree::Config[:default_country_id]) rescue Spree::Country.first
- @user.build_bill_address({:country => country}, :without_protection => true) if !@user.bill_address
- @user.build_ship_address({:country => country}, :without_protection => true) if !@user.ship_address
- respond_with @user
- end
-
- def create
- params[:user].delete(:bill_address_attributes) if params[:user][:bill_address_attributes].blank? || empty_address?(params[:user][:bill_address_attributes])
- params[:user].delete(:ship_address_attributes) if params[:user][:ship_address_attributes].blank? || empty_address?(params[:user][:ship_address_attributes])
- super
- end
-end
@@ -1,6 +1,4 @@
-Spree::UsersController.class_eval do
- include Spree::AddressHelper
-
+Spree::UsersController.class_eval do
def edit
country = Spree::Country.find(Spree::Config[:default_country_id]) rescue Spree::Country.first
@user.build_bill_address({:country => country}, :without_protection => true) if !@user.bill_address
@@ -1,20 +0,0 @@
-module Spree
- module AddressHelper
- def empty_address?(address)
- count = 0
- count += 1 if address[:firstname].blank?
- count += 1 if address[:lastname].blank?
- count += 1 if address[:address1].blank?
- count += 1 if address[:city].blank?
- count += 1 if address[:state_id].blank?
- count += 1 if address[:zipcode].blank?
- count += 1 if address[:phone].blank?
- if count == 7
- true
- else
- false
- end
- end
-
- end
-end
@@ -1,10 +1,18 @@
Spree::Address.class_eval do
- attr_accessible :tax_id_number, :vat_number
-
+
+ validates_format_of :tax_id_number, :with => /^[A-Z]{6}[A-Z0-9]{2}[A-Z][A-Z0-9]{2}[A-Z][A-Z0-9]{3}[A-Z]$/i, :if => :tax_id_present?
validates :vat_number, :length => {:maximum => 11}, :if => Proc.new {|a| !a.vat_number.blank? }
validates :tax_id_number, :length => {:in => 11..16}, :if => Proc.new {|a| !a.tax_id_number.blank? }
def empty?
attributes.except('id', 'created_at', 'updated_at', 'order_id', 'country_id', 'tax_id_number', 'vat_number').all? { |_, v| v.nil? }
end
+
+ def tax_id_present?
+ !tax_id_number.blank?
+ end
+
+ def use_tax_id_number?
+ @use_tax_id_number == true || @use_tax_id_number == "true" || @use_tax_id_number == "1"
+ end
end
@@ -0,0 +1,23 @@
+Spree::Order.class_eval do
+ before_validation :clone_shipping_address, :unless => :use_shipping?
+
+ attr_accessor :use_shipping
+
+ def clone_shipping_address
+ if ship_address && ship_address.valid? and self.bill_address.nil?
+ self.bill_address = ship_address.clone
+ elsif ship_address && ship_address.valid?
+ self.bill_address.attributes = ship_address.attributes.except('id', 'updated_at', 'created_at')
+ end
+ true
+ end
+
+ def billing_eq_shipping_address?
+ (bill_address.empty? && ship_address.empty?) || ship_address.same_as?(bill_address)
+ end
+
+ private
+ def use_shipping?
+ @use_shipping == true || @use_shipping == "true" || @use_shipping == "1"
+ end
+end
Oops, something went wrong.

0 comments on commit 9c35647

Please sign in to comment.