Browse Source

fix localizeContainersToAnotherPage shared container

zealllot 1 year ago
parent
commit
548853c7fa
2 changed files with 6 additions and 4 deletions
  1. 5 4
      pagebuilder/editor.go
  2. 1 0
      pagebuilder/models.go

+ 5 - 4
pagebuilder/editor.go

@@ -758,8 +758,8 @@ func (b *Builder) localizeContainersToAnotherPage(db *gorm.DB, pageID int, pageV
 			newModelID = reflectutils.MustGet(model, "ID").(uint)
 		} else {
 			var count int64
-			var temp Container
-			if err = db.Where("model_name = ? AND locale_code = ?", c.ModelName, toPageLocale).First(&temp).Count(&count).Error; err != nil && err != gorm.ErrRecordNotFound {
+			var sharedCon Container
+			if err = db.Where("localize_from_model_id = ? AND locale_code = ? AND shared = ?", c.ModelID, toPageLocale, true).First(&sharedCon).Count(&count).Error; err != nil && err != gorm.ErrRecordNotFound {
 				return
 			}
 
@@ -776,8 +776,8 @@ func (b *Builder) localizeContainersToAnotherPage(db *gorm.DB, pageID int, pageV
 				}
 				newModelID = reflectutils.MustGet(model, "ID").(uint)
 			} else {
-				newModelID = temp.ModelID
-				newDisplayName = temp.DisplayName
+				newModelID = sharedCon.ModelID
+				newDisplayName = sharedCon.DisplayName
 			}
 		}
 
@@ -796,6 +796,7 @@ func (b *Builder) localizeContainersToAnotherPage(db *gorm.DB, pageID int, pageV
 		newCon.DisplayOrder = c.DisplayOrder
 		newCon.Shared = c.Shared
 		newCon.LocaleCode = toPageLocale
+		newCon.LocalizeFromModelID = c.ModelID
 
 		if err = db.Save(&newCon).Error; err != nil {
 			return

+ 1 - 0
pagebuilder/models.go

@@ -141,6 +141,7 @@ type Container struct {
 	DisplayName  string
 
 	l10n.Locale
+	LocalizeFromModelID uint
 }
 
 func (c *Container) PrimarySlug() string {