From 86cf5eb17ac5fcfe767da424b9b2c779ddb478e3 Mon Sep 17 00:00:00 2001 From: Mayur Shah Date: Thu, 5 Dec 2024 16:12:02 +0530 Subject: [PATCH] Update gem to support the latest Solidus version(4.4) --- .../admin_subscribable_product_checkbox.rb | 16 +++--- .../admin_subscribable_variant_checkbox.rb | 16 +++--- .../views/admin_subscriptions_menu_link.rb | 18 ++++--- .../views/admin_users_subscriptions_tab.rb | 16 +++--- .../views/subscription_line_item_fields.rb | 16 +++--- config/locales/en.yml | 7 --- .../_subscription_fields.html.erb | 49 +++++++++++-------- lib/solidus_subscriptions/checkout.rb | 1 - .../permission_sets/default_customer.rb | 10 ++++ .../subscription_management.rb | 10 ++++ .../subscription_line_item_builder.rb | 2 - 11 files changed, 100 insertions(+), 61 deletions(-) diff --git a/app/overrides/views/admin_subscribable_product_checkbox.rb b/app/overrides/views/admin_subscribable_product_checkbox.rb index aafa2ef9..d15d5025 100644 --- a/app/overrides/views/admin_subscribable_product_checkbox.rb +++ b/app/overrides/views/admin_subscribable_product_checkbox.rb @@ -1,8 +1,12 @@ # frozen_string_literal: true -Deface::Override.new( - virtual_path: "spree/admin/products/_form", - name: "solidus_subscriptions_product_subscribable_checkbox", - insert_after: "[data-hook='admin_product_form_promotionable']", - partial: "spree/admin/products/subscribable_checkbox" -) +module Views + module AdminSubscribableProductCheckbox + Deface::Override.new( + virtual_path: "spree/admin/products/_form", + name: "solidus_subscriptions_product_subscribable_checkbox", + insert_after: "[data-hook='admin_product_form_promotionable']", + partial: "spree/admin/products/subscribable_checkbox" + ) + end +end diff --git a/app/overrides/views/admin_subscribable_variant_checkbox.rb b/app/overrides/views/admin_subscribable_variant_checkbox.rb index 744fee5f..057e9476 100644 --- a/app/overrides/views/admin_subscribable_variant_checkbox.rb +++ b/app/overrides/views/admin_subscribable_variant_checkbox.rb @@ -1,8 +1,12 @@ # frozen_string_literal: true -Deface::Override.new( - virtual_path: "spree/admin/variants/_form", - name: "solidus_subscriptions_variant_subscribable_checkbox", - insert_after: "[data-hook='track_inventory']", - partial: "spree/admin/variants/subscribable_checkbox" -) +module Views + module AdminSubscribableVariantCheckbox + Deface::Override.new( + virtual_path: "spree/admin/variants/_form", + name: "solidus_subscriptions_variant_subscribable_checkbox", + insert_after: "[data-hook='track_inventory']", + partial: "spree/admin/variants/subscribable_checkbox" + ) + end +end diff --git a/app/overrides/views/admin_subscriptions_menu_link.rb b/app/overrides/views/admin_subscriptions_menu_link.rb index aaffe33c..d99bd384 100644 --- a/app/overrides/views/admin_subscriptions_menu_link.rb +++ b/app/overrides/views/admin_subscriptions_menu_link.rb @@ -1,10 +1,14 @@ # frozen_string_literal: true -if !Spree::Backend::Config.respond_to?(:menu_items) - Deface::Override.new( - virtual_path: 'spree/admin/shared/_menu', - name: :add_subcriptions_admin_link, - insert_bottom: "[data-hook='admin_tabs']", - partial: 'spree/admin/shared/subscription_tab' - ) +module Views + module AdminSubscriptionsMenuLink + if !Spree::Backend::Config.respond_to?(:menu_items) + Deface::Override.new( + virtual_path: 'spree/admin/shared/_menu', + name: :add_subcriptions_admin_link, + insert_bottom: "[data-hook='admin_tabs']", + partial: 'spree/admin/shared/subscription_tab' + ) + end + end end diff --git a/app/overrides/views/admin_users_subscriptions_tab.rb b/app/overrides/views/admin_users_subscriptions_tab.rb index a69e16d4..dcb92667 100644 --- a/app/overrides/views/admin_users_subscriptions_tab.rb +++ b/app/overrides/views/admin_users_subscriptions_tab.rb @@ -1,8 +1,12 @@ # frozen_string_literal: true -Deface::Override.new( - virtual_path: 'spree/admin/users/_tabs', - name: 'solidus_subscriptions_admin_users_subscriptions_tab', - insert_bottom: "[data-hook='admin_user_tab_options']", - partial: 'spree/admin/users/subscription_tab' -) +module Views + module AdminUsersSubscriptionsTab + Deface::Override.new( + virtual_path: 'spree/admin/users/_tabs', + name: 'solidus_subscriptions_admin_users_subscriptions_tab', + insert_bottom: "[data-hook='admin_user_tab_options']", + partial: 'spree/admin/users/subscription_tab' + ) + end +end diff --git a/app/overrides/views/subscription_line_item_fields.rb b/app/overrides/views/subscription_line_item_fields.rb index a076026b..ea6864a1 100644 --- a/app/overrides/views/subscription_line_item_fields.rb +++ b/app/overrides/views/subscription_line_item_fields.rb @@ -1,8 +1,12 @@ # frozen_string_literal: true -Deface::Override.new( - virtual_path: "spree/products/_cart_form", - name: "subscription_line_item_fields", - insert_after: "[data-hook='inside_product_cart_form']", - partial: "spree/frontend/products/subscription_line_item_fields" -) +module Views + module SubscriptionLineItemFields + Deface::Override.new( + virtual_path: "spree/products/_cart_form", + name: "subscription_line_item_fields", + insert_after: "[data-hook='inside_product_cart_form']", + partial: "spree/frontend/products/subscription_line_item_fields" + ) + end +end diff --git a/config/locales/en.yml b/config/locales/en.yml index 48f7ab2e..c1c1fce3 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -82,13 +82,6 @@ en: name: Subscription Order description: Order fulfills a subscription - products: - cart_form: - quantity: I want - quantity_suffix: items - interval_length: every - subscription_fields: Subscription Settings - activerecord: attributes: solidus_subscriptions/line_item/interval_units: diff --git a/lib/generators/solidus_subscriptions/install/templates/app/views/cart_line_items/_subscription_fields.html.erb b/lib/generators/solidus_subscriptions/install/templates/app/views/cart_line_items/_subscription_fields.html.erb index e7088aa3..dfda14f1 100644 --- a/lib/generators/solidus_subscriptions/install/templates/app/views/cart_line_items/_subscription_fields.html.erb +++ b/lib/generators/solidus_subscriptions/install/templates/app/views/cart_line_items/_subscription_fields.html.erb @@ -1,30 +1,39 @@ -<%= content_tag :h3, t('.subscription_fields') %> -<%= fields_for :'subscription_line_item', SolidusSubscriptions::LineItem.new do |ff| %> -
- <%= ff.label :quantity, t('.quantity') %> - <%= ff.number_field :quantity %> - <%= ff.label :quantity, t('.quantity_suffix') %> -
- -
- <%= ff.label :interval_length, t('.interval_length') %> - <%= ff.number_field :interval_length %> - - <%= ff.collection_radio_buttons :interval_units, SolidusSubscriptions::LineItem.interval_units.to_a, :first, :first %> -
- - <%= ff.hidden_field :subscribable_id %> +<% if @product.subscribable %> + <%= content_tag :h3, t('.subscription_fields') %> + <%= fields_for :'subscription_line_item', SolidusSubscriptions::LineItem.new do |ff| %> +
+ <%= ff.label :quantity, t('.quantity') %> + <%= ff.number_field :quantity %> + <%= ff.label :quantity, t('.quantity_suffix') %> +
+ +
+ <%= ff.label :interval_length, t('.interval_length') %> + <%= ff.number_field :interval_length %> + + <%= ff.collection_radio_buttons :interval_units, SolidusSubscriptions::LineItem.interval_units.to_a, :first, :first %> +
+ + <%= ff.hidden_field :subscribable_id %> + <% end %> <% end %> + diff --git a/lib/solidus_subscriptions/checkout.rb b/lib/solidus_subscriptions/checkout.rb index 7bed8235..9b39f3a1 100644 --- a/lib/solidus_subscriptions/checkout.rb +++ b/lib/solidus_subscriptions/checkout.rb @@ -42,7 +42,6 @@ def populate_order(order) end def finalize_order(order) - ::Spree::PromotionHandler::Cart.new(order).activate order.recalculate order.checkout_steps[0...-1].each do diff --git a/lib/solidus_subscriptions/permission_sets/default_customer.rb b/lib/solidus_subscriptions/permission_sets/default_customer.rb index 499e920f..28fcf2c4 100644 --- a/lib/solidus_subscriptions/permission_sets/default_customer.rb +++ b/lib/solidus_subscriptions/permission_sets/default_customer.rb @@ -3,6 +3,16 @@ module SolidusSubscriptions module PermissionSets class DefaultCustomer < ::Spree::PermissionSets::Base + class << self + def privilege + :customer + end + + def category + :subscription + end + end + def activate! can [:show, :display, :update, :skip, :cancel, :pause, :resume], Subscription, ['user_id = ?', user.id] do |subscription, guest_token| (subscription.guest_token.present? && subscription.guest_token == guest_token) || diff --git a/lib/solidus_subscriptions/permission_sets/subscription_management.rb b/lib/solidus_subscriptions/permission_sets/subscription_management.rb index f96ed53f..46551db3 100644 --- a/lib/solidus_subscriptions/permission_sets/subscription_management.rb +++ b/lib/solidus_subscriptions/permission_sets/subscription_management.rb @@ -3,6 +3,16 @@ module SolidusSubscriptions module PermissionSets class SubscriptionManagement < ::Spree::PermissionSets::Base + class << self + def privilege + :manage + end + + def category + :subscription + end + end + def activate! can :manage, Subscription can :manage, LineItem diff --git a/lib/solidus_subscriptions/subscription_line_item_builder.rb b/lib/solidus_subscriptions/subscription_line_item_builder.rb index 73541023..303c4de0 100644 --- a/lib/solidus_subscriptions/subscription_line_item_builder.rb +++ b/lib/solidus_subscriptions/subscription_line_item_builder.rb @@ -9,8 +9,6 @@ def create_subscription_line_item(line_item) subscription_params.merge(spree_line_item: line_item) ) - # Rerun the promotion handler to pickup subscription promotions - ::Spree::PromotionHandler::Cart.new(line_item.order).activate line_item.order.recalculate end