Class: SolidusConfigurableKits::PriceSelector

Inherits:
Spree::Variant::PriceSelector
  • Object
show all
Defined in:
app/services/solidus_configurable_kits/price_selector.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.pricing_options_classObject



5
6
7
# File 'app/services/solidus_configurable_kits/price_selector.rb', line 5

def self.pricing_options_class
  SolidusConfigurableKits::PricingOptions
end

Instance Method Details

#price_for(price_options) ⇒ Spree::Money?

The variant’s price, given a set of pricing options

Parameters:

  • price_options (Spree::Variant::PricingOptions)

    Pricing Options to abide by

Returns:

  • (Spree::Money, nil)

    The most specific price for this set of pricing options.



12
13
14
15
16
17
18
19
20
# File 'app/services/solidus_configurable_kits/price_selector.rb', line 12

def price_for(price_options)
  ::Spree::Deprecation.warn(
    "price_for is deprecated and will be removed. The price_for method
    should return a Spree::Price as described. Please use
    #price_for_options and adjust your frontend code to explicitly call
    &.money where required"
  )
  price_for_options(price_options)&.money
end

#price_for_options(price_options) ⇒ Spree::Price?

The variant’s Spree::Price record, given a set of pricing options

Parameters:

  • price_options (Spree::Variant::PricingOptions)

    Pricing Options to abide by

Returns:

  • (Spree::Price, nil)

    The most specific price for this set of pricing options.



25
26
27
28
29
30
31
32
# File 'app/services/solidus_configurable_kits/price_selector.rb', line 25

def price_for_options(price_options)
  variant.currently_valid_prices.detect do |price|
    (price.country_iso == price_options.desired_attributes[:country_iso] ||
      price.country_iso.nil?
    ) && price.currency == price_options.desired_attributes[:currency] &&
    price.kit_item == price_options.desired_attributes[:kit_item]
  end
end