1. Go to this page and download the library: Download flowstore/lookup library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
flowstore / lookup example snippets
// config/lookup.php
'context' => [
// Nombre del parámetro de entrada con el id
'id_param' => 'integration_id',
// (opcional) Clase que implementa IntegrationContextResolver
// 'resolver' => App\Resolvers\MyContextResolver::class,
'resolver' => null,
// (opcional) Resolver genérico basado en Eloquent
'eloquent' => [
// 'model' => App\\Models\\IntegrationTenant::class,
// 'channel_column' => 'channel_key',
// 'credentials_column' => 'credentials',
],
],
// config/lookup.php
'context' => [
'id_param' => 'tenant_id', // en vez de integration_id
'resolver' => null,
'eloquent' => [ /* ... opcional ... */ ],
],
// app/Resolvers/MyContextResolver.php
namespace App\Resolvers;
use App\Models\IntegrationTenant;
use Flowstore\Lookup\Contracts\IntegrationContextResolver;
use Flowstore\Lookup\DTO\IntegrationContext;
final class MyContextResolver implements IntegrationContextResolver
{
public function resolve($integrationId): IntegrationContext
{
$tenant = IntegrationTenant::findOrFail($integrationId);
return new IntegrationContext(
channelKey: (string) $tenant->channel_key,
credentials: (array) $tenant->credentials,
);
}
}
use Flowstore\Lookup\DTO\IntegrationContext;
use Flowstore\Lookup\Support\AbstractLookupProvider;
final class ShopifyLookupProvider extends AbstractLookupProvider
{
public function resources(): array { return ['product']; }
public function testConnection(IntegrationContext $context): void {}
public function lookup(IntegrationContext $context, string $entity, array $params = [])
{
// ... obtén $payload remoto y mapea los campos de tu modelo
// Crear o actualizar un registro único por external_id
$product = $this->persistUpdateOrCreate(
\App\Models\Product::class,
['external_id' => $payload['id']],
[
'name' => $payload['title'],
'price' => $payload['price'],
]
);
// Upsert masivo
$this->persistUpsert(
\App\Models\Product::class,
$rows /* [[ 'external_id' => '...', 'name' => '...' ], ...] */,
['external_id'],
['name','price']
);
return $product; // o devuelve el payload para que lo mapee el mapper
}
}