Sha256: 4b685b515f4a5f21fb71d80c2d6d0c65cede233a8fd40c0f2dd1f64f474538b7

Contents?: true

Size: 1.78 KB

Versions: 1

Compression:

Stored size: 1.78 KB

Contents

class Plugins::Ecommerce::Order < Plugins::Ecommerce::Cart
  self.table_name = 'plugins_ecommerce_orders'
  has_many :metas, ->{ where(object_class: 'Plugins::Ecommerce::Cart')}, :class_name => "CamaleonCms::Meta", foreign_key: :objectid, dependent: :delete_all
  default_scope { where(kind: 'order') }
  # status:
  #         bank_pending => pending of verification for bank transfer orders
  #         on_delivery => pending to mark as paid after after delivery
  #         paid => paid by some method
  #         canceled => canceled order
  #         shipped => shipped status
  #         accepted => received status

  def paid?
    status == 'paid'
  end

  def accepted?
    status == 'accepted'
  end

  def accepted!
    update_columns({status: 'accepted', accepted_at: Time.current})
  end

  def shipped?
    status == 'shipped'
  end

  def shipped!(code)
    update_columns({status: 'shipped', shipped_at: Time.current})
    set_meta('consignment_number', code)
  end

  def canceled?
    status == 'canceled'
  end

  def canceled!
    update_columns({status: 'canceled', shipped_at: Time.current})
  end

  def received?
    status == 'received'
  end

  def bank_pending?
    status == 'bank_pending'
  end

  def on_delivery_pending?
    status == 'on_delivery'
  end

  def bank_confirmed!
    update_columns({status: 'paid', updated_at: Time.current})
  end

  def on_delivery_confirmed!
    update_columns({status: 'paid', updated_at: Time.current})
  end

  def payment_data
    get_meta('payment_data', {})
  end

  # return the date of the current status
  def action_date
    case object.status
      when 'paid'
        object.created_at
      when 'canceled'
        object.closed_at
      when 'shipped'
        object.shipped_at
      when 'accepted'
        object.accepted_at
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
camaleon_ecommerce-1.2.1 app/models/plugins/ecommerce/order.rb