class Fdcart

Constants

VERSION

Public Class Methods

new(owner) click to toggle source
# File lib/fdcart.rb, line 3
def initialize(owner)
  @owner = owner
end

Public Instance Methods

add(part, count, *extra) click to toggle source
# File lib/fdcart.rb, line 6
def add(part, count, *extra)
  cart = nil
  count.to_i.times do
    cart = {
        part: part,
        owner: @owner
    }
    extra.each do |val|
      if val
        if !val[:externo].blank?
          cart[:proveedor_externo] = val[:externo]
        elsif val.is_a?(Almacen)
          cart[:part_owner] = val
        elsif val.is_a?(PluginVentaPrecio)
          cart[:transporte] = val
        elsif val.is_a?(OrdenReparacion)
          cart[:belongs] = val
        elsif val.is_a?(User)
          cart[:user] = val
        end
      end
    end
    cart = Cart.create!(cart)
  end
  cart || nil
end
get() click to toggle source
# File lib/fdcart.rb, line 37
def get
  Cart.where(owner: @owner)
end
get_by_belongs_ids(ids: []) click to toggle source
# File lib/fdcart.rb, line 44
def get_by_belongs_ids(ids: [])
  Cart.where(
      :belongs_id.in => ids
  )
end
get_by_ids(ids: []) click to toggle source
# File lib/fdcart.rb, line 41
def get_by_ids(ids: [])
  get.where(:_id.in => ids)
end
remove(id) click to toggle source
# File lib/fdcart.rb, line 33
def remove(id)
  Cart.find(id)&.destroy
end