diff --git a/Gemfile b/Gemfile index cc1d1932..fafb55b0 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,7 @@ source 'https://rubygems.org' +gem 'rails-controller-testing' gem 'spree', github: 'spree/spree', branch: 'master' gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: 'master' -gem 'rails-controller-testing' gemspec diff --git a/Rakefile b/Rakefile index 875f1f0d..d93b361d 100644 --- a/Rakefile +++ b/Rakefile @@ -7,9 +7,9 @@ require 'spree/testing_support/extension_rake' RSpec::Core::RakeTask.new task :default do - if Dir["spec/dummy"].empty? + if Dir['spec/dummy'].empty? Rake::Task[:test_app].invoke - Dir.chdir("../../") + Dir.chdir('../../') end Rake::Task[:spec].invoke end diff --git a/app/controllers/spree_analytics_trackers/store_controller_decorator.rb b/app/controllers/spree_analytics_trackers/store_controller_decorator.rb index 99293610..30077a02 100644 --- a/app/controllers/spree_analytics_trackers/store_controller_decorator.rb +++ b/app/controllers/spree_analytics_trackers/store_controller_decorator.rb @@ -2,12 +2,10 @@ module SpreeAnalyticsTrackers module StoreControllerDecorator def self.included(base) base.include ::Spree::BaseHelper - + base.helper 'spree/trackers' end end end -if defined?(Spree::StoreController) - ::Spree::StoreController.include(::SpreeAnalyticsTrackers::StoreControllerDecorator) -end +::Spree::StoreController.include(::SpreeAnalyticsTrackers::StoreControllerDecorator) if defined?(Spree::StoreController) diff --git a/app/helpers/spree/trackers_helper.rb b/app/helpers/spree/trackers_helper.rb index 2cf2015e..f44929dc 100644 --- a/app/helpers/spree/trackers_helper.rb +++ b/app/helpers/spree/trackers_helper.rb @@ -11,7 +11,7 @@ def product_for_segment(product, optional = {}) product_hash = Rails.cache.fetch(cache_key) do { product_id: product.id, - sku: product.sku, + sku: product.sku || product.id, category: product.category&.name, name: product.name, brand: product.brand&.name, @@ -25,7 +25,7 @@ def product_for_segment(product, optional = {}) hash[:image_url] = default_image_for_product_or_variant(product) end.merge(optional).to_json.html_safe end - + def product_for_google(product, optional = {}) cache_key = [ 'spree-google-product', @@ -36,12 +36,12 @@ def product_for_google(product, optional = {}) Rails.cache.fetch(cache_key) do { - item_id: product.sku, + item_id: product.id, item_name: product.name, item_category: product.category&.name, item_brand: product.brand&.name, price: product.price_in(current_currency).amount&.to_f, - currency: current_currency, + currency: current_currency }.merge(optional).to_json.html_safe end end @@ -60,7 +60,7 @@ def ga_line_item(line_item) Rails.cache.fetch(cache_key) do product = line_item.product { - id: variant.sku, + id: variant.id, name: variant.name, category: product.category&.name, variant: variant.options_text, diff --git a/app/models/spree/tracker.rb b/app/models/spree/tracker.rb index 5c2d6e37..361d30af 100644 --- a/app/models/spree/tracker.rb +++ b/app/models/spree/tracker.rb @@ -1,11 +1,11 @@ module Spree class Tracker < Spree::Base - TRACKING_ENGINES = %i(google_analytics segment).freeze + TRACKING_ENGINES = %i[google_analytics segment].freeze enum engine: TRACKING_ENGINES after_commit :clear_cache - validates :analytics_id, presence: true, uniqueness: { scope: [:engine, :store_id], case_sensitive: false } + validates :analytics_id, presence: true, uniqueness: { scope: %i[engine store_id], case_sensitive: false } validates :store, presence: true scope :active, -> { where(active: true) } @@ -19,7 +19,9 @@ def self.current(engine = nil, store = nil) tracker = Rails.cache.fetch("current_tracker/#{engine}/#{store.id}") do active.find_by(store: store, engine: engine) end - tracker.analytics_id.present? ? tracker : nil if tracker + return unless tracker + + tracker.analytics_id.present? ? tracker : nil end def clear_cache diff --git a/app/overrides/add_cart_viewed_to_orders_edit.rb b/app/overrides/add_cart_viewed_to_orders_edit.rb deleted file mode 100644 index 276dd3b5..00000000 --- a/app/overrides/add_cart_viewed_to_orders_edit.rb +++ /dev/null @@ -1,11 +0,0 @@ -spree_version = Gem.loaded_specs['spree_core'].version -unless spree_version >= Gem::Version.create('3.4.0') && spree_version < Gem::Version.create('3.5.0') - Deface::Override.new( - virtual_path: 'spree/orders/edit', - name: 'add_cart_viewed_to_orders_edit', - insert_top: '[data-hook="cart_container"]', - text: <<-HTML - <%= render partial: 'spree/shared/trackers/segment/cart_viewed', formats: :js %> - HTML - ) -end diff --git a/app/overrides/add_checkout_step_viewed_to_checkout_edit.rb b/app/overrides/add_checkout_step_viewed_to_checkout_edit.rb deleted file mode 100644 index 477e7624..00000000 --- a/app/overrides/add_checkout_step_viewed_to_checkout_edit.rb +++ /dev/null @@ -1,20 +0,0 @@ -spree_version = Gem.loaded_specs['spree_core'].version -unless spree_version >= Gem::Version.create('3.4.0') && spree_version < Gem::Version.create('3.5.0') - Deface::Override.new( - virtual_path: 'spree/checkout/edit', - name: 'add_segment_checkout_step_viewed_to_checkout_edit', - insert_after: '[data-hook="checkout_content"]', - text: <<-HTML - <%= render partial: 'spree/shared/trackers/segment/checkout_step_viewed', formats: :js %> - HTML - ) - - Deface::Override.new( - virtual_path: 'spree/checkout/edit', - name: 'add_ga_checkout_step_viewed_to_checkout_edit', - insert_after: '[data-hook="checkout_content"]', - text: <<-HTML - <%= render partial: 'spree/shared/trackers/google_analytics/checkout_step_viewed', formats: :js %> - HTML - ) -end diff --git a/app/overrides/add_google_analytics_add_shipping_info_to_payment.rb b/app/overrides/add_google_analytics_add_shipping_info_to_payment.rb deleted file mode 100644 index ca27f8aa..00000000 --- a/app/overrides/add_google_analytics_add_shipping_info_to_payment.rb +++ /dev/null @@ -1,11 +0,0 @@ -spree_version = Gem.loaded_specs['spree_core'].version -unless spree_version >= Gem::Version.create('3.4.0') && spree_version < Gem::Version.create('3.5.0') - Deface::Override.new( - virtual_path: 'spree/checkout/_payment', - name: 'add_google_analytics_add_shipping_info_to_payment', - insert_bottom: '[data-hook="checkout_payment_step"]', - text: <<-HTML - <%= render partial: 'spree/shared/trackers/google_analytics/add_shipping_info', formats: :js %> - HTML - ) -end diff --git a/app/overrides/add_google_analytics_begin_application_to_registration.rb b/app/overrides/add_google_analytics_begin_application_to_registration.rb deleted file mode 100644 index 65f5958a..00000000 --- a/app/overrides/add_google_analytics_begin_application_to_registration.rb +++ /dev/null @@ -1,11 +0,0 @@ -spree_version = Gem.loaded_specs['spree_core'].version -unless spree_version >= Gem::Version.create('3.4.0') && spree_version < Gem::Version.create('3.5.0') - Deface::Override.new( - virtual_path: 'spree/user_registrations/new', - name: 'add_google_analytics_begin_application_to_registration', - insert_bottom: '[data-hook="wholesale_login_extras"]', - text: <<-HTML - <%= render partial: 'spree/shared/trackers/google_analytics/begin_application', formats: :js %> - HTML - ) -end diff --git a/app/overrides/add_google_analytics_begin_checkout_to_address.rb b/app/overrides/add_google_analytics_begin_checkout_to_address.rb deleted file mode 100644 index 7f0eae24..00000000 --- a/app/overrides/add_google_analytics_begin_checkout_to_address.rb +++ /dev/null @@ -1,11 +0,0 @@ -spree_version = Gem.loaded_specs['spree_core'].version -unless spree_version >= Gem::Version.create('3.4.0') && spree_version < Gem::Version.create('3.5.0') - Deface::Override.new( - virtual_path: 'spree/checkout/_address', - name: 'add_google_analytics_begin_checkout_to_address', - insert_bottom: '[data-hook="checkout_address_step"]', - text: <<-HTML - <%= render partial: 'spree/shared/trackers/google_analytics/begin_checkout', formats: :js %> - HTML - ) -end diff --git a/app/overrides/add_google_analytics_contact_info_added_to_store_address.rb b/app/overrides/add_google_analytics_contact_info_added_to_store_address.rb deleted file mode 100644 index 0671bdcb..00000000 --- a/app/overrides/add_google_analytics_contact_info_added_to_store_address.rb +++ /dev/null @@ -1,11 +0,0 @@ -spree_version = Gem.loaded_specs['spree_core'].version -unless spree_version >= Gem::Version.create('3.4.0') && spree_version < Gem::Version.create('3.5.0') - Deface::Override.new( - virtual_path: 'spree/addresses/new_wholesale', - name: 'add_google_analytics_contact_info_added_to_store_address', - insert_bottom: '[data-hook="new_wholesale_address"]', - text: <<-HTML - <%= render partial: 'spree/shared/trackers/google_analytics/contact_info_added', formats: :js %> - HTML - ) -end diff --git a/app/overrides/add_google_analytics_generate_lead_to_store_address.rb b/app/overrides/add_google_analytics_generate_lead_to_store_address.rb deleted file mode 100644 index c6ceeca1..00000000 --- a/app/overrides/add_google_analytics_generate_lead_to_store_address.rb +++ /dev/null @@ -1,11 +0,0 @@ -spree_version = Gem.loaded_specs['spree_core'].version -unless spree_version >= Gem::Version.create('3.4.0') && spree_version < Gem::Version.create('3.5.0') - Deface::Override.new( - virtual_path: 'spree/addresses/new_wholesale', - name: 'add_google_analytics_generate_lead_to_store_address', - insert_bottom: '[data-hook="new_wholesale_address"]', - text: <<-HTML - <%= render partial: 'spree/shared/trackers/google_analytics/generate_lead', formats: :js %> - HTML - ) -end diff --git a/app/overrides/add_google_analytics_page_view_to_spree_application.rb b/app/overrides/add_google_analytics_page_view_to_spree_application.rb deleted file mode 100644 index 247b7ea2..00000000 --- a/app/overrides/add_google_analytics_page_view_to_spree_application.rb +++ /dev/null @@ -1,11 +0,0 @@ -spree_version = Gem.loaded_specs['spree_core'].version -unless spree_version >= Gem::Version.create('3.3.0') && spree_version < Gem::Version.create('3.5.0') && spree_version != Gem::Version.create('3.5.0.alpha') - Deface::Override.new( - virtual_path: 'spree/shared/_head', - name: 'add_google_analytics_page_viewed_to_spree_application', - insert_before: 'meta', - text: <<-HTML - <%= render partial: 'spree/shared/trackers/google_analytics/page_viewed', formats: :js %> - HTML - ) -end diff --git a/app/overrides/add_google_analytics_sign_up_to_contact_information.rb b/app/overrides/add_google_analytics_sign_up_to_contact_information.rb deleted file mode 100644 index 4e778c2a..00000000 --- a/app/overrides/add_google_analytics_sign_up_to_contact_information.rb +++ /dev/null @@ -1,11 +0,0 @@ -spree_version = Gem.loaded_specs['spree_core'].version -unless spree_version >= Gem::Version.create('3.4.0') && spree_version < Gem::Version.create('3.5.0') - Deface::Override.new( - virtual_path: 'spree/wholesalers/new', - name: 'add_google_analytics_sign_up_to_contact_information', - insert_bottom: '[data-hook="wholesaler_inside_form"]', - text: <<-HTML - <%= render partial: 'spree/shared/trackers/google_analytics/sign_up', formats: :js %> - HTML - ) -end diff --git a/app/overrides/add_google_analytics_to_spree_application.rb b/app/overrides/add_google_analytics_to_spree_application.rb deleted file mode 100644 index cdf714db..00000000 --- a/app/overrides/add_google_analytics_to_spree_application.rb +++ /dev/null @@ -1,10 +0,0 @@ -if Gem.loaded_specs['spree_core'].version >= Gem::Version.create('3.5.0.alpha') - Deface::Override.new( - virtual_path: 'spree/shared/_head', - name: 'add_google_analytics_initializer_to_spree_application', - insert_after: 'title', - text: <<-HTML - <%= render partial: 'spree/shared/trackers/google_analytics/initializer', formats: :js %> - HTML - ) -end diff --git a/app/overrides/add_google_analytics_view_item_list_to_products.rb b/app/overrides/add_google_analytics_view_item_list_to_products.rb deleted file mode 100644 index dc235483..00000000 --- a/app/overrides/add_google_analytics_view_item_list_to_products.rb +++ /dev/null @@ -1,11 +0,0 @@ -spree_version = Gem.loaded_specs['spree_core'].version -unless spree_version >= Gem::Version.create('3.4.0') && spree_version < Gem::Version.create('3.5.0') - Deface::Override.new( - virtual_path: 'spree/shared/_products', - name: 'add_google_analytics_view_item_list_to_products', - insert_after: '[data-hook="homepage_products"]', - text: <<-HTML - <%= render partial: 'spree/shared/trackers/google_analytics/product_list_viewed', formats: :js %> - HTML - ) -end diff --git a/app/overrides/add_google_purchase_to_orders_show.rb b/app/overrides/add_google_purchase_to_orders_show.rb deleted file mode 100644 index 140ec709..00000000 --- a/app/overrides/add_google_purchase_to_orders_show.rb +++ /dev/null @@ -1,10 +0,0 @@ -if Gem.loaded_specs['spree_core'].version >= Gem::Version.create('3.5.0') - Deface::Override.new( - virtual_path: 'spree/orders/show', - name: 'add_google_purchase_to_orders_show', - insert_before: "#order_summary", - text: <<-HTML - <%= render partial: 'spree/shared/trackers/google_analytics/purchase', formats: :js %> - HTML - ) -end diff --git a/app/overrides/add_order_complete_to_orders_show.rb b/app/overrides/add_order_complete_to_orders_show.rb deleted file mode 100644 index 8bd68050..00000000 --- a/app/overrides/add_order_complete_to_orders_show.rb +++ /dev/null @@ -1,11 +0,0 @@ -spree_version = Gem.loaded_specs['spree_core'].version -unless spree_version >= Gem::Version.create('3.3.0') && spree_version < Gem::Version.create('3.5.0') - Deface::Override.new( - virtual_path: 'spree/orders/show', - name: 'add_order_complete_to_orders_show', - insert_before: "#order_summary", - text: <<-HTML - <%= render partial: 'spree/shared/trackers/segment/order_complete', formats: :js %> - HTML - ) -end diff --git a/app/overrides/add_product_list_filtered_to_taxons_show.rb b/app/overrides/add_product_list_filtered_to_taxons_show.rb deleted file mode 100644 index d46f3ea7..00000000 --- a/app/overrides/add_product_list_filtered_to_taxons_show.rb +++ /dev/null @@ -1,11 +0,0 @@ -spree_version = Gem.loaded_specs['spree_core'].version -unless spree_version >= Gem::Version.create('3.4.0') && spree_version < Gem::Version.create('3.5.0') - Deface::Override.new( - virtual_path: 'spree/taxons/_header', - name: 'add_product_list_filtered_to_taxons_show', - insert_before: ".taxon-title", - text: <<-HTML - <%= render partial: 'spree/shared/trackers/segment/product_list_filtered', formats: :js %> - HTML - ) -end diff --git a/app/overrides/add_product_list_viewed_to_products_list.rb b/app/overrides/add_product_list_viewed_to_products_list.rb deleted file mode 100644 index 2712e520..00000000 --- a/app/overrides/add_product_list_viewed_to_products_list.rb +++ /dev/null @@ -1,11 +0,0 @@ -spree_version = Gem.loaded_specs['spree_core'].version -unless spree_version >= Gem::Version.create('3.4.0') && spree_version < Gem::Version.create('3.5.0') - Deface::Override.new( - virtual_path: 'spree/shared/_products', - name: 'add_product_list_viewed_to_products_list', - insert_before: '[data-hook="homepage_products"]', - text: <<-HTML - <%= render partial: 'spree/shared/trackers/segment/product_list_viewed', formats: :js %> - HTML - ) -end diff --git a/app/overrides/add_product_viewed_to_products_show.rb b/app/overrides/add_product_viewed_to_products_show.rb deleted file mode 100644 index 982071d5..00000000 --- a/app/overrides/add_product_viewed_to_products_show.rb +++ /dev/null @@ -1,20 +0,0 @@ -spree_version = Gem.loaded_specs['spree_core'].version -unless spree_version >= Gem::Version.create('3.4.0') && spree_version < Gem::Version.create('3.5.0') - Deface::Override.new( - virtual_path: 'spree/products/show', - name: 'add_product_viewed_to_products_show', - insert_bottom: '[data-hook="product_show"]', - text: <<-HTML - <%= render partial: 'spree/shared/trackers/segment/product_viewed', formats: :js %> - HTML - ) - - Deface::Override.new( - virtual_path: 'spree/products/show', - name: 'add_product_viewed_to_products_show', - insert_bottom: '[data-hook="product_show"]', - text: <<-HTML - <%= render partial: 'spree/shared/trackers/google_analytics/product_viewed', formats: :js %> - HTML - ) -end diff --git a/app/overrides/add_products_searched_to_products_list.rb b/app/overrides/add_products_searched_to_products_list.rb deleted file mode 100644 index 7c7f6a7e..00000000 --- a/app/overrides/add_products_searched_to_products_list.rb +++ /dev/null @@ -1,11 +0,0 @@ -spree_version = Gem.loaded_specs['spree_core'].version -unless spree_version >= Gem::Version.create('3.4.0') && spree_version < Gem::Version.create('3.5.0') - Deface::Override.new( - virtual_path: 'spree/products/index', - name: 'add_products_searched_to_products_list', - insert_before: '[data-hook="search_results"]', - text: <<-HTML - <%= render partial: 'spree/shared/trackers/segment/products_searched', formats: :js %> - HTML - ) -end diff --git a/app/overrides/add_segment_initializer_to_layout.rb b/app/overrides/add_segment_initializer_to_layout.rb deleted file mode 100644 index 65503536..00000000 --- a/app/overrides/add_segment_initializer_to_layout.rb +++ /dev/null @@ -1,11 +0,0 @@ -spree_version = Gem.loaded_specs['spree_core'].version -unless spree_version >= Gem::Version.create('3.3.0') && spree_version < Gem::Version.create('3.5.0') && spree_version != Gem::Version.create('3.5.0.alpha') - Deface::Override.new( - virtual_path: 'spree/shared/_head', - name: 'add_segment_initializer_to_layout', - insert_after: 'title', - text: <<-HTML - <%= render partial: 'spree/shared/trackers/segment/initializer', formats: :js %> - HTML - ) -end diff --git a/app/overrides/add_segment_page_viewed_to_layout.rb b/app/overrides/add_segment_page_viewed_to_layout.rb deleted file mode 100644 index c62c9fdc..00000000 --- a/app/overrides/add_segment_page_viewed_to_layout.rb +++ /dev/null @@ -1,11 +0,0 @@ -spree_version = Gem.loaded_specs['spree_core'].version -unless spree_version >= Gem::Version.create('3.3.0') && spree_version < Gem::Version.create('3.5.0') && spree_version != Gem::Version.create('3.5.0.alpha') - Deface::Override.new( - virtual_path: 'spree/shared/_head', - name: 'add_segment_page_tracker_to_body', - insert_before: 'meta', - text: <<-HTML - <%= render partial: 'spree/shared/trackers/segment/page_viewed', formats: :js %> - HTML - ) -end diff --git a/app/presenters/spree_analytics_trackers/base_presenter.rb b/app/presenters/spree_analytics_trackers/base_presenter.rb index 3bc82e3d..91c64b51 100644 --- a/app/presenters/spree_analytics_trackers/base_presenter.rb +++ b/app/presenters/spree_analytics_trackers/base_presenter.rb @@ -7,7 +7,7 @@ def initialize(resource = {}, options = {}) @options = options end - def to_json + def to_json(*_args) serialize_resource(@resource, @options).to_json end end diff --git a/app/presenters/spree_analytics_trackers/segment/order_presenter.rb b/app/presenters/spree_analytics_trackers/segment/order_presenter.rb index cfdf496a..6d162082 100644 --- a/app/presenters/spree_analytics_trackers/segment/order_presenter.rb +++ b/app/presenters/spree_analytics_trackers/segment/order_presenter.rb @@ -3,7 +3,7 @@ module Segment class OrderPresenter < SpreeAnalyticsTrackers::BasePresenter private - def serialize_resource(resource, options = {}) + def serialize_resource(resource, _options = {}) { order_id: resource.number.to_s, total: resource.total&.to_f, @@ -16,8 +16,6 @@ def serialize_resource(resource, options = {}) } end - private - def serialize_line_item(line_item) { product_id: line_item.product_id&.to_s, diff --git a/app/presenters/spree_analytics_trackers/segment/product_presenter.rb b/app/presenters/spree_analytics_trackers/segment/product_presenter.rb deleted file mode 100644 index 7bf013fd..00000000 --- a/app/presenters/spree_analytics_trackers/segment/product_presenter.rb +++ /dev/null @@ -1,40 +0,0 @@ -module SpreeAnalyticsTrackers - module Segment - class ProductPresenter < SpreeAnalyticsTrackers::BasePresenter - private - - def serialize_resource(resource, options = {}) - { - resource_id: resource.id.to_s, - sku: resource.sku&.to_s, - category: resource.category&.name, - name: resource.name, - brand: brand_name, - price: resource.price_in(current_currency).amount&.to_f, - currency: current_currency, - url: resource_url(resource) - }.tap do |hash| - hash[:image_url] = segment_image_url(hash, options) - end.merge(options) - end - - def segment_image_url(hash, options) - - end - - def brand_name - resource.vendor.name if defined?(SpreeMultiVendor) && resource.defined?(:vendor) && resource.vendor.present? - - resource.brand&.name - end - - def current_currency - @current_currency ||= options[:current_currency] - end - - def locale - @locale ||= options[:locale] - end - end - end -end diff --git a/app/views/spree/checkout/_address.html.erb b/app/views/spree/checkout/_address.html.erb new file mode 100644 index 00000000..fd602234 --- /dev/null +++ b/app/views/spree/checkout/_address.html.erb @@ -0,0 +1,73 @@ +<% if !try_spree_current_user || try_spree_current_user.email.blank? %> +
+ <%= Spree.t(:payment_type).upcase %> +
+ +<%= Spree.t('cart_page.empty_info').html_safe %>
+<%= Spree.t(:order_success_explain) %>
+ <% end %> + ++ <%= accurate_title %> / <%= pretty_date(@order.completed_at) %> +
+ <%= render partial: 'spree/shared/order_details', locals: { order: @order } %> +