Skip to content

Commit

Permalink
Start reading stock level from product catalog
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszreszke committed Nov 12, 2024
1 parent 17d9a93 commit b0fc081
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 6 additions & 2 deletions rails_application/app/controllers/products_controller.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
class ProductsController < ApplicationController
def index
@products = Product.all
@products = Product.joins(:product_catalog).select("products.id, products.name, products.price, products.vat_rate, products.sku, product_catalogs.stock_level")
end

def show
@product = Product.find(params[:id])
@product = Product
.where(id: params[:id])
.joins(:product_catalog)
.select("products.id, products.name, products.price, products.vat_rate, products.sku, product_catalogs.stock_level")
.first
end

def new
Expand Down
2 changes: 2 additions & 0 deletions rails_application/app/models/product.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ class Product < ApplicationRecord
validate :validate_vat_rate
validates :sku, presence: true

has_one :product_catalog, class_name: "Inventory::ProductCatalog", foreign_key: :product_id

default_scope { where(latest: true) }

before_create :set_stock_level
Expand Down

0 comments on commit b0fc081

Please sign in to comment.