Feature: Creating product import resolvers, wiring import job
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Core\MigrateImport\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
||||
|
||||
class ImportMapping extends Model
|
||||
{
|
||||
protected $guarded = [];
|
||||
|
||||
public function model(): MorphTo
|
||||
{
|
||||
return $this->morphTo();
|
||||
}
|
||||
|
||||
public static function resolve(string $source, string $sourceType, string $externalId): ?Model
|
||||
{
|
||||
return static::query()
|
||||
->where('source', $source)
|
||||
->where('source_type', $sourceType)
|
||||
->where('external_id', $externalId)
|
||||
->first()
|
||||
?->model;
|
||||
}
|
||||
|
||||
public static function record(string $source, string $sourceType, string $externalId, Model $model): self
|
||||
{
|
||||
return static::query()->updateOrCreate(
|
||||
[
|
||||
'source' => $source,
|
||||
'source_type' => $sourceType,
|
||||
'external_id' => $externalId,
|
||||
],
|
||||
[
|
||||
'model_type' => $model->getMorphClass(),
|
||||
'model_id' => $model->getKey(),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user