Last active
April 4, 2023 19:22
-
-
Save voronkovich/c0ec1d60f1cef89c84bbc4ee26a61baa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/Parsers/ProductImagesParser.php b/src/Parsers/ProductImagesParser.php | |
index 8b13cb9..67505a0 100644 | |
--- a/src/Parsers/ProductImagesParser.php | |
+++ b/src/Parsers/ProductImagesParser.php | |
@@ -69,7 +69,7 @@ class ProductImagesParser { | |
$guid | |
); | |
- if ( is_null( $image_id ) ) { | |
+ if ( is_null( $image_id ) || ! Utils::post_exists( $image_id ) ) { | |
$image_id = $this->upload_image( $image, $guid ); | |
} | |
diff --git a/src/Utils.php b/src/Utils.php | |
index a985acc..2ccef14 100644 | |
--- a/src/Utils.php | |
+++ b/src/Utils.php | |
@@ -314,4 +314,19 @@ class Utils { | |
return is_string( $product_map_key ) ? $product_map_key : '_edi_1c_guid'; | |
} | |
+ | |
+ /** | |
+ * Check post existense. | |
+ * | |
+ * @param int $post_id Post ID. | |
+ * | |
+ * @return bool | |
+ */ | |
+ public static function post_exists( int $post_id ): bool { | |
+ global $wpdb; | |
+ | |
+ return (bool) $wpdb->get_var( | |
+ "SELECT COUNT(*) FROM {$wpdb->posts} WHERE id={$post_id}" | |
+ ); | |
+ } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://wordpress.org/support/topic/%d0%bf%d1%80%d0%be%d0%b1%d0%bb%d0%b5%d0%bc%d0%b0-%d1%81-%d0%b7%d0%b0%d0%b3%d1%80%d1%83%d0%b7%d0%ba%d0%be%d0%b9-%d0%b8%d0%b7%d0%be%d0%b1%d1%80%d0%b0%d0%b6%d0%b5%d0%bd%d0%b8%d0%b9-%d1%82%d0%be%d0%b2-3/
How to apply patch
curl https://gist.githubusercontent.com/voronkovich/c0ec1d60f1cef89c84bbc4ee26a61baa/raw/107768495dc38656b5c5a43b313ffd4dd0507ca4/edi1c-product-images-bug.patch | git apply -