@@ -160,74 +160,63 @@ protected function createBaseLoadSelect($entityId, $storeId, $attributeId)
160160 public function createBatchBaseSelect ($ storeId , $ attributeId )
161161 {
162162 $ linkField = $ this ->metadata ->getLinkField ();
163- $ conn = $ this ->getConnection ();
164163
165- $ positionCheckSql = $ conn ->getCheckSql (
164+ $ positionCheckSql = $ this -> getConnection () ->getCheckSql (
166165 'value.position IS NULL ' ,
167166 'default_value.position ' ,
168167 'value.position '
169168 );
170169
171170 $ mainTableAlias = $ this ->getMainTableAlias ();
172171
173- $ storeCondition = $ conn ->quoteInto ('value.store_id = ? ' , (int )$ storeId );
174- $ defStoreCondition = $ conn ->quoteInto ('default_value.store_id = ? ' , Store::DEFAULT_STORE_ID );
175- $ select = $ conn ->select ()
176- ->from (
177- [$ mainTableAlias => $ this ->getMainTable ()],
172+ $ select = $ this ->getConnection ()->select ()->from (
173+ [$ mainTableAlias => $ this ->getMainTable ()],
174+ [
175+ 'value_id ' ,
176+ 'file ' => 'value ' ,
177+ 'media_type '
178+ ]
179+ )->joinInner (
180+ ['entity ' => $ this ->getTable (self ::GALLERY_VALUE_TO_ENTITY_TABLE )],
181+ $ mainTableAlias . '.value_id = entity.value_id ' ,
182+ [$ linkField ]
183+ )->joinLeft (
184+ ['value ' => $ this ->getTable (self ::GALLERY_VALUE_TABLE )],
185+ implode (
186+ ' AND ' ,
178187 [
179- ' value_id ' ,
180- ' file ' => ' value ' ,
181- 'media_type '
188+ $ mainTableAlias . ' .value_id = value. value_id ' ,
189+ $ this -> getConnection ()-> quoteInto ( ' value.store_id = ? ' , ( int ) $ storeId ) ,
190+ 'value. ' . $ linkField . ' = entity. ' . $ linkField ,
182191 ]
183- )
184- ->joinInner (
185- ['entity ' => $ this ->getTable (self ::GALLERY_VALUE_TO_ENTITY_TABLE )],
186- $ mainTableAlias . '.value_id = entity.value_id ' ,
187- [$ linkField ]
188- )
189- ->joinLeft (
190- ['value ' => $ this ->getTable (self ::GALLERY_VALUE_TABLE )],
191- implode (
192- ' AND ' ,
193- [
194- $ mainTableAlias . '.value_id = value.value_id ' ,
195- $ storeCondition ,
196- 'value. ' . $ linkField . ' = entity. ' . $ linkField ,
197- ]
198- ),
199- []
200- )
201- ->joinLeft (
202- ['default_value ' => $ this ->getTable (self ::GALLERY_VALUE_TABLE )],
203- implode (
204- ' AND ' ,
205- [
206- $ mainTableAlias . '.value_id = default_value.value_id ' ,
207- $ defStoreCondition ,
208- 'default_value. ' . $ linkField . ' = entity. ' . $ linkField ,
209- ]
210- ),
211- []
212- )
213- ->columns ([
214- 'label ' => $ conn ->getIfNullSql ('`value`.`label` ' , '`default_value`.`label` ' ),
215- 'position ' => $ conn ->getIfNullSql ('`value`.`position` ' , '`default_value`.`position` ' ),
216- 'disabled ' => $ conn ->getIfNullSql ('`value`.`disabled` ' , '`default_value`.`disabled` ' ),
217- 'label_default ' => 'default_value.label ' ,
218- 'position_default ' => 'default_value.position ' ,
219- 'disabled_default ' => 'default_value.disabled '
220- ])
221- ->where ($ mainTableAlias . '.attribute_id = ? ' , $ attributeId )
222- ->where ($ mainTableAlias . '.disabled = 0 ' );
223-
224- // filter entities by store
225- if ($ storeId > 0 ) {
226- $ orWhere = $ storeCondition . ' OR ' . $ defStoreCondition ;
227- $ select ->where ($ orWhere );
228- }
229-
230- $ select ->order ($ positionCheckSql . ' ' . \Magento \Framework \DB \Select::SQL_ASC );
192+ ),
193+ []
194+ )->joinLeft (
195+ ['default_value ' => $ this ->getTable (self ::GALLERY_VALUE_TABLE )],
196+ implode (
197+ ' AND ' ,
198+ [
199+ $ mainTableAlias . '.value_id = default_value.value_id ' ,
200+ $ this ->getConnection ()->quoteInto ('default_value.store_id = ? ' , Store::DEFAULT_STORE_ID ),
201+ 'default_value. ' . $ linkField . ' = entity. ' . $ linkField ,
202+ ]
203+ ),
204+ []
205+ )->columns ([
206+ 'label ' => $ this ->getConnection ()->getIfNullSql ('`value`.`label` ' , '`default_value`.`label` ' ),
207+ 'position ' => $ this ->getConnection ()->getIfNullSql ('`value`.`position` ' , '`default_value`.`position` ' ),
208+ 'disabled ' => $ this ->getConnection ()->getIfNullSql ('`value`.`disabled` ' , '`default_value`.`disabled` ' ),
209+ 'label_default ' => 'default_value.label ' ,
210+ 'position_default ' => 'default_value.position ' ,
211+ 'disabled_default ' => 'default_value.disabled '
212+ ])->where (
213+ $ mainTableAlias . '.attribute_id = ? ' ,
214+ $ attributeId
215+ )->where (
216+ $ mainTableAlias . '.disabled = 0 '
217+ )->order (
218+ $ positionCheckSql . ' ' . \Magento \Framework \DB \Select::SQL_ASC
219+ );
231220
232221 return $ select ;
233222 }
0 commit comments