glysellin 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/MIT-LICENSE +20 -0
- data/README.md +100 -0
- data/Rakefile +29 -0
- data/app/assets/javascripts/glysellin/address.coffee +38 -0
- data/app/assets/javascripts/glysellin/async-cart.coffee +139 -0
- data/app/assets/javascripts/glysellin/base.js +6 -0
- data/app/assets/javascripts/glysellin/cart.coffee +54 -0
- data/app/assets/javascripts/glysellin/main.coffee +0 -0
- data/app/assets/javascripts/glysellin/product.coffee +0 -0
- data/app/assets/stylesheets/glysellin/application.css +13 -0
- data/app/assets/stylesheets/glysellin/orders.css +4 -0
- data/app/assets/stylesheets/glysellin/products.css +4 -0
- data/app/controllers/glysellin/cart/addresses_controller.rb +17 -0
- data/app/controllers/glysellin/cart/discount_code_controller.rb +10 -0
- data/app/controllers/glysellin/cart/payment_method_controller.rb +17 -0
- data/app/controllers/glysellin/cart/products_controller.rb +37 -0
- data/app/controllers/glysellin/cart/shipping_method_controller.rb +18 -0
- data/app/controllers/glysellin/cart/state_controller.rb +15 -0
- data/app/controllers/glysellin/cart_controller.rb +53 -0
- data/app/controllers/glysellin/orders_controller.rb +53 -0
- data/app/controllers/glysellin/products_controller.rb +12 -0
- data/app/helpers/glysellin/application_helper.rb +4 -0
- data/app/helpers/glysellin/cart_helper.rb +21 -0
- data/app/helpers/glysellin/orders_helper.rb +35 -0
- data/app/helpers/glysellin/products_helper.rb +4 -0
- data/app/mailers/glysellin/order_admin_mailer.rb +17 -0
- data/app/mailers/glysellin/order_customer_mailer.rb +27 -0
- data/app/models/glysellin/address.rb +35 -0
- data/app/models/glysellin/brand.rb +14 -0
- data/app/models/glysellin/discount_code.rb +36 -0
- data/app/models/glysellin/discount_type.rb +9 -0
- data/app/models/glysellin/order.rb +243 -0
- data/app/models/glysellin/order_adjustment.rb +19 -0
- data/app/models/glysellin/order_item.rb +38 -0
- data/app/models/glysellin/orderer.rb +28 -0
- data/app/models/glysellin/payment.rb +46 -0
- data/app/models/glysellin/payment_method.rb +36 -0
- data/app/models/glysellin/product.rb +136 -0
- data/app/models/glysellin/product_image.rb +11 -0
- data/app/models/glysellin/product_property.rb +22 -0
- data/app/models/glysellin/product_property_type.rb +11 -0
- data/app/models/glysellin/product_type.rb +11 -0
- data/app/models/glysellin/shipping_method.rb +22 -0
- data/app/models/glysellin/taxonomy.rb +35 -0
- data/app/models/glysellin/variant.rb +100 -0
- data/app/views/glysellin/cart/_added_to_cart_warning.html.erb +21 -0
- data/app/views/glysellin/cart/_cart.html.erb +13 -0
- data/app/views/glysellin/cart/_navigation.html.erb +11 -0
- data/app/views/glysellin/cart/_products.html.erb +125 -0
- data/app/views/glysellin/cart/_recap.html.erb +16 -0
- data/app/views/glysellin/cart/recap/_addresses.html.erb +13 -0
- data/app/views/glysellin/cart/recap/_products.html.erb +63 -0
- data/app/views/glysellin/cart/show.html.erb +13 -0
- data/app/views/glysellin/cart/states/_addresses.html.erb +25 -0
- data/app/views/glysellin/cart/states/_choose_payment_method.html.erb +14 -0
- data/app/views/glysellin/cart/states/_choose_shipping_method.html.erb +14 -0
- data/app/views/glysellin/cart/states/_filled.html.erb +3 -0
- data/app/views/glysellin/cart/states/_init.html.erb +5 -0
- data/app/views/glysellin/cart/states/_ready.html.erb +1 -0
- data/app/views/glysellin/order_admin_mailer/_order_header.text.erb +5 -0
- data/app/views/glysellin/order_admin_mailer/send_check_order_created_email.text.erb +8 -0
- data/app/views/glysellin/order_admin_mailer/send_order_paid_email.text.erb +8 -0
- data/app/views/glysellin/order_customer_mailer/_order_footer.text.erb +3 -0
- data/app/views/glysellin/order_customer_mailer/_order_header.text.erb +5 -0
- data/app/views/glysellin/order_customer_mailer/send_order_created_email.text.erb +7 -0
- data/app/views/glysellin/order_customer_mailer/send_order_paid_email.text.erb +7 -0
- data/app/views/glysellin/order_customer_mailer/send_order_shipped_email.text.erb +8 -0
- data/app/views/glysellin/orders/_addresses_fields.html.erb +29 -0
- data/app/views/glysellin/orders/_order.html.erb +18 -0
- data/app/views/glysellin/orders/_payment_canceled.html.erb +13 -0
- data/app/views/glysellin/orders/_payment_successful.html.erb +6 -0
- data/app/views/glysellin/orders/payment_response.html.erb +5 -0
- data/app/views/glysellin/payment_methods/_paypal-integral.html.erb +22 -0
- data/app/views/glysellin/products/_add_to_cart.html.erb +16 -0
- data/app/views/glysellin/products/_item.html.erb +21 -0
- data/app/views/glysellin/products/filter.html.erb +0 -0
- data/app/views/glysellin/products/index.html.erb +3 -0
- data/app/views/glysellin/products/show.html.erb +3 -0
- data/app/views/glysellin/shared/_address.html.erb +11 -0
- data/app/views/glysellin/shared/_address.text.erb +7 -0
- data/app/views/glysellin/shared/_order.text.erb +56 -0
- data/app/views/glysellin/shared/mailer/_footer.text.erb +2 -0
- data/app/views/layouts/glysellin/application.html.erb +14 -0
- data/config/locales/glysellin.en.yml +113 -0
- data/config/locales/glysellin.fr.yml +119 -0
- data/db/migrate/20120206115004_create_glysellin_orders.rb +16 -0
- data/db/migrate/20120206115132_create_glysellin_customers.rb +8 -0
- data/db/migrate/20120206115657_create_glysellin_addresses.rb +22 -0
- data/db/migrate/20120206124505_create_glysellin_products.rb +20 -0
- data/db/migrate/20120206124545_create_glysellin_order_items.rb +15 -0
- data/db/migrate/20120206124630_create_glysellin_product_images.rb +10 -0
- data/db/migrate/20120206125210_add_attachment_image_to_product_image.rb +15 -0
- data/db/migrate/20120206130920_create_glysellin_payments.rb +13 -0
- data/db/migrate/20120206131042_create_glysellin_payment_methods.rb +10 -0
- data/db/migrate/20120207175050_create_glysellin_taxonomies.rb +11 -0
- data/db/migrate/20120207175158_create_products_taxonomies_table.rb +12 -0
- data/db/migrate/20120515143231_create_brands.rb +9 -0
- data/db/migrate/20120515143233_add_attachment_image_to_brands.rb +15 -0
- data/db/migrate/20120620151705_create_product_properties.rb +12 -0
- data/db/migrate/20130204121211_create_glysellin_discount_types.rb +10 -0
- data/db/migrate/20130204121228_create_glysellin_discount_codes.rb +15 -0
- data/db/migrate/20130204125310_create_glysellin_order_adjustments.rb +13 -0
- data/db/migrate/20130204202102_create_glysellin_shipping_methods.rb +12 -0
- data/db/migrate/20130204202109_add_shipping_method_id_to_glysellin_orders.rb +5 -0
- data/db/migrate/20130205110036_add_weight_to_glysellin_products.rb +5 -0
- data/db/migrate/20130205120541_add_weight_to_glysellin_order_items.rb +5 -0
- data/db/migrate/20130208162813_create_glysellin_variants.rb +17 -0
- data/db/migrate/20130208165020_create_glysellin_product_property_types.rb +7 -0
- data/db/migrate/20130211105557_add_type_id_to_glysellin_product_properties.rb +5 -0
- data/db/migrate/20130211112302_add_variant_id_to_glysellin_product_properties.rb +13 -0
- data/db/migrate/20130211152651_add_product_id_to_glysellin_variants.rb +5 -0
- data/db/migrate/20130212131658_add_weight_to_glysellin_variants.rb +5 -0
- data/db/migrate/20130212132253_remove_variant_columns_from_glysellin_products.rb +15 -0
- data/db/migrate/20130212154943_remove_eot_price_from_glysellin_products.rb +9 -0
- data/db/migrate/20130214184204_create_glysellin_product_types.rb +9 -0
- data/db/migrate/20130214184352_create_product_type_behavior.rb +15 -0
- data/db/migrate/20130221102200_add_unmarked_price_to_glysellin_variants.rb +5 -0
- data/db/migrate/20130311135842_add_addressable_to_glysellin_addresses.rb +6 -0
- data/db/migrate/20130314114048_change_addressable_associations_in_glysellin_addresses.rb +15 -0
- data/db/migrate/20130325113903_remove_address_ids_from_glysellin_orders.rb +11 -0
- data/db/seeds/shipping_carrier/rates/colissimo.csv +16 -0
- data/db/seeds/shipping_carrier/rates/lettre-max.csv +9 -0
- data/lib/active_model/model.rb +101 -0
- data/lib/generators/glysellin/install/USAGE +8 -0
- data/lib/generators/glysellin/install/install_generator.rb +50 -0
- data/lib/generators/glysellin/install/templates/initializer.rb +119 -0
- data/lib/generators/glysellin/install/templates/order_observer.rb +12 -0
- data/lib/generators/glysellin/install/utils.rb +11 -0
- data/lib/glysellin.rb +124 -0
- data/lib/glysellin/acts_as_sellable.rb +14 -0
- data/lib/glysellin/cart.rb +21 -0
- data/lib/glysellin/cart/address.rb +16 -0
- data/lib/glysellin/cart/adjustment.rb +17 -0
- data/lib/glysellin/cart/adjustment/base.rb +41 -0
- data/lib/glysellin/cart/adjustment/discount_code.rb +43 -0
- data/lib/glysellin/cart/adjustment/shipping_method.rb +31 -0
- data/lib/glysellin/cart/basket.rb +482 -0
- data/lib/glysellin/cart/customer.rb +36 -0
- data/lib/glysellin/cart/model_wrapper.rb +90 -0
- data/lib/glysellin/cart/nested_resource.rb +39 -0
- data/lib/glysellin/cart/payment_method.rb +8 -0
- data/lib/glysellin/cart/product.rb +16 -0
- data/lib/glysellin/cart/select.rb +31 -0
- data/lib/glysellin/cart/serializable.rb +30 -0
- data/lib/glysellin/cart/shipping_method.rb +8 -0
- data/lib/glysellin/discount_type_calculator.rb +7 -0
- data/lib/glysellin/discount_type_calculator/base.rb +30 -0
- data/lib/glysellin/discount_type_calculator/order_percentage.rb +16 -0
- data/lib/glysellin/engine.rb +14 -0
- data/lib/glysellin/engine/routes.rb +61 -0
- data/lib/glysellin/gateway.rb +16 -0
- data/lib/glysellin/gateway/atos.rb +111 -0
- data/lib/glysellin/gateway/base.rb +43 -0
- data/lib/glysellin/gateway/check.rb +34 -0
- data/lib/glysellin/gateway/paypal_integral.rb +71 -0
- data/lib/glysellin/helpers.rb +15 -0
- data/lib/glysellin/helpers/controller.rb +22 -0
- data/lib/glysellin/helpers/countries.rb +261 -0
- data/lib/glysellin/helpers/views.rb +28 -0
- data/lib/glysellin/product_methods.rb +66 -0
- data/lib/glysellin/products_list.rb +72 -0
- data/lib/glysellin/property_finder.rb +13 -0
- data/lib/glysellin/shipping_carrier.rb +14 -0
- data/lib/glysellin/shipping_carrier/base.rb +55 -0
- data/lib/glysellin/shipping_carrier/colissimo.rb +19 -0
- data/lib/glysellin/shipping_carrier/flat_rate.rb +19 -0
- data/lib/glysellin/shipping_carrier/free_shipping.rb +14 -0
- data/lib/glysellin/shipping_carrier/helpers/country_weight_table.rb +65 -0
- data/lib/glysellin/shipping_carrier/lettre_max.rb +19 -0
- data/lib/glysellin/version.rb +3 -0
- data/lib/tasks/glysellin_tasks.rake +37 -0
- metadata +341 -0
@@ -0,0 +1,17 @@
|
|
1
|
+
module Glysellin
|
2
|
+
module Cart
|
3
|
+
class PaymentMethodController < CartController
|
4
|
+
def update
|
5
|
+
current_cart.update(params[:glysellin_cart_basket])
|
6
|
+
|
7
|
+
if current_cart.valid?
|
8
|
+
current_cart.payment_method_chosen!
|
9
|
+
redirect_to cart_path
|
10
|
+
else
|
11
|
+
current_cart.state = "choose_payment_method"
|
12
|
+
render "glysellin/cart/show"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Glysellin
|
2
|
+
module Cart
|
3
|
+
class ProductsController < CartController
|
4
|
+
def create
|
5
|
+
current_cart.add(params[:cart])
|
6
|
+
current_cart.products_added!
|
7
|
+
@product_added_to_cart = true
|
8
|
+
render_cart_partial
|
9
|
+
end
|
10
|
+
|
11
|
+
def update
|
12
|
+
current_cart.set_quantity(params[:id], params[:quantity], override: true)
|
13
|
+
|
14
|
+
product = current_cart.product(params[:id])
|
15
|
+
variant, quantity = product.variant, product.quantity
|
16
|
+
|
17
|
+
render json: {
|
18
|
+
quantity: quantity,
|
19
|
+
eot_price: number_to_currency(quantity * variant.eot_price),
|
20
|
+
price: number_to_currency(quantity * variant.price)
|
21
|
+
}.merge(totals_hash)
|
22
|
+
end
|
23
|
+
|
24
|
+
def destroy
|
25
|
+
current_cart.remove(params[:id])
|
26
|
+
redirect_to cart_path
|
27
|
+
end
|
28
|
+
|
29
|
+
def validate
|
30
|
+
current_cart.update(params[:glysellin_cart_basket])
|
31
|
+
current_cart.validated! if current_cart.valid?
|
32
|
+
current_cart.customer = current_user
|
33
|
+
redirect_to cart_path
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Glysellin
|
2
|
+
module Cart
|
3
|
+
class ShippingMethodController < CartController
|
4
|
+
def update
|
5
|
+
current_cart.update(params[:glysellin_cart_basket])
|
6
|
+
|
7
|
+
if current_cart.valid?
|
8
|
+
current_cart.shipping_method_chosen!
|
9
|
+
redirect_to cart_path
|
10
|
+
else
|
11
|
+
current_cart.state = "choose_shipping_method"
|
12
|
+
current_cart.valid?
|
13
|
+
render "glysellin/cart/show"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Glysellin
|
2
|
+
module Cart
|
3
|
+
class StateController < CartController
|
4
|
+
def show
|
5
|
+
state = params[:state]
|
6
|
+
|
7
|
+
if current_cart.available_states.include?(state)
|
8
|
+
current_cart.state = state.to_sym
|
9
|
+
end
|
10
|
+
|
11
|
+
redirect_to cart_path
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Glysellin
|
2
|
+
class CartController < ApplicationController
|
3
|
+
include ActionView::Helpers::NumberHelper
|
4
|
+
|
5
|
+
before_filter :set_cart
|
6
|
+
after_filter :update_cart_in_session
|
7
|
+
|
8
|
+
def show
|
9
|
+
current_cart.update_quantities!
|
10
|
+
end
|
11
|
+
|
12
|
+
def destroy
|
13
|
+
reset_cart!
|
14
|
+
redirect_to cart_path
|
15
|
+
end
|
16
|
+
|
17
|
+
protected
|
18
|
+
|
19
|
+
def render_cart_partial
|
20
|
+
render partial: 'cart', locals: { cart: current_cart }
|
21
|
+
end
|
22
|
+
|
23
|
+
def set_cart
|
24
|
+
@states = current_cart.available_states
|
25
|
+
end
|
26
|
+
|
27
|
+
# Helper method to set cookie value
|
28
|
+
def update_cart_in_session options = {}
|
29
|
+
if current_cart.errors.any?
|
30
|
+
flash[:error] =
|
31
|
+
t("glysellin.errors.cart.state_transitions.#{ current_cart.state }")
|
32
|
+
end
|
33
|
+
|
34
|
+
session["glysellin.cart"] = current_cart.serialize
|
35
|
+
end
|
36
|
+
|
37
|
+
def totals_hash
|
38
|
+
adjustment = current_cart.discount
|
39
|
+
|
40
|
+
discount_name = adjustment.name rescue nil
|
41
|
+
discount_value = number_to_currency(adjustment.value) rescue nil
|
42
|
+
|
43
|
+
{
|
44
|
+
discount_name: discount_name,
|
45
|
+
discount_value: discount_value,
|
46
|
+
total_eot_price: number_to_currency(current_cart.total_eot_price),
|
47
|
+
total_price: number_to_currency(current_cart.total_price),
|
48
|
+
eot_subtotal: number_to_currency(current_cart.eot_subtotal),
|
49
|
+
subtotal: number_to_currency(current_cart.subtotal)
|
50
|
+
}
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Glysellin
|
2
|
+
class OrdersController < ApplicationController
|
3
|
+
protect_from_forgery :except => :gateway_response
|
4
|
+
|
5
|
+
def index
|
6
|
+
@orders = Order.from_customer(current_user)
|
7
|
+
end
|
8
|
+
|
9
|
+
def show
|
10
|
+
user_order = if user_signed_in?
|
11
|
+
Order.where('id = ? AND customer_id = ?', params[:id], current_user.id)
|
12
|
+
else
|
13
|
+
[]
|
14
|
+
end
|
15
|
+
|
16
|
+
if user_order.length > 0
|
17
|
+
@order = user_order.first
|
18
|
+
else
|
19
|
+
flash[:alert] = t('glysellin.controllers.errors.order_doesnt_exist')
|
20
|
+
redirect_to :action => 'index'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def gateway_response
|
25
|
+
# Get gateway object
|
26
|
+
gateway = if params[:id]
|
27
|
+
PaymentMethod.gateway_from_order_ref(params[:id])
|
28
|
+
else
|
29
|
+
PaymentMethod.gateway_from_raw_post(request.raw_post, params[:gateway])
|
30
|
+
end
|
31
|
+
# Process payment
|
32
|
+
if gateway.process_payment! request.raw_post
|
33
|
+
OrderCustomerMailer.send_order_paid_email(gateway.order).deliver
|
34
|
+
OrderAdminMailer.send_order_paid_email(gateway.order).deliver
|
35
|
+
end
|
36
|
+
# Log errors if existing
|
37
|
+
gateway.errors.each do |msg|
|
38
|
+
logger.error "[ Glysellin ] Gateway Error : #{ msg }"
|
39
|
+
end if gateway.errors.length > 1
|
40
|
+
|
41
|
+
render gateway.response
|
42
|
+
end
|
43
|
+
|
44
|
+
def payment_response
|
45
|
+
if params[:type]
|
46
|
+
@order = nil
|
47
|
+
@response_type = params[:type]
|
48
|
+
else
|
49
|
+
@order = Order.find_by_ref(params[:id])
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Glysellin
|
2
|
+
class ProductsController < ApplicationController
|
3
|
+
def index
|
4
|
+
@products = Glysellin::Product.order('created_at DESC').limit(10)
|
5
|
+
@products = @products.with_taxonomy(params[:taxonomy_id]) if params[:taxonomy_id]
|
6
|
+
end
|
7
|
+
|
8
|
+
def show
|
9
|
+
@product = Glysellin::Product.find(params[:id])
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Glysellin
|
2
|
+
module CartHelper
|
3
|
+
def add_to_cart_form product, options = {}
|
4
|
+
# Default to remote form
|
5
|
+
options[:remote] = true unless options[:remote] == false
|
6
|
+
# Render actual form
|
7
|
+
render partial: 'glysellin/products/add_to_cart', locals: {
|
8
|
+
product: product,
|
9
|
+
options: options
|
10
|
+
}
|
11
|
+
end
|
12
|
+
|
13
|
+
def added_to_cart_warning
|
14
|
+
render partial: 'glysellin/cart/added_to_cart_warning'
|
15
|
+
end
|
16
|
+
|
17
|
+
def render_cart cart
|
18
|
+
render partial: "glysellin/cart/cart", locals: { cart: cart }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Glysellin
|
2
|
+
module OrdersHelper
|
3
|
+
|
4
|
+
# Generates Orderer form fields
|
5
|
+
#
|
6
|
+
# @param form Form object to which the fields are added
|
7
|
+
# @param record Optional model object that implements Glysellin::Orderer
|
8
|
+
#
|
9
|
+
def addresses_fields_for form, record = nil
|
10
|
+
# Copy addresses from record to form object
|
11
|
+
if record
|
12
|
+
%w(billing_address shipping_address).each do |addr|
|
13
|
+
if (address = record.send("#{ addr }"))
|
14
|
+
attrs = address.attributes.select do |key, value|
|
15
|
+
Glysellin::Address.accessible_attributes.include?(key)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
unless (address = form.object.send(addr).presence) && address.id.present?
|
20
|
+
form.object.send("#{ addr }=", Glysellin::Address.new(attrs))
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
unless form.object.use_another_address_for_shipping.present?
|
25
|
+
form.object.use_another_address_for_shipping = record.use_another_address_for_shipping
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
form.object.build_billing_address unless form.object.billing_address
|
30
|
+
form.object.build_shipping_address unless form.object.shipping_address
|
31
|
+
|
32
|
+
render partial: 'glysellin/orders/addresses_fields', locals: { form: form }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class Glysellin::OrderAdminMailer < ActionMailer::Base
|
2
|
+
default from: Glysellin.contact_email, to: Glysellin.admin_email
|
3
|
+
|
4
|
+
def send_order_paid_email order
|
5
|
+
@order = order
|
6
|
+
mail(
|
7
|
+
subject: Glysellin.mailer_subjects.call[:admin][:send_order_paid_email]
|
8
|
+
)
|
9
|
+
end
|
10
|
+
|
11
|
+
def send_check_order_created_email order
|
12
|
+
@order = order
|
13
|
+
mail(
|
14
|
+
subject: Glysellin.mailer_subjects.call[:admin][:send_check_order_created_email]
|
15
|
+
)
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class Glysellin::OrderCustomerMailer < ActionMailer::Base
|
2
|
+
default from: Glysellin.contact_email
|
3
|
+
|
4
|
+
def send_order_created_email order
|
5
|
+
@order = order
|
6
|
+
mail(
|
7
|
+
to: @order.email,
|
8
|
+
subject: Glysellin.mailer_subjects.call[:customer][:send_order_created_email]
|
9
|
+
)
|
10
|
+
end
|
11
|
+
|
12
|
+
def send_order_paid_email order
|
13
|
+
@order = order
|
14
|
+
mail(
|
15
|
+
to: @order.email,
|
16
|
+
subject: Glysellin.mailer_subjects.call[:customer][:send_order_paid_email]
|
17
|
+
)
|
18
|
+
end
|
19
|
+
|
20
|
+
def send_order_shipped_email order
|
21
|
+
@order = order
|
22
|
+
mail(
|
23
|
+
to: @order.email,
|
24
|
+
subject: Glysellin.mailer_subjects.call[:customer][:send_order_shipped_email]
|
25
|
+
)
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Glysellin
|
2
|
+
class Address < ActiveRecord::Base
|
3
|
+
self.table_name = 'glysellin_addresses'
|
4
|
+
|
5
|
+
# Additional fields can be added through Glysellin.config.additional_address_fields in an app initializer
|
6
|
+
store :additional_fields, :accessors => Glysellin.additional_address_fields
|
7
|
+
attr_accessible *Glysellin.additional_address_fields
|
8
|
+
# Relations
|
9
|
+
#
|
10
|
+
# And address can be used as shipping or billing address
|
11
|
+
belongs_to :shipped_addressable, polymorphic: true
|
12
|
+
belongs_to :billed_addressable, polymorphic: true
|
13
|
+
|
14
|
+
attr_accessible :activated, :first_name, :last_name, :address, :zip, :city,
|
15
|
+
:country, :tel, :fax, :company, :company_name, :vat_number,
|
16
|
+
:address_details, :additional_fields, :shipped_addressable_type,
|
17
|
+
:shipped_addressable_id, :billed_addressable_type, :billed_addressable_id
|
18
|
+
|
19
|
+
# Validations
|
20
|
+
#
|
21
|
+
# Validates presence of the fields defined in the config file or the glysellin initializer
|
22
|
+
validates_presence_of *Glysellin.address_presence_validation_keys
|
23
|
+
|
24
|
+
def same_as?(other)
|
25
|
+
clone_attributes == other.clone_attributes
|
26
|
+
end
|
27
|
+
|
28
|
+
def clone_attributes
|
29
|
+
clone.attributes.select do |key, value|
|
30
|
+
self.class.accessible_attributes.include?(key) &&
|
31
|
+
!key.to_s.match(/_addressable_(type|id)$/)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Glysellin
|
2
|
+
class DiscountCode < ActiveRecord::Base
|
3
|
+
self.table_name = 'glysellin_discount_codes'
|
4
|
+
|
5
|
+
attr_accessible :code, :discount_type_id, :expires_on, :name, :value
|
6
|
+
|
7
|
+
belongs_to :discount_type, inverse_of: :discount_codes
|
8
|
+
has_many :order_adjustments, as: :adjustment
|
9
|
+
|
10
|
+
validates_presence_of :name, :code, :discount_type, :value
|
11
|
+
|
12
|
+
def code=(val)
|
13
|
+
super(val.downcase)
|
14
|
+
end
|
15
|
+
|
16
|
+
def applicable?
|
17
|
+
!expires_on || expires_on > Time.now
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_adjustment order
|
21
|
+
calculator = Glysellin.discount_type_calculators[discount_type.identifier].new(order, value)
|
22
|
+
|
23
|
+
{
|
24
|
+
name: name,
|
25
|
+
value: -calculator.calculate,
|
26
|
+
adjustment: self
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
class << self
|
31
|
+
def from_code code
|
32
|
+
find_by_code(code.downcase)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|