Sha256: 8489ced498c8de44d094a6e88564f48cae61a71190840722b6b8c45db40102ec

Contents?: true

Size: 712 Bytes

Versions: 1

Compression:

Stored size: 712 Bytes

Contents

class Plugins::Ecommerce::ProductItemService
  def initialize(site, product_item)
    @site = site
    @product_item = product_item
  end

  attr_reader :site, :product_item

  def user
    @user ||= product_item.cart.user
  end

  def product
    @product ||= product_item.product
  end

  def decrement_qty!
    available_qty = Plugins::Ecommerce::UserProductService.new(
      site, user, product, product_item.variation_id).available_qty
    val = (available_qty - product_item.qty).to_i
    if val >= 0
      if product_item.variation_id.present?
        product_item.product_variation.update_column(:qty, val)
      else
        product.update_field_value('ecommerce_qty', val)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
camaleon_ecommerce-1.2 app/services/plugins/ecommerce/product_item_service.rb