From d01d27f7ea1b3ddc669747dcbdca44bd3b14b1fb Mon Sep 17 00:00:00 2001 From: Konstantinos Arvanitakis Date: Thu, 27 Aug 2026 00:46:43 +0300 Subject: [PATCH] Hotfix: Correcting ProductResolver when importing Products --- .../JudgeMe/Resolvers/ProductResolver.php | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/MigrateImport/JudgeMe/Resolvers/ProductResolver.php b/src/MigrateImport/JudgeMe/Resolvers/ProductResolver.php index ad68d91..d1cf3b9 100644 --- a/src/MigrateImport/JudgeMe/Resolvers/ProductResolver.php +++ b/src/MigrateImport/JudgeMe/Resolvers/ProductResolver.php @@ -7,13 +7,23 @@ use Lunar\Models\Url; class ProductResolver { + /** + * A slug can have more than one `lunar_urls` row pointing at it across import + * batches — e.g. a product soft-deleted and re-imported leaves its old URL row + * behind, still matching the same slug. Picking "whichever Url row matches + * first" (as a plain Url::where('slug', ...)->first() would) can resolve to a + * soft-deleted product, silently failing every downstream write for that + * product (e.g. JudgeMeExportImporter logging "no product found" for a handle + * that, in isolation, clearly exists). Join against `lunar_products` directly + * so only a URL pointing at a live (non-deleted) product resolves. + */ public function resolve(string $handle): ?Product { - $url = Url::query() - ->where('slug', $handle) - ->where('element_type', (new Product)->getMorphClass()) + return Product::query() + ->join('lunar_urls', 'lunar_urls.element_id', '=', 'lunar_products.id') + ->where('lunar_urls.slug', $handle) + ->where('lunar_urls.element_type', (new Product)->getMorphClass()) + ->select('lunar_products.*') ->first(); - - return $url?->element; } }