22
33namespace Salecto \MediaStorageSync \Observer \Product ;
44
5+ use Magento \Catalog \Api \ProductRepositoryInterface ;
6+ use Magento \Catalog \Model \Product \Gallery \ReadHandler as GalleryReadHandler ;
57use Magento \Framework \Event \ObserverInterface ;
68use Magento \Framework \Event \Observer ;
7- use Magento \Catalog \Model \Product \Gallery \ReadHandler as GalleryReadHandler ;
89use Salecto \MediaStorageSync \Model \Sync ;
910use Salecto \MediaStorageSync \Model \Config ;
1011use Salecto \MediaStorageSync \Helper \Data as Helper ;
@@ -15,6 +16,7 @@ class CollectionObserver implements ObserverInterface
1516 protected $ sync ;
1617 protected $ configModel ;
1718 protected $ helper ;
19+ protected $ productRepository ;
1820
1921 /**
2022 * ProductObserver constructor.
@@ -27,15 +29,15 @@ public function __construct(
2729 GalleryReadHandler $ galleryReadHandler ,
2830 Sync $ syncModel ,
2931 Config $ configModel ,
30- Helper $ helper
31- )
32- {
32+ Helper $ helper,
33+ ProductRepositoryInterface $ productRepository
34+ ) {
3335 $ this ->galleryReadHandler = $ galleryReadHandler ;
3436 $ this ->sync = $ syncModel ;
3537 $ this ->configModel = $ configModel ;
3638 $ this ->helper = $ helper ;
39+ $ this ->productRepository = $ productRepository ;
3740 }
38-
3941 /**
4042 * @param Observer $observer
4143 */
@@ -44,17 +46,18 @@ public function execute(Observer $observer)
4446 if ($ this ->configModel ->isEnabled ()) {
4547 $ collection = $ observer ->getCollection ();
4648 foreach ($ collection as $ product ) {
49+ $ product = $ this ->productRepository ->getById ($ product ->getId ());
4750 $ this ->galleryReadHandler ->execute ($ product );
4851 $ mediaGalleryImages = $ product ->getMediaGalleryImages ();
49-
5052 if (!empty ($ mediaGalleryImages )) {
5153 foreach ($ mediaGalleryImages as $ mediaGalleryImage ) {
52- $ file = $ mediaGalleryImage ->getData (' path ' );
54+ $ file = $ mediaGalleryImage ->getData (" path " );
5355 $ fileIsNotAvailable = $ this ->helper ->fileIsNotAvailable ($ file );
54-
5556 if ($ fileIsNotAvailable ) {
5657 $ this ->sync ->sync (
57- $ this ->helper ->getCatalogMediaConfigPath () . "/ " . $ mediaGalleryImage ->getData ('file ' ),
58+ $ this ->helper ->getCatalogMediaConfigPath () .
59+ "/ " .
60+ $ mediaGalleryImage ->getData ("file " ),
5861 $ this ->helper ->getMediaBaseDir ()
5962 );
6063 }
0 commit comments