Class: Item::Materials::Checks::CerazorbLimit

Inherits:
BaseService
  • Object
show all
Defined in:
app/services/item/materials/checks/cerazorb_limit.rb

Overview

OBSOLETE DO NOT USE ####
Cerazorb is no longer sold, ThermalSheet does not have these constraints

Defined Under Namespace

Classes: Result

Constant Summary collapse

THRESHOLD_MAX =

Threshold max.

100

Instance Method Summary collapse

Instance Method Details

#cz_2x2_lines(container) ⇒ Object (protected)



41
42
43
# File 'app/services/item/materials/checks/cerazorb_limit.rb', line 41

def cz_2x2_lines(container)
  container.line_items.joins(:item).where(items: { sku: %w[CZRG-SH5MM-24X24 CZRG-SH5MM-24X24-P12] })
end

#cz_2x2_quantities(container) ⇒ Object (protected)



45
46
47
# File 'app/services/item/materials/checks/cerazorb_limit.rb', line 45

def cz_2x2_quantities(container)
  cz_2x2_lines(container).sum { |li| li.item.is_kit? ? li.quantity * li.item.kit_target_item_relations.sum(:quantity) : li.quantity }
end

#process(container:, options: {}) ⇒ Result

rubocop:disable Lint/UnusedMethodArgument
options: is part of the shared Item::Materials::Checks polymorphic API
invoked by Item::Materials::Check#perform_checks_raw. Even though this
particular check ignores the value, the kwarg name has to stay as
options: so the bulk dispatch site keeps working.
:reek:UnusedParameters

Parameters:

  • container (Quote, Order, RoomConfiguration)

    the resource to check

  • options (Hash) (defaults to: {})

    shared check options passed by Item::Materials::Check

Options Hash (options:):

  • :for_www (Boolean)

    whether the check runs for the public site

  • :for_cart (Boolean)

    whether the check runs for the cart

Returns:

  • (Result)

    status and any material alerts



28
29
30
31
32
33
34
35
36
37
# File 'app/services/item/materials/checks/cerazorb_limit.rb', line 28

def process(container:, options: {})
  # rubocop:enable Lint/UnusedMethodArgument
  return Result.new(status: :skipped) unless qualify?(container)

  material_alerts = []
  if (qty = cz_2x2_quantities(container)) > THRESHOLD_MAX
    material_alerts << Item::Materials::Alert.new(name: "You're exceeding the maximum recommended number of 2x2 Cerazorb sheets (#{qty}, maximum recommended: #{THRESHOLD_MAX}), please switch to 4x4 sheets", container: container)
  end
  Result.new(status: :ok, alerts: material_alerts)
end

#qualify?(container) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
# File 'app/services/item/materials/checks/cerazorb_limit.rb', line 13

def qualify?(container)
  cz_2x2_lines(container).exists?
end