Spree-spl is a plugin that provides a promotion switcher for Spree, enabling enhanced loyalty program functionality.
Add spree-spl to your Gemfile and run bundle install:
gem 'spree-seo'After installation, add the following methods to CartControllerDecorator:
promotion_switcher(spree_current_order, spree_current_user, check_only)
spree_current_order.reloadThese methods must be manually added to your repository in the Storefront endpoints:
add_itemset_quantity
Add the following method to AccountControllerDecorator:
module AccountControllerDecorator
def user_update_params
public_metadata = super['public_metadata']
params = super
if public_metadata['spl_no_card'].present? && public_metadata['spl_card_active'].nil?
update_order(spl_card: public_metadata['spl_no_card'], active: true)
params[:public_metadata] = params[:public_metadata].merge({ 'spl_card_active' => true })
elsif public_metadata['spl_no_card'].present?
update_order(spl_card: public_metadata['spl_no_card'], active: public_metadata['spl_card_active'])
else
update_order(spl_card: public_metadata['spl_no_card'])
end
public_metadata['spl_no_card'].present? ? params : super
end
endAdditionally, the following methods must be manually added to your repository in the Storefront endpoint associate:
promotion_switcher(spree_current_order, spree_current_user, check_only)
spree_current_order.reloadFor the Storefront endpoint apply_coupon_code, add the following method before the coupon_handler method:
switch_spl_active_param(spree_current_order, spree_current_user, check_only)Then, before render_error_payload, include:
unless [:coupon_code_already_applied].include?(result.status_code)
maintain_spl_adjustments(spree_current_order, spree_current_user)
endFinally, for the Storefront endpoint remove_coupon_code, manually add the following methods to your repository:
switch_spl_active_param(spree_current_order, spree_current_user, check_only)
spree_current_order.reloadNext, add the following methods to CheckoutControllerDecorator:
promotion_switcher(result.value, spree_current_user, check_only)These methods must be manually added to your repository in the Storefront endpoints before render_order:
updatecomplete
Also, add the following methods manually to AdjustmentUpdaterDecorator to method persist_totals:
set_spree_adjustments if shipment_with_adjustments? || order_with_adjustments?
recalculate_spl_adjustments(attributes, totals) if line_item_with_spl_adjustments?To run tests type in terminal:
bundle update
bundle exec rake test_app
bundle exec rspec