forgeos_commerce_front 1.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +339 -0
- data/COPYING.LESSER +165 -0
- data/Gemfile +2 -0
- data/LICENSE +2 -0
- data/README.textile +28 -0
- data/app/assets/images/commerce_front/cart/calulate.png +0 -0
- data/app/assets/images/commerce_front/cart/cart.png +0 -0
- data/app/assets/images/commerce_front/cart/change_quantity.png +0 -0
- data/app/assets/images/commerce_front/cart/delete.png +0 -0
- data/app/assets/images/commerce_front/cart/reduction.png +0 -0
- data/app/assets/images/commerce_front/cart/steps_left.png +0 -0
- data/app/assets/images/commerce_front/cart/steps_right.png +0 -0
- data/app/assets/images/commerce_front/product.jpg +0 -0
- data/app/assets/javascripts/commerce_front/functions.js +10 -0
- data/app/assets/javascripts/commerce_front/init.js +4 -0
- data/app/assets/javascripts/commerce_front/jquery.jnotify.min.js +21 -0
- data/app/assets/stylesheets/commerce_front/_cart.css.sass +97 -0
- data/app/assets/stylesheets/commerce_front/_common.css.sass +13 -0
- data/app/assets/stylesheets/commerce_front/_forms.css.sass +15 -0
- data/app/assets/stylesheets/commerce_front/_jnotify.css.sass +65 -0
- data/app/assets/stylesheets/commerce_front/style.css.sass +4 -0
- data/app/controllers/addresses_controller.rb +71 -0
- data/app/controllers/application_controller.rb +21 -0
- data/app/controllers/cart_controller.rb +144 -0
- data/app/controllers/newsletters_controller.rb +20 -0
- data/app/controllers/order_controller.rb +413 -0
- data/app/controllers/orders_controller.rb +32 -0
- data/app/controllers/person_sessions_controller.rb +23 -0
- data/app/controllers/users_controller.rb +164 -0
- data/app/helpers/application_helper.rb +73 -0
- data/app/helpers/cart_helper.rb +25 -0
- data/app/helpers/order_helper.rb +59 -0
- data/app/models/address.rb +18 -0
- data/app/models/notifier.rb +88 -0
- data/app/models/order.rb +13 -0
- data/app/models/user.rb +16 -0
- data/app/models/user_address.rb +15 -0
- data/app/views/addresses/_address_form.html.haml +18 -0
- data/app/views/addresses/_multiple_address_form.html.haml +27 -0
- data/app/views/cart/_free_products.html.haml +3 -0
- data/app/views/cart/_tbody.html.haml +25 -0
- data/app/views/cart/_total.html.haml +46 -0
- data/app/views/cart/index.html.haml +32 -0
- data/app/views/notifier/newsletter.html.haml +2 -0
- data/app/views/notifier/reset_password.html.haml +9 -0
- data/app/views/notifier/validation_user_account.html.haml +9 -0
- data/app/views/notifier/waiting_for_cheque_notification.html.haml +2 -0
- data/app/views/order/_form_address.html.haml +44 -0
- data/app/views/order/_tbody.html.haml +21 -0
- data/app/views/order/_total.html.haml +50 -0
- data/app/views/order/cheque_payment.html.haml +1 -0
- data/app/views/order/create.html.haml +76 -0
- data/app/views/order/deliveries.html.haml +28 -0
- data/app/views/order/new.html.haml +26 -0
- data/app/views/order/so_colissimo.html.haml +8 -0
- data/app/views/orders/index.html.haml +34 -0
- data/app/views/person_sessions/_form.html.haml +23 -0
- data/app/views/person_sessions/new.html.haml +1 -0
- data/app/views/person_sessions/new_reset_password.html.haml +7 -0
- data/app/views/users/_edit_form.html.haml +61 -0
- data/app/views/users/_form_create.html.haml +27 -0
- data/app/views/users/_form_quick_create.html.haml +16 -0
- data/app/views/users/_login_or_new.html.haml +10 -0
- data/app/views/users/forgotten_password.html.haml +12 -0
- data/app/views/users/new.html.haml +1 -0
- data/app/views/users/new_password.html.haml +10 -0
- data/app/views/users/show.html.haml +1 -0
- data/config/commerce.example.yml +27 -0
- data/config/initializers/commerce_front.rb +6 -0
- data/config/locales/fr.yml +85 -0
- data/config/routes.rb +17 -0
- data/db/migrate/20110311134232_add_form_attributes_to_addresses.rb +9 -0
- data/lib/field_error_proc_changer.rb +19 -0
- data/lib/forgeos/commerce_front.rb +6 -0
- data/lib/forgeos/commerce_front/engine.rb +10 -0
- data/lib/forgeos/commerce_front/version.rb +5 -0
- data/lib/forgeos_commerce_front.rb +1 -0
- data/lib/tasks/install.rake +13 -0
- data/recipes/deploy.rb +6 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/javascripts/application.js +9 -0
- data/test/dummy/app/assets/stylesheets/application.css +7 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +42 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +27 -0
- data/test/dummy/config/environments/production.rb +51 -0
- data/test/dummy/config/environments/test.rb +39 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +10 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +58 -0
- data/test/dummy/log/development.log +0 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +26 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/forgeos_commerce_front_test.rb +7 -0
- data/test/test_helper.rb +10 -0
- metadata +197 -0
data/Gemfile
ADDED
data/LICENSE
ADDED
data/README.textile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
h1. ForgeosCommerceFront
|
2
|
+
|
3
|
+
ForgeosCommerceFront is an extension which add front fonctionnalities
|
4
|
+
|
5
|
+
VERSION : 0.1.0
|
6
|
+
|
7
|
+
h1. Prerequisites
|
8
|
+
|
9
|
+
h2. Plugins
|
10
|
+
|
11
|
+
* ForgeosCore
|
12
|
+
* ForgeosCMS
|
13
|
+
* ForgeosCommerce
|
14
|
+
|
15
|
+
h2. Initialize
|
16
|
+
|
17
|
+
<pre><code>
|
18
|
+
$ ./script/generate plugin_migration forgeos_commerce_front
|
19
|
+
</code></pre>
|
20
|
+
|
21
|
+
Launch FogeosCommerce Install :
|
22
|
+
|
23
|
+
<pre><code>
|
24
|
+
$ rake forgeos:commerce_front:install
|
25
|
+
</code></pre>
|
26
|
+
|
27
|
+
|
28
|
+
Powered by "Webpulser":http://www.webpulser.com
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,10 @@
|
|
1
|
+
function notifications(){
|
2
|
+
$.getJSON('/notifications', function(data) {
|
3
|
+
if (data.notice != null)
|
4
|
+
$.jnotify(data.notice, 5000);
|
5
|
+
if (data.error != null)
|
6
|
+
$.jnotify(data.error,'error',true);
|
7
|
+
if (data.warning != null)
|
8
|
+
$.jnotify(data.warning,'warning', 5000);
|
9
|
+
});
|
10
|
+
}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
/*
|
2
|
+
* jNotify jQuery Plug-in
|
3
|
+
*
|
4
|
+
* Copyright 2010 Giva, Inc. (http://www.givainc.com/labs/)
|
5
|
+
*
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
* you may not use this file except in compliance with the License.
|
8
|
+
* You may obtain a copy of the License at
|
9
|
+
*
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
*
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
* See the License for the specific language governing permissions and
|
16
|
+
* limitations under the License.
|
17
|
+
*
|
18
|
+
* Date: 2010-09-30
|
19
|
+
* Rev: 1.1.00
|
20
|
+
*/
|
21
|
+
(function(B){B.jnotify=function(K,M,L){return new C(K,M,L)};B.jnotify.version="1.1.00";var J,D=[],E=0,H=false,I=false,G,F,A={type:"",delay:2000,sticky:false,closeLabel:"×",showClose:true,fadeSpeed:1000,slideSpeed:250,classContainer:"jnotify-container",classNotification:"jnotify-notification",classBackground:"jnotify-background",classClose:"jnotify-close",classMessage:"jnotify-message",init:null,create:null,beforeRemove:null,remove:null,transition:null};B.jnotify.setup=function(K){A=B.extend({},A,K)};B.jnotify.play=function(M,N){if(H&&(M!==true)||(D.length==0)){return }H=true;var L=D.shift();F=L;var K=(arguments.length>=2)?parseInt(N,10):L.options.delay;G=setTimeout(function(){G=0;L.remove(function(){if(D.length==0){H=false}else{if(!I){B.jnotify.play(true)}}})},K)};B.jnotify.pause=function(){clearTimeout(G);if(G){D.unshift(F)}I=H=true};B.jnotify.resume=function(){I=false;B.jnotify.play(true,0)};function C(P,N){var M=this,K=typeof N;if(K=="number"){N=B.extend({},A,{delay:N})}else{if(K=="boolean"){N=B.extend({},A,{sticky:true})}else{if(K=="string"){N=B.extend({},A,{type:N,delay:((arguments.length>2)&&(typeof arguments[2]=="number"))?arguments[2]:A.delay,sticky:((arguments.length>2)&&(typeof arguments[2]=="boolean"))?arguments[2]:A.sticky})}else{N=B.extend({},A,N)}}}this.options=N;if(!J){J=B('<div class="'+A.classContainer+'" />').appendTo("body");if(B.isFunction(N.init)){N.init.apply(M,[J])}}function O(S){var R='<div class="'+N.classNotification+(N.type.length?(" "+N.classNotification+"-"+N.type):"")+'"><div class="'+N.classBackground+'"></div>'+(N.sticky&&N.showClose?('<a class="'+N.classClose+'">'+N.closeLabel+"</a>"):"")+'<div class="'+N.classMessage+'"><div>'+S+"</div></div></div>";E++;var Q=B(R);if(N.sticky){Q.find("a."+N.classClose).bind("click.jnotify",function(){M.remove()})}if(B.isFunction(N.create)){N.create.apply(M,[Q])}return Q.appendTo(J)}this.remove=function(U){var Q=L.find("."+N.classMessage),S=Q.parent();var R=E--;if(B.isFunction(N.beforeRemove)){N.beforeRemove.apply(M,[Q])}function T(){S.remove();if(B.isFunction(U)){U.apply(M,[Q])}if(B.isFunction(N.remove)){N.remove.apply(M,[Q])}}if(B.isFunction(N.transition)){N.transition.apply(M,[S,Q,R,T,N])}else{Q.fadeTo(N.fadeSpeed,0.01,function(){if(R<=1){T()}else{S.slideUp(N.slideSpeed,T)}});if(E<=0){S.fadeOut(N.fadeSpeed)}}};var L=O(P);if(!N.sticky){D.push(this);B.jnotify.play()}return this}})(jQuery);
|
@@ -0,0 +1,97 @@
|
|
1
|
+
.checkout_links
|
2
|
+
margin-top: 20px
|
3
|
+
background-color: #f4f4f4
|
4
|
+
height: 40px
|
5
|
+
margin-left: auto
|
6
|
+
margin-right: auto
|
7
|
+
+borderCorner
|
8
|
+
width: 385px
|
9
|
+
.checkout_link
|
10
|
+
+borderCorner
|
11
|
+
display: block
|
12
|
+
float: left
|
13
|
+
margin-right: 20px
|
14
|
+
line-height: 40px
|
15
|
+
padding: 0 5px
|
16
|
+
&.checkout_link_0
|
17
|
+
margin-left: 20px
|
18
|
+
span
|
19
|
+
a
|
20
|
+
color: #666666
|
21
|
+
text-decoration: none
|
22
|
+
&:hover
|
23
|
+
background-color: #ff9900
|
24
|
+
span
|
25
|
+
a
|
26
|
+
color: white
|
27
|
+
&.current_checkout_link
|
28
|
+
background-color: #ff9900
|
29
|
+
span
|
30
|
+
a
|
31
|
+
color: white
|
32
|
+
|
33
|
+
.cart_content
|
34
|
+
p
|
35
|
+
text-align: none !important
|
36
|
+
#cart_table
|
37
|
+
width: 100%
|
38
|
+
margin: 10px 0
|
39
|
+
thead
|
40
|
+
tr
|
41
|
+
border:
|
42
|
+
bottom: 1px solid #ff6600
|
43
|
+
th
|
44
|
+
padding: 5px
|
45
|
+
tbody
|
46
|
+
tr
|
47
|
+
background:
|
48
|
+
color: #eeeeee
|
49
|
+
margin-bottom: 20px
|
50
|
+
border:
|
51
|
+
bottom: 20px solid white
|
52
|
+
td
|
53
|
+
&.article
|
54
|
+
.product_info
|
55
|
+
a
|
56
|
+
display: block
|
57
|
+
span
|
58
|
+
display: block
|
59
|
+
vertical-align: middle
|
60
|
+
border:
|
61
|
+
right: 1px dotted #cccccc
|
62
|
+
padding: 10px
|
63
|
+
&.center
|
64
|
+
text-align: center
|
65
|
+
&.total_price
|
66
|
+
border:
|
67
|
+
right: 0
|
68
|
+
.delete_product
|
69
|
+
background:
|
70
|
+
image: url("/images/commerce_front/cart/delete.png")
|
71
|
+
repeat: no-repeat
|
72
|
+
position: center
|
73
|
+
height: 30px
|
74
|
+
width: 30px
|
75
|
+
display: block
|
76
|
+
text-indent: -9999px
|
77
|
+
margin: auto
|
78
|
+
.less_product, .more_product
|
79
|
+
background:
|
80
|
+
image: url("/images/commerce_front/cart/change_quantity.png")
|
81
|
+
repeat: no-repeat
|
82
|
+
position: center
|
83
|
+
text-align: center
|
84
|
+
color: white
|
85
|
+
font-weight: bold
|
86
|
+
float: left
|
87
|
+
margin: 2px 5px 0
|
88
|
+
width: 27px
|
89
|
+
height: 17px
|
90
|
+
line-height: 17px
|
91
|
+
.quantity
|
92
|
+
border: 1px solid #eeeeee
|
93
|
+
+borderCorner
|
94
|
+
float: left
|
95
|
+
margin: 0
|
96
|
+
width: 40px
|
97
|
+
text-align: center
|
@@ -0,0 +1,13 @@
|
|
1
|
+
=borderCorner($topLeft: 4px, $topRight: 4px, $bottomRight: 4px, $bottomLeft: 4px)
|
2
|
+
-moz-border-radius-topleft: $topLeft
|
3
|
+
-moz-border-radius-topright: $topRight
|
4
|
+
-moz-border-radius-bottomright: $bottomRight
|
5
|
+
-moz-border-radius-bottomleft: $bottomLeft
|
6
|
+
-webkit-border-top-left-radius: $topLeft
|
7
|
+
-webkit-border-top-right-radius: $topRight
|
8
|
+
-webkit-border-bottom-right-radius: $bottomRight
|
9
|
+
-webkit-border-bottom-left-radius: $bottomLeft
|
10
|
+
border-top-left-radius: $topLeft
|
11
|
+
border-top-right-radius: $topRight
|
12
|
+
border-bottom-right-radius: $bottomRight
|
13
|
+
border-bottom-left-radius: $bottomLeft
|
@@ -0,0 +1,15 @@
|
|
1
|
+
textarea, input[type="text"], input[type="password"]
|
2
|
+
border: solid 1px #b2b2b2
|
3
|
+
+borderCorner
|
4
|
+
&.error_on_this_field
|
5
|
+
border-color: red
|
6
|
+
|
7
|
+
.field_error
|
8
|
+
color: red
|
9
|
+
|
10
|
+
.account_form
|
11
|
+
label,
|
12
|
+
textarea,
|
13
|
+
input[type="text"],
|
14
|
+
input[type="password"]
|
15
|
+
display: block
|
@@ -0,0 +1,65 @@
|
|
1
|
+
.jnotify-container
|
2
|
+
position: fixed
|
3
|
+
top: 0
|
4
|
+
left: 0
|
5
|
+
width: 100%
|
6
|
+
z-index: 100000
|
7
|
+
.jnotify-notification
|
8
|
+
position: relative
|
9
|
+
.jnotify-background
|
10
|
+
position: absolute
|
11
|
+
top: 0
|
12
|
+
left: 0
|
13
|
+
width: 100%
|
14
|
+
height: 100%
|
15
|
+
background-color: #e3f0db
|
16
|
+
filter: alpha(opacity = 90)
|
17
|
+
-moz-opacity: 0.9
|
18
|
+
opacity: 0.9
|
19
|
+
z-index: 1
|
20
|
+
a.jnotify-close
|
21
|
+
position: absolute
|
22
|
+
top: 2px
|
23
|
+
right: 5px
|
24
|
+
padding: 0 5px
|
25
|
+
font: bold 1.4em Arial, Helvetica, sans-serif
|
26
|
+
line-height: 1em
|
27
|
+
color: #567b1b
|
28
|
+
text-decoration: none
|
29
|
+
z-index: 3
|
30
|
+
cursor: pointer
|
31
|
+
&:link, &:visited, &:focus, &:hover
|
32
|
+
position: absolute
|
33
|
+
top: 2px
|
34
|
+
right: 5px
|
35
|
+
padding: 0 5px
|
36
|
+
font: bold 1.4em Arial, Helvetica, sans-serif
|
37
|
+
line-height: 1em
|
38
|
+
color: #567b1b
|
39
|
+
text-decoration: none
|
40
|
+
z-index: 3
|
41
|
+
cursor: pointer
|
42
|
+
.jnotify-message
|
43
|
+
position: relative
|
44
|
+
z-index: 2
|
45
|
+
padding: 20px
|
46
|
+
text-align: center
|
47
|
+
color: #567b1b
|
48
|
+
font: bold 1.4em Arial, Helvetica, sans-serif
|
49
|
+
line-height: 1.2em
|
50
|
+
*
|
51
|
+
font-size: 1em
|
52
|
+
.jnotify-notification-error
|
53
|
+
.jnotify-background
|
54
|
+
background-color: #d79eac
|
55
|
+
.jnotify-close, .jnotify-message
|
56
|
+
color: #a72947 !important
|
57
|
+
.jnotify-notification-warning
|
58
|
+
.jnotify-background
|
59
|
+
background-color: #fff7d1
|
60
|
+
.jnotify-close, .jnotify-message
|
61
|
+
color: #c2a928 !important
|
62
|
+
|
63
|
+
/* notification type == "error"
|
64
|
+
|
65
|
+
/* notification type == "warning"
|
@@ -0,0 +1,71 @@
|
|
1
|
+
class AddressesController < ApplicationController
|
2
|
+
#before_filter :manage_address, :only => [:create]
|
3
|
+
#before_filter :login_required, :only => [:show, :update]
|
4
|
+
before_filter :get_address, :only => [:show, :update]
|
5
|
+
skip_before_filter :verify_authenticity_token
|
6
|
+
|
7
|
+
def show
|
8
|
+
respond_to do |format|
|
9
|
+
format.html { page_not_found }
|
10
|
+
format.json { render :json => @address.to_json }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def new
|
15
|
+
@address = UserAddress.new(params[:address])
|
16
|
+
render(:update) do |page|
|
17
|
+
page.replace_html '#delivery_address .account-form', :partial => 'address_form', :locals => {:address => @address}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def update
|
22
|
+
if @address.update_attributes(params[:address])
|
23
|
+
flash[:notice] = I18n.t('address_update_ok').capitalize
|
24
|
+
else
|
25
|
+
flash[:error] = "Une erreur est survenue lors de la mise à jour de l'addresse"
|
26
|
+
end
|
27
|
+
render(:update) do |page|
|
28
|
+
page.replace_html '#delivery_address .account-form', :partial => 'address_form', :locals => {:address => @address}
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
#def manage_address
|
35
|
+
# if params[:user] && params[:user][:address_invoice_attributes]
|
36
|
+
# params[:user][:address_invoice_attributes][:name] = params[:user][:lastname]
|
37
|
+
# params[:user][:address_invoice_attributes][:firstname] = params[:user][:firstname]
|
38
|
+
# params[:user][:address_invoice_attributes][:phone] = params[:user][:phone]
|
39
|
+
# params[:user][:address_invoice_attributes][:email] = params[:user][:email]
|
40
|
+
# params[:user][:address_invoice_attributes][:designation] = 'Première adresse'
|
41
|
+
# params[:user][:address_invoice_attributes][:civility] = params[:civility]
|
42
|
+
|
43
|
+
# params[:user][:address_delivery_attributes] = params[:user][:address_invoice_attributes]
|
44
|
+
# params[:user][:address_delivery_attributes][:designation] = 'Seconde adresse'
|
45
|
+
# end
|
46
|
+
#end
|
47
|
+
|
48
|
+
def get_address
|
49
|
+
@address = UserAddress.first(:conditions => ['id = ? AND person_id IS NOT NULL', params[:id]])
|
50
|
+
if not @address
|
51
|
+
flash[:error] = 'Utilisateur non trouvé'
|
52
|
+
return render :nothing => true, :status => 404
|
53
|
+
elsif not current_user
|
54
|
+
flash[:error] = 'Vous devez être connecté pour avoir accès à cette ressource'
|
55
|
+
return render :nothing => true, :status => 401
|
56
|
+
elsif current_user.id != @address.person_id
|
57
|
+
flash[:error] = 'Accès interdit'
|
58
|
+
return render :nothing => true, :status => 401
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def destroy
|
63
|
+
if @address.destroy
|
64
|
+
flash[:notice] = "L'adresse a bien été supprimée"
|
65
|
+
else
|
66
|
+
flash[:error] = "Une erreur est survenue lors de la suppression de l'adresse"
|
67
|
+
end
|
68
|
+
render :nothing => true
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# Filters added to this controller apply to all controllers in the application.
|
2
|
+
# Likewise, all the methods added will be available for all controllers.
|
3
|
+
|
4
|
+
#require 'app/models/product'
|
5
|
+
class ApplicationController < ActionController::Base
|
6
|
+
helper :all # include all helpers, all the time
|
7
|
+
|
8
|
+
def get_login_link
|
9
|
+
render :partial => '/users/login_link'
|
10
|
+
end
|
11
|
+
|
12
|
+
def set_locale_with_config
|
13
|
+
if Forgeos::CONFIG[:multilang]
|
14
|
+
set_locale_without_config
|
15
|
+
elsif locale = Forgeos::CONFIG[:default_locale]
|
16
|
+
I18n.locale = locale
|
17
|
+
ActiveRecord::Base.locale = locale
|
18
|
+
end
|
19
|
+
end
|
20
|
+
alias_method_chain :set_locale, :config
|
21
|
+
end
|
@@ -0,0 +1,144 @@
|
|
1
|
+
require 'ruleby'
|
2
|
+
class CartController < ApplicationController
|
3
|
+
include Ruleby
|
4
|
+
skip_before_filter :verify_authenticity_token, :only => [:add_product]
|
5
|
+
skip_before_filter :get_menu, :only => [:update_quantity, :delete_product]
|
6
|
+
before_filter :special_offer, :only => [:index, :add_voucher]
|
7
|
+
before_filter :check_voucher_code, :only => [:add_voucher]
|
8
|
+
before_filter :voucher, :only => [:index, :add_voucher]
|
9
|
+
|
10
|
+
def index
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
## add a product
|
15
|
+
def add_product
|
16
|
+
if params[:id]
|
17
|
+
current_cart.add_product_id( params[:id],1 )
|
18
|
+
redirect_to(:action => 'index')
|
19
|
+
else
|
20
|
+
redirect_to(:back)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
## delete or add a product
|
25
|
+
def update_quantity
|
26
|
+
cart_product = current_cart.cart_items.find_by_id(params[:id])
|
27
|
+
unless cart_product.nil?
|
28
|
+
new_quantity = params[:quantity].to_i
|
29
|
+
if cart_product.quantity < new_quantity ## add a product
|
30
|
+
if !cart_product.product.stop_sales
|
31
|
+
cart_product.update_attributes( :quantity => new_quantity )
|
32
|
+
elsif cart_product.product.stock >= new_quantity
|
33
|
+
cart_product.update_attributes( :quantity => new_quantity )
|
34
|
+
else
|
35
|
+
flash[:quantity_warning] = "Le stock disponible est insuffisant."
|
36
|
+
end
|
37
|
+
else ## delete a product
|
38
|
+
cart_product.update_attributes( :quantity => new_quantity )
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
current_cart.reload
|
43
|
+
|
44
|
+
special_offer
|
45
|
+
voucher
|
46
|
+
|
47
|
+
if request.xhr?
|
48
|
+
render(:update) do |page|
|
49
|
+
page.replace_html 'tbody', :partial => 'tbody'
|
50
|
+
page.replace_html 'cart_total', :partial => 'total'
|
51
|
+
page.replace_html 'free_products', :partial => 'free_products'
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def delete_product
|
57
|
+
cart_product = current_cart.cart_items.find_by_id(params[:id])
|
58
|
+
current_cart.cart_items.find_all_by_product_id(cart_product.product_id).collect(&:delete) unless cart_product.nil?
|
59
|
+
current_cart.reload
|
60
|
+
special_offer
|
61
|
+
voucher
|
62
|
+
if request.xhr?
|
63
|
+
render(:update) do |page|
|
64
|
+
page.replace_html 'tbody', :partial => 'tbody'
|
65
|
+
page.replace_html 'cart_total', :partial => 'total'
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def add_voucher
|
71
|
+
voucher = VoucherRule.find_by_id(current_cart.voucher)
|
72
|
+
if voucher.nil?
|
73
|
+
session.delete(:voucher_code)
|
74
|
+
render(:update) do |page|
|
75
|
+
page.replace_html 'voucher_message' , "<span>Le code promo #{@voucher_code} est invalide2.</span>"
|
76
|
+
page.replace_html 'tbody', :partial => 'tbody'
|
77
|
+
page.replace_html 'cart_total', :partial => 'total'
|
78
|
+
page.replace_html 'free_products', :partial => 'free_products'
|
79
|
+
end
|
80
|
+
else
|
81
|
+
session[:voucher_code] = voucher.code
|
82
|
+
render(:update) do |page|
|
83
|
+
page.replace_html 'voucher_message' , "<span>Code validé ! #{voucher.name}</span>"
|
84
|
+
page.replace_html 'tbody', :partial => 'tbody'
|
85
|
+
page.replace_html 'cart_total', :partial => 'total'
|
86
|
+
page.replace_html 'free_products', :partial => 'free_products'
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def get_cart_items_count
|
92
|
+
render :text => "#{current_cart.cart_items.count} articles"
|
93
|
+
end
|
94
|
+
|
95
|
+
private
|
96
|
+
def check_voucher_code
|
97
|
+
@voucher_code = params[:voucher_code] || session[:voucher_code]
|
98
|
+
voucher = VoucherRule.find_all_by_active_and_code(true,@voucher_code)
|
99
|
+
#get_transporters ## because the shipping was maybe offer with a voucher
|
100
|
+
render(:update) do |page|
|
101
|
+
page.replace_html 'voucher_message' , "<span>Le code promo #{@voucher_code} est invalide.</span>"
|
102
|
+
page.replace_html 'tbody', :partial => 'tbody'
|
103
|
+
page.replace_html 'cart_total', :partial => 'total'
|
104
|
+
session.delete(:voucher_code) if session[:voucher_code]
|
105
|
+
end if voucher.blank? or voucher.nil?
|
106
|
+
end
|
107
|
+
|
108
|
+
def special_offer
|
109
|
+
begin
|
110
|
+
engine :special_offer_engine do |e|
|
111
|
+
rule_builder = SpecialOffer.new(e)
|
112
|
+
rule_builder.cart = current_cart
|
113
|
+
@free_product_ids = []
|
114
|
+
rule_builder.free_product_ids = @free_product_ids
|
115
|
+
rule_builder.rules
|
116
|
+
current_cart.cart_items.each do |cart_product|
|
117
|
+
e.assert cart_product.product
|
118
|
+
end
|
119
|
+
e.assert current_cart
|
120
|
+
e.match
|
121
|
+
end
|
122
|
+
rescue Exception
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def voucher
|
127
|
+
begin
|
128
|
+
engine :voucher_engine do |e|
|
129
|
+
rule_builder = Voucher.new(e)
|
130
|
+
rule_builder.cart = current_cart
|
131
|
+
rule_builder.code = @voucher_code || session[:voucher_code]
|
132
|
+
rule_builder.free_product_ids = @free_product_ids
|
133
|
+
rule_builder.rules
|
134
|
+
current_cart.cart_items.each do |cart_product|
|
135
|
+
e.assert cart_product.product
|
136
|
+
end
|
137
|
+
e.assert current_cart
|
138
|
+
e.match
|
139
|
+
end
|
140
|
+
rescue Exception
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
end
|