Skip to content

Commit

Permalink
Update gem to support the latest Solidus version(4.4)
Browse files Browse the repository at this point in the history
  • Loading branch information
shahmayur001 committed Dec 6, 2024
1 parent fe9b6d5 commit 86cf5eb
Show file tree
Hide file tree
Showing 11 changed files with 100 additions and 61 deletions.
16 changes: 10 additions & 6 deletions app/overrides/views/admin_subscribable_product_checkbox.rb
Original file line number Diff line number Diff line change
@@ -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
16 changes: 10 additions & 6 deletions app/overrides/views/admin_subscribable_variant_checkbox.rb
Original file line number Diff line number Diff line change
@@ -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
18 changes: 11 additions & 7 deletions app/overrides/views/admin_subscriptions_menu_link.rb
Original file line number Diff line number Diff line change
@@ -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
16 changes: 10 additions & 6 deletions app/overrides/views/admin_users_subscriptions_tab.rb
Original file line number Diff line number Diff line change
@@ -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
16 changes: 10 additions & 6 deletions app/overrides/views/subscription_line_item_fields.rb
Original file line number Diff line number Diff line change
@@ -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
7 changes: 0 additions & 7 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,39 @@
<%= content_tag :h3, t('.subscription_fields') %>
<%= fields_for :'subscription_line_item', SolidusSubscriptions::LineItem.new do |ff| %>
<div>
<%= ff.label :quantity, t('.quantity') %>
<%= ff.number_field :quantity %>
<%= ff.label :quantity, t('.quantity_suffix') %>
</div>

<div>
<%= 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 %>
</div>

<%= ff.hidden_field :subscribable_id %>
<% if @product.subscribable %>
<%= content_tag :h3, t('.subscription_fields') %>
<%= fields_for :'subscription_line_item', SolidusSubscriptions::LineItem.new do |ff| %>
<div>
<%= ff.label :quantity, t('.quantity') %>
<%= ff.number_field :quantity %>
<%= ff.label :quantity, t('.quantity_suffix') %>
</div>

<div>
<%= 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 %>
</div>

<%= ff.hidden_field :subscribable_id %>
<% end %>
<% end %>

<script>
document.addEventListener("DOMContentLoaded", function(e) {
var cartForm = document.querySelector('.product-page__info form');
var cartForm = document.querySelector('form[action="/cart_line_items"]');

cartForm.addEventListener('submit', function(e) {
var quantityInput = e.target.querySelector('[name*="quantity"]');
var subscriptionQuantityInput = e.target.querySelector('[name*="subscribable_id"]');
var variantInput = e.target.querySelector('[name*="variant_id"]:checked');
var subscribableInput = e.target.querySelector('[name*="subscription_line_item[subscribable_id]"]');

if (!variantInput) {
variantInput = cartForm.querySelector('[name="variant_id"]');
}

subscribableInput.value = variantInput.value;

subscriptionQuantityInput.value = quantityInput.value;
return true;
});
});
</script>

1 change: 0 additions & 1 deletion lib/solidus_subscriptions/checkout.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions lib/solidus_subscriptions/permission_sets/default_customer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions lib/solidus_subscriptions/subscription_line_item_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 86cf5eb

Please sign in to comment.