Browse Source

Shop, product images from parent product

Vova Tkach 5 years ago
parent
commit
3845950621
2 changed files with 30 additions and 0 deletions
  1. 28 0
      engine/fetdata/shop_product.go
  2. 2 0
      modules/module_shop.go

+ 28 - 0
engine/fetdata/shop_product.go

@@ -50,6 +50,34 @@ func (this *ShopProduct) load() *ShopProduct {
 		}
 	}
 
+	// Get images from parent
+	if len(this.images) <= 0 && this.object.A_parent_id() > 0 {
+		if rows, err := this.wrap.DB.Query(
+			`SELECT
+				shop_product_images.product_id,
+				shop_product_images.filename
+			FROM
+				shop_product_images
+			WHERE
+				shop_product_images.product_id = ?
+			ORDER BY
+				shop_product_images.ord ASC
+			;`,
+			this.object.A_parent_id(),
+		); err == nil {
+			defer rows.Close()
+			for rows.Next() {
+				img := utils.MySql_shop_product_image{}
+				if err := rows.Scan(
+					&img.A_product_id,
+					&img.A_filename,
+				); *this.wrap.LogCpError(&err) == nil {
+					this.images = append(this.images, &ShopProductImage{wrap: this.wrap, object: &img})
+				}
+			}
+		}
+	}
+
 	filter_ids := []int{}
 	filter_names := map[int]string{}
 	filter_values := map[int][]string{}

+ 2 - 0
modules/module_shop.go

@@ -451,6 +451,7 @@ func (this *Modules) RegisterModule_Shop() *Module {
 			err := wrap.DB.QueryRow(`
 				SELECT
 					shop_products.id,
+					shop_products.parent_id,
 					shop_products.user,
 					shop_products.currency,
 					shop_products.price,
@@ -479,6 +480,7 @@ func (this *Modules) RegisterModule_Shop() *Module {
 				wrap.UrlArgs[1],
 			).Scan(
 				&row.A_id,
+				&row.A_parent,
 				&row.A_user,
 				&row.A_currency,
 				&row.A_price,