@@ -1750,11 +1750,7 @@ protected function _saveProducts()
1750
1750
$ position = 0 ;
1751
1751
foreach ($ rowImages as $ column => $ columnImages ) {
1752
1752
foreach ($ columnImages as $ columnImageKey => $ columnImage ) {
1753
- $ filePath = filter_var ($ columnImage , FILTER_VALIDATE_URL )
1754
- ? $ columnImage
1755
- : $ importDir . DS . $ columnImage ;
1756
-
1757
- $ uploadedFile = $ this ->getAlreadyExistedImage ($ rowExistingImages , $ filePath );
1753
+ $ uploadedFile = $ this ->getAlreadyExistedImage ($ rowExistingImages , $ columnImage , $ importDir );
1758
1754
if (!$ uploadedFile && !isset ($ uploadedImages [$ columnImage ])) {
1759
1755
$ uploadedFile = $ this ->uploadMediaFiles ($ columnImage );
1760
1756
$ uploadedFile = $ uploadedFile ?: $ this ->getSystemFile ($ columnImage );
@@ -1948,30 +1944,30 @@ protected function _saveProducts()
1948
1944
/**
1949
1945
* Returns image hash by path
1950
1946
*
1951
- * @param string $filePath
1947
+ * @param string $path
1952
1948
* @return string
1953
1949
*/
1954
- private function getFileHash (string $ filePath ): string
1950
+ private function getFileHash (string $ path ): string
1955
1951
{
1956
- try {
1957
- $ fileExists = $ this ->fileDriver ->isExists ($ filePath );
1958
- } catch (\Exception $ exception ) {
1959
- $ fileExists = false ;
1960
- }
1961
-
1962
- return $ fileExists ? hash_file (self ::HASH_ALGORITHM , $ filePath ) : '' ;
1952
+ return hash_file (self ::HASH_ALGORITHM , $ path );
1963
1953
}
1964
1954
1965
1955
/**
1966
1956
* Returns existed image
1967
1957
*
1968
1958
* @param array $imageRow
1969
- * @param string $filePath
1959
+ * @param string $columnImage
1960
+ * @param string $importDir
1970
1961
* @return string
1971
1962
*/
1972
- private function getAlreadyExistedImage (array $ imageRow , string $ filePath ): string
1963
+ private function getAlreadyExistedImage (array $ imageRow , string $ columnImage , string $ importDir ): string
1973
1964
{
1974
- $ hash = $ this ->getFileHash ($ filePath );
1965
+ if (filter_var ($ columnImage , FILTER_VALIDATE_URL )) {
1966
+ $ hash = $ this ->getFileHash ($ columnImage );
1967
+ } else {
1968
+ $ path = $ importDir . DS . $ columnImage ;
1969
+ $ hash = $ this ->isFileExists ($ path ) ? $ this ->getFileHash ($ path ) : '' ;
1970
+ }
1975
1971
1976
1972
return array_reduce (
1977
1973
$ imageRow ,
@@ -2013,6 +2009,23 @@ private function addImageHashes(array &$images): void
2013
2009
}
2014
2010
}
2015
2011
2012
+ /**
2013
+ * Is file exists
2014
+ *
2015
+ * @param string $path
2016
+ * @return bool
2017
+ */
2018
+ private function isFileExists (string $ path ): bool
2019
+ {
2020
+ try {
2021
+ $ fileExists = $ this ->fileDriver ->isExists ($ path );
2022
+ } catch (\Exception $ exception ) {
2023
+ $ fileExists = false ;
2024
+ }
2025
+
2026
+ return $ fileExists ;
2027
+ }
2028
+
2016
2029
/**
2017
2030
* Clears entries from Image Set and Row Data marked as no_selection
2018
2031
*
0 commit comments