spree_order_groove 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +14 -0
- data/.rspec +1 -0
- data/Gemfile +7 -0
- data/LICENSE +26 -0
- data/README.md +60 -0
- data/Rakefile +21 -0
- data/app/assets/javascripts/spree/backend/spree_order_groove.js +2 -0
- data/app/assets/javascripts/spree/frontend/spree_order_groove.js +2 -0
- data/app/assets/stylesheets/spree/backend/spree_order_groove.css +4 -0
- data/app/assets/stylesheets/spree/frontend/spree_order_groove.css +4 -0
- data/app/controllers/spree/api/orders_controller_decorator.rb +293 -0
- data/app/controllers/spree/checkout_controller_decorator.rb +102 -0
- data/app/controllers/spree/orders_controller_decorator.rb +4 -0
- data/app/controllers/spree/store_controller_decorator.rb +24 -0
- data/app/models/spree/ordergroove_configuration.rb +12 -0
- data/app/models/spree/promotion/rules/autodelivery.rb +23 -0
- data/app/overrides/decorate_ordergroove_div_cart.rb +6 -0
- data/app/overrides/decorate_ordergroove_div_cart_remove.rb +6 -0
- data/app/overrides/decorate_ordergroove_div_product_main.rb +6 -0
- data/app/overrides/decorate_ordergroove_tags_cart.rb +6 -0
- data/app/overrides/decorate_ordergroove_tags_product.rb +6 -0
- data/app/views/spree/admin/promotions/rules/_autodelivery_rule.html.erb +0 -0
- data/app/views/spree/api/orders/ogcreateorder.v1.rabl +2 -0
- data/app/views/spree/shared/_ordergroove_line_item_div.html.erb +4 -0
- data/app/views/spree/shared/_ordergroove_line_item_div_remove.html.erb +3 -0
- data/app/views/spree/shared/_ordergroove_tags.html.erb +56 -0
- data/bin/rails +7 -0
- data/config/locales/en.yml +10 -0
- data/config/ordergroove.yml +35 -0
- data/config/routes.rb +10 -0
- data/db/migrate/20150604115532_add_auto_delivery_to_spree_line_items.spree_order_groove.rb +5 -0
- data/lib/generators/spree_order_groove/install/install_generator.rb +31 -0
- data/lib/rc4.rb +64 -0
- data/lib/spree_order_groove.rb +2 -0
- data/lib/spree_order_groove/engine.rb +23 -0
- data/lib/spree_order_groove/factories.rb +6 -0
- data/spec/spec_helper.rb +87 -0
- data/spree_order_groove.gemspec +31 -0
- metadata +268 -0
@@ -0,0 +1,102 @@
|
|
1
|
+
Spree::CheckoutController.class_eval do
|
2
|
+
before_action :apply_autodelivery
|
3
|
+
before_action :set_cc_number
|
4
|
+
|
5
|
+
# this action is updated to post to orderGroove
|
6
|
+
def update
|
7
|
+
if @order.update_from_params(params, permitted_checkout_attributes, request.headers.env)
|
8
|
+
@order.temporary_address = !params[:save_user_address]
|
9
|
+
unless @order.next
|
10
|
+
flash[:error] = @order.errors.full_messages.join("\n")
|
11
|
+
redirect_to checkout_state_path(@order.state) and return
|
12
|
+
end
|
13
|
+
|
14
|
+
if @order.completed?
|
15
|
+
@current_order = nil
|
16
|
+
flash.notice = Spree.t(:order_processed_successfully)
|
17
|
+
flash['order_completed'] = true
|
18
|
+
|
19
|
+
# this is the changes, if you find the spree version is different, copy this change to your version
|
20
|
+
byebug
|
21
|
+
og_autoship=cookies[:og_autoship]||0
|
22
|
+
merchant_id= Spree::OrdergrooveConfiguration.account["#{current_store.code}"]["og_merchant_id"]
|
23
|
+
hashkey= Spree::OrdergrooveConfiguration.account["#{current_store.code}"]["og_hashkey"]
|
24
|
+
og_subscription_url= Spree::OrdergrooveConfiguration.account["#{current_store.code}"]["og_subscription_url_#{ENV["RAILS_ENV"]}"]
|
25
|
+
|
26
|
+
if og_autoship.to_i==1
|
27
|
+
|
28
|
+
rc4=RC4.new(hashkey)
|
29
|
+
Rails.logger.error("*" * 50)
|
30
|
+
Rails.logger.error("Order: " + @order.number + "subscribed to auto delivery, post to order groove now")
|
31
|
+
Rails.logger.error("*" * 50)
|
32
|
+
#encode the subscription
|
33
|
+
subscription={:merchant_id =>merchant_id.to_s, :session_id=>cookies[:og_session_id], :merchant_order_id =>@order.number}
|
34
|
+
billing_address=@order.bill_address
|
35
|
+
subscription[:user]={:user_id=> @order.user_id.to_s, :first_name=>CGI.escape(billing_address.firstname), :last_name=>CGI.escape(billing_address.lastname), :email=>@order.checkout.email}
|
36
|
+
subscription[:user][:billing_address]={:first_name=>CGI.escape(billing_address.firstname), :last_name=>CGI.escape(billing_address.lastname),:company_name=>"",:address=>CGI.escape(billing_address.address1),
|
37
|
+
:address2=>CGI.escape(billing_address.address2||''),:city=>CGI.escape(billing_address.city),:state_province_code=>(billing_address.state_id==nil ? billing_address.state_name : State.find(billing_address.state_id).abbr),:zip_postal_code=>billing_address.zipcode,:phone=>billing_address.phone,
|
38
|
+
:fax=>"",:country_code=>Country.find(billing_address.country_id).iso}
|
39
|
+
billing_address=@order.ship_address
|
40
|
+
subscription[:user][:shipping_address]={:first_name=>CGI.escape(billing_address.firstname), :last_name=>CGI.escape(billing_address.lastname),:company_name=>"",:address=>CGI.escape(billing_address.address1),
|
41
|
+
:address2=>CGI.escape(billing_address.address2||''),:city=>CGI.escape(billing_address.city),:state_province_code=>(billing_address.state_id==nil ? billing_address.state_name : State.find(billing_address.state_id).abbr),:zip_postal_code=>billing_address.zipcode,:phone=>billing_address.phone,
|
42
|
+
:fax=>"",:country_code=>Country.find(billing_address.country_id).iso}
|
43
|
+
|
44
|
+
payment={:cc_holder=>CGI.escape(Base64.encode64(rc4.encrypt(billing_address.firstname + ' ' + billing_address.lastname)).chomp), :cc_type=>'1',:cc_number=> CGI.escape(session[:cc].chomp()),:cc_exp_date=>CGI.escape(Base64.encode64(rc4.encrypt(((@order.payments[0].source[:month].to_i<10 ? '0' : '') +@order.payments[0].source[:month] + '/' + @order.payments[0].source[:year]))).chomp) }
|
45
|
+
subscription[:payment] =payment
|
46
|
+
|
47
|
+
else
|
48
|
+
subscription={:merchant_id =>merchant_id.to_s, :session_id=>cookies[:og_session_id]}
|
49
|
+
end
|
50
|
+
|
51
|
+
session[:cc] = ''
|
52
|
+
|
53
|
+
# now post to orderGroove
|
54
|
+
require "net/https"
|
55
|
+
require "uri"
|
56
|
+
#CheckoutsHelper.fetch("POST",og_subscription_url,'create_request='+ subscription.to_json )
|
57
|
+
url=og_subscription_url
|
58
|
+
method="POST"
|
59
|
+
body= 'create_request='+ subscription.to_json
|
60
|
+
headers={}
|
61
|
+
headers["Content-Type"] = 'application/json' unless body.nil?
|
62
|
+
|
63
|
+
begin
|
64
|
+
uri = URI.parse(url)
|
65
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
66
|
+
http.read_timeout = 2
|
67
|
+
http.use_ssl = true
|
68
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
69
|
+
|
70
|
+
request = Net::HTTP::Post.new(uri.request_uri)
|
71
|
+
request.body=body
|
72
|
+
|
73
|
+
response = http.request(request)
|
74
|
+
rescue
|
75
|
+
Rails.logger.error("Order: " + @order.number + "post to order groove fail")
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
redirect_to completion_route
|
80
|
+
else
|
81
|
+
redirect_to checkout_state_path(@order.state)
|
82
|
+
end
|
83
|
+
else
|
84
|
+
render :edit
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
private
|
89
|
+
# remember the cc in session
|
90
|
+
def set_cc_number
|
91
|
+
# this is the changes, if you find the spree version is different, copy this change to your version
|
92
|
+
|
93
|
+
|
94
|
+
if params[:state]=="payment" && params[:payment_source] && cookies[:og_autoship]
|
95
|
+
hashkey= Spree::OrdergrooveConfiguration.account["#{current_store.code}"]["og_hashkey"]
|
96
|
+
rc4=RC4.new(hashkey)
|
97
|
+
session[:cc] = Base64.encode64(rc4.encrypt(params[:payment_source].first.last[:number]))
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
Spree::StoreController.class_eval do
|
2
|
+
protected
|
3
|
+
# This method is placed here so that the CheckoutController
|
4
|
+
# and OrdersController can both reference it (or any other controller
|
5
|
+
# which needs it)
|
6
|
+
def apply_autodelivery
|
7
|
+
if !!@order && !(["complete", "awaiting_return", "returned"].include? @order.state)
|
8
|
+
auto_delivery = cookies[:og_autoship] && cookies[:og_cart_autoship]
|
9
|
+
og_ioi = JSON.parse(cookies[:og_cart_autoship] || '[]')
|
10
|
+
|
11
|
+
@order.line_items.each do |l|
|
12
|
+
l.auto_delivery = (cookies[:og_autoship]=="1" && (og_ioi.map{|d| d['id']}.include? l.variant_id.to_s))
|
13
|
+
l.save
|
14
|
+
end
|
15
|
+
|
16
|
+
#@order.save!
|
17
|
+
#handler = Spree::PromotionHandler::Autodelivery.new(@order).apply
|
18
|
+
#else
|
19
|
+
# @order.autodelivery = nil
|
20
|
+
#end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Spree
|
2
|
+
class OrdergrooveConfiguration
|
3
|
+
|
4
|
+
def self.account
|
5
|
+
bronto_yml=File.join(Rails.root,'config/ordergroove.yml')
|
6
|
+
if File.exist? bronto_yml
|
7
|
+
bronto_yml=File.join(Rails.root,'config/ordergroove.yml')
|
8
|
+
YAML.load(File.read(bronto_yml))
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Spree
|
2
|
+
class Promotion
|
3
|
+
module Rules
|
4
|
+
class Autodelivery < PromotionRule
|
5
|
+
|
6
|
+
def applicable?(promotable)
|
7
|
+
promotable.is_a?(Spree::Order)
|
8
|
+
end
|
9
|
+
|
10
|
+
def eligible?(order, options = {}) #line_item is target
|
11
|
+
|
12
|
+
order.line_items.any? {|l| l[:auto_delivery]}
|
13
|
+
end
|
14
|
+
|
15
|
+
def actionable?(line_item)
|
16
|
+
|
17
|
+
line_item.auto_delivery
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
File without changes
|
@@ -0,0 +1,56 @@
|
|
1
|
+
<%
|
2
|
+
# order groove tags
|
3
|
+
step=0
|
4
|
+
if !!@product
|
5
|
+
step =1
|
6
|
+
elsif !!@order
|
7
|
+
if @order.state == "address" || @order.state == "cart"
|
8
|
+
step=2
|
9
|
+
elsif @order.state == "payment" || @order.state == "confirm"
|
10
|
+
step=3
|
11
|
+
elsif @order.state == "complete"
|
12
|
+
step=4
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
logger.info "Step got here: #{step}"
|
17
|
+
if step>0
|
18
|
+
merchant_id= Spree::OrdergrooveConfiguration.account["#{current_store.code}"]["og_merchant_id"]
|
19
|
+
hashkey= Spree::OrdergrooveConfiguration.account["#{current_store.code}"]["og_hashkey"]
|
20
|
+
og_tag_url= Spree::OrdergrooveConfiguration.account["#{current_store.code}"]["og_tag_url_#{ENV["RAILS_ENV"]}"]
|
21
|
+
|
22
|
+
rc4=RC4.new(hashkey)
|
23
|
+
unless hashkey.blank?
|
24
|
+
if !!@order && step < 4 # cart review or order review page
|
25
|
+
products_json=@order.line_items.map{|item| {:id=> item.variant_id, :quantity=> item.quantity, :unit_price=> item.price, :total_price=> (item.price*item.quantity) }}.to_json
|
26
|
+
%>
|
27
|
+
<script type="text/javascript">
|
28
|
+
var og_settings = {
|
29
|
+
"products": <%= raw(products_json) %>,
|
30
|
+
"subtotal": "<%= @order.item_total %>",
|
31
|
+
"tax_total": "<%= (100*@order.line_item_adjustments.tax.eligible.map{|t| t.amount}.sum).to_i/100.00 %>",
|
32
|
+
"shipping_total": "<%= (100*@order.line_item_adjustments.shipping.eligible.map{|t| t.amount}.sum).to_i/100.00 %>",
|
33
|
+
"order_total": "<%= @order.total.to_s %>"
|
34
|
+
};
|
35
|
+
</script>
|
36
|
+
|
37
|
+
<%
|
38
|
+
elsif step==4 %>
|
39
|
+
<div id="og-div"></div>
|
40
|
+
<script type="text/javascript">
|
41
|
+
var og_settings = {}
|
42
|
+
</script>
|
43
|
+
<%
|
44
|
+
elsif step==1 # product page
|
45
|
+
%>
|
46
|
+
<script type="text/javascript">
|
47
|
+
var og_settings = og_settings || {"product": { "id":"<%= @product.id.to_s %>" } };
|
48
|
+
</script>
|
49
|
+
|
50
|
+
<% end %>
|
51
|
+
|
52
|
+
<script type="text/javascript" src="<%= og_tag_url %>/<%= merchant_id%>/core-model.js"></script>
|
53
|
+
<script type="text/javascript" src="<%= og_tag_url %>/<%= merchant_id%>/<%= step%>/controller.js"></script>
|
54
|
+
<% end %>
|
55
|
+
|
56
|
+
<% end %>
|
data/bin/rails
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
2
|
+
|
3
|
+
ENGINE_ROOT = File.expand_path('../..', __FILE__)
|
4
|
+
ENGINE_PATH = File.expand_path('../../lib/spree_order_groove/engine', __FILE__)
|
5
|
+
|
6
|
+
require 'rails/all'
|
7
|
+
require 'rails/engine/commands'
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# Sample localization file for English. Add more files in this directory for other locales.
|
2
|
+
# See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
|
3
|
+
|
4
|
+
en:
|
5
|
+
hello: "Hello world"
|
6
|
+
spree:
|
7
|
+
promotion_rule_types:
|
8
|
+
autodelivery:
|
9
|
+
name: "Autodelivery Rule"
|
10
|
+
description: "Order Groove Auto delivery discount"
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# order Groove for auto delivery
|
4
|
+
|
5
|
+
default: &default
|
6
|
+
og_tag_url_development : https://staging.static.ordergroove.com
|
7
|
+
og_tag_url_production : https://static.ordergroove.com
|
8
|
+
og_subscription_url_development : https://staging.sc.ordergroove.com/subscription/create
|
9
|
+
og_subscription_url_production : https://sc.ordergroove.com/subscription/create
|
10
|
+
og_bulkdiscount_url_development : https://staging.v2.ordergroove.com/utilities/html/
|
11
|
+
og_bulkdiscount_url_production : https://api.ordergroove.com/utilities/html/
|
12
|
+
|
13
|
+
og_ftp_host_production : feeds.ordergroove.com
|
14
|
+
og_ftp_host_development : staging.feeds.ordergroove.com
|
15
|
+
og_ftp_passive : 1
|
16
|
+
|
17
|
+
store1:
|
18
|
+
<<: *default
|
19
|
+
og_merchant_id : your_merchagne_id
|
20
|
+
og_hashkey : your_hashkey
|
21
|
+
og_ftp_user : your_ftp_user
|
22
|
+
og_ftp_pass : your_ftp_passworkd
|
23
|
+
|
24
|
+
pwb:
|
25
|
+
<<: *default
|
26
|
+
og_merchant_id : your_merchagne_id
|
27
|
+
og_hashkey : your_hashkey
|
28
|
+
og_ftp_user : your_ftp_user
|
29
|
+
og_ftp_pass : your_ftp_passworkd
|
30
|
+
he:
|
31
|
+
<<: *default
|
32
|
+
og_merchant_id : your_merchagne_id
|
33
|
+
og_hashkey : your_hashkey
|
34
|
+
og_ftp_user : your_ftp_user
|
35
|
+
og_ftp_pass : your_ftp_passworkd
|
data/config/routes.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
module SpreeOrderGroove
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
|
5
|
+
class_option :auto_run_migrations, :type => :boolean, :default => false
|
6
|
+
|
7
|
+
def add_javascripts
|
8
|
+
append_file 'vendor/assets/javascripts/spree/frontend/all.js', "//= require spree/frontend/spree_order_groove\n"
|
9
|
+
append_file 'vendor/assets/javascripts/spree/backend/all.js', "//= require spree/backend/spree_order_groove\n"
|
10
|
+
end
|
11
|
+
|
12
|
+
def add_stylesheets
|
13
|
+
inject_into_file 'vendor/assets/stylesheets/spree/frontend/all.css', " *= require spree/frontend/spree_order_groove\n", :before => /\*\//, :verbose => true
|
14
|
+
inject_into_file 'vendor/assets/stylesheets/spree/backend/all.css', " *= require spree/backend/spree_order_groove\n", :before => /\*\//, :verbose => true
|
15
|
+
end
|
16
|
+
|
17
|
+
def add_migrations
|
18
|
+
run 'bundle exec rake railties:install:migrations FROM=spree_order_groove'
|
19
|
+
end
|
20
|
+
|
21
|
+
def run_migrations
|
22
|
+
run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask 'Would you like to run the migrations now? [Y/n]')
|
23
|
+
if run_migrations
|
24
|
+
run 'bundle exec rake db:migrate'
|
25
|
+
else
|
26
|
+
puts 'Skipping rake db:migrate, don\'t forget to run it!'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/rc4.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# https://github.com/benolee/ruby-rc4.git
|
2
|
+
# == RC4
|
3
|
+
#
|
4
|
+
# RC4 is a pure Ruby implementation of the Rc4 algorithm.
|
5
|
+
#
|
6
|
+
# == Usage
|
7
|
+
#
|
8
|
+
# First require the gem:
|
9
|
+
#
|
10
|
+
# require 'rc4'
|
11
|
+
|
12
|
+
|
13
|
+
class RC4
|
14
|
+
|
15
|
+
def initialize(str) #the key
|
16
|
+
raise SyntaxError, "RC4: Key supplied is blank" if str.eql?('')
|
17
|
+
@str = str
|
18
|
+
end
|
19
|
+
|
20
|
+
def encrypt(text)
|
21
|
+
process text
|
22
|
+
end
|
23
|
+
|
24
|
+
def decrypt(text)
|
25
|
+
process text
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def reset
|
31
|
+
@q1, @q2 = 0, 0
|
32
|
+
@key = []
|
33
|
+
@str.each_byte {|elem| @key << elem} while @key.size < 256
|
34
|
+
@key.slice!(256..@key.size-1) if @key.size >= 256
|
35
|
+
@s = (0..255).to_a
|
36
|
+
j = 0
|
37
|
+
0.upto(255) do |i|
|
38
|
+
j = (j + @s[i] + @key[i] )%256
|
39
|
+
@s[i], @s[j] = @s[j], @s[i]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def process(text)
|
44
|
+
reset
|
45
|
+
out = ""
|
46
|
+
0.upto(text.length-1) do |i|
|
47
|
+
if RUBY_VERSION >= "1.9.0"
|
48
|
+
char = text[i].ord
|
49
|
+
else
|
50
|
+
char = text[i]
|
51
|
+
end
|
52
|
+
out += (char ^ round).chr
|
53
|
+
end
|
54
|
+
out
|
55
|
+
end
|
56
|
+
|
57
|
+
def round
|
58
|
+
@q1 = (@q1 + 1)%256
|
59
|
+
@q2 = (@q2 + @s[@q1])%256
|
60
|
+
@s[@q1], @s[@q2] = @s[@q2], @s[@q1]
|
61
|
+
@s[(@s[@q1]+@s[@q2])%256]
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|