Class: Spree::Order

Inherits:
Base
  • Object
show all
Extended by:
DisplayMoney
Includes:
Checkout, Payments
Defined in:
app/models/spree/order.rb,
app/models/spree/order/payments.rb,
app/models/spree/order/checkout.rb

Overview

The customers cart until completed, then acts as permanent record of the transaction.

`Spree::Order` is the heart of the Solidus system, as it acts as the customer's cart as they shop. Once an order is complete, it serves as the permanent record of their purchase. It has many responsibilities:

  • Records and validates attributes like `total` and relationships like

`Spree::LineItem` as an ActiveRecord model.

  • Implements a customizable state machine to manage the lifecycle of an order.

  • Implements business logic to provide a single interface for quesitons like

`checkout_allowed?` or `payment_required?`.

* Implements an interface for mutating the order with methods like

`empty!` and `fulfill!`.

Defined Under Namespace

Modules: Checkout, Payments Classes: CannotRebuildShipments, InsufficientStock

Constant Summary

ORDER_NUMBER_LENGTH =
9
ORDER_NUMBER_LETTERS =
false
ORDER_NUMBER_PREFIX =
'R'

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods included from DisplayMoney

money_methods

Methods included from Payments

#authorize_payments!, #capture_payments!, #process_payments!, #unprocessed_payments

Methods included from Checkout

#can_go_to_state?, #checkout_step_index, #checkout_steps, #has_checkout_step?, included, #passed_checkout_step?

Methods inherited from Base

display_includes, #initialize_preference_defaults, page, preference

Methods included from Preferences::Preferable

#default_preferences, #defined_preferences, #get_preference, #has_preference!, #has_preference?, #preference_default, #preference_type, #set_preference

Instance Attribute Details

- (Object) coupon_code

Returns the value of attribute coupon_code



49
50
51
# File 'app/models/spree/order.rb', line 49

def coupon_code
  @coupon_code
end

- (Object) temporary_address

Returns the value of attribute temporary_address



50
51
52
# File 'app/models/spree/order.rb', line 50

def temporary_address
  @temporary_address
end

- (Object) temporary_payment_source Also known as: temporary_credit_card

Returns the value of attribute temporary_payment_source



52
53
54
# File 'app/models/spree/order.rb', line 52

def temporary_payment_source
  @temporary_payment_source
end

- (Object) use_billing

Returns the value of attribute use_billing



122
123
124
# File 'app/models/spree/order.rb', line 122

def use_billing
  @use_billing
end

Class Method Details

+ (Object) by_customer(customer)



154
155
156
# File 'app/models/spree/order.rb', line 154

def self.by_customer(customer)
  joins(:user).where("#{Spree.user_class.table_name}.email" => customer)
end

+ (Object) by_state(state)



158
159
160
# File 'app/models/spree/order.rb', line 158

def self.by_state(state)
  where(state: state)
end

+ (Object) complete



162
163
164
# File 'app/models/spree/order.rb', line 162

def self.complete
  where.not(completed_at: nil)
end

+ (Object) incomplete



166
167
168
# File 'app/models/spree/order.rb', line 166

def self.incomplete
  where(completed_at: nil)
end

+ (Object) register_line_item_comparison_hook(hook)

Use this method in other gems that wish to register their own custom logic that should be called when determining if two line items are equal.



178
179
180
# File 'app/models/spree/order.rb', line 178

def self.register_line_item_comparison_hook(hook)
  line_item_comparison_hooks.add(hook)
end

+ (Object) register_update_hook(hook)

Use this method in other gems that wish to register their own custom logic that should be called after Order#update



172
173
174
# File 'app/models/spree/order.rb', line 172

def self.register_update_hook(hook)
  update_hooks.add(hook)
end

Instance Method Details

- (Object) add_default_payment_from_wallet Also known as: assign_default_credit_card



722
723
724
725
726
727
728
729
730
731
732
733
734
# File 'app/models/spree/order.rb', line 722

def add_default_payment_from_wallet
  builder = Spree::Config.default_payment_builder_class.new(self)

  if payment = builder.build
    payments << payment

    if bill_address.nil?
      # this is one of 2 places still using User#bill_address
      self.bill_address = payment.source.try(:address) ||
                          user.bill_address
    end
  end
end

- (Object) add_payment_sources_to_wallet Also known as: persist_user_credit_card



714
715
716
717
718
# File 'app/models/spree/order.rb', line 714

def add_payment_sources_to_wallet
  Spree::Config.
    add_payment_sources_to_wallet_class.new(self).
    add_to_wallet
end

- (Object) add_store_credit_payments



615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
# File 'app/models/spree/order.rb', line 615

def add_store_credit_payments
  return if user.nil?
  return if payments.store_credits.checkout.empty? && user.total_available_store_credit.zero?

  payments.store_credits.checkout.each(&:invalidate!)

  # this can happen when multiple payments are present, auto_capture is
  # turned off, and one of the payments fails when the user tries to
  # complete the order, which sends the order back to the 'payment' state.
  authorized_total = payments.pending.sum(:amount)

  remaining_total = outstanding_balance - authorized_total

  if user.store_credits.any?
    payment_method = Spree::PaymentMethod::StoreCredit.first

    user.store_credits.order_by_priority.each do |credit|
      break if remaining_total.zero?
      next if credit.amount_remaining.zero?

      amount_to_take = [credit.amount_remaining, remaining_total].min
      payments.create!(source: credit,
                       payment_method: payment_method,
                       amount: amount_to_take,
                       state: 'checkout',
                       response_code: credit.generate_authorization_code)
      remaining_total -= amount_to_take
    end
  end

  other_payments = payments.checkout.not_store_credits
  if remaining_total.zero?
    other_payments.each(&:invalidate!)
  elsif other_payments.size == 1
    other_payments.first.update_attributes!(amount: remaining_total)
  end

  payments.reset

  if payments.where(state: %w(checkout pending)).sum(:amount) != total
    errors.add(:base, Spree.t("store_credit.errors.unable_to_fund")) && (return false)
  end
end

- (Boolean) all_inventory_units_returned?

Returns:

  • (Boolean)


270
271
272
# File 'app/models/spree/order.rb', line 270

def all_inventory_units_returned?
  inventory_units.all?(&:returned?)
end

- (Boolean) allow_cancel?

Returns:

  • (Boolean)


265
266
267
268
# File 'app/models/spree/order.rb', line 265

def allow_cancel?
  return false unless completed? && state != 'canceled'
  shipment_state.nil? || %w{ready backorder pending}.include?(shipment_state)
end

- (Object) amount

For compatiblity with Calculator::PriceSack



183
184
185
# File 'app/models/spree/order.rb', line 183

def amount
  line_items.map(&:amount).sum
end

- (Object) apply_free_shipping_promotions



533
534
535
536
# File 'app/models/spree/order.rb', line 533

def apply_free_shipping_promotions
  Spree::PromotionHandler::FreeShipping.new(self).activate
  update!
end

- (Boolean) approved?

Returns:

  • (Boolean)


589
590
591
# File 'app/models/spree/order.rb', line 589

def approved?
  !!approved_at
end

- (Object) assign_billing_to_shipping_address



260
261
262
263
# File 'app/models/spree/order.rb', line 260

def assign_billing_to_shipping_address
  self.ship_address = bill_address if bill_address
  true
end

- (Object) assign_default_addresses!



698
699
700
701
702
703
704
705
706
# File 'app/models/spree/order.rb', line 698

def assign_default_addresses!
  if user
    # this is one of 2 places still using User#bill_address
    self.bill_address ||= user.bill_address if user.bill_address.try!(:valid?)
    # Skip setting ship address if order doesn't have a delivery checkout step
    # to avoid triggering validations on shipping address
    self.ship_address ||= user.ship_address if user.ship_address.try!(:valid?) && checkout_steps.include?("delivery")
  end
end

- (Object) associate_user!(user, override_email = true)

Associates the specified user with the order.



287
288
289
290
291
292
293
294
295
296
297
298
299
# File 'app/models/spree/order.rb', line 287

def associate_user!(user, override_email = true)
  self.user = user
  attrs_to_set = { user_id: user.try(:id) }
  attrs_to_set[:email] = user.try(:email) if override_email
  attrs_to_set[:created_by_id] = user.try(:id) if created_by.blank?

  if persisted?
    # immediately persist the changes we just made, but don't use save since we might have an invalid address associated
    self.class.unscoped.where(id: id).update_all(attrs_to_set)
  end

  assign_attributes(attrs_to_set)
end

- (Object) available_payment_methods



445
446
447
448
449
450
# File 'app/models/spree/order.rb', line 445

def available_payment_methods
  @available_payment_methods ||= Spree::PaymentMethod
    .available_to_store(store)
    .available_to_users
    .sort_by(&:position)
end

- (Boolean) backordered?

Returns:

  • (Boolean)


231
232
233
# File 'app/models/spree/order.rb', line 231

def backordered?
  shipments.any?(&:backordered?)
end

- (Object) bill_address_attributes=(attributes)



690
691
692
# File 'app/models/spree/order.rb', line 690

def bill_address_attributes=(attributes)
  self.bill_address = Spree::Address.immutable_merge(bill_address, attributes)
end

- (Boolean) can_add_coupon?

Returns:

  • (Boolean)


508
509
510
# File 'app/models/spree/order.rb', line 508

def can_add_coupon?
  Spree::Promotion.order_activatable?(self)
end

- (Boolean) can_approve?

Returns:

  • (Boolean)


593
594
595
# File 'app/models/spree/order.rb', line 593

def can_approve?
  !approved?
end

- (Boolean) can_ship?

Returns:

  • (Boolean)


393
394
395
# File 'app/models/spree/order.rb', line 393

def can_ship?
  complete? || resumed? || awaiting_return? || returned?
end

- (Object) canceled_by(user)



579
580
581
582
583
584
585
586
587
# File 'app/models/spree/order.rb', line 579

def canceled_by(user)
  transaction do
    cancel!
    update_columns(
      canceler_id: user.id,
      canceled_at: Time.current
    )
  end
end

- (Object) cancellations



282
283
284
# File 'app/models/spree/order.rb', line 282

def cancellations
  @cancellations ||= Spree::OrderCancellations.new(self)
end

- (Boolean) checkout_allowed?

Indicates whether or not the user is allowed to proceed to checkout. Currently this is implemented as a check for whether or not there is at least one LineItem in the Order. Feel free to override this logic in your own application if you require additional steps before allowing a checkout.

Returns:

  • (Boolean)


217
218
219
# File 'app/models/spree/order.rb', line 217

def checkout_allowed?
  line_items.count > 0
end

- (Boolean) completed?

Returns:

  • (Boolean)


209
210
211
# File 'app/models/spree/order.rb', line 209

def completed?
  completed_at.present?
end

- (Boolean) confirmation_required?

Returns:

  • (Boolean)


226
227
228
# File 'app/models/spree/order.rb', line 226

def confirmation_required?
  true
end

- (Boolean) contains?(variant, options = {})

Returns:

  • (Boolean)


326
327
328
# File 'app/models/spree/order.rb', line 326

def contains?(variant, options = {})
  find_line_item_by_variant(variant, options).present?
end

- (Object) contents



274
275
276
# File 'app/models/spree/order.rb', line 274

def contents
  @contents ||= Spree::OrderContents.new(self)
end

- (Boolean) covered_by_store_credit? Also known as: covered_by_store_credit

Returns:

  • (Boolean)


659
660
661
662
# File 'app/models/spree/order.rb', line 659

def covered_by_store_credit?
  return false unless user
  user.total_available_store_credit >= total
end

- (Object) create_proposed_shipments



522
523
524
525
526
527
528
529
530
531
# File 'app/models/spree/order.rb', line 522

def create_proposed_shipments
  if completed?
    raise CannotRebuildShipments.new(Spree.t(:cannot_rebuild_shipments_order_completed))
  elsif shipments.any? { |s| !s.pending? }
    raise CannotRebuildShipments.new(Spree.t(:cannot_rebuild_shipments_shipments_not_pending))
  else
    shipments.destroy_all
    self.shipments = Spree::Config.stock.coordinator_class.new(self).shipments
  end
end

- (Object) create_tax_charge!

Deprecated.

This now happens during #update!

Creates new tax charges if there are any applicable rates. If prices already include taxes then price adjustments are created instead.



362
363
364
# File 'app/models/spree/order.rb', line 362

def create_tax_charge!
  Spree::Config.tax_adjuster_class.new(self).adjust!
end

- (Object) credit_cards



397
398
399
400
# File 'app/models/spree/order.rb', line 397

def credit_cards
  credit_card_ids = payments.from_credit_card.pluck(:source_id).uniq
  Spree::CreditCard.where(id: credit_card_ids)
end

- (Object) currency



197
198
199
# File 'app/models/spree/order.rb', line 197

def currency
  self[:currency] || Spree::Config[:currency]
end

- (Object) deliver_order_confirmation_email



435
436
437
438
# File 'app/models/spree/order.rb', line 435

def deliver_order_confirmation_email
  Spree::OrderMailer.confirm_email(self).deliver_later
  update_column(:confirmation_delivered, true)
end

- (Object) discounted_item_amount

Sum of all line item amounts after promotions, before added tax



193
194
195
# File 'app/models/spree/order.rb', line 193

def discounted_item_amount
  line_items.to_a.sum(&:discounted_amount)
end

- (Object) display_store_credit_remaining_after_capture



686
687
688
# File 'app/models/spree/order.rb', line 686

def display_store_credit_remaining_after_capture
  Spree::Money.new(total_available_store_credit - total_applicable_store_credit, { currency: currency })
end

- (Object) display_total_applicable_store_credit



682
683
684
# File 'app/models/spree/order.rb', line 682

def display_total_applicable_store_credit
  Spree::Money.new(-total_applicable_store_credit, { currency: currency })
end

- (Object) empty!



473
474
475
476
477
478
479
# File 'app/models/spree/order.rb', line 473

def empty!
  line_items.destroy_all
  adjustments.destroy_all
  shipments.destroy_all

  update!
end

- (Object) ensure_line_item_variants_are_not_deleted

Check to see if any line item variants are soft, deleted. If so add error and restart checkout.



459
460
461
462
463
464
465
466
467
# File 'app/models/spree/order.rb', line 459

def ensure_line_item_variants_are_not_deleted
  if line_items.any? { |li| li.variant.paranoia_destroyed? }
    errors.add(:base, Spree.t(:deleted_variants_present))
    restart_checkout_flow
    false
  else
    true
  end
end

- (Object) ensure_shipping_address



516
517
518
519
520
# File 'app/models/spree/order.rb', line 516

def ensure_shipping_address
  unless ship_address && ship_address.valid?
    errors.add(:base, Spree.t(:ship_address_required)) && (return false)
  end
end

- (Object) ensure_updated_shipments

Clean shipments and make order back to address state

At some point the might need to force the order to transition from address to delivery again so that proper updated shipments are created. e.g. customer goes back from payment step and changes order items



543
544
545
546
547
548
549
# File 'app/models/spree/order.rb', line 543

def ensure_updated_shipments
  if !completed? && shipments.all?(&:pending?)
    shipments.destroy_all
    update_column(:shipment_total, 0)
    restart_checkout_flow
  end
end

- (Object) finalize!

Finalizes an in progress order after checkout is complete. Called after transition to complete state when payments will have been processed



409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
# File 'app/models/spree/order.rb', line 409

def finalize!
  # lock all adjustments (coupon promotions, etc.)
  all_adjustments.each(&:finalize!)

  # update payment and shipment(s) states, and save
  updater.update_payment_state
  shipments.each do |shipment|
    shipment.update!(self)
    shipment.finalize!
  end

  updater.update_shipment_state
  save!
  updater.run_hooks

  touch :completed_at

  deliver_order_confirmation_email unless confirmation_delivered?
end

- (Object) find_line_item_by_variant(variant, options = {})



335
336
337
338
339
340
# File 'app/models/spree/order.rb', line 335

def find_line_item_by_variant(variant, options = {})
  line_items.detect { |line_item|
                line_item.variant_id == variant.id &&
                  line_item_options_match(line_item, options)
  }
end

- (Object) fulfill!



429
430
431
432
433
# File 'app/models/spree/order.rb', line 429

def fulfill!
  shipments.each { |shipment| shipment.update!(self) if shipment.persisted? }
  updater.update_shipment_state
  save!
end

- (Object) generate_order_number(options = {})



301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
# File 'app/models/spree/order.rb', line 301

def generate_order_number(options = {})
  options[:length]  ||= ORDER_NUMBER_LENGTH
  options[:letters] ||= ORDER_NUMBER_LETTERS
  options[:prefix]  ||= ORDER_NUMBER_PREFIX

  possible = (0..9).to_a
  possible += ('A'..'Z').to_a if options[:letters]

  self.number ||= loop do
    # Make a random number.
    random = "#{options[:prefix]}#{(0...options[:length]).map { possible.sample }.join}"
    # Use the random  number if no other order exists with it.
    if self.class.exists?(number: random)
      # If over half of all possible options are taken add another digit.
      options[:length] += 1 if self.class.count > (10**options[:length] / 2)
    else
      break random
    end
  end
end

Returns:

  • (Boolean)


601
602
603
604
# File 'app/models/spree/order.rb', line 601

def has_non_reimbursement_related_refunds?
  refunds.non_reimbursement.exists? ||
    payments.offset_payment.exists? # how old versions of spree stored refunds
end

- (Object) insufficient_stock_lines



452
453
454
# File 'app/models/spree/order.rb', line 452

def insufficient_stock_lines
  line_items.select(&:insufficient_stock?)
end

- (Boolean) is_risky?

Returns:

  • (Boolean)


575
576
577
# File 'app/models/spree/order.rb', line 575

def is_risky?
  payments.risky.count > 0
end

- (Object) line_item_options_match(line_item, options)

This method enables extensions to participate in the “Are these line items equal” decision.

When adding to cart, an extension would send something like: params=…

and would provide:

def product_customizations_match



351
352
353
354
355
356
357
# File 'app/models/spree/order.rb', line 351

def line_item_options_match(line_item, options)
  return true unless options

  line_item_comparison_hooks.all? { |hook|
    send(hook, line_item, options)
  }
end

- (Object) merge!(*args)



469
470
471
# File 'app/models/spree/order.rb', line 469

def merge!(*args)
  Spree::Config.order_merger_class.new(self).merge!(*args)
end

- (Object) name



387
388
389
390
391
# File 'app/models/spree/order.rb', line 387

def name
  if (address = bill_address || ship_address)
    "#{address.firstname} #{address.lastname}"
  end
end

- (Object) order_total_after_store_credit



670
671
672
# File 'app/models/spree/order.rb', line 670

def order_total_after_store_credit
  total - total_applicable_store_credit
end

- (Object) outstanding_balance



367
368
369
370
371
372
373
374
375
376
377
# File 'app/models/spree/order.rb', line 367

def outstanding_balance
  # If reimbursement has happened add it back to total to prevent balance_due payment state
  # See: https://github.com/spree/spree/issues/6229
  adjusted_payment_total = payment_total + refund_total

  if state == 'canceled'
    -1 * adjusted_payment_total
  else
    total - adjusted_payment_total
  end
end

- (Boolean) outstanding_balance?

Returns:

  • (Boolean)


379
380
381
# File 'app/models/spree/order.rb', line 379

def outstanding_balance?
  outstanding_balance != 0
end

- (Boolean) paid?

Helper methods for checkout steps

Returns:

  • (Boolean)


441
442
443
# File 'app/models/spree/order.rb', line 441

def paid?
  %w(paid credit_owed).include?(payment_state)
end

- (Boolean) payment_required?

Is this a free order in which case the payment step should be skipped

Returns:

  • (Boolean)


222
223
224
# File 'app/models/spree/order.rb', line 222

def payment_required?
  total > 0
end

- (Object) persist_user_address!



708
709
710
711
712
# File 'app/models/spree/order.rb', line 708

def persist_user_address!
  if !temporary_address && user && user.respond_to?(:persist_order_address) && bill_address_id
    user.persist_order_address(self)
  end
end

- (Object) pre_tax_item_amount

Sum of all line item amounts pre-tax



188
189
190
# File 'app/models/spree/order.rb', line 188

def pre_tax_item_amount
  line_items.to_a.sum(&:pre_tax_amount)
end

- (Object) quantity



597
598
599
# File 'app/models/spree/order.rb', line 597

def quantity
  line_items.sum(:quantity)
end

- (Object) quantity_of(variant, options = {})



330
331
332
333
# File 'app/models/spree/order.rb', line 330

def quantity_of(variant, options = {})
  line_item = find_line_item_by_variant(variant, options)
  line_item ? line_item.quantity : 0
end

- (Object) refresh_shipment_rates



561
562
563
# File 'app/models/spree/order.rb', line 561

def refresh_shipment_rates
  shipments.map(&:refresh_rates)
end

- (Object) refund_total



383
384
385
# File 'app/models/spree/order.rb', line 383

def refund_total
  payments.flat_map(&:refunds).sum(&:amount)
end

- (Object) restart_checkout_flow



551
552
553
554
555
556
557
558
559
# File 'app/models/spree/order.rb', line 551

def restart_checkout_flow
  return if state == 'cart'

  update_columns(
    state: 'cart',
    updated_at: Time.current
  )
  next! if line_items.size > 0
end

- (Object) set_shipments_cost



569
570
571
572
# File 'app/models/spree/order.rb', line 569

def set_shipments_cost
  shipments.each(&:update_amounts)
  update!
end

- (Object) ship_address_attributes=(attributes)



694
695
696
# File 'app/models/spree/order.rb', line 694

def ship_address_attributes=(attributes)
  self.ship_address = Spree::Address.immutable_merge(ship_address, attributes)
end

- (Boolean) shipped?

Returns:

  • (Boolean)


512
513
514
# File 'app/models/spree/order.rb', line 512

def shipped?
  %w(partial shipped).include?(shipment_state)
end

- (Object) shipped_shipments



322
323
324
# File 'app/models/spree/order.rb', line 322

def shipped_shipments
  shipments.shipped
end

- (Object) shipping



278
279
280
# File 'app/models/spree/order.rb', line 278

def shipping
  @shipping ||= Spree::OrderShipping.new(self)
end

- (Object) shipping_discount



201
202
203
# File 'app/models/spree/order.rb', line 201

def shipping_discount
  shipment_adjustments.eligible.sum(:amount) * - 1
end

- (Boolean) shipping_eq_billing_address?

Returns:

  • (Boolean)


565
566
567
# File 'app/models/spree/order.rb', line 565

def shipping_eq_billing_address?
  bill_address == ship_address
end

- (Object) state_changed(name)



484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
# File 'app/models/spree/order.rb', line 484

def state_changed(name)
  state = "#{name}_state"
  if persisted?
    old_state = send("#{state}_was")
    new_state = send(state)
    unless old_state == new_state
      state_changes.create(
        previous_state: old_state,
        next_state:     new_state,
        name:           name,
        user_id:        user_id
      )
    end
  end
end

- (Object) tax_address

Returns the address for taxation based on configuration



244
245
246
247
248
249
250
# File 'app/models/spree/order.rb', line 244

def tax_address
  if Spree::Config[:tax_using_ship_address]
    ship_address
  else
    bill_address
  end || store.default_cart_tax_location
end

- (Object) tax_total



611
612
613
# File 'app/models/spree/order.rb', line 611

def tax_total
  additional_tax_total + included_tax_total
end

- (Object) tax_zone

Returns the relevant zone (if any) to be used for taxation purposes. Uses default tax zone unless there is a specific match



237
238
239
# File 'app/models/spree/order.rb', line 237

def tax_zone
  Spree::Zone.match(tax_address) || Spree::Zone.default_tax
end

- (Object) to_param



205
206
207
# File 'app/models/spree/order.rb', line 205

def to_param
  number
end

- (Object) token



606
607
608
609
# File 'app/models/spree/order.rb', line 606

def token
  Spree::Deprecation.warn("Spree::Order#token is DEPRECATED, please use #guest_token instead.", caller)
  guest_token
end

- (Object) total_applicable_store_credit



674
675
676
677
678
679
680
# File 'app/models/spree/order.rb', line 674

def total_applicable_store_credit
  if confirm? || complete?
    payments.store_credits.valid.sum(:amount)
  else
    [total, (user.try(:total_available_store_credit) || 0.0)].min
  end
end

- (Object) total_available_store_credit



665
666
667
668
# File 'app/models/spree/order.rb', line 665

def total_available_store_credit
  return 0.0 unless user
  user.total_available_store_credit
end

- (Object) update!



256
257
258
# File 'app/models/spree/order.rb', line 256

def update!
  updater.update
end

- (Object) updater



252
253
254
# File 'app/models/spree/order.rb', line 252

def updater
  @updater ||= Spree::OrderUpdater.new(self)
end

- (Object) valid_credit_cards



402
403
404
405
# File 'app/models/spree/order.rb', line 402

def valid_credit_cards
  credit_card_ids = payments.from_credit_card.valid.pluck(:source_id).uniq
  Spree::CreditCard.where(id: credit_card_ids)
end