@@ -61,6 +61,9 @@ public function writeAll(
6161 $ entityValues = [];
6262 $ langValuesByIdLang = [];
6363 $ shopValues = [];
64+ $ entityTableName = null ;
65+ $ langTableName = null ;
66+ $ shopTableName = null ;
6467
6568 foreach ($ definitions as $ definition ) {
6669 $ moduleKey = $ definition ->getNormalizedModuleKey ();
@@ -83,6 +86,7 @@ public function writeAll(
8386 $ columnName = $ definition ->getStorageColumnName ();
8487
8588 if (ExtraPropertyScope::LANG === $ definition ->getScope ()) {
89+ $ langTableName ??= $ definition ->getExtraTableName ();
8690 if (is_array ($ value )) {
8791 // Multilang array: one entry per language.
8892 foreach ($ value as $ langId => $ langValue ) {
@@ -96,24 +100,26 @@ public function writeAll(
96100 $ langValuesByIdLang [$ defaultLangId ][$ columnName ] = $ value ;
97101 }
98102 } elseif (ExtraPropertyScope::SHOP === $ definition ->getScope ()) {
103+ $ shopTableName ??= $ definition ->getExtraTableName ();
99104 $ shopValues [$ columnName ] = $ value ;
100105 } else {
106+ $ entityTableName ??= $ definition ->getExtraTableName ();
101107 $ entityValues [$ columnName ] = $ value ;
102108 }
103109 }
104110
105111 $ shopId = $ shopConstraint ->isSingleShopContext () ? $ shopConstraint ->getShopId ()->getValue () : null ;
106112
107- if (!empty ($ entityValues )) {
108- $ this ->writeCommon ($ entityName , $ primaryKeyName , $ entityId , $ entityValues );
113+ if (!empty ($ entityValues ) && null !== $ entityTableName ) {
114+ $ this ->writeCommon ($ entityTableName , $ primaryKeyName , $ entityId , $ entityValues );
109115 }
110116
111- if (!empty ($ langValuesByIdLang ) && null !== $ shopId ) {
112- $ this ->writeLang ($ entityName , $ primaryKeyName , $ entityId , $ shopId , $ langValuesByIdLang );
117+ if (!empty ($ langValuesByIdLang ) && null !== $ langTableName && null !== $ shopId ) {
118+ $ this ->writeLang ($ langTableName , $ primaryKeyName , $ entityId , $ shopId , $ langValuesByIdLang );
113119 }
114120
115- if (!empty ($ shopValues ) && null !== $ shopId ) {
116- $ this ->writeShop ($ entityName , $ primaryKeyName , $ entityId , $ shopId , $ shopValues );
121+ if (!empty ($ shopValues ) && null !== $ shopTableName && null !== $ shopId ) {
122+ $ this ->writeShop ($ shopTableName , $ primaryKeyName , $ entityId , $ shopId , $ shopValues );
117123 }
118124 }
119125
@@ -191,23 +197,24 @@ public function deleteAll(string $entityName, string $primaryKeyName, int $entit
191197 /**
192198 * Writes common-scope (entity-level) values for one entity instance.
193199 *
200+ * @param string $extraTableName Extra table name without DB prefix (from ExtraPropertyDefinition::getExtraTableName())
194201 * @param array<string, mixed> $columnValues
195202 */
196- protected function writeCommon (string $ entityName , string $ primaryKeyName , int $ entityId , array $ columnValues ): void
203+ protected function writeCommon (string $ extraTableName , string $ primaryKeyName , int $ entityId , array $ columnValues ): void
197204 {
198- $ fullTableName = $ this ->prefix . ExtraPropertyDefinition::buildExtraTableName ($ entityName , ExtraPropertyScope::COMMON );
199- $ sql = $ this ->buildUpsertSql ($ fullTableName , $ primaryKeyName , [], $ columnValues );
205+ $ sql = $ this ->buildUpsertSql ($ this ->prefix . $ extraTableName , $ primaryKeyName , [], $ columnValues );
200206 $ this ->connection ->executeStatement ($ sql , [$ entityId , ...array_values ($ columnValues )]);
201207 }
202208
203209 /**
204210 * Writes lang-scope values for one entity instance, one row per language.
205211 *
212+ * @param string $extraTableName Extra table name without DB prefix (from ExtraPropertyDefinition::getExtraTableName())
206213 * @param array<int, array<string, mixed>> $langValuesByIdLang [idLang => ['column' => value]]
207214 */
208- protected function writeLang (string $ entityName , string $ primaryKeyName , int $ entityId , int $ shopId , array $ langValuesByIdLang ): void
215+ protected function writeLang (string $ extraTableName , string $ primaryKeyName , int $ entityId , int $ shopId , array $ langValuesByIdLang ): void
209216 {
210- $ fullTableName = $ this ->prefix . ExtraPropertyDefinition:: buildExtraTableName ( $ entityName , ExtraPropertyScope:: LANG ) ;
217+ $ fullTableName = $ this ->prefix . $ extraTableName ;
211218
212219 foreach ($ langValuesByIdLang as $ idLang => $ columnValues ) {
213220 if (empty ($ columnValues )) {
@@ -221,12 +228,12 @@ protected function writeLang(string $entityName, string $primaryKeyName, int $en
221228 /**
222229 * Writes shop-scope values for one entity instance.
223230 *
231+ * @param string $extraTableName Extra table name without DB prefix (from ExtraPropertyDefinition::getExtraTableName())
224232 * @param array<string, mixed> $columnValues
225233 */
226- protected function writeShop (string $ entityName , string $ primaryKeyName , int $ entityId , int $ shopId , array $ columnValues ): void
234+ protected function writeShop (string $ extraTableName , string $ primaryKeyName , int $ entityId , int $ shopId , array $ columnValues ): void
227235 {
228- $ fullTableName = $ this ->prefix . ExtraPropertyDefinition::buildExtraTableName ($ entityName , ExtraPropertyScope::SHOP );
229- $ sql = $ this ->buildUpsertSql ($ fullTableName , $ primaryKeyName , ['id_shop ' ], $ columnValues );
236+ $ sql = $ this ->buildUpsertSql ($ this ->prefix . $ extraTableName , $ primaryKeyName , ['id_shop ' ], $ columnValues );
230237 $ this ->connection ->executeStatement ($ sql , [$ entityId , $ shopId , ...array_values ($ columnValues )]);
231238 }
232239
0 commit comments