Moving shopfront trial progress bar logic into enterprises helper and dealing with expiry

This commit is contained in:
Rob Harrington
2014-11-26 15:16:53 +11:00
parent f5acf36771
commit a8dde3bbb9
4 changed files with 24 additions and 14 deletions

View File

@@ -45,4 +45,20 @@ module EnterprisesHelper
options[:data] = { :action => 'remove', :confirm => enterprise_confirm_delete_message(enterprise) }
link_to_with_icon 'icon-trash', name, url, options
end
def shop_trial_in_progress?(enterprise)
!!enterprise.shop_trial_start_date &&
(enterprise.shop_trial_start_date + Enterprise::SHOP_TRIAL_LENGTH.days > Time.now) &&
%w(own any).include?(enterprise.sells)
end
def shop_trial_expired?(enterprise)
!!enterprise.shop_trial_start_date &&
(enterprise.shop_trial_start_date + Enterprise::SHOP_TRIAL_LENGTH.days <= Time.now) &&
%w(own any).include?(enterprise.sells)
end
def remaining_trial_days(enterprise)
distance_of_time_in_words(Time.now, enterprise.shop_trial_start_date + Enterprise::SHOP_TRIAL_LENGTH.days)
end
end

View File

@@ -285,16 +285,6 @@ class Enterprise < ActiveRecord::Base
shipping_methods.any? && payment_methods.available.any?
end
def shop_trial_in_progress?
!!shop_trial_start_date &&
(shop_trial_start_date + SHOP_TRIAL_LENGTH.days > Time.now) &&
%w(own any).include?(sells)
end
def remaining_trial_days
distance_of_time_in_words(Time.now, shop_trial_start_date + SHOP_TRIAL_LENGTH.days)
end
protected
def devise_mailer

View File

@@ -2,5 +2,4 @@
- enterprise = spree_current_user.enterprises.first if OpenFoodNetwork::Permissions.new(spree_current_user).manages_one_enterprise?
- if enterprise && enterprise.shop_trial_in_progress?
= render 'spree/admin/shared/trial_progress_bar', enterprise: enterprise
= render 'spree/admin/shared/trial_progress_bar', enterprise: enterprise

View File

@@ -1,2 +1,7 @@
#trial_progress_bar
= "Your shopfront trial expires in #{enterprise.remaining_trial_days}."
- if enterprise
-if shop_trial_in_progress?(enterprise)
#trial_progress_bar
= "Your shopfront trial expires in #{remaining_trial_days(enterprise)}."
-elsif shop_trial_expired?(enterprise)
#trial_progress_bar
= "Good news! We have decided to extend shopfront trials until further notice (probably around March 2015)."