Hotfix: Correcting ProductResolver when importing Products
This commit is contained in:
@@ -7,13 +7,23 @@ use Lunar\Models\Url;
|
|||||||
|
|
||||||
class ProductResolver
|
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
|
public function resolve(string $handle): ?Product
|
||||||
{
|
{
|
||||||
$url = Url::query()
|
return Product::query()
|
||||||
->where('slug', $handle)
|
->join('lunar_urls', 'lunar_urls.element_id', '=', 'lunar_products.id')
|
||||||
->where('element_type', (new Product)->getMorphClass())
|
->where('lunar_urls.slug', $handle)
|
||||||
|
->where('lunar_urls.element_type', (new Product)->getMorphClass())
|
||||||
|
->select('lunar_products.*')
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
return $url?->element;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user