Skip to content

Commit ce8ef35

Browse files
bansari-salectoJupiter Lewis
andauthored
Fixed error on configurable and virtual product detail page (#5)
* Update composer.json Co-authored-by: Jupiter Lewis <[email protected]>
1 parent 330c4e5 commit ce8ef35

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

Observer/Product/CollectionObserver.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
namespace Salecto\MediaStorageSync\Observer\Product;
44

5+
use Magento\Catalog\Api\ProductRepositoryInterface;
6+
use Magento\Catalog\Model\Product\Gallery\ReadHandler as GalleryReadHandler;
57
use Magento\Framework\Event\ObserverInterface;
68
use Magento\Framework\Event\Observer;
7-
use Magento\Catalog\Model\Product\Gallery\ReadHandler as GalleryReadHandler;
89
use Salecto\MediaStorageSync\Model\Sync;
910
use Salecto\MediaStorageSync\Model\Config;
1011
use 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
}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"magento/module-media-storage": "*"
77
},
88
"type": "magento2-module",
9-
"version": "1.0.3",
9+
"version": "1.0.4",
1010
"license": "MIT",
1111
"autoload": {
1212
"files": [

0 commit comments

Comments
 (0)