Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

module SolidusSubscriptions
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

module SolidusSubscriptions
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

module SolidusSubscriptions
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

module SolidusSubscriptions
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

module SolidusSubscriptions
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
8 changes: 0 additions & 8 deletions app/overrides/views/admin_subscribable_product_checkbox.rb

This file was deleted.

8 changes: 0 additions & 8 deletions app/overrides/views/admin_subscribable_variant_checkbox.rb

This file was deleted.

10 changes: 0 additions & 10 deletions app/overrides/views/admin_subscriptions_menu_link.rb

This file was deleted.

8 changes: 0 additions & 8 deletions app/overrides/views/admin_users_subscriptions_tab.rb

This file was deleted.

8 changes: 0 additions & 8 deletions app/overrides/views/subscription_line_item_fields.rb

This file was deleted.

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
Comment on lines -12 to -13
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess my only concern is this. Is this safe? Do we need to do something different to handle legacy versus new promotions engines?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jarednorman Man, like really, from the bottom of my heart, could you be more specific, I am sure when you write this kind of comments you already have a very specific way in mind to do it.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mamhoff can you see anything that you dislike?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And I wish that the PR explained why this seemingly random line was removed, but it doesn't even mention it. 🤷🏻‍♂️

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jarednorman that is actually a tangible point and helps much more than the previous comment!!!

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jarednorman hey, sorry for replying so late. The issue of the removal of ::Spree::PromotionHandler::Cart.new(line_item.order).activate was discussed here: gms-electronics#1 If you have something else to consider please tell us.

line_item.order.recalculate
end

Expand Down