Skip to content
This repository was archived by the owner on Mar 31, 2026. It is now read-only.
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
5 changes: 5 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 2
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
Metrics/MethodLength:
Max: 11

# Offense count: 1
# Configuration parameters: Mode, AllowedMethods, AllowedPatterns, AllowBangMethods, WaywardPredicates.
# AllowedMethods: call
Expand Down
15 changes: 0 additions & 15 deletions app/models/order_updater_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,4 @@ def perform_update_sparta_state_job # rubocop:disable Metrics/AbcSize
UpdateSpartaStateJob.perform_later(order.token, 'D', order.number, order.store) if order.payment_state == 'paid'
UpdateSpartaStateJob.perform_later(order.token, 'C', order.number, order.store) if order.state == 'canceled'
end

def check_spl_adjustments # rubocop:disable Metrics/MethodLength
if order.public_metadata['spl_card_active'] == true
updated_any_adjustment = false
order.adjustments.each do |adjustment|
if adjustment.source_type != 'SPL' && adjustment.eligible?
adjustment.update(eligible: false)
updated_any_adjustment = true
end
end
updated_any_adjustment
else
false
end
end
end
20 changes: 7 additions & 13 deletions app/models/spree/adjustable/adjustments_updater_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,22 @@
module Spree
module Adjustable
module AdjustmentsUpdaterDecorator
SPL_SOURCE_TYPE = 'SPL'

private

def set_spree_adjustments
adjustable = @adjustable.is_a?(::Spree::Order) ? @adjustable : @adjustable.order

@adjustable.adjustments.destroy_all if adjustable.public_metadata[:spl_card_active]
end

def shipment_with_adjustments?
@adjustable.is_a?(::Spree::Shipment) && @adjustable.order.public_metadata.key?(:spl_card_active)
end

def order_with_adjustments?
@adjustable.is_a?(::Spree::Order) && @adjustable.public_metadata.key?(:spl_card_active)
@adjustable.is_a?(::Spree::Order) ? @adjustable : @adjustable.order
end

def line_item_with_spl_adjustments?
@adjustable.is_a?(::Spree::LineItem) && @adjustable.adjustments.any? { |adj| adj.source_type == 'SPL' }
@adjustable.is_a?(::Spree::LineItem) && @adjustable.adjustments.any? { |adj| adj.source_type == SPL_SOURCE_TYPE }
end

def recalculate_spl_adjustments(attributes, totals)
sparta_adjustments = @adjustable.adjustments.select { |adj| adj.source_type == 'SPL' && adj.eligible? }
sparta_adjustments = @adjustable.adjustments.select do |adj|
adj.source_type == SPL_SOURCE_TYPE && adj.eligible?
end
total_adjustment_amount = sparta_adjustments.sum(&:amount)
assign_spl_totals(attributes, total_adjustment_amount, Time.current)
@adjustable.update_columns(totals)
Expand Down
16 changes: 7 additions & 9 deletions app/services/promotion_switcher_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@ def initialize(order, check_only)
@order = order
end

def call # rubocop:disable Metrics/AbcSize
return unless order.public_metadata.key?(:spl_card_active)

apply_sparta_discount(order, check_only) if cast_boolean(order.public_metadata[:spl_card_active])
remove_sparta_discount(order) unless cast_boolean(order.public_metadata[:spl_card_active])
def call
apply_sparta_discount(order, check_only)
rescue StandardError => e
Rails.logger.error("[PromotionSwitcher] Failed for Order #{order.id}: #{e.message}")
remove_sparta_discount(order)
Expand All @@ -25,10 +22,11 @@ def call # rubocop:disable Metrics/AbcSize
attr_accessor :check_only, :line_items, :order

def apply_sparta_discount(order, check_only)
return unless order.line_items.any? && order.public_metadata['spl_no_card'].present?
return unless order.line_items.any?

card_number = prepare_card_number_if_exist(order.public_metadata)
spl_response = Spl::SpartaLoyaltyService.new(order.token,
order.public_metadata['spl_no_card'],
card_number,
order.line_items,
DateTime.current,
order.products,
Expand All @@ -43,7 +41,7 @@ def create_sparta_adjustments(spl_response, order)
ApplySpartaDiscountService.new(spl_response, order).call
end

def remove_sparta_discount(order)
RemoveSpartaDiscountService.destroy_all_sparta_adjustments(order)
def prepare_card_number_if_exist(metadata)
cast_boolean(metadata[:spl_card_active]) ? metadata['spl_no_card'] : ''
end
end
2 changes: 1 addition & 1 deletion app/services/spl/login_account_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def send_request(url, body)
Spl::SendRequestService.new(url, body).call
end

def prepare_login_body # rubocop:disable Metrics/MethodLength
def prepare_login_body
{
context: {
prgCode: @store.private_metadata['spl_prg_code']
Expand Down
15 changes: 0 additions & 15 deletions app/services/spree/cart/recalculate_decorator.rb

This file was deleted.

4 changes: 0 additions & 4 deletions config/initializers/spree_spl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@
Spree::Adjustable::AdjustmentsUpdaterDecorator
)

::Spree::Cart::Recalculate.prepend(
Spree::Cart::RecalculateDecorator
)

::Spree::PromotionHandler::Cart.prepend(
CartDecorator
)
Expand Down
Loading