diff --git a/Gemfile b/Gemfile index 7c082d4..f36708e 100644 --- a/Gemfile +++ b/Gemfile @@ -19,7 +19,7 @@ gem 'sass-rails', '~> 5.0' gem 'uglifier', '>= 1.3.0' # See https://github.com/rails/execjs#readme for more supported runtimes # gem 'therubyracer', platforms: :ruby -gem 'bcrypt', platforms: :ruby +gem 'bcrypt', '3.1.11', platforms: :ruby gem 'breadcrumbs_on_rails' gem 'devise' gem 'paperclip' @@ -42,6 +42,8 @@ gem 'acts_as_tree' # Use Capistrano for deployment # gem 'capistrano-rails', group: :development +gem 'draper' + group :development, :test do # Call 'byebug' anywhere in the code to # stop execution and get a debugger console @@ -66,3 +68,4 @@ end gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby] gem 'kaminari', '1.1.1' +gem 'geocoder' diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 8456459..48236f8 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -12,3 +12,7 @@ // //= require rails-ujs // require turbolinks + +function closeDiv(div_id) { + $(div_id).html(""); +}; diff --git a/app/controllers/checkout_controller.rb b/app/controllers/checkout_controller.rb index 79419d2..a84fb49 100644 --- a/app/controllers/checkout_controller.rb +++ b/app/controllers/checkout_controller.rb @@ -26,12 +26,15 @@ class CheckoutController < ShopController def end_order if !@cart.blank? && !@order.blank? - if RecaptchaVerifier.verify(params['g-recaptcha-response'], request.ip) + if @ss.recaptcha_chk.eql?(false) || (@ss.recaptcha_chk.eql?(true) && RecaptchaVerifier.verify(params['g-recaptcha-response'], request.ip)) if @order.update_attributes(order_params) @order.status = 1 # kopiujemy wszystkie produkty z koszyka i odejmujemy od ilosci # z rezerwacji jesli jest taka potrzeba copy_cart_prod_to_order(@cart, @order) + orders_max_number = Order.where('order_number IS NOT NULL') + .order('order_number DESC').first + @order.order_number = orders_max_number.order_number + 1 @order.save # usunac ciasteczko z koszykiem jesli wszystko sie udalo delete_cookies_for_cart diff --git a/app/controllers/ps_admin/image_controller.rb b/app/controllers/ps_admin/image_controller.rb index db42e86..894f044 100644 --- a/app/controllers/ps_admin/image_controller.rb +++ b/app/controllers/ps_admin/image_controller.rb @@ -80,9 +80,13 @@ module PsAdmin image = Image.where(id: params[:id]).first unless image.blank? if image.cover.eql?(true) - img = Image.where('imageable_type = ? AND imageable_id = ? AND id != ?', image.imageable_type, image.imageable_id, image.id).first - img.cover = true - img.save + img = Image.by_image_type(image.imageable_type) + .where('imageable_id = ? AND id != ?', + image.imageable_id, image.id).first + unless img.blank? + img.cover = true + img.save + end end image.destroy end diff --git a/app/controllers/ps_admin/order_controller.rb b/app/controllers/ps_admin/order_controller.rb index 21db86a..87b50ef 100644 --- a/app/controllers/ps_admin/order_controller.rb +++ b/app/controllers/ps_admin/order_controller.rb @@ -9,8 +9,8 @@ module PsAdmin end def show - otp = OrderToPdf.new(@order).call - puts "#{otp.inspect}" + #otp = OrderToPdf.new(@order).call + #puts "#{otp.inspect}" end def destroy diff --git a/app/controllers/shop_controller.rb b/app/controllers/shop_controller.rb index ebefeff..f87cfab 100644 --- a/app/controllers/shop_controller.rb +++ b/app/controllers/shop_controller.rb @@ -4,6 +4,7 @@ class ShopController < ApplicationController include PageContent def set_settings + Rails.logger.error request.location.country_code @ss = ScSetting.first redirect_to '/closed.html' if @ss.shop_active.eql?(false) end diff --git a/app/decorators/application_decorator.rb b/app/decorators/application_decorator.rb new file mode 100644 index 0000000..5caf08b --- /dev/null +++ b/app/decorators/application_decorator.rb @@ -0,0 +1,8 @@ +class ApplicationDecorator < Draper::Decorator + # Define methods for all decorated objects. + # Helpers are accessed through `helpers` (aka `h`). For example: + # + # def percent_amount + # h.number_to_percentage object.amount, precision: 2 + # end +end diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index 6a4f3b0..5ff92a4 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -1,5 +1,6 @@ # App Mailer class ApplicationMailer < ActionMailer::Base - default from: 'Kaktusiarnia ' + default from: 'Kaktusiarnia ', + reply_to: 'kaktusiarnia@kaktusiarnia.pl' layout 'mailer' end diff --git a/app/mailers/order_mailer.rb b/app/mailers/order_mailer.rb index c7cdb1f..9b9a8e2 100644 --- a/app/mailers/order_mailer.rb +++ b/app/mailers/order_mailer.rb @@ -17,7 +17,8 @@ class OrderMailer < ApplicationMailer sleep(5) #to make sure pdf file saved on the disk mail(subject: "Nowe zamówienie nr: #{@order.beauty_id}", from: "#{ss.shop_name} ", - to: ss.shop_owners_emails) + to: ss.shop_owners_emails, + reply_to: @order.email) end def status_change(order) diff --git a/app/models/image.rb b/app/models/image.rb index 577e6c2..66857a5 100644 --- a/app/models/image.rb +++ b/app/models/image.rb @@ -14,7 +14,7 @@ class Image < ApplicationRecord } # before_post_process :rename_file validates_attachment_content_type :image, content_type: /\Aimage/ - validates_attachment_file_name :image, matches: [/png\z/, /jpe?g\z/] + validates_attachment_file_name :image, matches: [/png\z/, /jpe?g\z/, /PNG\z/, /JPE?G\z/] do_not_validate_attachment_file_type :image scope :by_image_type, ->(type) { where(imageable_type: type) } scope :by_position_desc, -> { order(position: :desc) } diff --git a/app/models/order.rb b/app/models/order.rb index 7292001..dba8f9e 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -28,7 +28,8 @@ class Order < ApplicationRecord 3 => 'Oczekuje na płatność', 4 => 'Zapłacone', 5 => 'Wysłane', - 6 => 'Zakończone' + 6 => 'Zakończone', + 7 => 'Anulowane' }.freeze ORDER_STATUSES_HTML = { @@ -38,7 +39,8 @@ class Order < ApplicationRecord 3 => 'Oczekuje na płatność', 4 => 'Zapłacone', 5 => 'Wysłane', - 6 => 'Zakończone' + 6 => 'Zakończone', + 7 => 'Anulowane' }.freeze def order_summary @@ -50,7 +52,11 @@ class Order < ApplicationRecord end def beauty_id - id.to_s.rjust(8, '0') + if order_number.nil? + '---------' + else + order_number.to_s.rjust(8, '0') + end end def date_checkout @@ -74,7 +80,7 @@ class Order < ApplicationRecord end def address - "#{street}\n#{zip_code} #{city}\n\n#{phone}" + "#{street}\n#{zip_code} #{city}\n\ntel: #{phone}" end def order_value diff --git a/app/models/order_history.rb b/app/models/order_history.rb index 24c36c1..53a7514 100644 --- a/app/models/order_history.rb +++ b/app/models/order_history.rb @@ -1,4 +1,4 @@ -# historia statusow zamowien +# Order change status history class OrderHistory < ApplicationRecord belongs_to :order scope :by_create_desc, -> { order(created_at: :desc) } diff --git a/app/views/checkout/order.html.erb b/app/views/checkout/order.html.erb index a72fd65..0ea3ee5 100644 --- a/app/views/checkout/order.html.erb +++ b/app/views/checkout/order.html.erb @@ -11,8 +11,10 @@ <% else %> -<% content_for :header_scripts do %> - +<% if @ss.recaptcha_chk.eql?(true) %> + <% content_for :header_scripts do %> + + <% end %> <% end %>
@@ -84,7 +86,9 @@
<%= javascript_tag do %> +<% if @ss.recaptcha_chk.eql?(true) %> var onRecaptchaElementLoad = function() { grecaptcha.render('recaptcha', { 'sitekey' : '<%= j ENV["REACAPTCHA_SITE_KEY"]%>', 'hl': 'pl' }); }; +<% end %> $('#changetabbutton1').click(function(e){ e.preventDefault(); $('#checkout_tabs a[href="#billing-info"]').tab('show'); diff --git a/app/views/checkout/partials/_payment_methods.html.erb b/app/views/checkout/partials/_payment_methods.html.erb index a6dc1be..ed0ba61 100644 --- a/app/views/checkout/partials/_payment_methods.html.erb +++ b/app/views/checkout/partials/_payment_methods.html.erb @@ -40,10 +40,12 @@
+ <% if @ss.recaptcha_chk.eql?(true) %>
Potwierdź, że nie jesteś robotem
+ <% end %>
<%= raw submit_tag(raw('Potwierdzam zamówienie'), class: "btn btn-default btn-md round pull-right") %>
diff --git a/app/views/order_mailer/new_order_to_shop_owner.html.erb b/app/views/order_mailer/new_order_to_shop_owner.html.erb index 4a8e384..8060c96 100644 --- a/app/views/order_mailer/new_order_to_shop_owner.html.erb +++ b/app/views/order_mailer/new_order_to_shop_owner.html.erb @@ -80,6 +80,7 @@ <%= @order.full_name %>
+ <%= @order.email %>
<%= raw @order.address.gsub(/(\r\n|\n\r|\r|\n)/, '
') %> diff --git a/app/views/order_mailer/new_order_to_shop_owner.text.erb b/app/views/order_mailer/new_order_to_shop_owner.text.erb index 2799266..eebc48f 100644 --- a/app/views/order_mailer/new_order_to_shop_owner.text.erb +++ b/app/views/order_mailer/new_order_to_shop_owner.text.erb @@ -20,6 +20,7 @@ order_arr << [{:value => 'Razem do zapłaty', :colspan => 3, :align => :right}, Adres dostawy <%= @order.full_name %> +<%= @order.email %> <%= @order.address %> diff --git a/app/views/ps_admin/image/partials/_images.html.erb b/app/views/ps_admin/image/partials/_images.html.erb index 584d3a1..4b3e0bf 100644 --- a/app/views/ps_admin/image/partials/_images.html.erb +++ b/app/views/ps_admin/image/partials/_images.html.erb @@ -28,7 +28,7 @@ <% end %> - <%= image_tag image.image.url(:medium) %> + <%= link_to image_tag(image.image.url(:medium)), image.image.url(:original), target: '_blank' %> <%= raw image.cover.eql?(true) ? '

' : link_to(raw('

'), {controller: '/ps_admin/image', action: 'set_cover', id: image.id, product_id: @product.id, cover: 1}, remote: true) %> <%= raw image.active.eql?(true) ? link_to(raw('

'), {controller: '/ps_admin/image', action: 'set_active', id: image.id, product_id: @product.id, active: 0}, remote: true) : link_to(raw('

'), {controller: '/ps_admin/image', action: 'set_active', id: image.id, product_id: @product.id, active: 1}, remote: true) %> diff --git a/app/views/ps_admin/product/partials/_show.html.erb b/app/views/ps_admin/product/partials/_show.html.erb index 77e9eb1..921d2d7 100644 --- a/app/views/ps_admin/product/partials/_show.html.erb +++ b/app/views/ps_admin/product/partials/_show.html.erb @@ -49,7 +49,7 @@
@@ -58,7 +58,7 @@ <%= javascript_include_tag 'bootstrap-editable' %>