@@ -58,7 +58,7 @@ public function __construct(
5858 $ this ->helperImage = $ helperImage ;
5959 $ this ->_imageFactory = $ imageFactory ;
6060 $ 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 );
6262 $ this ->helper = $ helper ;
6363
6464 parent ::__construct ($ context , $ data );
@@ -136,8 +136,10 @@ public function getCategories()
136136 if ($ this ->isExcluded ($ categoryId )) return ;
137137
138138 $ sortAttribute = $ this ->getSortAttribute ();
139+ $ attributesSelect = ['name ' , 'url_key ' , 'url_path ' , 'image ' ,'description ' ];
140+ if ($ this ->isShowThumbnail ()) $ attributesSelect [] = 'magepow_thumbnail ' ;
139141 $ categories = $ this ->categoryFactory ->create ()->getCollection ()
140- ->addAttributeToSelect ([ ' name ' , ' url_key ' , ' url_path ' , ' image ' , ' description ' ] )
142+ ->addAttributeToSelect ($ attributesSelect )
141143 ->addAttributeToFilter ('parent_id ' , $ categoryId )
142144 ->addIsActiveFilter ();
143145
@@ -163,29 +165,30 @@ public function getDescription($category)
163165
164166 public function getImage ($ category )
165167 {
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 );
173171 }
174- return $ this ->getImageUrl ($ image );
172+
173+ return $ this ->getImageUrl ($ category );
175174 }
176175
177176 public function getImageInfo ($ image )
178177 {
179178 if (is_object ($ image )){
180- $ img = $ image ->getImage ();
179+ $ img = $ this -> isShowThumbnail () ? $ image -> getData ( ' magepow_thumbnail ' ): $ image ->getImage ();
181180 if (!$ img ) return $ image ;
182181 } else {
183182 $ img = $ image ;
184183 }
185184 $ _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 );
189192 return $ _image ;
190193 }
191194 return $ image ;
0 commit comments