-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
upgraded controllers and models to modules also upgraded overrides an… #66
base: master
Are you sure you want to change the base?
Changes from 7 commits
a12c622
4d8a1fc
de25ceb
aaabf51
71ea88a
0450149
d9c5a47
9c4d34f
4222d9b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
Spree.ready(function($) { | ||
Spree.addToCartFormSubmissionOptions = function() { | ||
$cartForm = $(ADD_TO_CART_FORM_SELECTOR); | ||
if($cartForm.find('.cart_radio_button:checked').val() == ".subscription_options") { | ||
options = { | ||
subscribe: true, | ||
subscription_frequency_id: $cartForm.find('#subscription_subscription_frequency_id option:selected').val(), | ||
delivery_number: parseInt($cartForm.find('#subscription_delivery_number').val()) | ||
}; | ||
return options; | ||
} | ||
return {}; | ||
} | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
// Placeholder manifest file. | ||
//= require spree/frontend/cart_radio_button.js | ||
//= require spree/frontend/datepicker | ||
//= require spree/frontend/cart_form_subscription_button | ||
//= require spree/frontend/ajax_handler.js | ||
//= require spree/frontend/update_quantity_in_cart | ||
// the installer will append this file to the app vendored assets here: vendor/assets/javascripts/spree/frontend/all.js' |
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module SpreeProductSubscriptions | ||
module BaseControllerDecorator | ||
|
||
def self.prepended(base) | ||
base.add_flash_types :success, :error | ||
end | ||
|
||
end | ||
end | ||
|
||
Spree::BaseController.prepend SpreeProductSubscriptions::BaseControllerDecorator |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module SpreeProductSubscriptions::LineItemsControllerDecorator | ||
|
||
def self.prepended(base) | ||
base.line_item_options += [:subscribe, :delivery_number, :subscription_frequency_id] | ||
end | ||
|
||
|
||
end | ||
|
||
Spree::Api::V1::LineItemsController.prepend SpreeProductSubscriptions::LineItemsControllerDecorator |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module SpreeProductSubscriptions::UsersControllerDecorator | ||
|
||
def self.prepended(base) | ||
base.before_action :load_subscriptions, only: :show | ||
end | ||
|
||
private | ||
|
||
def load_subscriptions | ||
@orders = @user.orders.complete.order(completed_at: :desc) | ||
@subscriptions = Spree::Subscription.active.order(created_at: :desc).with_parent_orders(@orders) | ||
end | ||
|
||
end | ||
|
||
Spree::UsersController.prepend SpreeProductSubscriptions::UsersControllerDecorator |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,20 +95,20 @@ def number_of_deliveries_left | |
|
||
def pause | ||
run_callbacks :pause do | ||
update_attributes(paused: true) | ||
update(paused: true) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lets discuss |
||
end | ||
end | ||
|
||
def unpause | ||
run_callbacks :unpause do | ||
update_attributes(paused: false) | ||
update(paused: false) | ||
end | ||
end | ||
|
||
def cancel | ||
self.cancelled = true | ||
run_callbacks :cancel do | ||
update_attributes(cancelled_at: Time.current) | ||
update(cancelled_at: Time.current) | ||
end | ||
end | ||
|
||
|
@@ -189,7 +189,12 @@ def make_new_order | |
end | ||
|
||
def add_variant_to_order(order) | ||
order.contents.add(variant, quantity) | ||
# order.contents.add(variant, quantity) Contents removed from Spree 4 | ||
Spree::Cart::AddItem.call( | ||
order: order, | ||
variant: variant, | ||
quantity: quantity | ||
) | ||
order.next | ||
end | ||
|
||
|
@@ -236,7 +241,7 @@ def confirm_order(order) | |
def order_attributes | ||
{ | ||
currency: parent_order.currency, | ||
guest_token: parent_order.guest_token, | ||
token: parent_order.token, | ||
store: parent_order.store, | ||
user: parent_order.user, | ||
created_by: parent_order.user, | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
module SpreeProductSubscriptions::OrderDecorator | ||
|
||
def self.prepended(base) | ||
base.has_one :order_subscription, class_name: "Spree::OrderSubscription", dependent: :destroy | ||
base.has_one :parent_subscription, through: :order_subscription, source: :subscription | ||
base.has_many :subscriptions, class_name: "Spree::Subscription", | ||
foreign_key: :parent_order_id, | ||
dependent: :restrict_with_error | ||
base.after_update :update_subscriptions | ||
base.state_machine.after_transition to: :complete, do: :enable_subscriptions, if: :any_disabled_subscription? | ||
base.alias_attribute :guest_token, :token | ||
end | ||
|
||
private | ||
|
||
def enable_subscriptions | ||
subscriptions.each do |subscription| | ||
subscription.update( | ||
source: payments.from_credit_card.first.source, | ||
enabled: true, | ||
ship_address: ship_address.clone, | ||
bill_address: bill_address.clone | ||
) | ||
end | ||
end | ||
|
||
def any_disabled_subscription? | ||
subscriptions.disabled.any? | ||
end | ||
|
||
def update_subscriptions | ||
line_items.each do |line_item| | ||
if line_item.subscription_attributes_present? | ||
subscriptions.find_by(variant: line_item.variant).update(line_item.updatable_subscription_attributes) | ||
end | ||
end | ||
end | ||
end | ||
|
||
Spree::Order.prepend SpreeProductSubscriptions::OrderDecorator |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module SpreeProductSubscriptions::ProductDecorator | ||
|
||
def self.prepended(base) | ||
base.has_many :subscriptions, through: :variants_including_master, source: :subscriptions, dependent: :restrict_with_error | ||
base.has_many :product_subscription_frequencies, class_name: "Spree::ProductSubscriptionFrequency", dependent: :destroy | ||
base.has_many :subscription_frequencies, through: :product_subscription_frequencies, dependent: :destroy | ||
base.validates :subscription_frequencies, presence: true, if: :subscribable? | ||
base.scope :subscribable, -> { where(subscribable: true) } | ||
base.whitelisted_ransackable_attributes += %w( is_subscribable ) | ||
base.alias_attribute :subscribable, :is_subscribable | ||
end | ||
|
||
end | ||
|
||
Spree::Product.prepend SpreeProductSubscriptions::ProductDecorator |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module SpreeProductSubscriptions::VariantDecorator | ||
|
||
|
||
def self.prepended(base) | ||
base.has_many :subscriptions, class_name: "Spree::Subscription", dependent: :restrict_with_error | ||
base.delegate :variants_including_master, to: :product, prefix: true | ||
base.alias_method :product_variants, :product_variants_including_master | ||
end | ||
|
||
end | ||
|
||
Spree::Variant.prepend SpreeProductSubscriptions::VariantDecorator |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
Deface::Override.new( | ||
virtual_path: "spree/products/_cart_form", | ||
name: "add_checkboxes_to_cart_form", | ||
insert_before: ".add-to-cart", | ||
insert_after: "hr:last", | ||
partial: "spree/products/cart_checkboxes" | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets discuss