Sha256: eb3a858c7bf12a882ba3f4b53fe38edb4585d38998fe0ab4ee71127cfa044c16

Contents?: true

Size: 546 Bytes

Versions: 1

Compression:

Stored size: 546 Bytes

Contents

module Shopper
  module OrderProductHelpers
    def create_or_increment_product(type, id, quantity = 1)
      item = order_items.find_or_initialize_by(product_type: type.camelize, product_id: id)
      item.quantity = item.persisted? ? item.quantity + quantity.to_i : quantity
      item.save ? item : false
    end

    def create_or_update_product(type, id, quantity = 1)
      item = order_items.find_or_initialize_by(product_type: type.camelize, product_id: id)
      item.quantity = quantity
      item.save ? item : false
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
shoppper-0.1.0 app/models/concerns/shopper/order_product_helpers.rb