@@ -58,7 +58,7 @@ public function __construct(
58
58
$ this ->helperImage = $ helperImage ;
59
59
$ this ->_imageFactory = $ imageFactory ;
60
60
$ this ->_filesystem = $ context ->getFilesystem ();
61
- $ this ->_directoryRed = $ this ->_filesystem ->getDirectoryRead (\Magento \Framework \App \Filesystem \DirectoryList::MEDIA );
61
+ $ this ->_directoryPub = $ this ->_filesystem ->getDirectoryRead (\Magento \Framework \App \Filesystem \DirectoryList::PUB );
62
62
$ this ->helper = $ helper ;
63
63
64
64
parent ::__construct ($ context , $ data );
@@ -136,8 +136,10 @@ public function getCategories()
136
136
if ($ this ->isExcluded ($ categoryId )) return ;
137
137
138
138
$ sortAttribute = $ this ->getSortAttribute ();
139
+ $ attributesSelect = ['name ' , 'url_key ' , 'url_path ' , 'image ' ,'description ' ];
140
+ if ($ this ->isShowThumbnail ()) $ attributesSelect [] = 'magepow_thumbnail ' ;
139
141
$ categories = $ this ->categoryFactory ->create ()->getCollection ()
140
- ->addAttributeToSelect ([ ' name ' , ' url_key ' , ' url_path ' , ' image ' , ' description ' ] )
142
+ ->addAttributeToSelect ($ attributesSelect )
141
143
->addAttributeToFilter ('parent_id ' , $ categoryId )
142
144
->addIsActiveFilter ();
143
145
@@ -163,29 +165,30 @@ public function getDescription($category)
163
165
164
166
public function getImage ($ category )
165
167
{
166
- if ($ this ->isShowThumbnail ()!=1 ){
167
- return $ this ->getImageUrl ($ category );
168
- }else {
169
- $ id = $ category ->getId ();
170
- $ category = $ this ->categoryFactory ->create ();
171
- $ category ->load ($ id );
172
- $ image = ($ category ->getData ('magepow_thumbnail ' ) != NULL ) ? $ category ->getData ('magepow_thumbnail ' ) : '' ;
168
+ if ($ this ->isShowThumbnail ()){
169
+ $ image = ($ category ->getData ('magepow_thumbnail ' )) ? $ category ->getData ('magepow_thumbnail ' ) : '' ;
170
+ return $ this ->getImageUrl ($ image );
173
171
}
174
- return $ this ->getImageUrl ($ image );
172
+
173
+ return $ this ->getImageUrl ($ category );
175
174
}
176
175
177
176
public function getImageInfo ($ image )
178
177
{
179
178
if (is_object ($ image )){
180
- $ img = $ image ->getImage ();
179
+ $ img = $ this -> isShowThumbnail () ? $ image -> getData ( ' magepow_thumbnail ' ): $ image ->getImage ();
181
180
if (!$ img ) return $ image ;
182
181
} else {
183
182
$ img = $ image ;
184
183
}
185
184
$ _image = $ this ->_imageFactory ->create ();
186
- $ absPath = $ this ->_directoryRed ->getAbsolutePath () . str_replace ('/pub/media/ ' , '' , $ img );
187
- if (file_exists ($ absPath ) ){
188
- $ _image ->open ($ absPath );
185
+ $ mediaPath = $ this ->_directoryPub ->getAbsolutePath ();
186
+ $ mediaPath = explode (DIRECTORY_SEPARATOR , $ mediaPath );
187
+ $ img = explode (DIRECTORY_SEPARATOR , $ img );
188
+ $ imagePath = array_unique (array_merge ($ mediaPath , $ img ));
189
+ $ imagePath = implode (DIRECTORY_SEPARATOR , $ imagePath );
190
+ if (file_exists ($ imagePath ) ){
191
+ $ _image ->open ($ imagePath );
189
192
return $ _image ;
190
193
}
191
194
return $ image ;
0 commit comments