Class: Spree::Pricing::Context
- Inherits:
-
Object
- Object
- Spree::Pricing::Context
- Defined in:
- lib/spree/core/pricing/context.rb
Instance Attribute Summary collapse
-
#currency ⇒ Object
readonly
Returns the value of attribute currency.
-
#date ⇒ Object
readonly
Returns the value of attribute date.
-
#order ⇒ Object
readonly
Returns the value of attribute order.
-
#quantity ⇒ Object
readonly
Returns the value of attribute quantity.
-
#store ⇒ Object
readonly
Returns the value of attribute store.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
-
#variant ⇒ Object
readonly
Returns the value of attribute variant.
-
#zone ⇒ Object
readonly
Returns the value of attribute zone.
Class Method Summary collapse
-
.from_currency(variant, currency) ⇒ Spree::Pricing::Context
Returns a new context from a variant and currency.
- .from_order(variant, order, quantity: nil) ⇒ Object
Instance Method Summary collapse
-
#cache_key ⇒ String
Returns the cache key for the context.
-
#initialize(variant: nil, currency:, store: nil, zone: nil, user: nil, quantity: nil, date: nil, order: nil) ⇒ Context
constructor
Initializes the context.
Constructor Details
#initialize(variant: nil, currency:, store: nil, zone: nil, user: nil, quantity: nil, date: nil, order: nil) ⇒ Context
Initializes the context
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/spree/core/pricing/context.rb', line 15 def initialize(variant: nil, currency:, store: nil, zone: nil, user: nil, quantity: nil, date: nil, order: nil) @variant = variant @currency = currency @store = store || Spree::Current.store @zone = zone || Spree::Current.zone @user = user @quantity = quantity @date = date || Time.current @order = order end |
Instance Attribute Details
#currency ⇒ Object (readonly)
Returns the value of attribute currency.
4 5 6 |
# File 'lib/spree/core/pricing/context.rb', line 4 def currency @currency end |
#date ⇒ Object (readonly)
Returns the value of attribute date.
4 5 6 |
# File 'lib/spree/core/pricing/context.rb', line 4 def date @date end |
#order ⇒ Object (readonly)
Returns the value of attribute order.
4 5 6 |
# File 'lib/spree/core/pricing/context.rb', line 4 def order @order end |
#quantity ⇒ Object (readonly)
Returns the value of attribute quantity.
4 5 6 |
# File 'lib/spree/core/pricing/context.rb', line 4 def quantity @quantity end |
#store ⇒ Object (readonly)
Returns the value of attribute store.
4 5 6 |
# File 'lib/spree/core/pricing/context.rb', line 4 def store @store end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
4 5 6 |
# File 'lib/spree/core/pricing/context.rb', line 4 def user @user end |
#variant ⇒ Object (readonly)
Returns the value of attribute variant.
4 5 6 |
# File 'lib/spree/core/pricing/context.rb', line 4 def variant @variant end |
#zone ⇒ Object (readonly)
Returns the value of attribute zone.
4 5 6 |
# File 'lib/spree/core/pricing/context.rb', line 4 def zone @zone end |
Class Method Details
.from_currency(variant, currency) ⇒ Spree::Pricing::Context
Returns a new context from a variant and currency
30 31 32 |
# File 'lib/spree/core/pricing/context.rb', line 30 def self.from_currency(variant, currency) new(variant: variant, currency: currency) end |
.from_order(variant, order, quantity: nil) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/spree/core/pricing/context.rb', line 34 def self.from_order(variant, order, quantity: nil) new( variant: variant, currency: order.currency, store: order.store, zone: order.tax_zone || order.store.checkout_zone, user: order.user, quantity: quantity || order.line_items.find_by(variant: variant)&.quantity, order: order ) end |
Instance Method Details
#cache_key ⇒ String
Returns the cache key for the context
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/spree/core/pricing/context.rb', line 48 def cache_key [ 'spree', 'pricing', variant.id, currency, store&.id, zone&.id, user&.id, quantity, date&.to_i ].compact.join('/') end |