diff --git a/app/repos/productsRepo/productsRepo.go b/app/repos/productsRepo/productsRepo.go index 5f0e1a9..02f36df 100644 --- a/app/repos/productsRepo/productsRepo.go +++ b/app/repos/productsRepo/productsRepo.go @@ -18,7 +18,7 @@ type UIProductsRepo interface { // GetJSON(p_id_product, p_id_shop, p_id_lang, p_id_customer, b2b_id_country, p_quantity int) (*json.RawMessage, error) Find(id_lang uint, userID uint, p find.Paging, filt *filters.FiltersList) (*find.Found[model.ProductInList], error) GetProductVariants(langID uint, productID uint, shopID uint, customerID uint, countryID uint, quantity uint) ([]view.ProductAttribute, error) - GetBase(p_id_product, p_id_shop, p_id_lang uint) (view.Product, error) + GetBase(p_id_product, p_id_shop, p_id_lang, p_id_customer uint) (view.Product, error) GetPrice(p_id_product uint, productAttributeID *uint, p_id_shop uint, p_id_customer uint, p_id_country uint, p_quantity uint) (view.Price, error) GetVariants(p_id_product, p_id_shop, p_id_lang, p_id_customer, p_id_country, p_quantity uint) ([]view.ProductAttribute, error) AddToFavorites(userID uint, productID uint) error @@ -33,11 +33,11 @@ func New() UIProductsRepo { return &ProductsRepo{} } -func (repo *ProductsRepo) GetBase(p_id_product, p_id_shop, p_id_lang uint) (view.Product, error) { +func (repo *ProductsRepo) GetBase(p_id_product, p_id_shop, p_id_lang, p_id_customer uint) (view.Product, error) { var result view.Product - err := db.DB.Raw(`CALL get_product_base(?,?,?)`, - p_id_product, p_id_shop, p_id_lang). + err := db.DB.Raw(`CALL get_product_base(?,?,?,?)`, + p_id_product, p_id_shop, p_id_lang, p_id_customer). Scan(&result).Error return result, err diff --git a/app/service/productService/productService.go b/app/service/productService/productService.go index 3296d88..c41b7ea 100644 --- a/app/service/productService/productService.go +++ b/app/service/productService/productService.go @@ -27,7 +27,7 @@ func (s *ProductService) Get( p_id_product, p_id_lang, p_id_customer, b2b_id_country, p_quantity uint, ) (*json.RawMessage, error) { - product, err := s.productsRepo.GetBase(p_id_product, constdata.SHOP_ID, p_id_lang) + product, err := s.productsRepo.GetBase(p_id_product, constdata.SHOP_ID, p_id_lang, p_id_customer) if err != nil { return nil, err } diff --git a/i18n/migrations/20260319163200_procedures.sql b/i18n/migrations/20260319163200_procedures.sql index 4f44cc0..267985a 100644 --- a/i18n/migrations/20260319163200_procedures.sql +++ b/i18n/migrations/20260319163200_procedures.sql @@ -319,7 +319,8 @@ DROP PROCEDURE IF EXISTS get_product_base // CREATE PROCEDURE get_product_base( IN p_id_product INT, IN p_id_shop INT, - IN p_id_lang INT + IN p_id_lang INT, + IN p_id_customer INT ) BEGIN SELECT @@ -376,14 +377,12 @@ BEGIN -- Relations m.name AS manufacturer, - cl.name AS category + cl.name AS category, - -- This doesn't fit to base product, I'll add proper is_favorite to product later - - -- EXISTS( - -- SELECT 1 FROM b2b_favorites f - -- WHERE f.user_id = p_id_customer AND f.product_id = p_id_product - -- ) AS is_favorite + EXISTS( + SELECT 1 FROM b2b_favorites f + WHERE f.user_id = p_id_customer AND f.product_id = p_id_product + ) AS is_favorite