Compare commits
26 Commits
integratio
...
7b565e7fa7
| Author | SHA1 | Date | |
|---|---|---|---|
| 7b565e7fa7 | |||
| cb76d1c559 | |||
| 135a3bea3e | |||
| 9e6923e732 | |||
| 18c23a112a | |||
| c1be9ecf7f | |||
| 979ed428a2 | |||
| 7889d747d9 | |||
| f6ce85cbde | |||
| 460eec3c78 | |||
| 2b1ef5f8a9 | |||
| 5ada399adf | |||
| aed818da6e | |||
| 018f3f6c13 | |||
| 217f86f624 | |||
| 25891cefbc | |||
| c66d2019d6 | |||
| 12d496544d | |||
| c31be9c927 | |||
| 67ede1a2b4 | |||
| e778d862ba | |||
| 1438ff66c7 | |||
| 873855c85a | |||
| 855ac13990 | |||
| 87153b7839 | |||
| 528772fc96 |
37
.env.example
37
.env.example
@@ -4,7 +4,6 @@ APP_KEY=
|
|||||||
APP_DEBUG=false
|
APP_DEBUG=false
|
||||||
APP_URL=http://localhost
|
APP_URL=http://localhost
|
||||||
FRONTEND_URL=http://localhost:4200
|
FRONTEND_URL=http://localhost:4200
|
||||||
INTEGRATION_SECRET=
|
|
||||||
|
|
||||||
APP_LOCALE=en
|
APP_LOCALE=en
|
||||||
APP_FALLBACK_LOCALE=en
|
APP_FALLBACK_LOCALE=en
|
||||||
@@ -15,6 +14,11 @@ APP_MAINTENANCE_DRIVER=file
|
|||||||
|
|
||||||
# PHP_CLI_SERVER_WORKERS=4
|
# PHP_CLI_SERVER_WORKERS=4
|
||||||
|
|
||||||
|
GOOGLE_CLIENT_ID=
|
||||||
|
GOOGLE_CLIENT_SECRET=
|
||||||
|
GOOGLE_REDIRECT_URI=http://localhost/auth/google/callback
|
||||||
|
|
||||||
|
|
||||||
BCRYPT_ROUNDS=12
|
BCRYPT_ROUNDS=12
|
||||||
|
|
||||||
LOG_CHANNEL=stack
|
LOG_CHANNEL=stack
|
||||||
@@ -22,20 +26,21 @@ LOG_STACK=single
|
|||||||
LOG_DEPRECATIONS_CHANNEL=null
|
LOG_DEPRECATIONS_CHANNEL=null
|
||||||
LOG_LEVEL=debug
|
LOG_LEVEL=debug
|
||||||
|
|
||||||
DB_CONNECTION=sqlite
|
DB_CONNECTION=mysql
|
||||||
# DB_HOST=127.0.0.1
|
DB_HOST=127.0.0.1
|
||||||
# DB_PORT=3306
|
DB_PORT=3306
|
||||||
# DB_DATABASE=laravel
|
DB_DATABASE=laravel
|
||||||
# DB_USERNAME=root
|
DB_USERNAME=root
|
||||||
# DB_PASSWORD=
|
DB_PASSWORD=
|
||||||
|
INTEGRATION_SECRET=change-me
|
||||||
SESSION_DRIVER=database
|
SESSION_DRIVER=database
|
||||||
SESSION_LIFETIME=120
|
SESSION_LIFETIME=120
|
||||||
SESSION_ENCRYPT=false
|
SESSION_ENCRYPT=false
|
||||||
SESSION_PATH=/
|
SESSION_PATH=/
|
||||||
SESSION_DOMAIN=null
|
SESSION_DOMAIN=null
|
||||||
|
SANCTUM_STATEFUL_DOMAINS=localhost,127.0.0.1
|
||||||
SANCTUM_EXPIRATION=720
|
SANCTUM_EXPIRATION=720
|
||||||
|
SESSION_SECURE_COOKIE=false
|
||||||
|
|
||||||
BROADCAST_CONNECTION=log
|
BROADCAST_CONNECTION=log
|
||||||
FILESYSTEM_DISK=local
|
FILESYSTEM_DISK=local
|
||||||
@@ -52,21 +57,19 @@ REDIS_PASSWORD=null
|
|||||||
REDIS_PORT=6379
|
REDIS_PORT=6379
|
||||||
|
|
||||||
MAIL_MAILER=smtp
|
MAIL_MAILER=smtp
|
||||||
MAIL_SCHEME=smtp
|
MAIL_SCHEME=null
|
||||||
MAIL_HOST=smtp.gmail.com
|
MAIL_HOST=127.0.0.1
|
||||||
MAIL_PORT=587
|
MAIL_PORT=2525
|
||||||
MAIL_USERNAME=null
|
MAIL_USERNAME=null
|
||||||
MAIL_PASSWORD=null
|
MAIL_PASSWORD=null
|
||||||
MAIL_FROM_ADDRESS="hello@example.com"
|
MAIL_FROM_ADDRESS="hello@example.com"
|
||||||
MAIL_FROM_NAME="${APP_NAME}"
|
MAIL_FROM_NAME="${APP_NAME}"
|
||||||
|
|
||||||
|
|
||||||
AWS_ENDPOINT=
|
AWS_ENDPOINT=
|
||||||
AWS_ACCESS_KEY_ID=
|
AWS_ACCESS_KEY_ID=
|
||||||
AWS_SECRET_ACCESS_KEY=
|
AWS_SECRET_ACCESS_KEY=
|
||||||
AWS_DEFAULT_REGION=garage
|
AWS_DEFAULT_REGION=us-east-1
|
||||||
AWS_BUCKET=
|
AWS_BUCKET=
|
||||||
AWS_USE_PATH_STYLE_ENDPOINT=
|
AWS_USE_PATH_STYLE_ENDPOINT=false
|
||||||
AWS_HTTP_VERIFY=
|
AWS_HTTP_VERIFY=true
|
||||||
|
|
||||||
VITE_APP_NAME="${APP_NAME}"
|
VITE_APP_NAME="${APP_NAME}"
|
||||||
|
|||||||
23
app/Domains/Auth/Controllers/GoogleAuthController.php
Normal file
23
app/Domains/Auth/Controllers/GoogleAuthController.php
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domains\Auth\Controllers;
|
||||||
|
|
||||||
|
use App\Domains\Auth\Services\GoogleAuthService;
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use Illuminate\Http\RedirectResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
class GoogleAuthController extends Controller
|
||||||
|
{
|
||||||
|
public function __construct(private readonly GoogleAuthService $googleAuthService) {}
|
||||||
|
|
||||||
|
public function redirect(Request $request): RedirectResponse
|
||||||
|
{
|
||||||
|
return $this->googleAuthService->redirect($request);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function callback(Request $request): RedirectResponse
|
||||||
|
{
|
||||||
|
return $this->googleAuthService->callback($request);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domains\Auth\Controllers;
|
||||||
|
|
||||||
|
use App\Domains\Auth\Requests\GoogleTokenExchangeRequest;
|
||||||
|
use App\Domains\Auth\Resources\UserResource;
|
||||||
|
use App\Domains\Auth\Services\GoogleAuthService;
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
|
||||||
|
class GoogleTokenExchangeController extends Controller
|
||||||
|
{
|
||||||
|
public function __construct(private readonly GoogleAuthService $googleAuthService) {}
|
||||||
|
|
||||||
|
public function __invoke(GoogleTokenExchangeRequest $request): JsonResponse
|
||||||
|
{
|
||||||
|
$authentication = $this->googleAuthService->exchange($request->validated('oauth_code'));
|
||||||
|
|
||||||
|
return response()->json([
|
||||||
|
'message' => 'Sesion iniciada correctamente.',
|
||||||
|
'token' => $authentication['token'],
|
||||||
|
'token_type' => 'Bearer',
|
||||||
|
'user' => UserResource::make($authentication['user']),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,7 +10,7 @@ use Illuminate\Foundation\Auth\User as Authenticatable;
|
|||||||
use Illuminate\Notifications\Notifiable;
|
use Illuminate\Notifications\Notifiable;
|
||||||
use Laravel\Sanctum\HasApiTokens;
|
use Laravel\Sanctum\HasApiTokens;
|
||||||
|
|
||||||
#[Fillable(['nombre_apellido', 'email', 'password', 'dni', 'telefono'])]
|
#[Fillable(['nombre_apellido', 'email', 'password', 'dni', 'telefono', 'google_id'])]
|
||||||
#[Hidden(['password', 'remember_token'])]
|
#[Hidden(['password', 'remember_token'])]
|
||||||
class User extends Authenticatable
|
class User extends Authenticatable
|
||||||
{
|
{
|
||||||
|
|||||||
21
app/Domains/Auth/Requests/GoogleTokenExchangeRequest.php
Normal file
21
app/Domains/Auth/Requests/GoogleTokenExchangeRequest.php
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domains\Auth\Requests;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class GoogleTokenExchangeRequest extends FormRequest
|
||||||
|
{
|
||||||
|
public function authorize(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return array<string, array<int, string>> */
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'oauth_code' => ['required', 'uuid'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@ namespace App\Domains\Auth\Requests;
|
|||||||
|
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
use Illuminate\Validation\Rule;
|
use Illuminate\Validation\Rule;
|
||||||
|
use Illuminate\Validation\Rules\Password;
|
||||||
|
|
||||||
class RegisterUserRequest extends FormRequest
|
class RegisterUserRequest extends FormRequest
|
||||||
{
|
{
|
||||||
@@ -18,9 +19,10 @@ class RegisterUserRequest extends FormRequest
|
|||||||
public function rules(): array
|
public function rules(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
'tenant_codigo' => ['nullable', 'string', Rule::exists('tenants', 'codigo')],
|
||||||
'nombre_apellido' => ['required', 'string', 'max:255'],
|
'nombre_apellido' => ['required', 'string', 'max:255'],
|
||||||
'email' => ['required', 'string', 'email', 'max:255', Rule::unique('users', 'email')],
|
'email' => ['required', 'string', 'email', 'max:255', Rule::unique('users', 'email')],
|
||||||
'password' => ['required', 'string', 'confirmed', \Illuminate\Validation\Rules\Password::min(8)->mixedCase()->symbols()],
|
'password' => ['required', 'string', 'confirmed', Password::min(8)->mixedCase()->symbols()],
|
||||||
'dni' => ['nullable', 'string', 'max:255'],
|
'dni' => ['nullable', 'string', 'max:255'],
|
||||||
'telefono' => ['nullable', 'string', 'max:255'],
|
'telefono' => ['nullable', 'string', 'max:255'],
|
||||||
];
|
];
|
||||||
|
|||||||
165
app/Domains/Auth/Services/GoogleAuthService.php
Normal file
165
app/Domains/Auth/Services/GoogleAuthService.php
Normal file
@@ -0,0 +1,165 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domains\Auth\Services;
|
||||||
|
|
||||||
|
use App\Domains\Auth\Models\User;
|
||||||
|
use App\Domains\Notification\Events\UserRegistered;
|
||||||
|
use App\Domains\Tenant\Models\Tenant;
|
||||||
|
use App\Domains\Tenant\Support\TenantDomainNormalizer;
|
||||||
|
use Illuminate\Http\RedirectResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\Cache;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
use Illuminate\Validation\ValidationException;
|
||||||
|
use Laravel\Socialite\Contracts\User as SocialiteUser;
|
||||||
|
use Laravel\Socialite\Facades\Socialite;
|
||||||
|
|
||||||
|
class GoogleAuthService
|
||||||
|
{
|
||||||
|
public function redirect(Request $request): RedirectResponse
|
||||||
|
{
|
||||||
|
$tenantCode = $request->string('tenant')->toString();
|
||||||
|
$returnUrl = $request->string('return_url')->toString();
|
||||||
|
|
||||||
|
$tenant = Tenant::query()->where('codigo', $tenantCode)->first();
|
||||||
|
|
||||||
|
if (! $tenant || ! $this->isTenantReturnUrl($returnUrl, $tenant)) {
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'tenant' => 'El tenant o la URL de retorno no son validos.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$state = (string) Str::uuid();
|
||||||
|
Cache::put("google-oauth-context:{$state}", [
|
||||||
|
'tenant_codigo' => $tenant->codigo,
|
||||||
|
'return_url' => rtrim($returnUrl, '/'),
|
||||||
|
], now()->addMinutes(10));
|
||||||
|
|
||||||
|
return Socialite::driver('google')
|
||||||
|
->scopes(['openid', 'profile', 'email'])
|
||||||
|
->stateless()
|
||||||
|
->with(['state' => $state])
|
||||||
|
->redirect();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function callback(Request $request): RedirectResponse
|
||||||
|
{
|
||||||
|
$state = $request->string('state')->toString();
|
||||||
|
|
||||||
|
/** @var array{tenant_codigo?: string, return_url?: string}|null $context */
|
||||||
|
$context = Str::isUuid($state) ? Cache::pull("google-oauth-context:{$state}") : null;
|
||||||
|
|
||||||
|
if (! is_array($context) || ! isset($context['tenant_codigo'], $context['return_url'])) {
|
||||||
|
abort(400, 'La solicitud de autenticacion expiro. Intenta nuevamente.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$tenant = Tenant::query()->where('codigo', $context['tenant_codigo'])->first();
|
||||||
|
|
||||||
|
if (! $tenant || ! $this->isTenantReturnUrl($context['return_url'], $tenant)) {
|
||||||
|
abort(400, 'La URL de retorno no es valida.');
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var SocialiteUser $googleUser */
|
||||||
|
$googleUser = Socialite::driver('google')->stateless()->user();
|
||||||
|
$user = $this->resolveUser($googleUser, $tenant);
|
||||||
|
$token = $user->createToken(
|
||||||
|
'google-oauth',
|
||||||
|
['*'],
|
||||||
|
now()->addMinutes((int) config('sanctum.expiration')),
|
||||||
|
)->plainTextToken;
|
||||||
|
|
||||||
|
$exchangeCode = (string) Str::uuid();
|
||||||
|
Cache::put("google-oauth-exchange:{$exchangeCode}", [
|
||||||
|
'user_id' => $user->id,
|
||||||
|
'token' => $token,
|
||||||
|
], now()->addMinutes(5));
|
||||||
|
|
||||||
|
return redirect()->to($context['return_url'].'/login?'.http_build_query([
|
||||||
|
'oauth_code' => $exchangeCode,
|
||||||
|
]));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return array{user: User, token: string} */
|
||||||
|
public function exchange(string $exchangeCode): array
|
||||||
|
{
|
||||||
|
/** @var array{user_id: int, token: string}|null $authentication */
|
||||||
|
$authentication = Cache::pull("google-oauth-exchange:{$exchangeCode}");
|
||||||
|
|
||||||
|
if (! $authentication) {
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'oauth_code' => 'El codigo de autenticacion expiro o ya fue utilizado.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'user' => User::query()->findOrFail($authentication['user_id']),
|
||||||
|
'token' => $authentication['token'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
private function resolveUser(SocialiteUser $googleUser, Tenant $tenant): User
|
||||||
|
{
|
||||||
|
$googleId = $googleUser->getId();
|
||||||
|
$email = $googleUser->getEmail();
|
||||||
|
|
||||||
|
if (! is_string($googleId) || $googleId === '' || ! is_string($email) || ! filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'google' => 'Google no devolvio una identidad valida.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$rawUser = $googleUser instanceof \Laravel\Socialite\Two\User ? $googleUser->getRaw() : [];
|
||||||
|
$emailVerified = $rawUser['email_verified'] ?? $rawUser['verified_email'] ?? false;
|
||||||
|
if (! in_array($emailVerified, [true, 'true', 1, '1'], true)) {
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'google' => 'La cuenta de Google debe tener el email verificado.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$user = User::query()->where('google_id', $googleId)->first();
|
||||||
|
if ($user) {
|
||||||
|
return $user;
|
||||||
|
}
|
||||||
|
|
||||||
|
$user = User::query()->where('email', $email)->first();
|
||||||
|
if ($user) {
|
||||||
|
$user->forceFill(['google_id' => $googleId])->save();
|
||||||
|
|
||||||
|
return $user;
|
||||||
|
}
|
||||||
|
|
||||||
|
$name = $googleUser->getName();
|
||||||
|
$user = User::query()->create([
|
||||||
|
'nombre_apellido' => is_string($name) && $name !== '' ? $name : $email,
|
||||||
|
'email' => $email,
|
||||||
|
'email_verified_at' => now(),
|
||||||
|
'google_id' => $googleId,
|
||||||
|
'password' => Str::password(64),
|
||||||
|
]);
|
||||||
|
|
||||||
|
UserRegistered::dispatch($user, $tenant->codigo);
|
||||||
|
|
||||||
|
return $user;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function isTenantReturnUrl(string $returnUrl, Tenant $tenant): bool
|
||||||
|
{
|
||||||
|
$parts = parse_url($returnUrl);
|
||||||
|
if (! is_array($parts)
|
||||||
|
|| ! isset($parts['scheme'], $parts['host'])
|
||||||
|
|| isset($parts['user'], $parts['pass'], $parts['query'], $parts['fragment'])
|
||||||
|
|| ($parts['path'] ?? '') !== '') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$scheme = strtolower($parts['scheme']);
|
||||||
|
$host = TenantDomainNormalizer::normalize($parts['host']);
|
||||||
|
$tenantDomain = TenantDomainNormalizer::normalize($tenant->dominio);
|
||||||
|
|
||||||
|
if ($host === null || $tenantDomain === null || $host !== $tenantDomain) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $scheme === 'https' || ($scheme === 'http' && in_array($host, ['localhost', '127.0.0.1'], true));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,20 +3,27 @@
|
|||||||
namespace App\Domains\Auth\Services;
|
namespace App\Domains\Auth\Services;
|
||||||
|
|
||||||
use App\Domains\Auth\Models\User;
|
use App\Domains\Auth\Models\User;
|
||||||
|
use App\Domains\Notification\Events\UserRegistered;
|
||||||
|
|
||||||
class RegisterUserService
|
class RegisterUserService
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @param array{nombre_apellido: string, email: string, password: string, dni?: string|null, telefono?: string|null} $data
|
* @param array{tenant_codigo?: string|null, nombre_apellido: string, email: string, password: string, dni?: string|null, telefono?: string|null} $data
|
||||||
*/
|
*/
|
||||||
public function register(array $data): User
|
public function register(array $data): User
|
||||||
{
|
{
|
||||||
return User::query()->create([
|
$user = User::query()->create([
|
||||||
'nombre_apellido' => $data['nombre_apellido'],
|
'nombre_apellido' => $data['nombre_apellido'],
|
||||||
'email' => $data['email'],
|
'email' => $data['email'],
|
||||||
'password' => $data['password'],
|
'password' => $data['password'],
|
||||||
'dni' => $data['dni'] ?? null,
|
'dni' => $data['dni'] ?? null,
|
||||||
'telefono' => $data['telefono'] ?? null,
|
'telefono' => $data['telefono'] ?? null,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
if (! empty($data['tenant_codigo'])) {
|
||||||
|
UserRegistered::dispatch($user, $data['tenant_codigo']);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $user;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use App\Domains\Auth\Controllers\GoogleTokenExchangeController;
|
||||||
use App\Domains\Auth\Controllers\LoginController;
|
use App\Domains\Auth\Controllers\LoginController;
|
||||||
use App\Domains\Auth\Controllers\LogoutController;
|
use App\Domains\Auth\Controllers\LogoutController;
|
||||||
use App\Domains\Auth\Controllers\MeController;
|
use App\Domains\Auth\Controllers\MeController;
|
||||||
@@ -9,6 +10,7 @@ use Illuminate\Support\Facades\Route;
|
|||||||
|
|
||||||
Route::post('/register', RegisterController::class);
|
Route::post('/register', RegisterController::class);
|
||||||
Route::post('/login', LoginController::class);
|
Route::post('/login', LoginController::class);
|
||||||
|
Route::post('/auth/google/exchange', GoogleTokenExchangeController::class);
|
||||||
Route::middleware('auth:sanctum')->post('/logout', LogoutController::class);
|
Route::middleware('auth:sanctum')->post('/logout', LogoutController::class);
|
||||||
Route::middleware('auth:sanctum')->get('/me', MeController::class);
|
Route::middleware('auth:sanctum')->get('/me', MeController::class);
|
||||||
Route::middleware('auth:sanctum')->put('/me', UpdateProfileController::class);
|
Route::middleware('auth:sanctum')->put('/me', UpdateProfileController::class);
|
||||||
|
|||||||
@@ -2,19 +2,25 @@
|
|||||||
|
|
||||||
namespace App\Domains\Catalog\Controllers;
|
namespace App\Domains\Catalog\Controllers;
|
||||||
|
|
||||||
|
use App\Domains\Catalog\Enums\GroupLayout;
|
||||||
use App\Domains\Catalog\Models\CatalogItem;
|
use App\Domains\Catalog\Models\CatalogItem;
|
||||||
use App\Domains\Catalog\Models\FeaturedGroup;
|
use App\Domains\Catalog\Models\FeaturedGroup;
|
||||||
|
use App\Domains\Catalog\Models\FeaturedItem;
|
||||||
use App\Domains\Catalog\Requests\CatalogItemDetailRequest;
|
use App\Domains\Catalog\Requests\CatalogItemDetailRequest;
|
||||||
use App\Domains\Catalog\Requests\FeaturedGroupPageRequest;
|
use App\Domains\Catalog\Requests\FeaturedGroupPageRequest;
|
||||||
|
use App\Domains\Catalog\Requests\SearchCatalogItemsRequest;
|
||||||
use App\Domains\Catalog\Requests\StoreCatalogItemRequest;
|
use App\Domains\Catalog\Requests\StoreCatalogItemRequest;
|
||||||
use App\Domains\Catalog\Resources\CatalogFeaturedGroupResource;
|
use App\Domains\Catalog\Resources\CatalogFeaturedGroupResource;
|
||||||
use App\Domains\Catalog\Resources\CatalogFeaturedItemResource;
|
use App\Domains\Catalog\Resources\CatalogFeaturedItemResource;
|
||||||
use App\Domains\Catalog\Resources\CatalogItemDetailResource;
|
use App\Domains\Catalog\Resources\CatalogItemDetailResource;
|
||||||
use App\Domains\Catalog\Resources\CatalogItemResource;
|
use App\Domains\Catalog\Resources\CatalogItemResource;
|
||||||
|
use App\Domains\Catalog\Resources\CatalogSearchItemResource;
|
||||||
use App\Domains\Catalog\Services\CatalogService;
|
use App\Domains\Catalog\Services\CatalogService;
|
||||||
use App\Domains\Tenant\Models\Tenant;
|
use App\Domains\Tenant\Models\Tenant;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
use Illuminate\Http\JsonResponse;
|
use Illuminate\Http\JsonResponse;
|
||||||
|
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
|
||||||
use Illuminate\Pagination\LengthAwarePaginator;
|
use Illuminate\Pagination\LengthAwarePaginator;
|
||||||
|
|
||||||
class CatalogController extends Controller
|
class CatalogController extends Controller
|
||||||
@@ -36,6 +42,21 @@ class CatalogController extends Controller
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function search(
|
||||||
|
SearchCatalogItemsRequest $request,
|
||||||
|
Tenant $tenant,
|
||||||
|
CatalogService $catalogService,
|
||||||
|
): AnonymousResourceCollection {
|
||||||
|
return CatalogSearchItemResource::collection(
|
||||||
|
$catalogService->search(
|
||||||
|
$tenant,
|
||||||
|
$request->validated('q'),
|
||||||
|
$tenant->search_items_per_page,
|
||||||
|
(int) $request->validated('page', 1),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public function featuredGroupItems(
|
public function featuredGroupItems(
|
||||||
FeaturedGroupPageRequest $request,
|
FeaturedGroupPageRequest $request,
|
||||||
Tenant $tenant,
|
Tenant $tenant,
|
||||||
@@ -81,9 +102,19 @@ class CatalogController extends Controller
|
|||||||
->setStatusCode(201);
|
->setStatusCode(201);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return array<string, mixed> */
|
/** @return array<array-key, mixed> */
|
||||||
private function featuredItemsResponse(FeaturedGroup $featuredGroup, int $page): array
|
private function featuredItemsResponse(FeaturedGroup $featuredGroup, int $page): array
|
||||||
{
|
{
|
||||||
|
if ($featuredGroup->group_layout !== GroupLayout::Paginated) {
|
||||||
|
$featuredItems = $this->featuredItemsQuery($featuredGroup)->get();
|
||||||
|
|
||||||
|
$featuredItems->each(
|
||||||
|
fn ($featuredItem) => $featuredItem->setRelation('featuredGroup', $featuredGroup)
|
||||||
|
);
|
||||||
|
|
||||||
|
return CatalogFeaturedItemResource::collection($featuredItems)->resolve();
|
||||||
|
}
|
||||||
|
|
||||||
$paginator = $this->paginateFeaturedItems($featuredGroup, $page);
|
$paginator = $this->paginateFeaturedItems($featuredGroup, $page);
|
||||||
|
|
||||||
$paginator->getCollection()->each(
|
$paginator->getCollection()->each(
|
||||||
@@ -99,25 +130,29 @@ class CatalogController extends Controller
|
|||||||
FeaturedGroup $featuredGroup,
|
FeaturedGroup $featuredGroup,
|
||||||
int $page,
|
int $page,
|
||||||
): LengthAwarePaginator {
|
): LengthAwarePaginator {
|
||||||
$paginator = $featuredGroup->featuredItems()
|
$paginator = $this->featuredItemsQuery($featuredGroup)->paginate(
|
||||||
->with([
|
perPage: self::ITEMS_PER_PAGE,
|
||||||
'catalogItem.inventory',
|
pageName: 'page',
|
||||||
'catalogItem.attachments',
|
page: $page,
|
||||||
'catalogItem.variants.inventory',
|
);
|
||||||
'catalogItem.variants.attachments',
|
|
||||||
'catalogItem.variants.definitions.itemAttribute.attribute',
|
|
||||||
'catalogItem.bundleComponents.catalogItem',
|
|
||||||
'catalogItem.bundleComponents.variant.catalogItem',
|
|
||||||
])
|
|
||||||
->paginate(
|
|
||||||
perPage: self::ITEMS_PER_PAGE,
|
|
||||||
pageName: 'page',
|
|
||||||
page: $page,
|
|
||||||
);
|
|
||||||
|
|
||||||
return $paginator->withPath(route('catalog.featured-groups.items.index', [
|
return $paginator->withPath(route('catalog.featured-groups.items.index', [
|
||||||
'tenant' => $featuredGroup->tenant_code,
|
'tenant' => $featuredGroup->tenant_code,
|
||||||
'featuredGroup' => $featuredGroup->id,
|
'featuredGroup' => $featuredGroup->id,
|
||||||
]));
|
]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @return HasMany<FeaturedItem, FeaturedGroup> */
|
||||||
|
private function featuredItemsQuery(FeaturedGroup $featuredGroup): HasMany
|
||||||
|
{
|
||||||
|
return $featuredGroup->featuredItems()->with([
|
||||||
|
'catalogItem.inventory',
|
||||||
|
'catalogItem.attachments',
|
||||||
|
'catalogItem.variants.inventory',
|
||||||
|
'catalogItem.variants.attachments',
|
||||||
|
'catalogItem.variants.definitions.itemAttribute.attribute',
|
||||||
|
'catalogItem.bundleComponents.catalogItem',
|
||||||
|
'catalogItem.bundleComponents.variant.catalogItem',
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
19
app/Domains/Catalog/Enums/GroupLayout.php
Normal file
19
app/Domains/Catalog/Enums/GroupLayout.php
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domains\Catalog\Enums;
|
||||||
|
|
||||||
|
enum GroupLayout: string
|
||||||
|
{
|
||||||
|
case Paginated = 'paginated';
|
||||||
|
case Simple = 'simple';
|
||||||
|
case SimpleVertical = 'simple_vertical';
|
||||||
|
case Carousel = 'carousel';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return list<string>
|
||||||
|
*/
|
||||||
|
public static function values(): array
|
||||||
|
{
|
||||||
|
return array_column(self::cases(), 'value');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Domains\Catalog\Models;
|
namespace App\Domains\Catalog\Models;
|
||||||
|
|
||||||
|
use App\Domains\Catalog\Enums\GroupLayout;
|
||||||
use App\Domains\Catalog\Enums\ProductLayout;
|
use App\Domains\Catalog\Enums\ProductLayout;
|
||||||
use App\Domains\Tenant\Models\Tenant;
|
use App\Domains\Tenant\Models\Tenant;
|
||||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||||
@@ -13,6 +14,7 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
|
|||||||
#[Fillable([
|
#[Fillable([
|
||||||
'tenant_code',
|
'tenant_code',
|
||||||
'product_layout',
|
'product_layout',
|
||||||
|
'group_layout',
|
||||||
'group_name',
|
'group_name',
|
||||||
'group_order',
|
'group_order',
|
||||||
])]
|
])]
|
||||||
@@ -28,6 +30,7 @@ class FeaturedGroup extends Model
|
|||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'product_layout' => ProductLayout::class,
|
'product_layout' => ProductLayout::class,
|
||||||
|
'group_layout' => GroupLayout::class,
|
||||||
'group_order' => 'integer',
|
'group_order' => 'integer',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
29
app/Domains/Catalog/Requests/SearchCatalogItemsRequest.php
Normal file
29
app/Domains/Catalog/Requests/SearchCatalogItemsRequest.php
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domains\Catalog\Requests;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class SearchCatalogItemsRequest extends FormRequest
|
||||||
|
{
|
||||||
|
public function authorize(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return array<string, list<string>> */
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'q' => ['required', 'string', 'min:2', 'max:100'],
|
||||||
|
'page' => ['sometimes', 'integer', 'min:1'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function prepareForValidation(): void
|
||||||
|
{
|
||||||
|
if ($this->has('q') && is_string($this->input('q'))) {
|
||||||
|
$this->merge(['q' => trim($this->string('q')->toString())]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,8 +9,8 @@ use Illuminate\Http\Resources\Json\JsonResource;
|
|||||||
/** @mixin FeaturedGroup */
|
/** @mixin FeaturedGroup */
|
||||||
class CatalogFeaturedGroupResource extends JsonResource
|
class CatalogFeaturedGroupResource extends JsonResource
|
||||||
{
|
{
|
||||||
/** @param array<string, mixed> $itemsPage */
|
/** @param array<array-key, mixed> $items */
|
||||||
public function __construct($resource, private readonly array $itemsPage)
|
public function __construct($resource, private readonly array $items)
|
||||||
{
|
{
|
||||||
parent::__construct($resource);
|
parent::__construct($resource);
|
||||||
}
|
}
|
||||||
@@ -22,8 +22,9 @@ class CatalogFeaturedGroupResource extends JsonResource
|
|||||||
'id' => $this->id,
|
'id' => $this->id,
|
||||||
'title' => $this->group_name,
|
'title' => $this->group_name,
|
||||||
'layout' => $this->product_layout->value,
|
'layout' => $this->product_layout->value,
|
||||||
|
'group_layout' => $this->group_layout->value,
|
||||||
'group_order' => $this->group_order,
|
'group_order' => $this->group_order,
|
||||||
'items' => $this->itemsPage,
|
'items' => $this->items,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
45
app/Domains/Catalog/Resources/CatalogSearchItemResource.php
Normal file
45
app/Domains/Catalog/Resources/CatalogSearchItemResource.php
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domains\Catalog\Resources;
|
||||||
|
|
||||||
|
use App\Domains\Catalog\Enums\InventoryPolicy;
|
||||||
|
use App\Domains\Catalog\Models\CatalogItem;
|
||||||
|
use App\Domains\Catalog\Models\Variant;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
|
|
||||||
|
/** @mixin CatalogItem */
|
||||||
|
class CatalogSearchItemResource extends JsonResource
|
||||||
|
{
|
||||||
|
/** @return array<string, mixed> */
|
||||||
|
public function toArray(Request $request): array
|
||||||
|
{
|
||||||
|
$attachment = $this->attachments->first()
|
||||||
|
?? $this->variants
|
||||||
|
->flatMap(fn (Variant $variant) => $variant->attachments)
|
||||||
|
->first();
|
||||||
|
|
||||||
|
return [
|
||||||
|
'id' => $this->id,
|
||||||
|
'type' => $this->type->value,
|
||||||
|
'nombre' => $this->nombre,
|
||||||
|
'descripcion' => $this->descripcion,
|
||||||
|
'precio' => $this->precio,
|
||||||
|
'image' => $attachment?->getTemporaryUrl(1440),
|
||||||
|
'stock_tecnico' => $this->availableStock(),
|
||||||
|
'variants' => $this->variants
|
||||||
|
->map(fn (Variant $variant): array => [
|
||||||
|
'id' => $variant->id,
|
||||||
|
'stock_tecnico' => $this->inventory_policy === InventoryPolicy::Unlimited
|
||||||
|
? null
|
||||||
|
: $variant->inventory?->availableStock(),
|
||||||
|
'values' => $variant->definitions
|
||||||
|
->mapWithKeys(fn ($definition) => [
|
||||||
|
$definition->itemAttribute?->attribute?->codigo => $definition->value,
|
||||||
|
])
|
||||||
|
->filter(fn ($value, $key): bool => $key !== null),
|
||||||
|
])
|
||||||
|
->values(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,6 +10,9 @@ use App\Domains\Catalog\Models\CatalogItem;
|
|||||||
use App\Domains\Catalog\Models\Inventory;
|
use App\Domains\Catalog\Models\Inventory;
|
||||||
use App\Domains\Catalog\Models\ItemAttribute;
|
use App\Domains\Catalog\Models\ItemAttribute;
|
||||||
use App\Domains\Catalog\Models\Variant;
|
use App\Domains\Catalog\Models\Variant;
|
||||||
|
use App\Domains\Tenant\Models\Tenant;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
use Illuminate\Pagination\LengthAwarePaginator;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use Illuminate\Validation\ValidationException;
|
use Illuminate\Validation\ValidationException;
|
||||||
@@ -158,6 +161,55 @@ class CatalogService
|
|||||||
return $catalogItem;
|
return $catalogItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @return LengthAwarePaginator<CatalogItem> */
|
||||||
|
public function search(
|
||||||
|
Tenant $tenant,
|
||||||
|
string $term,
|
||||||
|
int $perPage,
|
||||||
|
int $page,
|
||||||
|
): LengthAwarePaginator {
|
||||||
|
$normalizedTerm = mb_strtolower($term);
|
||||||
|
$containsPattern = "%{$normalizedTerm}%";
|
||||||
|
$startsWithPattern = "{$normalizedTerm}%";
|
||||||
|
|
||||||
|
$paginator = CatalogItem::query()
|
||||||
|
->where('tenant_code', $tenant->codigo)
|
||||||
|
->where(function (Builder $query) use ($containsPattern): void {
|
||||||
|
$query
|
||||||
|
->whereRaw('LOWER(nombre) LIKE ?', [$containsPattern])
|
||||||
|
->orWhereRaw('LOWER(descripcion) LIKE ?', [$containsPattern])
|
||||||
|
->orWhereHas(
|
||||||
|
'brand',
|
||||||
|
fn (Builder $brandQuery) => $brandQuery
|
||||||
|
->whereRaw('LOWER(nombre) LIKE ?', [$containsPattern])
|
||||||
|
)
|
||||||
|
->orWhereHas(
|
||||||
|
'category',
|
||||||
|
fn (Builder $categoryQuery) => $categoryQuery
|
||||||
|
->whereRaw('LOWER(nombre) LIKE ?', [$containsPattern])
|
||||||
|
);
|
||||||
|
})
|
||||||
|
->with([
|
||||||
|
'attachments',
|
||||||
|
'inventory',
|
||||||
|
'variants.inventory',
|
||||||
|
'variants.attachments',
|
||||||
|
'variants.definitions.itemAttribute.attribute',
|
||||||
|
'bundleComponents.catalogItem',
|
||||||
|
'bundleComponents.variant.catalogItem',
|
||||||
|
])
|
||||||
|
->orderByRaw(
|
||||||
|
'CASE WHEN LOWER(nombre) = ? THEN 0 WHEN LOWER(nombre) LIKE ? THEN 1 ELSE 2 END',
|
||||||
|
[$normalizedTerm, $startsWithPattern],
|
||||||
|
)
|
||||||
|
->orderBy('nombre')
|
||||||
|
->paginate(perPage: $perPage, pageName: 'page', page: $page);
|
||||||
|
|
||||||
|
return $paginator->withPath(route('catalog-items.index', [
|
||||||
|
'tenant' => $tenant->codigo,
|
||||||
|
]));
|
||||||
|
}
|
||||||
|
|
||||||
public function delete(CatalogItem $catalogItem): void
|
public function delete(CatalogItem $catalogItem): void
|
||||||
{
|
{
|
||||||
DB::transaction(function () use ($catalogItem): void {
|
DB::transaction(function () use ($catalogItem): void {
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ Route::prefix('tenants/{tenant:codigo}')->group(function (): void {
|
|||||||
Route::get('catalog', [CatalogController::class, 'index']);
|
Route::get('catalog', [CatalogController::class, 'index']);
|
||||||
Route::get('catalog/featured-groups/{featuredGroup}/items', [CatalogController::class, 'featuredGroupItems'])
|
Route::get('catalog/featured-groups/{featuredGroup}/items', [CatalogController::class, 'featuredGroupItems'])
|
||||||
->name('catalog.featured-groups.items.index');
|
->name('catalog.featured-groups.items.index');
|
||||||
|
Route::get('catalog-items', [CatalogController::class, 'search'])
|
||||||
|
->name('catalog-items.index');
|
||||||
Route::get('catalog-items/{catalogItem}', [CatalogController::class, 'show']);
|
Route::get('catalog-items/{catalogItem}', [CatalogController::class, 'show']);
|
||||||
Route::post('catalog-items', [CatalogController::class, 'store']);
|
Route::post('catalog-items', [CatalogController::class, 'store']);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -4,14 +4,16 @@ namespace App\Domains\Menu\Controllers;
|
|||||||
|
|
||||||
use App\Domains\Menu\Models\Menu;
|
use App\Domains\Menu\Models\Menu;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use Illuminate\Http\JsonResponse;
|
use Illuminate\Http\JsonResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
|
|
||||||
class MenuController extends Controller
|
class MenuController extends Controller
|
||||||
{
|
{
|
||||||
public function index(): JsonResponse
|
public function index(): JsonResponse
|
||||||
{
|
{
|
||||||
$menues = Menu::all();
|
$menues = Menu::all();
|
||||||
|
|
||||||
return response()->json($menues);
|
return response()->json($menues);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -19,10 +21,23 @@ class MenuController extends Controller
|
|||||||
{
|
{
|
||||||
$validated = $request->validate([
|
$validated = $request->validate([
|
||||||
'code' => 'required|string|unique:menues,code',
|
'code' => 'required|string|unique:menues,code',
|
||||||
|
'label' => 'required|string|max:255',
|
||||||
|
'parent_menu_code' => [
|
||||||
|
'nullable',
|
||||||
|
'string',
|
||||||
|
Rule::exists('menues', 'code'),
|
||||||
|
'different:code',
|
||||||
|
],
|
||||||
|
'content_type' => [
|
||||||
|
'sometimes',
|
||||||
|
Rule::in([Menu::CONTENT_TYPE_STATIC, Menu::CONTENT_TYPE_DYNAMIC]),
|
||||||
|
],
|
||||||
|
'static_content_schema' => 'required_if:content_type,static|nullable|array',
|
||||||
'route' => 'required|string',
|
'route' => 'required|string',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$menu = Menu::create($validated);
|
$menu = Menu::create($validated);
|
||||||
|
|
||||||
return response()->json($menu, 201);
|
return response()->json($menu, 201);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,17 +49,31 @@ class MenuController extends Controller
|
|||||||
public function update(Request $request, Menu $menu): JsonResponse
|
public function update(Request $request, Menu $menu): JsonResponse
|
||||||
{
|
{
|
||||||
$validated = $request->validate([
|
$validated = $request->validate([
|
||||||
'code' => 'sometimes|required|string|unique:menues,code,' . $menu->id,
|
'code' => 'sometimes|required|string|unique:menues,code,'.$menu->id,
|
||||||
|
'label' => 'sometimes|required|string|max:255',
|
||||||
|
'parent_menu_code' => [
|
||||||
|
'nullable',
|
||||||
|
'string',
|
||||||
|
Rule::exists('menues', 'code'),
|
||||||
|
Rule::notIn([$menu->code]),
|
||||||
|
],
|
||||||
|
'content_type' => [
|
||||||
|
'sometimes',
|
||||||
|
Rule::in([Menu::CONTENT_TYPE_STATIC, Menu::CONTENT_TYPE_DYNAMIC]),
|
||||||
|
],
|
||||||
|
'static_content_schema' => 'required_if:content_type,static|nullable|array',
|
||||||
'route' => 'sometimes|required|string',
|
'route' => 'sometimes|required|string',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$menu->update($validated);
|
$menu->update($validated);
|
||||||
|
|
||||||
return response()->json($menu);
|
return response()->json($menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function destroy(Menu $menu): JsonResponse
|
public function destroy(Menu $menu): JsonResponse
|
||||||
{
|
{
|
||||||
$menu->delete();
|
$menu->delete();
|
||||||
|
|
||||||
return response()->json(null, 204);
|
return response()->json(null, 204);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
32
app/Domains/Menu/Controllers/TenantMenuController.php
Normal file
32
app/Domains/Menu/Controllers/TenantMenuController.php
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domains\Menu\Controllers;
|
||||||
|
|
||||||
|
use App\Domains\Menu\Models\Menu;
|
||||||
|
use App\Domains\Menu\Requests\StoreTenantMenuRequest;
|
||||||
|
use App\Domains\Menu\Services\TenantMenuService;
|
||||||
|
use App\Domains\Tenant\Models\Tenant;
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
|
||||||
|
class TenantMenuController extends Controller
|
||||||
|
{
|
||||||
|
public function __construct(private readonly TenantMenuService $tenantMenuService) {}
|
||||||
|
|
||||||
|
public function store(
|
||||||
|
StoreTenantMenuRequest $request,
|
||||||
|
string $tenantCode,
|
||||||
|
string $menuCode,
|
||||||
|
): JsonResponse {
|
||||||
|
$tenant = Tenant::query()->where('codigo', $tenantCode)->firstOrFail();
|
||||||
|
$menu = Menu::query()->where('code', $menuCode)->firstOrFail();
|
||||||
|
|
||||||
|
$tenantMenu = $this->tenantMenuService->configure(
|
||||||
|
$tenant,
|
||||||
|
$menu,
|
||||||
|
$request->validated('static_content'),
|
||||||
|
);
|
||||||
|
|
||||||
|
return response()->json($tenantMenu);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,28 +5,77 @@ namespace App\Domains\Menu\Models;
|
|||||||
use App\Domains\Tenant\Models\Tenant;
|
use App\Domains\Tenant\Models\Tenant;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
|
use Illuminate\Validation\ValidationException;
|
||||||
|
|
||||||
class Menu extends Model
|
class Menu extends Model
|
||||||
{
|
{
|
||||||
use HasFactory;
|
use HasFactory;
|
||||||
|
|
||||||
|
public const CONTENT_TYPE_DYNAMIC = 'dynamic';
|
||||||
|
|
||||||
|
public const CONTENT_TYPE_STATIC = 'static';
|
||||||
|
|
||||||
protected $table = 'menues';
|
protected $table = 'menues';
|
||||||
|
|
||||||
|
protected $attributes = [
|
||||||
|
'content_type' => self::CONTENT_TYPE_DYNAMIC,
|
||||||
|
];
|
||||||
|
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'code',
|
'code',
|
||||||
|
'label',
|
||||||
|
'parent_menu_code',
|
||||||
|
'content_type',
|
||||||
|
'static_content_schema',
|
||||||
'route',
|
'route',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
protected function casts(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'static_content_schema' => 'array',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static function booted(): void
|
||||||
|
{
|
||||||
|
static::saving(function (self $menu): void {
|
||||||
|
if (
|
||||||
|
$menu->content_type === self::CONTENT_TYPE_STATIC
|
||||||
|
&& empty($menu->static_content_schema)
|
||||||
|
) {
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'static_content_schema' => 'El schema es obligatorio para los menús estáticos.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function parent(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(self::class, 'parent_menu_code', 'code');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function children(): HasMany
|
||||||
|
{
|
||||||
|
return $this->hasMany(self::class, 'parent_menu_code', 'code');
|
||||||
|
}
|
||||||
|
|
||||||
public function tenants(): BelongsToMany
|
public function tenants(): BelongsToMany
|
||||||
{
|
{
|
||||||
return $this->belongsToMany(
|
return $this->belongsToMany(
|
||||||
Tenant::class,
|
Tenant::class,
|
||||||
'tenant_menues',
|
'tenants_menues',
|
||||||
'menu_code',
|
'menu_code',
|
||||||
'tenant_codigo',
|
'tenant_code',
|
||||||
'code',
|
'code',
|
||||||
'codigo'
|
'codigo'
|
||||||
)->withTimestamps();
|
)
|
||||||
|
->using(TenantMenu::class)
|
||||||
|
->withPivot('static_content')
|
||||||
|
->withTimestamps();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,9 +2,36 @@
|
|||||||
|
|
||||||
namespace App\Domains\Menu\Models;
|
namespace App\Domains\Menu\Models;
|
||||||
|
|
||||||
|
use App\Domains\Tenant\Models\Tenant;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
use Illuminate\Database\Eloquent\Relations\Pivot;
|
use Illuminate\Database\Eloquent\Relations\Pivot;
|
||||||
|
|
||||||
class TenantMenu extends Pivot
|
class TenantMenu extends Pivot
|
||||||
{
|
{
|
||||||
protected $table = 'tenant_menues';
|
protected $table = 'tenants_menues';
|
||||||
|
|
||||||
|
public $incrementing = true;
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'tenant_code',
|
||||||
|
'menu_code',
|
||||||
|
'static_content',
|
||||||
|
];
|
||||||
|
|
||||||
|
protected function casts(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'static_content' => 'array',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function tenant(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Tenant::class, 'tenant_code', 'codigo');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function menu(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Menu::class, 'menu_code', 'code');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
49
app/Domains/Menu/Requests/StoreTenantMenuRequest.php
Normal file
49
app/Domains/Menu/Requests/StoreTenantMenuRequest.php
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domains\Menu\Requests;
|
||||||
|
|
||||||
|
use App\Domains\Menu\Models\Menu;
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
use Illuminate\Validation\ValidationException;
|
||||||
|
|
||||||
|
class StoreTenantMenuRequest extends FormRequest
|
||||||
|
{
|
||||||
|
private ?Menu $menuModel = null;
|
||||||
|
|
||||||
|
public function authorize(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function prepareForValidation(): void
|
||||||
|
{
|
||||||
|
$this->menuModel = Menu::query()
|
||||||
|
->where('code', $this->route('menu_code'))
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if (! $this->menuModel) {
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'menu_code' => 'El menú indicado no existe.',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
if ($this->menuModel?->content_type !== Menu::CONTENT_TYPE_STATIC) {
|
||||||
|
return [
|
||||||
|
'static_content' => ['nullable', 'array'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$rules = [
|
||||||
|
'static_content' => ['required', 'array'],
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($this->menuModel->static_content_schema as $field => $rule) {
|
||||||
|
$rules["static_content.{$field}"] = $rule;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $rules;
|
||||||
|
}
|
||||||
|
}
|
||||||
26
app/Domains/Menu/Services/TenantMenuService.php
Normal file
26
app/Domains/Menu/Services/TenantMenuService.php
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domains\Menu\Services;
|
||||||
|
|
||||||
|
use App\Domains\Menu\Models\Menu;
|
||||||
|
use App\Domains\Menu\Models\TenantMenu;
|
||||||
|
use App\Domains\Tenant\Models\Tenant;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class TenantMenuService
|
||||||
|
{
|
||||||
|
public function configure(Tenant $tenant, Menu $menu, ?array $staticContent): TenantMenu
|
||||||
|
{
|
||||||
|
return DB::transaction(fn () => TenantMenu::query()->updateOrCreate(
|
||||||
|
[
|
||||||
|
'tenant_code' => $tenant->codigo,
|
||||||
|
'menu_code' => $menu->code,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'static_content' => $menu->content_type === Menu::CONTENT_TYPE_STATIC
|
||||||
|
? $staticContent
|
||||||
|
: null,
|
||||||
|
],
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\Domains\Menu\Controllers\MenuController;
|
use App\Domains\Menu\Controllers\MenuController;
|
||||||
|
use App\Domains\Menu\Controllers\TenantMenuController;
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
|
|
||||||
Route::apiResource('menues', MenuController::class);
|
Route::apiResource('menues', MenuController::class);
|
||||||
|
|
||||||
|
Route::post(
|
||||||
|
'{tenant_code}/menues/{menu_code}',
|
||||||
|
[TenantMenuController::class, 'store']
|
||||||
|
);
|
||||||
|
|||||||
20
app/Domains/Notification/Events/TicketsAvailable.php
Normal file
20
app/Domains/Notification/Events/TicketsAvailable.php
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domains\Notification\Events;
|
||||||
|
|
||||||
|
use App\Domains\Purchase\Models\Purchase;
|
||||||
|
use Illuminate\Foundation\Events\Dispatchable;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
|
||||||
|
class TicketsAvailable
|
||||||
|
{
|
||||||
|
use Dispatchable, SerializesModels;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<int, int> $ticketIds
|
||||||
|
*/
|
||||||
|
public function __construct(
|
||||||
|
public readonly Purchase $purchase,
|
||||||
|
public readonly array $ticketIds,
|
||||||
|
) {}
|
||||||
|
}
|
||||||
17
app/Domains/Notification/Events/UserRegistered.php
Normal file
17
app/Domains/Notification/Events/UserRegistered.php
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domains\Notification\Events;
|
||||||
|
|
||||||
|
use App\Domains\Auth\Models\User;
|
||||||
|
use Illuminate\Foundation\Events\Dispatchable;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
|
||||||
|
class UserRegistered
|
||||||
|
{
|
||||||
|
use Dispatchable, SerializesModels;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
public readonly User $user,
|
||||||
|
public readonly string $tenantCode,
|
||||||
|
) {}
|
||||||
|
}
|
||||||
25
app/Domains/Notification/Listeners/SendPurchasePaidEmail.php
Normal file
25
app/Domains/Notification/Listeners/SendPurchasePaidEmail.php
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domains\Notification\Listeners;
|
||||||
|
|
||||||
|
use App\Domains\Notification\Services\NotificationMailService;
|
||||||
|
use App\Domains\Purchase\Events\PurchasePaid;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueueAfterCommit;
|
||||||
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
|
|
||||||
|
class SendPurchasePaidEmail implements ShouldQueueAfterCommit
|
||||||
|
{
|
||||||
|
use InteractsWithQueue;
|
||||||
|
|
||||||
|
public string $queue = 'emails';
|
||||||
|
|
||||||
|
public int $tries = 3;
|
||||||
|
|
||||||
|
/** @var array<int, int> */
|
||||||
|
public array $backoff = [30, 120, 300];
|
||||||
|
|
||||||
|
public function handle(PurchasePaid $event): void
|
||||||
|
{
|
||||||
|
app(NotificationMailService::class)->sendPurchasePaid($event->purchase->getKey());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domains\Notification\Listeners;
|
||||||
|
|
||||||
|
use App\Domains\Notification\Events\TicketsAvailable;
|
||||||
|
use App\Domains\Notification\Services\NotificationMailService;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueueAfterCommit;
|
||||||
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
|
|
||||||
|
class SendTicketsAvailableEmail implements ShouldQueueAfterCommit
|
||||||
|
{
|
||||||
|
use InteractsWithQueue;
|
||||||
|
|
||||||
|
public string $queue = 'emails';
|
||||||
|
|
||||||
|
public int $tries = 3;
|
||||||
|
|
||||||
|
/** @var array<int, int> */
|
||||||
|
public array $backoff = [30, 120, 300];
|
||||||
|
|
||||||
|
public function handle(TicketsAvailable $event): void
|
||||||
|
{
|
||||||
|
app(NotificationMailService::class)->sendTicketsAvailable($event->purchase->getKey(), $event->ticketIds);
|
||||||
|
}
|
||||||
|
}
|
||||||
25
app/Domains/Notification/Listeners/SendWelcomeEmail.php
Normal file
25
app/Domains/Notification/Listeners/SendWelcomeEmail.php
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domains\Notification\Listeners;
|
||||||
|
|
||||||
|
use App\Domains\Notification\Events\UserRegistered;
|
||||||
|
use App\Domains\Notification\Services\NotificationMailService;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueueAfterCommit;
|
||||||
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
|
|
||||||
|
class SendWelcomeEmail implements ShouldQueueAfterCommit
|
||||||
|
{
|
||||||
|
use InteractsWithQueue;
|
||||||
|
|
||||||
|
public string $queue = 'emails';
|
||||||
|
|
||||||
|
public int $tries = 3;
|
||||||
|
|
||||||
|
/** @var array<int, int> */
|
||||||
|
public array $backoff = [30, 120, 300];
|
||||||
|
|
||||||
|
public function handle(UserRegistered $event): void
|
||||||
|
{
|
||||||
|
app(NotificationMailService::class)->sendWelcome($event->user->getKey(), $event->tenantCode);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domains\Notification\Services;
|
||||||
|
|
||||||
|
use App\Domains\Auth\Models\User;
|
||||||
|
use App\Domains\Integration\Services\MailService;
|
||||||
|
use App\Domains\Purchase\Models\Purchase;
|
||||||
|
use App\Domains\Tenant\Models\Tenant;
|
||||||
|
use App\Domains\Ticket\Models\Ticket;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
|
class NotificationMailService
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly MailService $mailService,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
public function sendWelcome(int $userId, string $tenantCode): void
|
||||||
|
{
|
||||||
|
$tenant = Tenant::query()->where('codigo', $tenantCode)->firstOrFail();
|
||||||
|
$user = User::query()->findOrFail($userId);
|
||||||
|
|
||||||
|
$this->mailService
|
||||||
|
->forTenant($tenantCode)
|
||||||
|
->send(
|
||||||
|
$user->email,
|
||||||
|
"Bienvenido a {$tenant->nombre}",
|
||||||
|
view('mail.notifications.welcome', compact('tenant', 'user'))->render(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function sendPurchasePaid(int $purchaseId): void
|
||||||
|
{
|
||||||
|
$purchase = Purchase::query()
|
||||||
|
->with(['tenant', 'user', 'items'])
|
||||||
|
->findOrFail($purchaseId);
|
||||||
|
|
||||||
|
$this->mailService
|
||||||
|
->forTenant($purchase->tenant_codigo)
|
||||||
|
->send(
|
||||||
|
$this->recipientFor($purchase),
|
||||||
|
"Pago confirmado - Compra #{$purchase->getKey()}",
|
||||||
|
view('mail.notifications.purchase-paid', compact('purchase'))->render(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @param array<int, int> $ticketIds */
|
||||||
|
public function sendTicketsAvailable(int $purchaseId, array $ticketIds): void
|
||||||
|
{
|
||||||
|
$purchase = Purchase::query()->with(['tenant', 'user'])->findOrFail($purchaseId);
|
||||||
|
/** @var Collection<int, Ticket> $tickets */
|
||||||
|
$tickets = Ticket::query()
|
||||||
|
->where('tenant_code', $purchase->tenant_codigo)
|
||||||
|
->where('user_id', $purchase->user_id)
|
||||||
|
->whereKey($ticketIds)
|
||||||
|
->get();
|
||||||
|
|
||||||
|
if ($tickets->isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->mailService
|
||||||
|
->forTenant($purchase->tenant_codigo)
|
||||||
|
->send(
|
||||||
|
$this->recipientFor($purchase),
|
||||||
|
'Tus tickets ya están disponibles',
|
||||||
|
view('mail.notifications.tickets-available', compact('purchase', 'tickets'))->render(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function recipientFor(Purchase $purchase): string
|
||||||
|
{
|
||||||
|
return (string) ($purchase->email ?: $purchase->user?->email);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,7 +15,10 @@ class BootstrapTenantController extends Controller
|
|||||||
$dominio = $request->validated('dominio');
|
$dominio = $request->validated('dominio');
|
||||||
|
|
||||||
return TenantResource::make(
|
return TenantResource::make(
|
||||||
Tenant::query()->with(['headerLogo', 'footerLogo', 'menues'])->where('dominio', $dominio)->firstOrFail()
|
Tenant::query()
|
||||||
|
->with(['headerLogo', 'footerLogo', 'mainCarouselImages', 'menues', 'socialMedia'])
|
||||||
|
->where('dominio', $dominio)
|
||||||
|
->firstOrFail()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,32 +13,41 @@ use Illuminate\Http\Response;
|
|||||||
|
|
||||||
class TenantController extends Controller
|
class TenantController extends Controller
|
||||||
{
|
{
|
||||||
public function __construct(protected TenantService $tenantService)
|
public function __construct(protected TenantService $tenantService) {}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public function index(): JsonResponse
|
public function index(): JsonResponse
|
||||||
{
|
{
|
||||||
return TenantResource::collection(Tenant::query()->with(['headerLogo', 'footerLogo'])->latest()->paginateFromRequest())->response();
|
return TenantResource::collection(
|
||||||
|
Tenant::query()
|
||||||
|
->with(['headerLogo', 'footerLogo', 'mainCarouselImages', 'socialMedia'])
|
||||||
|
->latest()
|
||||||
|
->paginateFromRequest()
|
||||||
|
)->response();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function store(StoreTenantRequest $request): JsonResponse
|
public function store(StoreTenantRequest $request): JsonResponse
|
||||||
{
|
{
|
||||||
$tenant = $this->tenantService->create($request->validated());
|
$tenant = $this->tenantService->create($request->validated());
|
||||||
|
|
||||||
return TenantResource::make($tenant->loadMissing(['headerLogo', 'footerLogo']))->response()->setStatusCode(201);
|
return TenantResource::make(
|
||||||
|
$tenant->loadMissing(['headerLogo', 'footerLogo', 'mainCarouselImages', 'socialMedia'])
|
||||||
|
)->response()->setStatusCode(201);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function show(Tenant $tenant): TenantResource
|
public function show(Tenant $tenant): TenantResource
|
||||||
{
|
{
|
||||||
return TenantResource::make($tenant->loadMissing(['headerLogo', 'footerLogo']));
|
return TenantResource::make(
|
||||||
|
$tenant->loadMissing(['headerLogo', 'footerLogo', 'mainCarouselImages', 'socialMedia'])
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function update(UpdateTenantRequest $request, Tenant $tenant): TenantResource
|
public function update(UpdateTenantRequest $request, Tenant $tenant): TenantResource
|
||||||
{
|
{
|
||||||
$tenant = $this->tenantService->update($tenant, $request->validated());
|
$tenant = $this->tenantService->update($tenant, $request->validated());
|
||||||
|
|
||||||
return TenantResource::make($tenant->loadMissing(['headerLogo', 'footerLogo']));
|
return TenantResource::make(
|
||||||
|
$tenant->loadMissing(['headerLogo', 'footerLogo', 'mainCarouselImages', 'socialMedia'])
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function destroy(Tenant $tenant): Response
|
public function destroy(Tenant $tenant): Response
|
||||||
|
|||||||
35
app/Domains/Tenant/Models/SocialMedia.php
Normal file
35
app/Domains/Tenant/Models/SocialMedia.php
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domains\Tenant\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||||
|
|
||||||
|
class SocialMedia extends Model
|
||||||
|
{
|
||||||
|
protected $table = 'social_media';
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'code',
|
||||||
|
'icon',
|
||||||
|
'name',
|
||||||
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return BelongsToMany<Tenant, $this>
|
||||||
|
*/
|
||||||
|
public function tenants(): BelongsToMany
|
||||||
|
{
|
||||||
|
return $this->belongsToMany(
|
||||||
|
Tenant::class,
|
||||||
|
'tenant_social_media',
|
||||||
|
'social_media_code',
|
||||||
|
'tenant_code',
|
||||||
|
'code',
|
||||||
|
'codigo'
|
||||||
|
)
|
||||||
|
->withPivot(['url', 'orden'])
|
||||||
|
->withTimestamps()
|
||||||
|
->orderByPivot('orden');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,8 +3,11 @@
|
|||||||
namespace App\Domains\Tenant\Models;
|
namespace App\Domains\Tenant\Models;
|
||||||
|
|
||||||
use App\Domains\Attachable\Models\Attachment;
|
use App\Domains\Attachable\Models\Attachment;
|
||||||
|
use App\Domains\Catalog\Enums\GroupLayout;
|
||||||
|
use App\Domains\Catalog\Enums\ProductLayout;
|
||||||
use App\Domains\Catalog\Models\CatalogItem;
|
use App\Domains\Catalog\Models\CatalogItem;
|
||||||
use App\Domains\Menu\Models\Menu;
|
use App\Domains\Menu\Models\Menu;
|
||||||
|
use App\Domains\Menu\Models\TenantMenu;
|
||||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
@@ -26,11 +29,20 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
|
|||||||
'footer_logo_id',
|
'footer_logo_id',
|
||||||
'hero_config',
|
'hero_config',
|
||||||
'event_config',
|
'event_config',
|
||||||
|
'search_product_layout',
|
||||||
|
'search_group_layout',
|
||||||
|
'search_items_per_page',
|
||||||
])]
|
])]
|
||||||
class Tenant extends Model
|
class Tenant extends Model
|
||||||
{
|
{
|
||||||
use HasFactory;
|
use HasFactory;
|
||||||
|
|
||||||
|
protected $attributes = [
|
||||||
|
'search_product_layout' => ProductLayout::ColumnWithImage->value,
|
||||||
|
'search_group_layout' => GroupLayout::Paginated->value,
|
||||||
|
'search_items_per_page' => 12,
|
||||||
|
];
|
||||||
|
|
||||||
public function getRouteKeyName(): string
|
public function getRouteKeyName(): string
|
||||||
{
|
{
|
||||||
return 'codigo';
|
return 'codigo';
|
||||||
@@ -46,6 +58,9 @@ class Tenant extends Model
|
|||||||
return [
|
return [
|
||||||
'hero_config' => 'array',
|
'hero_config' => 'array',
|
||||||
'event_config' => 'array',
|
'event_config' => 'array',
|
||||||
|
'search_product_layout' => ProductLayout::class,
|
||||||
|
'search_group_layout' => GroupLayout::class,
|
||||||
|
'search_items_per_page' => 'integer',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,20 +88,57 @@ class Tenant extends Model
|
|||||||
return $this->belongsTo(Attachment::class, 'hero_bg_image_id');
|
return $this->belongsTo(Attachment::class, 'hero_bg_image_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return BelongsToMany<Attachment, $this>
|
||||||
|
*/
|
||||||
|
public function mainCarouselImages(): BelongsToMany
|
||||||
|
{
|
||||||
|
return $this->belongsToMany(
|
||||||
|
Attachment::class,
|
||||||
|
'tenant_main_carousel_images',
|
||||||
|
'tenant_id',
|
||||||
|
'attachment_id'
|
||||||
|
)
|
||||||
|
->withPivot('orden')
|
||||||
|
->withTimestamps()
|
||||||
|
->orderByPivot('orden');
|
||||||
|
}
|
||||||
|
|
||||||
public function catalogItems(): HasMany
|
public function catalogItems(): HasMany
|
||||||
{
|
{
|
||||||
return $this->hasMany(CatalogItem::class, 'tenant_code', 'codigo');
|
return $this->hasMany(CatalogItem::class, 'tenant_code', 'codigo');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return BelongsToMany<SocialMedia, $this>
|
||||||
|
*/
|
||||||
|
public function socialMedia(): BelongsToMany
|
||||||
|
{
|
||||||
|
return $this->belongsToMany(
|
||||||
|
SocialMedia::class,
|
||||||
|
'tenant_social_media',
|
||||||
|
'tenant_code',
|
||||||
|
'social_media_code',
|
||||||
|
'codigo',
|
||||||
|
'code'
|
||||||
|
)
|
||||||
|
->withPivot(['url', 'orden'])
|
||||||
|
->withTimestamps()
|
||||||
|
->orderByPivot('orden');
|
||||||
|
}
|
||||||
|
|
||||||
public function menues(): BelongsToMany
|
public function menues(): BelongsToMany
|
||||||
{
|
{
|
||||||
return $this->belongsToMany(
|
return $this->belongsToMany(
|
||||||
Menu::class,
|
Menu::class,
|
||||||
'tenant_menues',
|
'tenants_menues',
|
||||||
'tenant_codigo',
|
'tenant_code',
|
||||||
'menu_code',
|
'menu_code',
|
||||||
'codigo',
|
'codigo',
|
||||||
'code'
|
'code'
|
||||||
)->withTimestamps();
|
)
|
||||||
|
->using(TenantMenu::class)
|
||||||
|
->withPivot('static_content')
|
||||||
|
->withTimestamps();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
namespace App\Domains\Tenant\Requests;
|
namespace App\Domains\Tenant\Requests;
|
||||||
|
|
||||||
|
use App\Domains\Catalog\Enums\GroupLayout;
|
||||||
|
use App\Domains\Catalog\Enums\ProductLayout;
|
||||||
use App\Domains\Shared\Rules\ImageOrBase64Rule;
|
use App\Domains\Shared\Rules\ImageOrBase64Rule;
|
||||||
use App\Domains\Tenant\Support\TenantDomainNormalizer;
|
use App\Domains\Tenant\Support\TenantDomainNormalizer;
|
||||||
use Closure;
|
use Closure;
|
||||||
@@ -35,8 +37,7 @@ class StoreTenantRequest extends FormRequest
|
|||||||
*/
|
*/
|
||||||
public function rules(): array
|
public function rules(): array
|
||||||
{
|
{
|
||||||
$logoRule = ['required', new ImageOrBase64Rule()];
|
$logoRule = ['required', new ImageOrBase64Rule];
|
||||||
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'codigo' => ['required', 'string', 'max:255', Rule::unique('tenants', 'codigo')],
|
'codigo' => ['required', 'string', 'max:255', Rule::unique('tenants', 'codigo')],
|
||||||
@@ -61,7 +62,18 @@ class StoreTenantRequest extends FormRequest
|
|||||||
'footer_bg_color' => ['required', 'string', 'regex:/^#([a-fA-F0-9]{3,4}|[a-fA-F0-9]{6}|[a-fA-F0-9]{8})$/'],
|
'footer_bg_color' => ['required', 'string', 'regex:/^#([a-fA-F0-9]{3,4}|[a-fA-F0-9]{6}|[a-fA-F0-9]{8})$/'],
|
||||||
'header_logo' => $logoRule,
|
'header_logo' => $logoRule,
|
||||||
'footer_logo' => $logoRule,
|
'footer_logo' => $logoRule,
|
||||||
'hero_bg_image' => ['nullable', new ImageOrBase64Rule()],
|
'hero_bg_image' => ['nullable', new ImageOrBase64Rule],
|
||||||
|
'main_carousel_images' => ['sometimes', 'array'],
|
||||||
|
'main_carousel_images.*' => ['required', 'distinct', new ImageOrBase64Rule],
|
||||||
|
'social_media' => ['sometimes', 'array'],
|
||||||
|
'social_media.*.code' => [
|
||||||
|
'required',
|
||||||
|
'string',
|
||||||
|
'distinct',
|
||||||
|
Rule::exists('social_media', 'code'),
|
||||||
|
],
|
||||||
|
'social_media.*.url' => ['required', 'url', 'max:2048'],
|
||||||
|
'social_media.*.orden' => ['sometimes', 'integer', 'min:0', 'distinct'],
|
||||||
'hero_config' => ['nullable', 'array'],
|
'hero_config' => ['nullable', 'array'],
|
||||||
'hero_config.title_html' => ['nullable', 'string'],
|
'hero_config.title_html' => ['nullable', 'string'],
|
||||||
'hero_config.description_html' => ['nullable', 'string'],
|
'hero_config.description_html' => ['nullable', 'string'],
|
||||||
@@ -72,6 +84,9 @@ class StoreTenantRequest extends FormRequest
|
|||||||
'event_config.location' => ['nullable', 'string'],
|
'event_config.location' => ['nullable', 'string'],
|
||||||
'event_config.dates' => ['nullable', 'array'],
|
'event_config.dates' => ['nullable', 'array'],
|
||||||
'event_config.dates.*' => ['required', 'string'],
|
'event_config.dates.*' => ['required', 'string'],
|
||||||
|
'search_product_layout' => ['sometimes', Rule::enum(ProductLayout::class)],
|
||||||
|
'search_group_layout' => ['sometimes', Rule::enum(GroupLayout::class)],
|
||||||
|
'search_items_per_page' => ['sometimes', 'integer', 'min:4', 'max:48'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
namespace App\Domains\Tenant\Requests;
|
namespace App\Domains\Tenant\Requests;
|
||||||
|
|
||||||
|
use App\Domains\Catalog\Enums\GroupLayout;
|
||||||
|
use App\Domains\Catalog\Enums\ProductLayout;
|
||||||
use App\Domains\Shared\Rules\ImageOrBase64Rule;
|
use App\Domains\Shared\Rules\ImageOrBase64Rule;
|
||||||
use App\Domains\Tenant\Models\Tenant;
|
use App\Domains\Tenant\Models\Tenant;
|
||||||
use App\Domains\Tenant\Support\TenantDomainNormalizer;
|
use App\Domains\Tenant\Support\TenantDomainNormalizer;
|
||||||
@@ -41,8 +43,7 @@ class UpdateTenantRequest extends FormRequest
|
|||||||
/** @var Tenant|null $tenant */
|
/** @var Tenant|null $tenant */
|
||||||
$tenant = $this->route('tenant');
|
$tenant = $this->route('tenant');
|
||||||
|
|
||||||
$logoRule = ['nullable', new ImageOrBase64Rule()];
|
$logoRule = ['nullable', new ImageOrBase64Rule];
|
||||||
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'codigo' => [
|
'codigo' => [
|
||||||
@@ -72,7 +73,18 @@ class UpdateTenantRequest extends FormRequest
|
|||||||
'footer_bg_color' => ['nullable', 'string', 'regex:/^#([a-fA-F0-9]{3,4}|[a-fA-F0-9]{6}|[a-fA-F0-9]{8})$/'],
|
'footer_bg_color' => ['nullable', 'string', 'regex:/^#([a-fA-F0-9]{3,4}|[a-fA-F0-9]{6}|[a-fA-F0-9]{8})$/'],
|
||||||
'header_logo' => $logoRule,
|
'header_logo' => $logoRule,
|
||||||
'footer_logo' => $logoRule,
|
'footer_logo' => $logoRule,
|
||||||
'hero_bg_image' => ['nullable', new ImageOrBase64Rule()],
|
'hero_bg_image' => ['nullable', new ImageOrBase64Rule],
|
||||||
|
'main_carousel_images' => ['sometimes', 'array'],
|
||||||
|
'main_carousel_images.*' => ['required', 'distinct', new ImageOrBase64Rule],
|
||||||
|
'social_media' => ['sometimes', 'array'],
|
||||||
|
'social_media.*.code' => [
|
||||||
|
'required',
|
||||||
|
'string',
|
||||||
|
'distinct',
|
||||||
|
Rule::exists('social_media', 'code'),
|
||||||
|
],
|
||||||
|
'social_media.*.url' => ['required', 'url', 'max:2048'],
|
||||||
|
'social_media.*.orden' => ['sometimes', 'integer', 'min:0', 'distinct'],
|
||||||
'hero_config' => ['nullable', 'array'],
|
'hero_config' => ['nullable', 'array'],
|
||||||
'hero_config.title_html' => ['nullable', 'string'],
|
'hero_config.title_html' => ['nullable', 'string'],
|
||||||
'hero_config.description_html' => ['nullable', 'string'],
|
'hero_config.description_html' => ['nullable', 'string'],
|
||||||
@@ -83,6 +95,9 @@ class UpdateTenantRequest extends FormRequest
|
|||||||
'event_config.location' => ['nullable', 'string'],
|
'event_config.location' => ['nullable', 'string'],
|
||||||
'event_config.dates' => ['nullable', 'array'],
|
'event_config.dates' => ['nullable', 'array'],
|
||||||
'event_config.dates.*' => ['required', 'string'],
|
'event_config.dates.*' => ['required', 'string'],
|
||||||
|
'search_product_layout' => ['sometimes', Rule::enum(ProductLayout::class)],
|
||||||
|
'search_group_layout' => ['sometimes', Rule::enum(GroupLayout::class)],
|
||||||
|
'search_items_per_page' => ['sometimes', 'integer', 'min:4', 'max:48'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,11 +2,14 @@
|
|||||||
|
|
||||||
namespace App\Domains\Tenant\Resources;
|
namespace App\Domains\Tenant\Resources;
|
||||||
|
|
||||||
|
use App\Domains\Menu\Models\Menu;
|
||||||
|
use App\Domains\Tenant\Models\Tenant;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Http\Resources\Json\JsonResource;
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @mixin \App\Domains\Tenant\Models\Tenant
|
* @mixin Tenant
|
||||||
*/
|
*/
|
||||||
class TenantResource extends JsonResource
|
class TenantResource extends JsonResource
|
||||||
{
|
{
|
||||||
@@ -34,10 +37,73 @@ class TenantResource extends JsonResource
|
|||||||
'footer_bg_color' => $this->footer_bg_color,
|
'footer_bg_color' => $this->footer_bg_color,
|
||||||
// 1 day
|
// 1 day
|
||||||
'header_logo' => $this->headerLogo?->getTemporaryUrl(1440),
|
'header_logo' => $this->headerLogo?->getTemporaryUrl(1440),
|
||||||
'footer_logo' => $this->footerLogo?->getTemporaryUrl(1440 ),
|
'footer_logo' => $this->footerLogo?->getTemporaryUrl(1440),
|
||||||
'hero_config' => $heroConfig,
|
'hero_config' => $heroConfig,
|
||||||
'event_config' => $this->event_config,
|
'event_config' => $this->event_config,
|
||||||
'menues' => $this->whenLoaded('menues'),
|
'search_product_layout' => $this->search_product_layout->value,
|
||||||
|
'search_group_layout' => $this->search_group_layout->value,
|
||||||
|
'search_items_per_page' => $this->search_items_per_page,
|
||||||
|
'main_carousel_images' => $this->whenLoaded(
|
||||||
|
'mainCarouselImages',
|
||||||
|
fn () => $this->mainCarouselImages
|
||||||
|
->map(fn ($attachment) => $attachment->getTemporaryUrl(1440))
|
||||||
|
->values()
|
||||||
|
),
|
||||||
|
'social_media' => $this->whenLoaded(
|
||||||
|
'socialMedia',
|
||||||
|
fn () => $this->socialMedia
|
||||||
|
->map(fn ($socialMedia) => [
|
||||||
|
'code' => $socialMedia->code,
|
||||||
|
'icon' => $socialMedia->icon,
|
||||||
|
'name' => $socialMedia->name,
|
||||||
|
'url' => $socialMedia->pivot->url,
|
||||||
|
])
|
||||||
|
->values()
|
||||||
|
),
|
||||||
|
'menues' => $this->whenLoaded(
|
||||||
|
'menues',
|
||||||
|
fn () => $this->menuTree($this->menues)
|
||||||
|
),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Collection<int, Menu> $menus
|
||||||
|
* @return Collection<int, array<string, mixed>>
|
||||||
|
*/
|
||||||
|
private function menuTree(Collection $menus): Collection
|
||||||
|
{
|
||||||
|
$menuCodes = $menus->pluck('code')->flip();
|
||||||
|
$childrenByParent = $menus
|
||||||
|
->filter(fn (Menu $menu) => $menu->parent_menu_code !== null)
|
||||||
|
->groupBy('parent_menu_code');
|
||||||
|
|
||||||
|
$formatMenu = function (Menu $menu) use (&$formatMenu, $childrenByParent): array {
|
||||||
|
$formatted = [
|
||||||
|
'id' => $menu->id,
|
||||||
|
'code' => $menu->code,
|
||||||
|
'label' => $menu->label,
|
||||||
|
'parent_menu_code' => $menu->parent_menu_code,
|
||||||
|
'content_type' => $menu->content_type,
|
||||||
|
'route' => $menu->route,
|
||||||
|
];
|
||||||
|
|
||||||
|
if ($menu->pivot?->static_content !== null) {
|
||||||
|
$formatted['static_content'] = $menu->pivot->static_content;
|
||||||
|
}
|
||||||
|
|
||||||
|
$formatted['submenues'] = $childrenByParent
|
||||||
|
->get($menu->code, collect())
|
||||||
|
->map($formatMenu)
|
||||||
|
->values();
|
||||||
|
|
||||||
|
return $formatted;
|
||||||
|
};
|
||||||
|
|
||||||
|
return $menus
|
||||||
|
->filter(fn (Menu $menu) => $menu->parent_menu_code === null
|
||||||
|
|| ! $menuCodes->has($menu->parent_menu_code))
|
||||||
|
->map($formatMenu)
|
||||||
|
->values();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,22 +2,22 @@
|
|||||||
|
|
||||||
namespace App\Domains\Tenant\Services;
|
namespace App\Domains\Tenant\Services;
|
||||||
|
|
||||||
|
use App\Domains\Attachable\Enums\AttachmentType;
|
||||||
|
use App\Domains\Attachable\Models\Attachment;
|
||||||
use App\Domains\Attachable\Services\AttachmentService;
|
use App\Domains\Attachable\Services\AttachmentService;
|
||||||
use App\Domains\Tenant\Models\Tenant;
|
use App\Domains\Tenant\Models\Tenant;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
use Illuminate\Validation\ValidationException;
|
||||||
|
|
||||||
class TenantService
|
class TenantService
|
||||||
{
|
{
|
||||||
public function __construct(protected AttachmentService $attachmentService)
|
public function __construct(protected AttachmentService $attachmentService) {}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new tenant and store its logos.
|
* Create a new tenant and store its logos.
|
||||||
*
|
*
|
||||||
* @param array<string, mixed> $data
|
* @param array<string, mixed> $data
|
||||||
* @return Tenant
|
|
||||||
*/
|
*/
|
||||||
public function create(array $data): Tenant
|
public function create(array $data): Tenant
|
||||||
{
|
{
|
||||||
@@ -25,13 +25,21 @@ class TenantService
|
|||||||
$headerLogo = $data['header_logo'] ?? null;
|
$headerLogo = $data['header_logo'] ?? null;
|
||||||
$footerLogo = $data['footer_logo'] ?? null;
|
$footerLogo = $data['footer_logo'] ?? null;
|
||||||
$heroBgImage = $data['hero_bg_image'] ?? null;
|
$heroBgImage = $data['hero_bg_image'] ?? null;
|
||||||
|
$mainCarouselImages = $data['main_carousel_images'] ?? [];
|
||||||
|
$socialMedia = $data['social_media'] ?? [];
|
||||||
|
|
||||||
unset($data['header_logo'], $data['footer_logo'], $data['hero_bg_image']);
|
unset(
|
||||||
|
$data['header_logo'],
|
||||||
|
$data['footer_logo'],
|
||||||
|
$data['hero_bg_image'],
|
||||||
|
$data['main_carousel_images'],
|
||||||
|
$data['social_media']
|
||||||
|
);
|
||||||
|
|
||||||
$headerAttachmentId = null;
|
$headerAttachmentId = null;
|
||||||
if ($headerLogo) {
|
if ($headerLogo) {
|
||||||
$attachment = Str::isUuid($headerLogo)
|
$attachment = Str::isUuid($headerLogo)
|
||||||
? \App\Domains\Attachable\Models\Attachment::query()->where('key', $headerLogo)->first()
|
? Attachment::query()->where('key', $headerLogo)->first()
|
||||||
: $this->attachmentService->store($headerLogo, 'tenants');
|
: $this->attachmentService->store($headerLogo, 'tenants');
|
||||||
|
|
||||||
if ($attachment) {
|
if ($attachment) {
|
||||||
@@ -42,7 +50,7 @@ class TenantService
|
|||||||
$footerAttachmentId = null;
|
$footerAttachmentId = null;
|
||||||
if ($footerLogo) {
|
if ($footerLogo) {
|
||||||
$attachment = Str::isUuid($footerLogo)
|
$attachment = Str::isUuid($footerLogo)
|
||||||
? \App\Domains\Attachable\Models\Attachment::query()->where('key', $footerLogo)->first()
|
? Attachment::query()->where('key', $footerLogo)->first()
|
||||||
: $this->attachmentService->store($footerLogo, 'tenants');
|
: $this->attachmentService->store($footerLogo, 'tenants');
|
||||||
|
|
||||||
if ($attachment) {
|
if ($attachment) {
|
||||||
@@ -55,7 +63,7 @@ class TenantService
|
|||||||
|
|
||||||
if ($heroBgImage) {
|
if ($heroBgImage) {
|
||||||
$attachment = Str::isUuid($heroBgImage)
|
$attachment = Str::isUuid($heroBgImage)
|
||||||
? \App\Domains\Attachable\Models\Attachment::query()->where('key', $heroBgImage)->first()
|
? Attachment::query()->where('key', $heroBgImage)->first()
|
||||||
: $this->attachmentService->store($heroBgImage, 'tenants');
|
: $this->attachmentService->store($heroBgImage, 'tenants');
|
||||||
|
|
||||||
if ($attachment) {
|
if ($attachment) {
|
||||||
@@ -67,6 +75,8 @@ class TenantService
|
|||||||
|
|
||||||
/** @var Tenant $tenant */
|
/** @var Tenant $tenant */
|
||||||
$tenant = Tenant::query()->create($data);
|
$tenant = Tenant::query()->create($data);
|
||||||
|
$this->syncMainCarouselImages($tenant, $mainCarouselImages);
|
||||||
|
$this->syncSocialMedia($tenant, $socialMedia);
|
||||||
|
|
||||||
return $tenant;
|
return $tenant;
|
||||||
});
|
});
|
||||||
@@ -75,9 +85,7 @@ class TenantService
|
|||||||
/**
|
/**
|
||||||
* Update an existing tenant and store new logos if uploaded.
|
* Update an existing tenant and store new logos if uploaded.
|
||||||
*
|
*
|
||||||
* @param Tenant $tenant
|
|
||||||
* @param array<string, mixed> $data
|
* @param array<string, mixed> $data
|
||||||
* @return Tenant
|
|
||||||
*/
|
*/
|
||||||
public function update(Tenant $tenant, array $data): Tenant
|
public function update(Tenant $tenant, array $data): Tenant
|
||||||
{
|
{
|
||||||
@@ -85,11 +93,21 @@ class TenantService
|
|||||||
$hasHeaderLogoKey = array_key_exists('header_logo', $data);
|
$hasHeaderLogoKey = array_key_exists('header_logo', $data);
|
||||||
$hasFooterLogoKey = array_key_exists('footer_logo', $data);
|
$hasFooterLogoKey = array_key_exists('footer_logo', $data);
|
||||||
$hasHeroBgImageKey = array_key_exists('hero_bg_image', $data);
|
$hasHeroBgImageKey = array_key_exists('hero_bg_image', $data);
|
||||||
|
$hasMainCarouselImagesKey = array_key_exists('main_carousel_images', $data);
|
||||||
|
$hasSocialMediaKey = array_key_exists('social_media', $data);
|
||||||
$headerLogo = $data['header_logo'] ?? null;
|
$headerLogo = $data['header_logo'] ?? null;
|
||||||
$footerLogo = $data['footer_logo'] ?? null;
|
$footerLogo = $data['footer_logo'] ?? null;
|
||||||
$heroBgImage = $data['hero_bg_image'] ?? null;
|
$heroBgImage = $data['hero_bg_image'] ?? null;
|
||||||
|
$mainCarouselImages = $data['main_carousel_images'] ?? [];
|
||||||
|
$socialMedia = $data['social_media'] ?? [];
|
||||||
|
|
||||||
unset($data['header_logo'], $data['footer_logo'], $data['hero_bg_image']);
|
unset(
|
||||||
|
$data['header_logo'],
|
||||||
|
$data['footer_logo'],
|
||||||
|
$data['hero_bg_image'],
|
||||||
|
$data['main_carousel_images'],
|
||||||
|
$data['social_media']
|
||||||
|
);
|
||||||
|
|
||||||
$oldHeroBgId = $tenant->hero_bg_image_id;
|
$oldHeroBgId = $tenant->hero_bg_image_id;
|
||||||
|
|
||||||
@@ -98,7 +116,7 @@ class TenantService
|
|||||||
if ($hasHeaderLogoKey) {
|
if ($hasHeaderLogoKey) {
|
||||||
if ($headerLogo) {
|
if ($headerLogo) {
|
||||||
$attachment = Str::isUuid($headerLogo)
|
$attachment = Str::isUuid($headerLogo)
|
||||||
? \App\Domains\Attachable\Models\Attachment::query()->where('key', $headerLogo)->first()
|
? Attachment::query()->where('key', $headerLogo)->first()
|
||||||
: $this->attachmentService->store($headerLogo, 'tenants');
|
: $this->attachmentService->store($headerLogo, 'tenants');
|
||||||
|
|
||||||
if ($attachment) {
|
if ($attachment) {
|
||||||
@@ -114,7 +132,7 @@ class TenantService
|
|||||||
if ($hasFooterLogoKey) {
|
if ($hasFooterLogoKey) {
|
||||||
if ($footerLogo) {
|
if ($footerLogo) {
|
||||||
$attachment = Str::isUuid($footerLogo)
|
$attachment = Str::isUuid($footerLogo)
|
||||||
? \App\Domains\Attachable\Models\Attachment::query()->where('key', $footerLogo)->first()
|
? Attachment::query()->where('key', $footerLogo)->first()
|
||||||
: $this->attachmentService->store($footerLogo, 'tenants');
|
: $this->attachmentService->store($footerLogo, 'tenants');
|
||||||
|
|
||||||
if ($attachment) {
|
if ($attachment) {
|
||||||
@@ -131,7 +149,7 @@ class TenantService
|
|||||||
if ($hasHeroBgImageKey) {
|
if ($hasHeroBgImageKey) {
|
||||||
if ($heroBgImage) {
|
if ($heroBgImage) {
|
||||||
$attachment = Str::isUuid($heroBgImage)
|
$attachment = Str::isUuid($heroBgImage)
|
||||||
? \App\Domains\Attachable\Models\Attachment::query()->where('key', $heroBgImage)->first()
|
? Attachment::query()->where('key', $heroBgImage)->first()
|
||||||
: $this->attachmentService->store($heroBgImage, 'tenants');
|
: $this->attachmentService->store($heroBgImage, 'tenants');
|
||||||
|
|
||||||
if ($attachment) {
|
if ($attachment) {
|
||||||
@@ -151,7 +169,70 @@ class TenantService
|
|||||||
|
|
||||||
$tenant->save();
|
$tenant->save();
|
||||||
|
|
||||||
|
if ($hasMainCarouselImagesKey) {
|
||||||
|
$this->syncMainCarouselImages($tenant, $mainCarouselImages);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($hasSocialMediaKey) {
|
||||||
|
$this->syncSocialMedia($tenant, $socialMedia);
|
||||||
|
}
|
||||||
|
|
||||||
return $tenant;
|
return $tenant;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<int, mixed> $images
|
||||||
|
*/
|
||||||
|
private function syncMainCarouselImages(Tenant $tenant, array $images): void
|
||||||
|
{
|
||||||
|
$attachments = [];
|
||||||
|
|
||||||
|
foreach (array_values($images) as $order => $image) {
|
||||||
|
$attachment = $this->resolveMainCarouselImage($image, $order);
|
||||||
|
$attachments[$attachment->id] = ['orden' => $order];
|
||||||
|
}
|
||||||
|
|
||||||
|
$tenant->mainCarouselImages()->sync($attachments);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<int, array{code: string, url: string, orden?: int}> $socialMedia
|
||||||
|
*/
|
||||||
|
private function syncSocialMedia(Tenant $tenant, array $socialMedia): void
|
||||||
|
{
|
||||||
|
$associations = [];
|
||||||
|
|
||||||
|
foreach (array_values($socialMedia) as $index => $item) {
|
||||||
|
$associations[$item['code']] = [
|
||||||
|
'url' => $item['url'],
|
||||||
|
'orden' => $item['orden'] ?? $index,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$tenant->socialMedia()->sync($associations);
|
||||||
|
$tenant->unsetRelation('socialMedia');
|
||||||
|
}
|
||||||
|
|
||||||
|
private function resolveMainCarouselImage(mixed $image, int $order): Attachment
|
||||||
|
{
|
||||||
|
if (is_string($image) && Str::isUuid($image)) {
|
||||||
|
$attachment = Attachment::query()
|
||||||
|
->where('key', $image)
|
||||||
|
->where('type', AttachmentType::Image->value)
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if ($attachment === null) {
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
"main_carousel_images.{$order}" => [
|
||||||
|
'La imagen indicada no existe o no es un attachment de tipo imagen.',
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $attachment;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->attachmentService->store($image, 'tenants/main-carousel');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
namespace App\Domains\Ticket\Listeners;
|
namespace App\Domains\Ticket\Listeners;
|
||||||
|
|
||||||
use App\Domains\Catalog\Models\CatalogItem;
|
use App\Domains\Catalog\Models\CatalogItem;
|
||||||
|
use App\Domains\Notification\Events\TicketsAvailable;
|
||||||
use App\Domains\Purchase\Events\PurchasePaid;
|
use App\Domains\Purchase\Events\PurchasePaid;
|
||||||
use App\Domains\Ticket\Exceptions\TicketGenerationException;
|
use App\Domains\Ticket\Exceptions\TicketGenerationException;
|
||||||
use App\Domains\Ticket\Services\TicketGeneratorService;
|
use App\Domains\Ticket\Services\TicketGeneratorService;
|
||||||
@@ -20,6 +21,7 @@ class GenerateTicketsForPaidPurchase
|
|||||||
->with(['user', 'items'])
|
->with(['user', 'items'])
|
||||||
->findOrFail($event->purchase->getKey());
|
->findOrFail($event->purchase->getKey());
|
||||||
$user = $purchase->user;
|
$user = $purchase->user;
|
||||||
|
$ticketIds = [];
|
||||||
|
|
||||||
foreach ($purchase->items as $purchaseItem) {
|
foreach ($purchase->items as $purchaseItem) {
|
||||||
$catalogItem = CatalogItem::query()
|
$catalogItem = CatalogItem::query()
|
||||||
@@ -38,12 +40,18 @@ class GenerateTicketsForPaidPurchase
|
|||||||
throw TicketGenerationException::purchaseWithoutUser($purchase);
|
throw TicketGenerationException::purchaseWithoutUser($purchase);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->ticketGenerator->generate(
|
$generatedTickets = $this->ticketGenerator->generate(
|
||||||
$catalogItem,
|
$catalogItem,
|
||||||
$user,
|
$user,
|
||||||
$purchaseItem->cantidad,
|
$purchaseItem->cantidad,
|
||||||
$purchaseItem->source_variant_id,
|
$purchaseItem->source_variant_id,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
array_push($ticketIds, ...$generatedTickets->pluck('id')->all());
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($ticketIds !== []) {
|
||||||
|
TicketsAvailable::dispatch($purchase, $ticketIds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,11 @@
|
|||||||
|
|
||||||
namespace App\Providers;
|
namespace App\Providers;
|
||||||
|
|
||||||
|
use App\Domains\Notification\Events\TicketsAvailable;
|
||||||
|
use App\Domains\Notification\Events\UserRegistered;
|
||||||
|
use App\Domains\Notification\Listeners\SendPurchasePaidEmail;
|
||||||
|
use App\Domains\Notification\Listeners\SendTicketsAvailableEmail;
|
||||||
|
use App\Domains\Notification\Listeners\SendWelcomeEmail;
|
||||||
use App\Domains\Purchase\Events\PurchasePaid;
|
use App\Domains\Purchase\Events\PurchasePaid;
|
||||||
use App\Domains\Ticket\Listeners\GenerateTicketsForPaidPurchase;
|
use App\Domains\Ticket\Listeners\GenerateTicketsForPaidPurchase;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
@@ -23,7 +28,10 @@ class AppServiceProvider extends ServiceProvider
|
|||||||
*/
|
*/
|
||||||
public function boot(): void
|
public function boot(): void
|
||||||
{
|
{
|
||||||
|
Event::listen(PurchasePaid::class, SendPurchasePaidEmail::class);
|
||||||
Event::listen(PurchasePaid::class, GenerateTicketsForPaidPurchase::class);
|
Event::listen(PurchasePaid::class, GenerateTicketsForPaidPurchase::class);
|
||||||
|
Event::listen(TicketsAvailable::class, SendTicketsAvailableEmail::class);
|
||||||
|
Event::listen(UserRegistered::class, SendWelcomeEmail::class);
|
||||||
|
|
||||||
Builder::macro('paginateFromRequest', function (int $defaultPerPage = 15, int $maxPerPage = 100, ?int $page = null) {
|
Builder::macro('paginateFromRequest', function (int $defaultPerPage = 15, int $maxPerPage = 100, ?int $page = null) {
|
||||||
/** @var Builder $this */
|
/** @var Builder $this */
|
||||||
|
|||||||
@@ -9,8 +9,9 @@
|
|||||||
"php": "^8.3",
|
"php": "^8.3",
|
||||||
"laravel/framework": "^13.8",
|
"laravel/framework": "^13.8",
|
||||||
"laravel/sanctum": "^4.3",
|
"laravel/sanctum": "^4.3",
|
||||||
|
"laravel/socialite": "^5.29",
|
||||||
"laravel/tinker": "^3.0",
|
"laravel/tinker": "^3.0",
|
||||||
"league/flysystem-aws-s3-v3": "^3.0"
|
"league/flysystem-aws-s3-v3": "^3.0"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"fakerphp/faker": "^1.23",
|
"fakerphp/faker": "^1.23",
|
||||||
@@ -44,7 +45,7 @@
|
|||||||
],
|
],
|
||||||
"dev": [
|
"dev": [
|
||||||
"Composer\\Config::disableProcessTimeout",
|
"Composer\\Config::disableProcessTimeout",
|
||||||
"npx concurrently -c \"#93c5fd,#c4b5fd,#fb7185,#fdba74\" \"php artisan serve\" \"php artisan queue:listen --tries=1 --timeout=0\" \"php artisan pail --timeout=0\" \"npm run dev\" --names=server,queue,logs,vite --kill-others"
|
"npx concurrently -c \"#93c5fd,#c4b5fd,#fb7185,#fdba74\" \"php artisan serve\" \"php artisan queue:listen --queue=emails,default --tries=1 --timeout=0\" \"php artisan pail --timeout=0\" \"npm run dev\" --names=server,queue,logs,vite --kill-others"
|
||||||
],
|
],
|
||||||
"test": [
|
"test": [
|
||||||
"@php artisan config:clear --ansi @no_additional_args",
|
"@php artisan config:clear --ansi @no_additional_args",
|
||||||
|
|||||||
883
composer.lock
generated
883
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -39,4 +39,10 @@ return [
|
|||||||
'secret' => env('INTEGRATION_SECRET'),
|
'secret' => env('INTEGRATION_SECRET'),
|
||||||
],
|
],
|
||||||
|
|
||||||
|
'google' => [
|
||||||
|
'client_id' => env('GOOGLE_CLIENT_ID'),
|
||||||
|
'client_secret' => env('GOOGLE_CLIENT_SECRET'),
|
||||||
|
'redirect' => env('GOOGLE_REDIRECT_URI'),
|
||||||
|
],
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::table('users', function (Blueprint $table): void {
|
||||||
|
$table->string('google_id')->nullable()->unique()->after('email');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('users', function (Blueprint $table): void {
|
||||||
|
$table->dropUnique(['google_id']);
|
||||||
|
$table->dropColumn('google_id');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Domains\Catalog\Enums\GroupLayout;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::table('featured_groups', function (Blueprint $table): void {
|
||||||
|
$table->enum('group_layout', GroupLayout::values())
|
||||||
|
->default(GroupLayout::Paginated->value)
|
||||||
|
->after('product_layout');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('featured_groups', function (Blueprint $table): void {
|
||||||
|
$table->dropColumn('group_layout');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::create('tenant_main_carousel_images', function (Blueprint $table): void {
|
||||||
|
$table->id();
|
||||||
|
$table->foreignId('tenant_id')
|
||||||
|
->constrained('tenants')
|
||||||
|
->cascadeOnDelete();
|
||||||
|
$table->foreignId('attachment_id')
|
||||||
|
->constrained('attachments')
|
||||||
|
->cascadeOnDelete();
|
||||||
|
$table->unsignedInteger('orden')->default(0);
|
||||||
|
$table->timestamps();
|
||||||
|
|
||||||
|
$table->unique(['tenant_id', 'attachment_id']);
|
||||||
|
$table->index(['tenant_id', 'orden']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('tenant_main_carousel_images');
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::create('social_media', function (Blueprint $table): void {
|
||||||
|
$table->id();
|
||||||
|
$table->string('code')->unique();
|
||||||
|
$table->string('icon');
|
||||||
|
$table->string('name');
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
|
||||||
|
Schema::create('tenant_social_media', function (Blueprint $table): void {
|
||||||
|
$table->id();
|
||||||
|
$table->string('tenant_code');
|
||||||
|
$table->string('social_media_code');
|
||||||
|
$table->string('url');
|
||||||
|
$table->timestamps();
|
||||||
|
|
||||||
|
$table->foreign('tenant_code')
|
||||||
|
->references('codigo')
|
||||||
|
->on('tenants')
|
||||||
|
->cascadeOnDelete();
|
||||||
|
$table->foreign('social_media_code')
|
||||||
|
->references('code')
|
||||||
|
->on('social_media')
|
||||||
|
->cascadeOnDelete();
|
||||||
|
$table->unique(['tenant_code', 'social_media_code']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('tenant_social_media');
|
||||||
|
Schema::dropIfExists('social_media');
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::table('tenant_social_media', function (Blueprint $table): void {
|
||||||
|
$table->unsignedInteger('orden')->default(0)->after('url');
|
||||||
|
$table->index(['tenant_code', 'orden']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('tenant_social_media', function (Blueprint $table): void {
|
||||||
|
$table->dropIndex(['tenant_code', 'orden']);
|
||||||
|
$table->dropColumn('orden');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::table('tenant_menues', function (Blueprint $table) {
|
||||||
|
$table->dropForeign(['tenant_codigo']);
|
||||||
|
$table->dropForeign(['menu_code']);
|
||||||
|
});
|
||||||
|
|
||||||
|
Schema::rename('tenant_menues', 'tenants_menues');
|
||||||
|
|
||||||
|
Schema::table('tenants_menues', function (Blueprint $table) {
|
||||||
|
$table->renameColumn('tenant_codigo', 'tenant_code');
|
||||||
|
$table->json('static_content')->nullable();
|
||||||
|
});
|
||||||
|
|
||||||
|
Schema::table('menues', function (Blueprint $table) {
|
||||||
|
$table->string('parent_menu_code')->nullable()->after('code');
|
||||||
|
$table->enum('content_type', ['static', 'dynamic'])
|
||||||
|
->default('dynamic')
|
||||||
|
->after('parent_menu_code');
|
||||||
|
$table->json('static_content_schema')->nullable()->after('content_type');
|
||||||
|
});
|
||||||
|
|
||||||
|
Schema::table('menues', function (Blueprint $table) {
|
||||||
|
$table->foreign('parent_menu_code')
|
||||||
|
->references('code')
|
||||||
|
->on('menues')
|
||||||
|
->nullOnDelete();
|
||||||
|
});
|
||||||
|
|
||||||
|
Schema::table('tenants_menues', function (Blueprint $table) {
|
||||||
|
$table->foreign('tenant_code')
|
||||||
|
->references('codigo')
|
||||||
|
->on('tenants')
|
||||||
|
->cascadeOnDelete();
|
||||||
|
$table->foreign('menu_code')
|
||||||
|
->references('code')
|
||||||
|
->on('menues')
|
||||||
|
->cascadeOnDelete();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('tenants_menues', function (Blueprint $table) {
|
||||||
|
$table->dropForeign(['tenant_code']);
|
||||||
|
$table->dropForeign(['menu_code']);
|
||||||
|
});
|
||||||
|
|
||||||
|
Schema::table('menues', function (Blueprint $table) {
|
||||||
|
$table->dropForeign(['parent_menu_code']);
|
||||||
|
$table->dropColumn([
|
||||||
|
'parent_menu_code',
|
||||||
|
'content_type',
|
||||||
|
'static_content_schema',
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
Schema::table('tenants_menues', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('static_content');
|
||||||
|
$table->renameColumn('tenant_code', 'tenant_codigo');
|
||||||
|
});
|
||||||
|
|
||||||
|
Schema::rename('tenants_menues', 'tenant_menues');
|
||||||
|
|
||||||
|
Schema::table('tenant_menues', function (Blueprint $table) {
|
||||||
|
$table->foreign('tenant_codigo')
|
||||||
|
->references('codigo')
|
||||||
|
->on('tenants')
|
||||||
|
->cascadeOnDelete();
|
||||||
|
$table->foreign('menu_code')
|
||||||
|
->references('code')
|
||||||
|
->on('menues')
|
||||||
|
->cascadeOnDelete();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,174 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Domains\Menu\Models\Menu;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
$now = now();
|
||||||
|
|
||||||
|
DB::table('menues')->updateOrInsert(
|
||||||
|
['code' => 'account'],
|
||||||
|
[
|
||||||
|
'parent_menu_code' => null,
|
||||||
|
'content_type' => Menu::CONTENT_TYPE_DYNAMIC,
|
||||||
|
'static_content_schema' => null,
|
||||||
|
'route' => '/mi-cuenta',
|
||||||
|
'created_at' => $now,
|
||||||
|
'updated_at' => $now,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
$menus = [
|
||||||
|
'profile' => [
|
||||||
|
'code' => 'account.profile',
|
||||||
|
'route' => '/mi-cuenta/datos-personales',
|
||||||
|
],
|
||||||
|
'purchases' => [
|
||||||
|
'code' => 'account.purchases',
|
||||||
|
'route' => '/mi-cuenta/compras',
|
||||||
|
],
|
||||||
|
'tickets' => [
|
||||||
|
'code' => 'account.tickets',
|
||||||
|
'route' => '/mi-cuenta/tickets',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($menus as $legacyCode => $menuData) {
|
||||||
|
$legacyMenu = DB::table('menues')->where('code', $legacyCode)->first();
|
||||||
|
|
||||||
|
DB::table('menues')->updateOrInsert(
|
||||||
|
['code' => $menuData['code']],
|
||||||
|
[
|
||||||
|
'parent_menu_code' => 'account',
|
||||||
|
'content_type' => $legacyMenu?->content_type ?? Menu::CONTENT_TYPE_DYNAMIC,
|
||||||
|
'static_content_schema' => $legacyMenu?->static_content_schema,
|
||||||
|
'route' => $menuData['route'],
|
||||||
|
'created_at' => $legacyMenu?->created_at ?? $now,
|
||||||
|
'updated_at' => $now,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
if (! $legacyMenu) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$assignments = DB::table('tenants_menues')
|
||||||
|
->where('menu_code', $legacyCode)
|
||||||
|
->get();
|
||||||
|
|
||||||
|
foreach ($assignments as $assignment) {
|
||||||
|
$alreadyAssigned = DB::table('tenants_menues')
|
||||||
|
->where('tenant_code', $assignment->tenant_code)
|
||||||
|
->where('menu_code', $menuData['code'])
|
||||||
|
->exists();
|
||||||
|
|
||||||
|
if (! $alreadyAssigned) {
|
||||||
|
DB::table('tenants_menues')->insert([
|
||||||
|
'tenant_code' => $assignment->tenant_code,
|
||||||
|
'menu_code' => $menuData['code'],
|
||||||
|
'static_content' => $assignment->static_content,
|
||||||
|
'created_at' => $assignment->created_at,
|
||||||
|
'updated_at' => $now,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::table('tenants_menues')->where('menu_code', $legacyCode)->delete();
|
||||||
|
DB::table('menues')->where('code', $legacyCode)->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
$tenantCodes = DB::table('tenants_menues')
|
||||||
|
->whereIn('menu_code', array_column($menus, 'code'))
|
||||||
|
->distinct()
|
||||||
|
->pluck('tenant_code');
|
||||||
|
|
||||||
|
foreach ($tenantCodes as $tenantCode) {
|
||||||
|
$alreadyAssigned = DB::table('tenants_menues')
|
||||||
|
->where('tenant_code', $tenantCode)
|
||||||
|
->where('menu_code', 'account')
|
||||||
|
->exists();
|
||||||
|
|
||||||
|
if ($alreadyAssigned) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::table('tenants_menues')->insert([
|
||||||
|
'tenant_code' => $tenantCode,
|
||||||
|
'menu_code' => 'account',
|
||||||
|
'static_content' => null,
|
||||||
|
'created_at' => $now,
|
||||||
|
'updated_at' => $now,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
$now = now();
|
||||||
|
$menus = [
|
||||||
|
'account.profile' => [
|
||||||
|
'code' => 'profile',
|
||||||
|
'route' => '/profile',
|
||||||
|
],
|
||||||
|
'account.purchases' => [
|
||||||
|
'code' => 'purchases',
|
||||||
|
'route' => '/purchases',
|
||||||
|
],
|
||||||
|
'account.tickets' => [
|
||||||
|
'code' => 'tickets',
|
||||||
|
'route' => '/tickets',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($menus as $accountCode => $menuData) {
|
||||||
|
$accountMenu = DB::table('menues')->where('code', $accountCode)->first();
|
||||||
|
|
||||||
|
DB::table('menues')->updateOrInsert(
|
||||||
|
['code' => $menuData['code']],
|
||||||
|
[
|
||||||
|
'parent_menu_code' => null,
|
||||||
|
'content_type' => $accountMenu?->content_type ?? Menu::CONTENT_TYPE_DYNAMIC,
|
||||||
|
'static_content_schema' => $accountMenu?->static_content_schema,
|
||||||
|
'route' => $menuData['route'],
|
||||||
|
'created_at' => $accountMenu?->created_at ?? $now,
|
||||||
|
'updated_at' => $now,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
if (! $accountMenu) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$assignments = DB::table('tenants_menues')
|
||||||
|
->where('menu_code', $accountCode)
|
||||||
|
->get();
|
||||||
|
|
||||||
|
foreach ($assignments as $assignment) {
|
||||||
|
$alreadyAssigned = DB::table('tenants_menues')
|
||||||
|
->where('tenant_code', $assignment->tenant_code)
|
||||||
|
->where('menu_code', $menuData['code'])
|
||||||
|
->exists();
|
||||||
|
|
||||||
|
if (! $alreadyAssigned) {
|
||||||
|
DB::table('tenants_menues')->insert([
|
||||||
|
'tenant_code' => $assignment->tenant_code,
|
||||||
|
'menu_code' => $menuData['code'],
|
||||||
|
'static_content' => $assignment->static_content,
|
||||||
|
'created_at' => $assignment->created_at,
|
||||||
|
'updated_at' => $now,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::table('tenants_menues')->where('menu_code', $accountCode)->delete();
|
||||||
|
DB::table('menues')->where('code', $accountCode)->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
DB::table('tenants_menues')->where('menu_code', 'account')->delete();
|
||||||
|
DB::table('menues')->where('code', 'account')->delete();
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
if (! Schema::hasColumn('menues', 'label')) {
|
||||||
|
Schema::table('menues', function (Blueprint $table) {
|
||||||
|
$table->string('label')->nullable()->after('code');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
$labels = [
|
||||||
|
'index' => 'Inicio',
|
||||||
|
'product.detail' => 'Detalle de producto',
|
||||||
|
'checkout' => 'Finalizar compra',
|
||||||
|
'account' => 'Mi cuenta',
|
||||||
|
'account.profile' => 'Datos personales',
|
||||||
|
'account.purchases' => 'Mis compras',
|
||||||
|
'account.tickets' => 'Mis tickets',
|
||||||
|
'help' => 'Ayuda',
|
||||||
|
'help.faq' => 'Preguntas frecuentes',
|
||||||
|
'help.contact' => 'Contacto',
|
||||||
|
'help.payment-methods' => 'Medios de pago',
|
||||||
|
'help.shipping' => 'Envíos',
|
||||||
|
'help.terms-and-conditions' => 'Términos y condiciones',
|
||||||
|
];
|
||||||
|
|
||||||
|
DB::table('menues')
|
||||||
|
->select(['id', 'code'])
|
||||||
|
->orderBy('id')
|
||||||
|
->eachById(function ($menu) use ($labels): void {
|
||||||
|
$fallback = Str::headline(Str::afterLast($menu->code, '.'));
|
||||||
|
|
||||||
|
DB::table('menues')
|
||||||
|
->where('id', $menu->id)
|
||||||
|
->update(['label' => $labels[$menu->code] ?? $fallback]);
|
||||||
|
});
|
||||||
|
|
||||||
|
Schema::table('menues', function (Blueprint $table) {
|
||||||
|
$table->string('label')->nullable(false)->change();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('menues', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('label');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Domains\Catalog\Enums\GroupLayout;
|
||||||
|
use App\Domains\Catalog\Enums\ProductLayout;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::table('tenants', function (Blueprint $table): void {
|
||||||
|
$table->enum('search_product_layout', ProductLayout::values())
|
||||||
|
->default(ProductLayout::ColumnWithImage->value);
|
||||||
|
$table->enum('search_group_layout', GroupLayout::values())
|
||||||
|
->default(GroupLayout::Paginated->value);
|
||||||
|
$table->unsignedTinyInteger('search_items_per_page')->default(12);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('tenants', function (Blueprint $table): void {
|
||||||
|
$table->dropColumn([
|
||||||
|
'search_product_layout',
|
||||||
|
'search_group_layout',
|
||||||
|
'search_items_per_page',
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -23,6 +23,7 @@ class DatabaseSeeder extends Seeder
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
$this->call([
|
$this->call([
|
||||||
|
SocialMediaSeeder::class,
|
||||||
TenantSeeder::class,
|
TenantSeeder::class,
|
||||||
AttributeSeeder::class,
|
AttributeSeeder::class,
|
||||||
CategorySeeder::class,
|
CategorySeeder::class,
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
namespace Database\Seeders;
|
namespace Database\Seeders;
|
||||||
|
|
||||||
use App\Domains\Catalog\Enums\CatalogItemType;
|
use App\Domains\Catalog\Enums\CatalogItemType;
|
||||||
|
use App\Domains\Catalog\Enums\GroupLayout;
|
||||||
use App\Domains\Catalog\Enums\InventoryPolicy;
|
use App\Domains\Catalog\Enums\InventoryPolicy;
|
||||||
use App\Domains\Catalog\Enums\ProductLayout;
|
use App\Domains\Catalog\Enums\ProductLayout;
|
||||||
use App\Domains\Catalog\Models\CatalogItem;
|
use App\Domains\Catalog\Models\CatalogItem;
|
||||||
@@ -138,41 +139,58 @@ class FiestaFutbolInfantilProductSeeder extends Seeder
|
|||||||
|
|
||||||
$groups = [
|
$groups = [
|
||||||
'Entradas' => [
|
'Entradas' => [
|
||||||
'entrada-general',
|
'product_layout' => ProductLayout::Row,
|
||||||
'entrada-general-todos-los-dias',
|
'group_layout' => GroupLayout::SimpleVertical,
|
||||||
|
'slugs' => [
|
||||||
|
'entrada-general',
|
||||||
|
'entrada-general-todos-los-dias',
|
||||||
|
],
|
||||||
],
|
],
|
||||||
'Estacionamiento' => [
|
'Estacionamiento' => [
|
||||||
'estacionamiento-auto',
|
'product_layout' => ProductLayout::ColumnWithCart,
|
||||||
'estacionamiento-moto',
|
'group_layout' => GroupLayout::Simple,
|
||||||
|
'slugs' => [
|
||||||
|
'estacionamiento-auto',
|
||||||
|
'estacionamiento-moto',
|
||||||
|
],
|
||||||
],
|
],
|
||||||
'Comidas' => [
|
'Comidas' => [
|
||||||
'hamburguesa-papa-frita',
|
'product_layout' => ProductLayout::ColumnWithCart,
|
||||||
'pancho',
|
'group_layout' => GroupLayout::Simple,
|
||||||
'combo-2-panchos-2-hamburguesas',
|
'slugs' => [
|
||||||
|
'hamburguesa-papa-frita',
|
||||||
|
'pancho',
|
||||||
|
'combo-2-panchos-2-hamburguesas',
|
||||||
|
],
|
||||||
],
|
],
|
||||||
'Bebidas' => [
|
'Bebidas' => [
|
||||||
'coca-cola-500ml',
|
'product_layout' => ProductLayout::ColumnWithCart,
|
||||||
'agua-mineral-1l',
|
'group_layout' => GroupLayout::Simple,
|
||||||
|
'slugs' => [
|
||||||
|
'coca-cola-500ml',
|
||||||
|
'agua-mineral-1l',
|
||||||
|
],
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
$catalogItems = CatalogItem::query()
|
$catalogItems = CatalogItem::query()
|
||||||
->where('tenant_code', $tenant->codigo)
|
->where('tenant_code', $tenant->codigo)
|
||||||
->whereIn('slug', collect($groups)->flatten()->all())
|
->whereIn('slug', collect($groups)->pluck('slugs')->flatten()->all())
|
||||||
->get()
|
->get()
|
||||||
->keyBy('slug');
|
->keyBy('slug');
|
||||||
|
|
||||||
$groupOrder = 0;
|
$groupOrder = 0;
|
||||||
foreach ($groups as $groupName => $slugs) {
|
foreach ($groups as $groupName => $config) {
|
||||||
$featuredGroup = FeaturedGroup::query()->create([
|
$featuredGroup = FeaturedGroup::query()->create([
|
||||||
'tenant_code' => $tenant->codigo,
|
'tenant_code' => $tenant->codigo,
|
||||||
'product_layout' => ProductLayout::Row,
|
'product_layout' => $config['product_layout'],
|
||||||
|
'group_layout' => $config['group_layout'],
|
||||||
'group_name' => $groupName,
|
'group_name' => $groupName,
|
||||||
'group_order' => $groupOrder++,
|
'group_order' => $groupOrder++,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$featuredGroup->featuredItems()->createMany(
|
$featuredGroup->featuredItems()->createMany(
|
||||||
collect($slugs)->values()->map(
|
collect($config['slugs'])->values()->map(
|
||||||
fn (string $slug, int $order): array => [
|
fn (string $slug, int $order): array => [
|
||||||
'catalog_item_id' => $catalogItems->get($slug)->id,
|
'catalog_item_id' => $catalogItems->get($slug)->id,
|
||||||
'order' => $order,
|
'order' => $order,
|
||||||
|
|||||||
@@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
namespace Database\Seeders;
|
namespace Database\Seeders;
|
||||||
|
|
||||||
use Illuminate\Database\Seeder;
|
|
||||||
use App\Domains\Menu\Models\Menu;
|
use App\Domains\Menu\Models\Menu;
|
||||||
use App\Domains\Tenant\Models\Tenant;
|
use App\Domains\Tenant\Models\Tenant;
|
||||||
|
use Illuminate\Database\Seeder;
|
||||||
|
|
||||||
class MenuSeeder extends Seeder
|
class MenuSeeder extends Seeder
|
||||||
{
|
{
|
||||||
@@ -14,35 +14,198 @@ class MenuSeeder extends Seeder
|
|||||||
public function run(): void
|
public function run(): void
|
||||||
{
|
{
|
||||||
$menus = [
|
$menus = [
|
||||||
['code' => 'index', 'route' => '/'],
|
['code' => 'index', 'label' => 'Inicio', 'route' => '/'],
|
||||||
['code' => 'product.detail', 'route' => '/product/:id'],
|
[
|
||||||
['code' => 'checkout', 'route' => '/checkout'],
|
'code' => 'product.detail',
|
||||||
['code' => 'profile', 'route' => '/profile'],
|
'label' => 'Detalle de producto',
|
||||||
['code' => 'purchases', 'route' => '/purchases'],
|
'route' => '/product/:id',
|
||||||
['code' => 'tickets', 'route' => '/tickets'],
|
],
|
||||||
|
['code' => 'checkout', 'label' => 'Finalizar compra', 'route' => '/checkout'],
|
||||||
|
[
|
||||||
|
'code' => 'account',
|
||||||
|
'label' => 'Mi cuenta',
|
||||||
|
'content_type' => Menu::CONTENT_TYPE_DYNAMIC,
|
||||||
|
'route' => '/mi-cuenta',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'code' => 'account.profile',
|
||||||
|
'label' => 'Datos personales',
|
||||||
|
'parent_menu_code' => 'account',
|
||||||
|
'route' => '/mi-cuenta/datos-personales',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'code' => 'account.purchases',
|
||||||
|
'label' => 'Mis compras',
|
||||||
|
'parent_menu_code' => 'account',
|
||||||
|
'route' => '/mi-cuenta/compras',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'code' => 'account.tickets',
|
||||||
|
'label' => 'Mis tickets',
|
||||||
|
'parent_menu_code' => 'account',
|
||||||
|
'route' => '/mi-cuenta/tickets',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'code' => 'help',
|
||||||
|
'label' => 'Ayuda',
|
||||||
|
'content_type' => Menu::CONTENT_TYPE_DYNAMIC,
|
||||||
|
'route' => '/ayuda',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'code' => 'help.faq',
|
||||||
|
'label' => 'Preguntas frecuentes',
|
||||||
|
'parent_menu_code' => 'help',
|
||||||
|
'content_type' => Menu::CONTENT_TYPE_STATIC,
|
||||||
|
'static_content_schema' => [
|
||||||
|
'*.pregunta' => 'required|string',
|
||||||
|
'*.respuesta' => 'required|string',
|
||||||
|
'*.is_active' => 'sometimes|boolean',
|
||||||
|
],
|
||||||
|
'route' => '/ayuda/preguntas-frecuentes',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'code' => 'help.contact',
|
||||||
|
'label' => 'Contacto',
|
||||||
|
'parent_menu_code' => 'help',
|
||||||
|
'content_type' => Menu::CONTENT_TYPE_STATIC,
|
||||||
|
'static_content_schema' => [
|
||||||
|
'whatsapp' => 'required|array',
|
||||||
|
'whatsapp.whatsapp_url' => 'required|url',
|
||||||
|
'whatsapp.whatsapp_label' => 'required|string',
|
||||||
|
'phone' => 'required|string',
|
||||||
|
'locations' => 'required|array|min:1',
|
||||||
|
'locations.*.label' => 'required|string',
|
||||||
|
'locations.*.addresses' => 'required|array|min:1',
|
||||||
|
'locations.*.addresses.*' => 'required|array:label,address,coordinates',
|
||||||
|
'locations.*.addresses.*.label' => 'required|string',
|
||||||
|
'locations.*.addresses.*.address' => 'required|string',
|
||||||
|
'locations.*.addresses.*.coordinates' => 'required|array|size:2',
|
||||||
|
'locations.*.addresses.*.coordinates.0' => 'required|numeric|between:-90,90',
|
||||||
|
'locations.*.addresses.*.coordinates.1' => 'required|numeric|between:-180,180',
|
||||||
|
'map_locations' => 'prohibited',
|
||||||
|
],
|
||||||
|
'route' => '/ayuda/contacto',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'code' => 'help.payment-methods',
|
||||||
|
'label' => 'Medios de pago',
|
||||||
|
'parent_menu_code' => 'help',
|
||||||
|
'content_type' => Menu::CONTENT_TYPE_DYNAMIC,
|
||||||
|
'route' => '/ayuda/medios-de-pago',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'code' => 'help.shipping',
|
||||||
|
'label' => 'Envíos',
|
||||||
|
'parent_menu_code' => 'help',
|
||||||
|
'content_type' => Menu::CONTENT_TYPE_DYNAMIC,
|
||||||
|
'route' => '/ayuda/envios',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'code' => 'help.terms-and-conditions',
|
||||||
|
'label' => 'Términos y condiciones',
|
||||||
|
'parent_menu_code' => 'help',
|
||||||
|
'content_type' => Menu::CONTENT_TYPE_DYNAMIC,
|
||||||
|
'route' => '/ayuda/terminos-y-condiciones',
|
||||||
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
foreach ($menus as $menuData) {
|
foreach ($menus as $menuData) {
|
||||||
Menu::firstOrCreate(['code' => $menuData['code']], $menuData);
|
$menuData = array_merge([
|
||||||
|
'parent_menu_code' => null,
|
||||||
|
'content_type' => Menu::CONTENT_TYPE_DYNAMIC,
|
||||||
|
'static_content_schema' => null,
|
||||||
|
], $menuData);
|
||||||
|
|
||||||
|
Menu::updateOrCreate(['code' => $menuData['code']], $menuData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Menu::query()
|
||||||
|
->whereIn('code', ['profile', 'purchases', 'tickets'])
|
||||||
|
->delete();
|
||||||
|
|
||||||
$tenants = Tenant::all();
|
$tenants = Tenant::all();
|
||||||
|
|
||||||
$allMenus = Menu::pluck('code')->toArray();
|
$allMenus = Menu::pluck('code')->toArray();
|
||||||
|
$helpMenuCodes = [
|
||||||
|
'help',
|
||||||
|
'help.faq',
|
||||||
|
'help.contact',
|
||||||
|
'help.payment-methods',
|
||||||
|
'help.shipping',
|
||||||
|
'help.terms-and-conditions',
|
||||||
|
];
|
||||||
|
$helpTenantCodes = [
|
||||||
|
'sonder',
|
||||||
|
'fiesta_futbol_infantil',
|
||||||
|
];
|
||||||
|
$frequentlyAskedQuestions = [
|
||||||
|
[
|
||||||
|
'pregunta' => '¿Hay algún límite de compra?',
|
||||||
|
'respuesta' => 'No hay un límite general de compra. La cantidad disponible depende del stock de cada producto.',
|
||||||
|
'is_active' => true,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'pregunta' => '¿Cuáles son los medios de pago disponibles?',
|
||||||
|
'respuesta' => 'Podés consultar y seleccionar los medios de pago habilitados al momento de finalizar tu compra.',
|
||||||
|
'is_active' => false,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'pregunta' => 'Necesito asesoramiento antes de comprar el producto, ¿cómo puedo hacer?',
|
||||||
|
'respuesta' => 'Nuestro equipo comercial está preparado para asesorarte, no dudes en escribirnos por WhatsApp al (0341) 6658247 de lunes a viernes de 8.30 a 20 horas. Los sábados, domingos y feriados te contestaremos lo más rápido posible.',
|
||||||
|
'is_active' => false,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
$contactContent = [
|
||||||
|
'whatsapp' => [
|
||||||
|
'whatsapp_url' => 'https://wa.me/543412602222',
|
||||||
|
'whatsapp_label' => 'Chatea con nosotros',
|
||||||
|
],
|
||||||
|
'phone' => '+54 9 (0341) 6658247',
|
||||||
|
'locations' => [
|
||||||
|
'rosario' => [
|
||||||
|
'label' => 'Rosario',
|
||||||
|
'addresses' => [
|
||||||
|
[
|
||||||
|
'label' => 'Gigante de Arroyito',
|
||||||
|
'address' => 'Av. Génova 640, Rosario',
|
||||||
|
'coordinates' => [-32.913997, -60.674567],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'label' => 'Telepagos',
|
||||||
|
'address' => 'Rioja 1150, piso 12, dpto. 3, Rosario',
|
||||||
|
'coordinates' => [-32.946820, -60.639320],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
foreach ($tenants as $tenant) {
|
foreach ($tenants as $tenant) {
|
||||||
$menuCodes = $allMenus;
|
$menuCodes = $allMenus;
|
||||||
|
|
||||||
if ($tenant->codigo === 'sonder') {
|
if ($tenant->codigo === 'sonder') {
|
||||||
// Sonder NO tiene tickets
|
// Sonder NO tiene tickets
|
||||||
$menuCodes = array_diff($menuCodes, ['tickets']);
|
$menuCodes = array_diff($menuCodes, ['account.tickets']);
|
||||||
} else {
|
} else {
|
||||||
// Los demás NO tienen product.detail
|
// Los demás NO tienen product.detail
|
||||||
$menuCodes = array_diff($menuCodes, ['product.detail']);
|
$menuCodes = array_diff($menuCodes, ['product.detail']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (! in_array($tenant->codigo, $helpTenantCodes, true)) {
|
||||||
|
$menuCodes = array_diff($menuCodes, $helpMenuCodes);
|
||||||
|
}
|
||||||
|
|
||||||
// Usar sync para asociar los menues al tenant
|
// Usar sync para asociar los menues al tenant
|
||||||
$tenant->menues()->sync($menuCodes);
|
$tenant->menues()->sync($menuCodes);
|
||||||
|
|
||||||
|
if (in_array($tenant->codigo, $helpTenantCodes, true)) {
|
||||||
|
$tenant->menues()->updateExistingPivot('help.faq', [
|
||||||
|
'static_content' => $frequentlyAskedQuestions,
|
||||||
|
]);
|
||||||
|
$tenant->menues()->updateExistingPivot('help.contact', [
|
||||||
|
'static_content' => $contactContent,
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace Database\Seeders;
|
namespace Database\Seeders;
|
||||||
|
|
||||||
|
use App\Domains\Catalog\Enums\GroupLayout;
|
||||||
use App\Domains\Catalog\Enums\InventoryPolicy;
|
use App\Domains\Catalog\Enums\InventoryPolicy;
|
||||||
use App\Domains\Catalog\Enums\ProductLayout;
|
use App\Domains\Catalog\Enums\ProductLayout;
|
||||||
use App\Domains\Catalog\Models\Attribute;
|
use App\Domains\Catalog\Models\Attribute;
|
||||||
@@ -167,11 +168,12 @@ class ProductCatalogFromImagesSeeder extends Seeder
|
|||||||
{
|
{
|
||||||
FeaturedGroup::query()->where('tenant_code', $tenant->codigo)->delete();
|
FeaturedGroup::query()->where('tenant_code', $tenant->codigo)->delete();
|
||||||
|
|
||||||
$group = FeaturedGroup::query()->create([
|
$paginatedGroup = FeaturedGroup::query()->create([
|
||||||
'tenant_code' => $tenant->codigo,
|
'tenant_code' => $tenant->codigo,
|
||||||
'product_layout' => ProductLayout::ColumnWithImage,
|
'product_layout' => ProductLayout::ColumnWithImage,
|
||||||
|
'group_layout' => GroupLayout::Paginated,
|
||||||
'group_name' => 'Productos',
|
'group_name' => 'Productos',
|
||||||
'group_order' => 0,
|
'group_order' => 2,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$items = CatalogItem::query()
|
$items = CatalogItem::query()
|
||||||
@@ -179,7 +181,7 @@ class ProductCatalogFromImagesSeeder extends Seeder
|
|||||||
->orderBy('id')
|
->orderBy('id')
|
||||||
->get('id');
|
->get('id');
|
||||||
|
|
||||||
$group->featuredItems()->createMany(
|
$paginatedGroup->featuredItems()->createMany(
|
||||||
$items->values()->map(
|
$items->values()->map(
|
||||||
fn (CatalogItem $item, int $order): array => [
|
fn (CatalogItem $item, int $order): array => [
|
||||||
'catalog_item_id' => $item->id,
|
'catalog_item_id' => $item->id,
|
||||||
@@ -187,6 +189,29 @@ class ProductCatalogFromImagesSeeder extends Seeder
|
|||||||
]
|
]
|
||||||
)->all()
|
)->all()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$carouselGroup = FeaturedGroup::query()->create([
|
||||||
|
'tenant_code' => $tenant->codigo,
|
||||||
|
'product_layout' => ProductLayout::ColumnWithImage,
|
||||||
|
'group_layout' => GroupLayout::Carousel,
|
||||||
|
'group_name' => 'Productos destacados',
|
||||||
|
'group_order' => 1,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$randomItems = CatalogItem::query()
|
||||||
|
->where('tenant_code', $tenant->codigo)
|
||||||
|
->inRandomOrder()
|
||||||
|
->limit(5)
|
||||||
|
->get('id');
|
||||||
|
|
||||||
|
$carouselGroup->featuredItems()->createMany(
|
||||||
|
$randomItems->values()->map(
|
||||||
|
fn (CatalogItem $item, int $order): array => [
|
||||||
|
'catalog_item_id' => $item->id,
|
||||||
|
'order' => $order,
|
||||||
|
]
|
||||||
|
)->all()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
42
database/seeders/SocialMediaSeeder.php
Normal file
42
database/seeders/SocialMediaSeeder.php
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Database\Seeders;
|
||||||
|
|
||||||
|
use App\Domains\Tenant\Models\SocialMedia;
|
||||||
|
use Illuminate\Database\Seeder;
|
||||||
|
|
||||||
|
class SocialMediaSeeder extends Seeder
|
||||||
|
{
|
||||||
|
public function run(): void
|
||||||
|
{
|
||||||
|
$socialMedia = [
|
||||||
|
[
|
||||||
|
'code' => 'facebook',
|
||||||
|
'icon' => 'fa-brands fa-facebook',
|
||||||
|
'name' => 'Facebook',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'code' => 'instagram',
|
||||||
|
'icon' => 'fa-brands fa-instagram',
|
||||||
|
'name' => 'Instagram',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'code' => 'whatsapp',
|
||||||
|
'icon' => 'fa-brands fa-whatsapp',
|
||||||
|
'name' => 'WhatsApp',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'code' => 'linkedin',
|
||||||
|
'icon' => 'fa-brands fa-linkedin-in',
|
||||||
|
'name' => 'LinkedIn',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($socialMedia as $socialMediaData) {
|
||||||
|
SocialMedia::query()->updateOrCreate(
|
||||||
|
['code' => $socialMediaData['code']],
|
||||||
|
$socialMediaData
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace Database\Seeders;
|
namespace Database\Seeders;
|
||||||
|
|
||||||
|
use App\Domains\Attachable\Services\AttachmentService;
|
||||||
use App\Domains\Tenant\Models\Tenant;
|
use App\Domains\Tenant\Models\Tenant;
|
||||||
use App\Domains\Tenant\Services\TenantService;
|
use App\Domains\Tenant\Services\TenantService;
|
||||||
use Illuminate\Database\Seeder;
|
use Illuminate\Database\Seeder;
|
||||||
@@ -9,9 +10,39 @@ use Illuminate\Http\UploadedFile;
|
|||||||
|
|
||||||
class TenantSeeder extends Seeder
|
class TenantSeeder extends Seeder
|
||||||
{
|
{
|
||||||
public function __construct(protected TenantService $tenantService)
|
private const SONDER_MAIN_CAROUSEL_IMAGES = [
|
||||||
{
|
'01-urban-team.png',
|
||||||
}
|
'02-running-shoes.png',
|
||||||
|
'03-streetwear.png',
|
||||||
|
'04-football-training.png',
|
||||||
|
'05-activewear-essentials.png',
|
||||||
|
'06-city-runners.png',
|
||||||
|
];
|
||||||
|
|
||||||
|
private const SOCIAL_MEDIA = [
|
||||||
|
[
|
||||||
|
'code' => 'instagram',
|
||||||
|
'url' => 'https://www.instagram.com/sonderargentina/',
|
||||||
|
'orden' => 0,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'code' => 'facebook',
|
||||||
|
'url' => 'https://www.facebook.com/SonderArgentina/',
|
||||||
|
'orden' => 1,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'code' => 'linkedin',
|
||||||
|
'url' => 'https://www.linkedin.com/company/35664983/',
|
||||||
|
'orden' => 2,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'code' => 'whatsapp',
|
||||||
|
'url' => 'https://wa.me/5493412602222',
|
||||||
|
'orden' => 3,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
public function __construct(protected TenantService $tenantService) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run the database seeds.
|
* Run the database seeds.
|
||||||
@@ -21,7 +52,7 @@ class TenantSeeder extends Seeder
|
|||||||
// Check if tenant 'sonder' already exists and delete it to prevent duplicates
|
// Check if tenant 'sonder' already exists and delete it to prevent duplicates
|
||||||
$existing = Tenant::query()->where('codigo', 'sonder')->first();
|
$existing = Tenant::query()->where('codigo', 'sonder')->first();
|
||||||
if ($existing) {
|
if ($existing) {
|
||||||
$attachmentService = app(\App\Domains\Attachable\Services\AttachmentService::class);
|
$attachmentService = app(AttachmentService::class);
|
||||||
if ($existing->headerLogo) {
|
if ($existing->headerLogo) {
|
||||||
try {
|
try {
|
||||||
$attachmentService->delete($existing->headerLogo);
|
$attachmentService->delete($existing->headerLogo);
|
||||||
@@ -36,6 +67,13 @@ class TenantSeeder extends Seeder
|
|||||||
// Ignore exception on cleanup
|
// Ignore exception on cleanup
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
foreach ($existing->mainCarouselImages as $mainCarouselImage) {
|
||||||
|
try {
|
||||||
|
$attachmentService->delete($mainCarouselImage);
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
// Ignore exception on cleanup
|
||||||
|
}
|
||||||
|
}
|
||||||
$existing->delete();
|
$existing->delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,7 +110,24 @@ class TenantSeeder extends Seeder
|
|||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
|
||||||
$tenant = $this->tenantService->create([
|
$mainCarouselImages = [];
|
||||||
|
foreach (self::SONDER_MAIN_CAROUSEL_IMAGES as $filename) {
|
||||||
|
$imagePath = public_path("images/sonder-main-carousel/{$filename}");
|
||||||
|
|
||||||
|
if (! file_exists($imagePath)) {
|
||||||
|
throw new \RuntimeException("Image not found at path: {$imagePath}");
|
||||||
|
}
|
||||||
|
|
||||||
|
$mainCarouselImages[] = new UploadedFile(
|
||||||
|
$imagePath,
|
||||||
|
$filename,
|
||||||
|
'image/png',
|
||||||
|
null,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->tenantService->create([
|
||||||
'codigo' => 'sonder',
|
'codigo' => 'sonder',
|
||||||
'nombre' => 'Sonder',
|
'nombre' => 'Sonder',
|
||||||
'dominio' => 'localhost',
|
'dominio' => 'localhost',
|
||||||
@@ -84,26 +139,31 @@ class TenantSeeder extends Seeder
|
|||||||
'footer_bg_color' => '#313131',
|
'footer_bg_color' => '#313131',
|
||||||
'header_logo' => $headerLogo,
|
'header_logo' => $headerLogo,
|
||||||
'footer_logo' => $footerLogo,
|
'footer_logo' => $footerLogo,
|
||||||
|
'main_carousel_images' => $mainCarouselImages,
|
||||||
|
'social_media' => self::SOCIAL_MEDIA,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Check if tenant 'fiesta_futbol_infantil' already exists
|
// Check if tenant 'fiesta_futbol_infantil' already exists
|
||||||
$existingFiesta = Tenant::query()->where('codigo', 'fiesta_futbol_infantil')->first();
|
$existingFiesta = Tenant::query()->where('codigo', 'fiesta_futbol_infantil')->first();
|
||||||
if ($existingFiesta) {
|
if ($existingFiesta) {
|
||||||
$attachmentService = app(\App\Domains\Attachable\Services\AttachmentService::class);
|
$attachmentService = app(AttachmentService::class);
|
||||||
if ($existingFiesta->headerLogo) {
|
if ($existingFiesta->headerLogo) {
|
||||||
try {
|
try {
|
||||||
$attachmentService->delete($existingFiesta->headerLogo);
|
$attachmentService->delete($existingFiesta->headerLogo);
|
||||||
} catch (\Throwable $e) {}
|
} catch (\Throwable $e) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if ($existingFiesta->footerLogo && $existingFiesta->footer_logo_id !== $existingFiesta->header_logo_id) {
|
if ($existingFiesta->footerLogo && $existingFiesta->footer_logo_id !== $existingFiesta->header_logo_id) {
|
||||||
try {
|
try {
|
||||||
$attachmentService->delete($existingFiesta->footerLogo);
|
$attachmentService->delete($existingFiesta->footerLogo);
|
||||||
} catch (\Throwable $e) {}
|
} catch (\Throwable $e) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if ($existingFiesta->heroBgImage) {
|
if ($existingFiesta->heroBgImage) {
|
||||||
try {
|
try {
|
||||||
$attachmentService->delete($existingFiesta->heroBgImage);
|
$attachmentService->delete($existingFiesta->heroBgImage);
|
||||||
} catch (\Throwable $e) {}
|
} catch (\Throwable $e) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$existingFiesta->delete();
|
$existingFiesta->delete();
|
||||||
}
|
}
|
||||||
@@ -178,6 +238,7 @@ class TenantSeeder extends Seeder
|
|||||||
'location' => 'Sunchales, Santa Fe',
|
'location' => 'Sunchales, Santa Fe',
|
||||||
'dates' => ['2026-10-09', '2026-10-10', '2026-10-11', '2026-10-12'],
|
'dates' => ['2026-10-09', '2026-10-10', '2026-10-11', '2026-10-12'],
|
||||||
],
|
],
|
||||||
|
'social_media' => self::SOCIAL_MEDIA,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
public/images/sonder-main-carousel/01-urban-team.png
Normal file
BIN
public/images/sonder-main-carousel/01-urban-team.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.9 MiB |
BIN
public/images/sonder-main-carousel/02-running-shoes.png
Normal file
BIN
public/images/sonder-main-carousel/02-running-shoes.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.1 MiB |
BIN
public/images/sonder-main-carousel/03-streetwear.png
Normal file
BIN
public/images/sonder-main-carousel/03-streetwear.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.9 MiB |
BIN
public/images/sonder-main-carousel/04-football-training.png
Normal file
BIN
public/images/sonder-main-carousel/04-football-training.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.1 MiB |
BIN
public/images/sonder-main-carousel/05-activewear-essentials.png
Normal file
BIN
public/images/sonder-main-carousel/05-activewear-essentials.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.0 MiB |
BIN
public/images/sonder-main-carousel/06-city-runners.png
Normal file
BIN
public/images/sonder-main-carousel/06-city-runners.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.0 MiB |
12
resources/views/mail/notifications/purchase-paid.blade.php
Normal file
12
resources/views/mail/notifications/purchase-paid.blade.php
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
<h1 style="margin: 0 0 20px;">¡Recibimos tu pago!</h1>
|
||||||
|
<p>La compra <strong>#{{ $purchase->id }}</strong> fue confirmada correctamente.</p>
|
||||||
|
<table role="presentation" style="width: 100%; border-collapse: collapse; margin: 20px 0;">
|
||||||
|
@foreach ($purchase->items as $item)
|
||||||
|
<tr>
|
||||||
|
<td style="padding: 8px 0; border-bottom: 1px solid #e2e8f0;">{{ $item->item_nombre }}</td>
|
||||||
|
<td style="padding: 8px 0; border-bottom: 1px solid #e2e8f0; text-align: center;">× {{ $item->cantidad }}</td>
|
||||||
|
<td style="padding: 8px 0; border-bottom: 1px solid #e2e8f0; text-align: right;">${{ number_format((float) $item->total, 2, ',', '.') }}</td>
|
||||||
|
</tr>
|
||||||
|
@endforeach
|
||||||
|
</table>
|
||||||
|
<p style="font-size: 18px;"><strong>Total pagado: ${{ number_format((float) $purchase->total, 2, ',', '.') }}</strong></p>
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
<h1 style="margin: 0 0 20px;">Tus tickets ya están disponibles</h1>
|
||||||
|
<p>Generamos {{ $tickets->count() }} {{ $tickets->count() === 1 ? 'ticket' : 'tickets' }} para la compra <strong>#{{ $purchase->id }}</strong>.</p>
|
||||||
|
<ul style="padding-left: 20px;">
|
||||||
|
@foreach ($tickets as $ticket)
|
||||||
|
<li style="margin-bottom: 8px;">{{ $ticket->name }}</li>
|
||||||
|
@endforeach
|
||||||
|
</ul>
|
||||||
3
resources/views/mail/notifications/welcome.blade.php
Normal file
3
resources/views/mail/notifications/welcome.blade.php
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<h1 style="margin: 0 0 20px;">¡Bienvenido a {{ $tenant->nombre }}!</h1>
|
||||||
|
<p>Hola {{ $user->nombre_apellido }}, tu cuenta fue creada correctamente.</p>
|
||||||
|
<p>Ya podés ingresar y comenzar a comprar.</p>
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use App\Domains\Auth\Controllers\GoogleAuthController;
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
|
|
||||||
Route::get('/', function () {
|
Route::get('/auth/google/redirect', [GoogleAuthController::class, 'redirect'])->name('auth.google.redirect');
|
||||||
return view('welcome');
|
Route::get('/api/auth/google/callback', [GoogleAuthController::class, 'callback'])->name('auth.google.callback');
|
||||||
});
|
|
||||||
|
|||||||
@@ -2,8 +2,13 @@
|
|||||||
|
|
||||||
namespace Tests\Feature\Auth;
|
namespace Tests\Feature\Auth;
|
||||||
|
|
||||||
|
use App\Domains\Attachable\Enums\AttachmentType;
|
||||||
|
use App\Domains\Attachable\Models\Attachment;
|
||||||
use App\Domains\Auth\Models\User;
|
use App\Domains\Auth\Models\User;
|
||||||
|
use App\Domains\Notification\Events\UserRegistered;
|
||||||
|
use App\Domains\Tenant\Models\Tenant;
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Illuminate\Support\Facades\Event;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
class RegisterControllerTest extends TestCase
|
class RegisterControllerTest extends TestCase
|
||||||
@@ -15,8 +20,8 @@ class RegisterControllerTest extends TestCase
|
|||||||
$response = $this->postJson('/api/register', [
|
$response = $this->postJson('/api/register', [
|
||||||
'nombre_apellido' => 'Ada Lovelace',
|
'nombre_apellido' => 'Ada Lovelace',
|
||||||
'email' => 'ada@example.com',
|
'email' => 'ada@example.com',
|
||||||
'password' => 'secret123',
|
'password' => 'Secret!123',
|
||||||
'password_confirmation' => 'secret123',
|
'password_confirmation' => 'Secret!123',
|
||||||
'dni' => '12345678A',
|
'dni' => '12345678A',
|
||||||
'telefono' => '+541122334455',
|
'telefono' => '+541122334455',
|
||||||
]);
|
]);
|
||||||
@@ -38,7 +43,7 @@ class RegisterControllerTest extends TestCase
|
|||||||
|
|
||||||
$user = User::query()->where('email', 'ada@example.com')->firstOrFail();
|
$user = User::query()->where('email', 'ada@example.com')->firstOrFail();
|
||||||
|
|
||||||
$this->assertNotSame('secret123', $user->password);
|
$this->assertNotSame('Secret!123', $user->password);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_it_registers_a_user_without_optional_fields(): void
|
public function test_it_registers_a_user_without_optional_fields(): void
|
||||||
@@ -46,8 +51,8 @@ class RegisterControllerTest extends TestCase
|
|||||||
$response = $this->postJson('/api/register', [
|
$response = $this->postJson('/api/register', [
|
||||||
'nombre_apellido' => 'Alan Turing',
|
'nombre_apellido' => 'Alan Turing',
|
||||||
'email' => 'alan@example.com',
|
'email' => 'alan@example.com',
|
||||||
'password' => 'secret123',
|
'password' => 'Secret!123',
|
||||||
'password_confirmation' => 'secret123',
|
'password_confirmation' => 'Secret!123',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$response
|
$response
|
||||||
@@ -66,6 +71,50 @@ class RegisterControllerTest extends TestCase
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_it_dispatches_the_welcome_notification_with_tenant_context(): void
|
||||||
|
{
|
||||||
|
Event::fake([UserRegistered::class]);
|
||||||
|
$header = Attachment::query()->create([
|
||||||
|
'path' => 'test/welcome-header.png',
|
||||||
|
'filename' => 'header.png',
|
||||||
|
'type' => AttachmentType::Image,
|
||||||
|
'mime_type' => 'image/png',
|
||||||
|
]);
|
||||||
|
$footer = Attachment::query()->create([
|
||||||
|
'path' => 'test/welcome-footer.png',
|
||||||
|
'filename' => 'footer.png',
|
||||||
|
'type' => AttachmentType::Image,
|
||||||
|
'mime_type' => 'image/png',
|
||||||
|
]);
|
||||||
|
$tenant = Tenant::query()->create([
|
||||||
|
'codigo' => 'welcome-tenant',
|
||||||
|
'nombre' => 'Welcome Tenant',
|
||||||
|
'dominio' => 'welcome.local',
|
||||||
|
'primary_color' => '#000000',
|
||||||
|
'secondary_color' => '#000000',
|
||||||
|
'danger_color' => '#000000',
|
||||||
|
'success_color' => '#000000',
|
||||||
|
'header_bg_color' => '#000000',
|
||||||
|
'footer_bg_color' => '#000000',
|
||||||
|
'header_logo_id' => $header->id,
|
||||||
|
'footer_logo_id' => $footer->id,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->postJson('/api/register', [
|
||||||
|
'tenant_codigo' => $tenant->codigo,
|
||||||
|
'nombre_apellido' => 'Grace Hopper',
|
||||||
|
'email' => 'grace@example.com',
|
||||||
|
'password' => 'Secret!123',
|
||||||
|
'password_confirmation' => 'Secret!123',
|
||||||
|
])->assertCreated();
|
||||||
|
|
||||||
|
Event::assertDispatched(
|
||||||
|
UserRegistered::class,
|
||||||
|
fn (UserRegistered $event): bool => $event->tenantCode === $tenant->codigo
|
||||||
|
&& $event->user->email === 'grace@example.com',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public function test_it_validates_required_fields_and_unique_email(): void
|
public function test_it_validates_required_fields_and_unique_email(): void
|
||||||
{
|
{
|
||||||
User::factory()->create([
|
User::factory()->create([
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ namespace Tests\Feature\Catalog;
|
|||||||
|
|
||||||
use App\Domains\Attachable\Enums\AttachmentType;
|
use App\Domains\Attachable\Enums\AttachmentType;
|
||||||
use App\Domains\Attachable\Models\Attachment;
|
use App\Domains\Attachable\Models\Attachment;
|
||||||
|
use App\Domains\Catalog\Enums\GroupLayout;
|
||||||
use App\Domains\Catalog\Enums\ProductLayout;
|
use App\Domains\Catalog\Enums\ProductLayout;
|
||||||
use App\Domains\Catalog\Models\CatalogItem;
|
use App\Domains\Catalog\Models\CatalogItem;
|
||||||
use App\Domains\Catalog\Models\FeaturedGroup;
|
use App\Domains\Catalog\Models\FeaturedGroup;
|
||||||
@@ -21,7 +22,13 @@ class CatalogControllerTest extends TestCase
|
|||||||
{
|
{
|
||||||
$tenant = $this->createTenant('catalog-index');
|
$tenant = $this->createTenant('catalog-index');
|
||||||
$row = $this->createGroup($tenant, ProductLayout::Row, 'Row', 2);
|
$row = $this->createGroup($tenant, ProductLayout::Row, 'Row', 2);
|
||||||
$cart = $this->createGroup($tenant, ProductLayout::ColumnWithCart, 'Cart', 1);
|
$cart = $this->createGroup(
|
||||||
|
$tenant,
|
||||||
|
ProductLayout::ColumnWithCart,
|
||||||
|
'Cart',
|
||||||
|
1,
|
||||||
|
GroupLayout::SimpleVertical,
|
||||||
|
);
|
||||||
|
|
||||||
$directInventory = Inventory::query()->create([
|
$directInventory = Inventory::query()->create([
|
||||||
'real_stock' => 10,
|
'real_stock' => 10,
|
||||||
@@ -50,14 +57,14 @@ class CatalogControllerTest extends TestCase
|
|||||||
->assertJsonCount(2)
|
->assertJsonCount(2)
|
||||||
->assertJsonPath('0.title', 'Cart')
|
->assertJsonPath('0.title', 'Cart')
|
||||||
->assertJsonPath('0.layout', ProductLayout::ColumnWithCart->value)
|
->assertJsonPath('0.layout', ProductLayout::ColumnWithCart->value)
|
||||||
->assertJsonPath('0.items.meta.current_page', 1)
|
->assertJsonPath('0.group_layout', GroupLayout::SimpleVertical->value)
|
||||||
->assertJsonPath('0.items.data.0.nombre', 'Variants')
|
->assertJsonPath('0.items.0.nombre', 'Variants')
|
||||||
->assertJsonPath('0.items.data.0.descripcion', 'Variants description')
|
->assertJsonPath('0.items.0.descripcion', 'Variants description')
|
||||||
->assertJsonPath('0.items.data.0.precio', '100.00')
|
->assertJsonPath('0.items.0.precio', '100.00')
|
||||||
->assertJsonPath('0.items.data.0.stock_tecnico', 7)
|
->assertJsonPath('0.items.0.stock_tecnico', 7)
|
||||||
->assertJsonCount(2, '0.items.data.0.variants')
|
->assertJsonCount(2, '0.items.0.variants')
|
||||||
->assertJsonPath('0.items.data.0.variants.0.stock_tecnico', 4)
|
->assertJsonPath('0.items.0.variants.0.stock_tecnico', 4)
|
||||||
->assertJsonPath('0.items.data.0.variants.1.stock_tecnico', 3)
|
->assertJsonPath('0.items.0.variants.1.stock_tecnico', 3)
|
||||||
->assertJsonPath('1.title', 'Row')
|
->assertJsonPath('1.title', 'Row')
|
||||||
->assertJsonPath('1.items.data.0.stock_tecnico', 8)
|
->assertJsonPath('1.items.data.0.stock_tecnico', 8)
|
||||||
->assertJsonCount(0, '1.items.data.0.variants');
|
->assertJsonCount(0, '1.items.data.0.variants');
|
||||||
@@ -137,15 +144,71 @@ class CatalogControllerTest extends TestCase
|
|||||||
->assertJsonPath('data.0.nombre', 'Item 13');
|
->assertJsonPath('data.0.nombre', 'Item 13');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_non_paginated_group_layouts_return_all_items_as_a_plain_array(): void
|
||||||
|
{
|
||||||
|
$tenant = $this->createTenant('catalog-simple-layouts');
|
||||||
|
$layouts = [
|
||||||
|
GroupLayout::Simple,
|
||||||
|
GroupLayout::SimpleVertical,
|
||||||
|
GroupLayout::Carousel,
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($layouts as $order => $groupLayout) {
|
||||||
|
$group = $this->createGroup(
|
||||||
|
$tenant,
|
||||||
|
ProductLayout::Row,
|
||||||
|
$groupLayout->value,
|
||||||
|
$order,
|
||||||
|
$groupLayout,
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach (range(1, 13) as $number) {
|
||||||
|
$item = $this->createItem($tenant, "{$groupLayout->value} Item {$number}");
|
||||||
|
$group->featuredItems()->create([
|
||||||
|
'catalog_item_id' => $item->id,
|
||||||
|
'order' => $number,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$response = $this->getJson("/api/tenants/{$tenant->codigo}/catalog")->assertOk();
|
||||||
|
$groups = $response->json();
|
||||||
|
|
||||||
|
foreach ($layouts as $index => $groupLayout) {
|
||||||
|
$this->assertSame($groupLayout->value, $groups[$index]['group_layout']);
|
||||||
|
$this->assertCount(13, $groups[$index]['items']);
|
||||||
|
$this->assertSame(
|
||||||
|
"{$groupLayout->value} Item 1",
|
||||||
|
$groups[$index]['items'][0]['nombre'],
|
||||||
|
);
|
||||||
|
$this->assertArrayNotHasKey('data', $groups[$index]['items']);
|
||||||
|
$this->assertArrayNotHasKey('meta', $groups[$index]['items']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$carouselGroup = FeaturedGroup::query()
|
||||||
|
->where('tenant_code', $tenant->codigo)
|
||||||
|
->where('group_layout', GroupLayout::Carousel)
|
||||||
|
->sole();
|
||||||
|
|
||||||
|
$this->getJson(
|
||||||
|
"/api/tenants/{$tenant->codigo}/catalog/featured-groups/{$carouselGroup->id}/items?page=2"
|
||||||
|
)
|
||||||
|
->assertOk()
|
||||||
|
->assertJsonCount(13)
|
||||||
|
->assertJsonPath('0.nombre', 'carousel Item 1');
|
||||||
|
}
|
||||||
|
|
||||||
private function createGroup(
|
private function createGroup(
|
||||||
Tenant $tenant,
|
Tenant $tenant,
|
||||||
ProductLayout $layout,
|
ProductLayout $layout,
|
||||||
string $name,
|
string $name,
|
||||||
int $order = 0,
|
int $order = 0,
|
||||||
|
GroupLayout $groupLayout = GroupLayout::Paginated,
|
||||||
): FeaturedGroup {
|
): FeaturedGroup {
|
||||||
return FeaturedGroup::query()->create([
|
return FeaturedGroup::query()->create([
|
||||||
'tenant_code' => $tenant->codigo,
|
'tenant_code' => $tenant->codigo,
|
||||||
'product_layout' => $layout,
|
'product_layout' => $layout,
|
||||||
|
'group_layout' => $groupLayout,
|
||||||
'group_name' => $name,
|
'group_name' => $name,
|
||||||
'group_order' => $order,
|
'group_order' => $order,
|
||||||
]);
|
]);
|
||||||
|
|||||||
@@ -78,6 +78,7 @@ class CatalogSchemaTest extends TestCase
|
|||||||
'id',
|
'id',
|
||||||
'tenant_code',
|
'tenant_code',
|
||||||
'product_layout',
|
'product_layout',
|
||||||
|
'group_layout',
|
||||||
'group_name',
|
'group_name',
|
||||||
'group_order',
|
'group_order',
|
||||||
], Schema::getColumnListing('featured_groups'));
|
], Schema::getColumnListing('featured_groups'));
|
||||||
|
|||||||
132
tests/Feature/Catalog/CatalogSearchTest.php
Normal file
132
tests/Feature/Catalog/CatalogSearchTest.php
Normal file
@@ -0,0 +1,132 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\Catalog;
|
||||||
|
|
||||||
|
use App\Domains\Attachable\Enums\AttachmentType;
|
||||||
|
use App\Domains\Attachable\Models\Attachment;
|
||||||
|
use App\Domains\Catalog\Enums\GroupLayout;
|
||||||
|
use App\Domains\Catalog\Enums\ProductLayout;
|
||||||
|
use App\Domains\Catalog\Models\CatalogItem;
|
||||||
|
use App\Domains\Catalog\Models\Inventory;
|
||||||
|
use App\Domains\Tenant\Models\Tenant;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class CatalogSearchTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase;
|
||||||
|
|
||||||
|
public function test_every_tenant_gets_default_search_layouts(): void
|
||||||
|
{
|
||||||
|
$tenant = $this->createTenant('search-default');
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('tenants', [
|
||||||
|
'codigo' => $tenant->codigo,
|
||||||
|
'search_product_layout' => ProductLayout::ColumnWithImage->value,
|
||||||
|
'search_group_layout' => GroupLayout::Paginated->value,
|
||||||
|
'search_items_per_page' => 12,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_search_layouts_can_be_updated_on_the_tenant_and_are_returned_by_bootstrap(): void
|
||||||
|
{
|
||||||
|
$tenant = $this->createTenant('search-config');
|
||||||
|
|
||||||
|
$this->putJson("/api/tenants/{$tenant->codigo}", [
|
||||||
|
'search_product_layout' => ProductLayout::Row->value,
|
||||||
|
'search_group_layout' => GroupLayout::SimpleVertical->value,
|
||||||
|
'search_items_per_page' => 24,
|
||||||
|
])
|
||||||
|
->assertOk()
|
||||||
|
->assertJsonPath('data.search_product_layout', ProductLayout::Row->value)
|
||||||
|
->assertJsonPath('data.search_group_layout', GroupLayout::SimpleVertical->value)
|
||||||
|
->assertJsonPath('data.search_items_per_page', 24);
|
||||||
|
|
||||||
|
$this->getJson("/api/tenants/bootstrap/{$tenant->dominio}")
|
||||||
|
->assertOk()
|
||||||
|
->assertJsonPath('data.search_product_layout', ProductLayout::Row->value)
|
||||||
|
->assertJsonPath('data.search_group_layout', GroupLayout::SimpleVertical->value)
|
||||||
|
->assertJsonPath('data.search_items_per_page', 24);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_search_is_tenant_scoped_relevant_and_uses_configured_page_size(): void
|
||||||
|
{
|
||||||
|
$tenant = $this->createTenant('search-items');
|
||||||
|
$otherTenant = $this->createTenant('other-search-items');
|
||||||
|
$tenant->update(['search_items_per_page' => 4]);
|
||||||
|
|
||||||
|
foreach (range(1, 5) as $number) {
|
||||||
|
$this->createCatalogItem($tenant, "Running {$number}");
|
||||||
|
}
|
||||||
|
$exactMatch = $this->createCatalogItem($tenant, 'Running');
|
||||||
|
$this->createCatalogItem($tenant, 'Unrelated');
|
||||||
|
$this->createCatalogItem($otherTenant, 'Running foreign');
|
||||||
|
|
||||||
|
$response = $this->getJson(
|
||||||
|
"/api/tenants/{$tenant->codigo}/catalog-items?q=running"
|
||||||
|
);
|
||||||
|
|
||||||
|
$response
|
||||||
|
->assertOk()
|
||||||
|
->assertJsonPath('meta.current_page', 1)
|
||||||
|
->assertJsonPath('meta.per_page', 4)
|
||||||
|
->assertJsonPath('meta.total', 6)
|
||||||
|
->assertJsonCount(4, 'data')
|
||||||
|
->assertJsonPath('data.0.id', $exactMatch->id)
|
||||||
|
->assertJsonMissing(['nombre' => 'Running foreign'])
|
||||||
|
->assertJsonMissing(['nombre' => 'Unrelated']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_search_validates_the_query(): void
|
||||||
|
{
|
||||||
|
$tenant = $this->createTenant('search-validation');
|
||||||
|
|
||||||
|
$this->getJson("/api/tenants/{$tenant->codigo}/catalog-items?q=a")
|
||||||
|
->assertUnprocessable()
|
||||||
|
->assertJsonValidationErrors('q');
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createCatalogItem(Tenant $tenant, string $name): CatalogItem
|
||||||
|
{
|
||||||
|
$inventory = Inventory::query()->create(['real_stock' => 10]);
|
||||||
|
|
||||||
|
return CatalogItem::query()->create([
|
||||||
|
'tenant_code' => $tenant->codigo,
|
||||||
|
'inventory_id' => $inventory->id,
|
||||||
|
'slug' => str($name)->slug()->toString(),
|
||||||
|
'nombre' => $name,
|
||||||
|
'descripcion' => "{$name} description",
|
||||||
|
'precio' => 100,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createTenant(string $code): Tenant
|
||||||
|
{
|
||||||
|
$headerLogo = $this->createAttachment("{$code}-header");
|
||||||
|
$footerLogo = $this->createAttachment("{$code}-footer");
|
||||||
|
|
||||||
|
return Tenant::query()->create([
|
||||||
|
'codigo' => $code,
|
||||||
|
'nombre' => ucfirst($code),
|
||||||
|
'dominio' => "{$code}.local",
|
||||||
|
'primary_color' => '#000000',
|
||||||
|
'secondary_color' => '#000000',
|
||||||
|
'danger_color' => '#000000',
|
||||||
|
'success_color' => '#000000',
|
||||||
|
'header_bg_color' => '#000000',
|
||||||
|
'footer_bg_color' => '#000000',
|
||||||
|
'header_logo_id' => $headerLogo->id,
|
||||||
|
'footer_logo_id' => $footerLogo->id,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createAttachment(string $name): Attachment
|
||||||
|
{
|
||||||
|
return Attachment::query()->create([
|
||||||
|
'path' => "test/{$name}.png",
|
||||||
|
'filename' => "{$name}.png",
|
||||||
|
'type' => AttachmentType::Image,
|
||||||
|
'mime_type' => 'image/png',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -19,6 +19,7 @@ use App\Domains\Tenant\Models\Tenant;
|
|||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
use Illuminate\Support\Facades\Cache;
|
use Illuminate\Support\Facades\Cache;
|
||||||
use Illuminate\Support\Facades\Http;
|
use Illuminate\Support\Facades\Http;
|
||||||
|
use Illuminate\Support\Facades\Queue;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
@@ -32,6 +33,7 @@ class TelepagosWebhookTest extends TestCase
|
|||||||
|
|
||||||
config(['services.integrations.secret' => 'base64:'.base64_encode(random_bytes(32))]);
|
config(['services.integrations.secret' => 'base64:'.base64_encode(random_bytes(32))]);
|
||||||
Cache::flush();
|
Cache::flush();
|
||||||
|
Queue::fake();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_transfer_payment_intent_requires_a_valid_transfer_payer_dni(): void
|
public function test_transfer_payment_intent_requires_a_valid_transfer_payer_dni(): void
|
||||||
|
|||||||
171
tests/Feature/Menu/TenantMenuControllerTest.php
Normal file
171
tests/Feature/Menu/TenantMenuControllerTest.php
Normal file
@@ -0,0 +1,171 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\Menu;
|
||||||
|
|
||||||
|
use App\Domains\Attachable\Enums\AttachmentType;
|
||||||
|
use App\Domains\Attachable\Models\Attachment;
|
||||||
|
use App\Domains\Menu\Models\Menu;
|
||||||
|
use App\Domains\Tenant\Models\Tenant;
|
||||||
|
use Database\Seeders\MenuSeeder;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class TenantMenuControllerTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase;
|
||||||
|
|
||||||
|
public function test_it_validates_static_content_with_the_menu_schema(): void
|
||||||
|
{
|
||||||
|
$tenant = $this->createTenant();
|
||||||
|
$menu = Menu::query()->create([
|
||||||
|
'code' => 'about',
|
||||||
|
'label' => 'Nosotros',
|
||||||
|
'content_type' => Menu::CONTENT_TYPE_STATIC,
|
||||||
|
'static_content_schema' => [
|
||||||
|
'title' => 'required|string|max:20',
|
||||||
|
'sections' => 'required|array|min:1',
|
||||||
|
'sections.*.body' => 'required|string',
|
||||||
|
],
|
||||||
|
'route' => '/about',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->postJson("/api/{$tenant->codigo}/menues/{$menu->code}", [
|
||||||
|
'static_content' => [
|
||||||
|
'title' => 123,
|
||||||
|
'sections' => [],
|
||||||
|
],
|
||||||
|
])
|
||||||
|
->assertUnprocessable()
|
||||||
|
->assertJsonValidationErrors([
|
||||||
|
'static_content.title',
|
||||||
|
'static_content.sections',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertDatabaseMissing('tenants_menues', [
|
||||||
|
'tenant_code' => $tenant->codigo,
|
||||||
|
'menu_code' => $menu->code,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_it_configures_a_static_menu_when_content_matches_the_schema(): void
|
||||||
|
{
|
||||||
|
$tenant = $this->createTenant();
|
||||||
|
$menu = Menu::query()->create([
|
||||||
|
'code' => 'about',
|
||||||
|
'label' => 'Nosotros',
|
||||||
|
'content_type' => Menu::CONTENT_TYPE_STATIC,
|
||||||
|
'static_content_schema' => [
|
||||||
|
'title' => 'required|string|max:20',
|
||||||
|
'sections' => 'required|array|min:1',
|
||||||
|
'sections.*.body' => 'required|string',
|
||||||
|
],
|
||||||
|
'route' => '/about',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$content = [
|
||||||
|
'title' => 'Nosotros',
|
||||||
|
'sections' => [
|
||||||
|
['body' => 'Nuestra historia'],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->postJson("/api/{$tenant->codigo}/menues/{$menu->code}", [
|
||||||
|
'static_content' => $content,
|
||||||
|
])
|
||||||
|
->assertOk()
|
||||||
|
->assertJsonPath('static_content.title', 'Nosotros')
|
||||||
|
->assertJsonPath('static_content.sections.0.body', 'Nuestra historia');
|
||||||
|
|
||||||
|
$this->assertSame(
|
||||||
|
$content,
|
||||||
|
$tenant->menues()->where('menues.code', $menu->code)->firstOrFail()->pivot->static_content
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_dynamic_menus_do_not_require_static_content(): void
|
||||||
|
{
|
||||||
|
$tenant = $this->createTenant();
|
||||||
|
$menu = Menu::query()->create([
|
||||||
|
'code' => 'catalog',
|
||||||
|
'label' => 'Catálogo',
|
||||||
|
'route' => '/catalog',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->postJson("/api/{$tenant->codigo}/menues/{$menu->code}")
|
||||||
|
->assertOk()
|
||||||
|
->assertJsonPath('static_content', null);
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('tenants_menues', [
|
||||||
|
'tenant_code' => $tenant->codigo,
|
||||||
|
'menu_code' => $menu->code,
|
||||||
|
'static_content' => null,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_contact_content_requires_coordinates_inside_each_address(): void
|
||||||
|
{
|
||||||
|
$tenant = $this->createTenant();
|
||||||
|
$this->seed(MenuSeeder::class);
|
||||||
|
|
||||||
|
$this->postJson("/api/{$tenant->codigo}/menues/help.contact", [
|
||||||
|
'static_content' => [
|
||||||
|
'whatsapp' => [
|
||||||
|
'whatsapp_url' => 'https://wa.me/543412602222',
|
||||||
|
'whatsapp_label' => 'Chatea con nosotros',
|
||||||
|
],
|
||||||
|
'phone' => '+54 9 (0341) 6658247',
|
||||||
|
'locations' => [
|
||||||
|
'rosario' => [
|
||||||
|
'label' => 'Rosario',
|
||||||
|
'addresses' => [
|
||||||
|
[
|
||||||
|
'label' => 'Av. San Lorenzo 1542',
|
||||||
|
'address' => 'Av. San Lorenzo 1542, Rosario',
|
||||||
|
'coordinates' => [-91, -181],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'map_locations' => [
|
||||||
|
'legacy_point' => [-32.946820, -60.639320],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
])
|
||||||
|
->assertUnprocessable()
|
||||||
|
->assertJsonValidationErrors([
|
||||||
|
'static_content.locations.rosario.addresses.0.coordinates.0',
|
||||||
|
'static_content.locations.rosario.addresses.0.coordinates.1',
|
||||||
|
'static_content.map_locations',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createTenant(): Tenant
|
||||||
|
{
|
||||||
|
$headerLogo = $this->createAttachment('header.png');
|
||||||
|
$footerLogo = $this->createAttachment('footer.png');
|
||||||
|
|
||||||
|
return Tenant::query()->create([
|
||||||
|
'codigo' => 'acme',
|
||||||
|
'nombre' => 'Acme',
|
||||||
|
'dominio' => 'acme.com',
|
||||||
|
'primary_color' => '#111111',
|
||||||
|
'secondary_color' => '#222222',
|
||||||
|
'danger_color' => '#333333',
|
||||||
|
'success_color' => '#444444',
|
||||||
|
'header_bg_color' => '#ffffff',
|
||||||
|
'footer_bg_color' => '#ffffff',
|
||||||
|
'header_logo_id' => $headerLogo->id,
|
||||||
|
'footer_logo_id' => $footerLogo->id,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createAttachment(string $filename): Attachment
|
||||||
|
{
|
||||||
|
return Attachment::query()->create([
|
||||||
|
'path' => "test/{$filename}",
|
||||||
|
'filename' => $filename,
|
||||||
|
'type' => AttachmentType::Image,
|
||||||
|
'mime_type' => 'image/png',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
138
tests/Feature/Notification/NotificationMailServiceTest.php
Normal file
138
tests/Feature/Notification/NotificationMailServiceTest.php
Normal file
@@ -0,0 +1,138 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\Notification;
|
||||||
|
|
||||||
|
use App\Domains\Attachable\Enums\AttachmentType;
|
||||||
|
use App\Domains\Attachable\Models\Attachment;
|
||||||
|
use App\Domains\Auth\Models\User;
|
||||||
|
use App\Domains\Catalog\Models\CatalogItem;
|
||||||
|
use App\Domains\Integration\Models\Integration;
|
||||||
|
use App\Domains\Notification\Services\NotificationMailService;
|
||||||
|
use App\Domains\Purchase\Models\Purchase;
|
||||||
|
use App\Domains\Tenant\Models\Tenant;
|
||||||
|
use App\Domains\Ticket\Models\Ticket;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Illuminate\Mail\Mailable;
|
||||||
|
use Illuminate\Support\Facades\Mail;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class NotificationMailServiceTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase;
|
||||||
|
|
||||||
|
private Tenant $tenant;
|
||||||
|
|
||||||
|
private User $user;
|
||||||
|
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
Mail::fake();
|
||||||
|
Integration::query()->create([
|
||||||
|
'integration_code' => 'email',
|
||||||
|
'name' => 'Email',
|
||||||
|
'url' => null,
|
||||||
|
'requires_tenant_configuration' => false,
|
||||||
|
'integration_data_schema' => [],
|
||||||
|
]);
|
||||||
|
$header = Attachment::query()->create([
|
||||||
|
'path' => 'test/mail-header.png',
|
||||||
|
'filename' => 'header.png',
|
||||||
|
'type' => AttachmentType::Image,
|
||||||
|
'mime_type' => 'image/png',
|
||||||
|
]);
|
||||||
|
$footer = Attachment::query()->create([
|
||||||
|
'path' => 'test/mail-footer.png',
|
||||||
|
'filename' => 'footer.png',
|
||||||
|
'type' => AttachmentType::Image,
|
||||||
|
'mime_type' => 'image/png',
|
||||||
|
]);
|
||||||
|
$this->tenant = Tenant::query()->create([
|
||||||
|
'codigo' => 'mail-tenant',
|
||||||
|
'nombre' => 'Mail Tenant',
|
||||||
|
'dominio' => 'mail.local',
|
||||||
|
'primary_color' => '#112233',
|
||||||
|
'secondary_color' => '#000000',
|
||||||
|
'danger_color' => '#000000',
|
||||||
|
'success_color' => '#000000',
|
||||||
|
'header_bg_color' => '#000000',
|
||||||
|
'footer_bg_color' => '#000000',
|
||||||
|
'header_logo_id' => $header->id,
|
||||||
|
'footer_logo_id' => $footer->id,
|
||||||
|
]);
|
||||||
|
$this->user = User::factory()->create([
|
||||||
|
'nombre_apellido' => 'Ada Lovelace',
|
||||||
|
'email' => 'ada@example.com',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_it_sends_a_branded_welcome_email(): void
|
||||||
|
{
|
||||||
|
app(NotificationMailService::class)->sendWelcome($this->user->id, $this->tenant->codigo);
|
||||||
|
|
||||||
|
Mail::assertSent(Mailable::class, function (Mailable $mail): bool {
|
||||||
|
$mail->assertTo('ada@example.com');
|
||||||
|
$mail->assertHasSubject('Bienvenido a Mail Tenant');
|
||||||
|
|
||||||
|
return str_contains($mail->render(), 'Ada Lovelace')
|
||||||
|
&& str_contains($mail->render(), 'Mail Tenant');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_it_sends_purchase_and_ticket_emails_to_the_purchase_recipient(): void
|
||||||
|
{
|
||||||
|
$purchase = Purchase::query()->create([
|
||||||
|
'tenant_codigo' => $this->tenant->codigo,
|
||||||
|
'user_id' => $this->user->id,
|
||||||
|
'status' => Purchase::STATUS_PAID,
|
||||||
|
'payment_method' => 'transfer',
|
||||||
|
'total' => 25,
|
||||||
|
'email' => 'checkout@example.com',
|
||||||
|
]);
|
||||||
|
$catalogItem = CatalogItem::query()->create([
|
||||||
|
'tenant_code' => $this->tenant->codigo,
|
||||||
|
'slug' => 'entrada',
|
||||||
|
'nombre' => 'Entrada',
|
||||||
|
'descripcion' => 'Entrada general',
|
||||||
|
'precio' => 25,
|
||||||
|
'has_tickets' => true,
|
||||||
|
]);
|
||||||
|
$purchase->items()->create([
|
||||||
|
'source_catalog_item_id' => $catalogItem->id,
|
||||||
|
'nombre' => 'Entrada',
|
||||||
|
'descripcion' => 'Entrada general',
|
||||||
|
'slug' => 'entrada',
|
||||||
|
'item_nombre' => 'Entrada general',
|
||||||
|
'variant_attributes' => [],
|
||||||
|
'cantidad' => 1,
|
||||||
|
'precio_unitario' => 25,
|
||||||
|
'total' => 25,
|
||||||
|
]);
|
||||||
|
$ticket = Ticket::query()->create([
|
||||||
|
'tenant_code' => $this->tenant->codigo,
|
||||||
|
'ticket' => fake()->uuid(),
|
||||||
|
'name' => 'Entrada general',
|
||||||
|
'description' => 'Entrada general',
|
||||||
|
'user_id' => $this->user->id,
|
||||||
|
]);
|
||||||
|
$service = app(NotificationMailService::class);
|
||||||
|
|
||||||
|
$service->sendPurchasePaid($purchase->id);
|
||||||
|
$service->sendTicketsAvailable($purchase->id, [$ticket->id]);
|
||||||
|
|
||||||
|
Mail::assertSent(Mailable::class, 2);
|
||||||
|
Mail::assertSent(Mailable::class, function (Mailable $mail) use ($purchase): bool {
|
||||||
|
$mail->assertTo('checkout@example.com');
|
||||||
|
|
||||||
|
return $mail->subject === "Pago confirmado - Compra #{$purchase->id}"
|
||||||
|
&& str_contains($mail->render(), 'Total pagado');
|
||||||
|
});
|
||||||
|
Mail::assertSent(Mailable::class, function (Mailable $mail): bool {
|
||||||
|
$mail->assertTo('checkout@example.com');
|
||||||
|
|
||||||
|
return $mail->subject === 'Tus tickets ya están disponibles'
|
||||||
|
&& str_contains($mail->render(), 'Entrada general');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,6 +15,7 @@ use App\Domains\Purchase\Models\Purchase;
|
|||||||
use App\Domains\Purchase\Services\CheckoutService;
|
use App\Domains\Purchase\Services\CheckoutService;
|
||||||
use App\Domains\Tenant\Models\Tenant;
|
use App\Domains\Tenant\Models\Tenant;
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Illuminate\Support\Facades\Queue;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
@@ -22,6 +23,13 @@ class StorePurchaseTest extends TestCase
|
|||||||
{
|
{
|
||||||
use RefreshDatabase;
|
use RefreshDatabase;
|
||||||
|
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
Queue::fake();
|
||||||
|
}
|
||||||
|
|
||||||
public function test_it_creates_a_purchase_from_cart_id_without_persisting_items_yet(): void
|
public function test_it_creates_a_purchase_from_cart_id_without_persisting_items_yet(): void
|
||||||
{
|
{
|
||||||
$tenant = $this->createTenant('sonder', 'Sonder', 'sonder.com.ar');
|
$tenant = $this->createTenant('sonder', 'Sonder', 'sonder.com.ar');
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ namespace Tests\Feature\Seeders;
|
|||||||
use App\Domains\Attachable\Enums\AttachmentType;
|
use App\Domains\Attachable\Enums\AttachmentType;
|
||||||
use App\Domains\Attachable\Models\Attachment;
|
use App\Domains\Attachable\Models\Attachment;
|
||||||
use App\Domains\Catalog\Enums\CatalogItemType;
|
use App\Domains\Catalog\Enums\CatalogItemType;
|
||||||
|
use App\Domains\Catalog\Enums\GroupLayout;
|
||||||
|
use App\Domains\Catalog\Enums\ProductLayout;
|
||||||
use App\Domains\Catalog\Models\Attribute;
|
use App\Domains\Catalog\Models\Attribute;
|
||||||
use App\Domains\Catalog\Models\CatalogItem;
|
use App\Domains\Catalog\Models\CatalogItem;
|
||||||
use App\Domains\Catalog\Models\FeaturedGroup;
|
use App\Domains\Catalog\Models\FeaturedGroup;
|
||||||
@@ -121,6 +123,12 @@ class FiestaFutbolInfantilProductSeederTest extends TestCase
|
|||||||
$this->assertSame(9, CatalogItem::query()->where('tenant_code', $tenant->codigo)->count());
|
$this->assertSame(9, CatalogItem::query()->where('tenant_code', $tenant->codigo)->count());
|
||||||
$this->assertSame(10, Inventory::query()->count());
|
$this->assertSame(10, Inventory::query()->count());
|
||||||
|
|
||||||
|
$featuredGroups = FeaturedGroup::query()
|
||||||
|
->where('tenant_code', $tenant->codigo)
|
||||||
|
->with('featuredItems.catalogItem')
|
||||||
|
->orderBy('group_order')
|
||||||
|
->get();
|
||||||
|
|
||||||
$this->assertSame(
|
$this->assertSame(
|
||||||
[
|
[
|
||||||
'Entradas' => ['entrada-general', 'entrada-general-todos-los-dias'],
|
'Entradas' => ['entrada-general', 'entrada-general-todos-los-dias'],
|
||||||
@@ -128,15 +136,28 @@ class FiestaFutbolInfantilProductSeederTest extends TestCase
|
|||||||
'Comidas' => ['hamburguesa-papa-frita', 'pancho', 'combo-2-panchos-2-hamburguesas'],
|
'Comidas' => ['hamburguesa-papa-frita', 'pancho', 'combo-2-panchos-2-hamburguesas'],
|
||||||
'Bebidas' => ['coca-cola-500ml', 'agua-mineral-1l'],
|
'Bebidas' => ['coca-cola-500ml', 'agua-mineral-1l'],
|
||||||
],
|
],
|
||||||
FeaturedGroup::query()
|
$featuredGroups
|
||||||
->where('tenant_code', $tenant->codigo)
|
|
||||||
->with('featuredItems.catalogItem')
|
|
||||||
->orderBy('group_order')
|
|
||||||
->get()
|
|
||||||
->mapWithKeys(fn (FeaturedGroup $group): array => [
|
->mapWithKeys(fn (FeaturedGroup $group): array => [
|
||||||
$group->group_name => $group->featuredItems->pluck('catalogItem.slug')->all(),
|
$group->group_name => $group->featuredItems->pluck('catalogItem.slug')->all(),
|
||||||
])
|
])
|
||||||
->all()
|
->all()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$this->assertSame(
|
||||||
|
[
|
||||||
|
['Entradas', ProductLayout::Row, GroupLayout::SimpleVertical, 0],
|
||||||
|
['Estacionamiento', ProductLayout::ColumnWithCart, GroupLayout::Simple, 1],
|
||||||
|
['Comidas', ProductLayout::ColumnWithCart, GroupLayout::Simple, 2],
|
||||||
|
['Bebidas', ProductLayout::ColumnWithCart, GroupLayout::Simple, 3],
|
||||||
|
],
|
||||||
|
$featuredGroups
|
||||||
|
->map(fn (FeaturedGroup $group): array => [
|
||||||
|
$group->group_name,
|
||||||
|
$group->product_layout,
|
||||||
|
$group->group_layout,
|
||||||
|
$group->group_order,
|
||||||
|
])
|
||||||
|
->all()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
202
tests/Feature/Seeders/MenuSeederTest.php
Normal file
202
tests/Feature/Seeders/MenuSeederTest.php
Normal file
@@ -0,0 +1,202 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\Seeders;
|
||||||
|
|
||||||
|
use App\Domains\Attachable\Enums\AttachmentType;
|
||||||
|
use App\Domains\Attachable\Models\Attachment;
|
||||||
|
use App\Domains\Menu\Models\Menu;
|
||||||
|
use App\Domains\Tenant\Models\Tenant;
|
||||||
|
use Database\Seeders\MenuSeeder;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class MenuSeederTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase;
|
||||||
|
|
||||||
|
public function test_it_seeds_the_account_menu_hierarchy(): void
|
||||||
|
{
|
||||||
|
$tenant = $this->createTenant('account_tenant');
|
||||||
|
|
||||||
|
$this->seed(MenuSeeder::class);
|
||||||
|
|
||||||
|
$account = Menu::query()
|
||||||
|
->with('children')
|
||||||
|
->where('code', 'account')
|
||||||
|
->firstOrFail();
|
||||||
|
|
||||||
|
$this->assertSame(Menu::CONTENT_TYPE_DYNAMIC, $account->content_type);
|
||||||
|
$this->assertSame('Mi cuenta', $account->label);
|
||||||
|
$this->assertSame('/mi-cuenta', $account->route);
|
||||||
|
$this->assertSame([
|
||||||
|
'account.profile',
|
||||||
|
'account.purchases',
|
||||||
|
'account.tickets',
|
||||||
|
], $account->children->pluck('code')->sort()->values()->all());
|
||||||
|
$this->assertSame([
|
||||||
|
'account.profile' => '/mi-cuenta/datos-personales',
|
||||||
|
'account.purchases' => '/mi-cuenta/compras',
|
||||||
|
'account.tickets' => '/mi-cuenta/tickets',
|
||||||
|
], $account->children->pluck('route', 'code')->sortKeys()->all());
|
||||||
|
|
||||||
|
$this->assertTrue(
|
||||||
|
$tenant->menues()->where('menues.code', 'account')->exists()
|
||||||
|
);
|
||||||
|
$this->assertFalse(
|
||||||
|
Menu::query()->whereIn('code', ['profile', 'purchases', 'tickets'])->exists()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_it_seeds_the_help_menu_hierarchy_and_content_schemas(): void
|
||||||
|
{
|
||||||
|
$this->seed(MenuSeeder::class);
|
||||||
|
|
||||||
|
$help = Menu::query()
|
||||||
|
->with('children')
|
||||||
|
->where('code', 'help')
|
||||||
|
->firstOrFail();
|
||||||
|
|
||||||
|
$this->assertSame(Menu::CONTENT_TYPE_DYNAMIC, $help->content_type);
|
||||||
|
$this->assertSame('Ayuda', $help->label);
|
||||||
|
$this->assertSame([
|
||||||
|
'help.contact',
|
||||||
|
'help.faq',
|
||||||
|
'help.payment-methods',
|
||||||
|
'help.shipping',
|
||||||
|
'help.terms-and-conditions',
|
||||||
|
], $help->children->pluck('code')->sort()->values()->all());
|
||||||
|
|
||||||
|
$faq = Menu::query()->where('code', 'help.faq')->firstOrFail();
|
||||||
|
$this->assertSame(Menu::CONTENT_TYPE_STATIC, $faq->content_type);
|
||||||
|
$this->assertEquals([
|
||||||
|
'*.pregunta' => 'required|string',
|
||||||
|
'*.respuesta' => 'required|string',
|
||||||
|
'*.is_active' => 'sometimes|boolean',
|
||||||
|
], $faq->static_content_schema);
|
||||||
|
|
||||||
|
$contact = Menu::query()->where('code', 'help.contact')->firstOrFail();
|
||||||
|
$this->assertSame(Menu::CONTENT_TYPE_STATIC, $contact->content_type);
|
||||||
|
$this->assertSame('required|url', $contact->static_content_schema['whatsapp.whatsapp_url']);
|
||||||
|
$this->assertSame('required|string', $contact->static_content_schema['phone']);
|
||||||
|
$this->assertSame(
|
||||||
|
'required|array|min:1',
|
||||||
|
$contact->static_content_schema['locations.*.addresses']
|
||||||
|
);
|
||||||
|
$this->assertSame(
|
||||||
|
'required|array|size:2',
|
||||||
|
$contact->static_content_schema['locations.*.addresses.*.coordinates']
|
||||||
|
);
|
||||||
|
$this->assertSame(
|
||||||
|
'required|string',
|
||||||
|
$contact->static_content_schema['locations.*.addresses.*.address']
|
||||||
|
);
|
||||||
|
$this->assertSame(
|
||||||
|
'required|numeric|between:-90,90',
|
||||||
|
$contact->static_content_schema['locations.*.addresses.*.coordinates.0']
|
||||||
|
);
|
||||||
|
$this->assertSame('prohibited', $contact->static_content_schema['map_locations']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_it_assigns_help_to_the_supported_tenants_with_faq_content(): void
|
||||||
|
{
|
||||||
|
$sonder = $this->createTenant('sonder');
|
||||||
|
$fiesta = $this->createTenant('fiesta_futbol_infantil');
|
||||||
|
$otherTenant = $this->createTenant('other');
|
||||||
|
|
||||||
|
$this->seed(MenuSeeder::class);
|
||||||
|
|
||||||
|
$expectedQuestions = [
|
||||||
|
[
|
||||||
|
'pregunta' => '¿Hay algún límite de compra?',
|
||||||
|
'respuesta' => 'No hay un límite general de compra. La cantidad disponible depende del stock de cada producto.',
|
||||||
|
'is_active' => true,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'pregunta' => '¿Cuáles son los medios de pago disponibles?',
|
||||||
|
'respuesta' => 'Podés consultar y seleccionar los medios de pago habilitados al momento de finalizar tu compra.',
|
||||||
|
'is_active' => false,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'pregunta' => 'Necesito asesoramiento antes de comprar el producto, ¿cómo puedo hacer?',
|
||||||
|
'respuesta' => 'Nuestro equipo comercial está preparado para asesorarte, no dudes en escribirnos por WhatsApp al (0341) 6658247 de lunes a viernes de 8.30 a 20 horas. Los sábados, domingos y feriados te contestaremos lo más rápido posible.',
|
||||||
|
'is_active' => false,
|
||||||
|
],
|
||||||
|
];
|
||||||
|
$expectedContact = [
|
||||||
|
'whatsapp' => [
|
||||||
|
'whatsapp_url' => 'https://wa.me/543412602222',
|
||||||
|
'whatsapp_label' => 'Chatea con nosotros',
|
||||||
|
],
|
||||||
|
'phone' => '+54 9 (0341) 6658247',
|
||||||
|
'locations' => [
|
||||||
|
'rosario' => [
|
||||||
|
'label' => 'Rosario',
|
||||||
|
'addresses' => [
|
||||||
|
[
|
||||||
|
'label' => 'Gigante de Arroyito',
|
||||||
|
'address' => 'Av. Génova 640, Rosario',
|
||||||
|
'coordinates' => [-32.913997, -60.674567],
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'label' => 'Telepagos',
|
||||||
|
'address' => 'Rioja 1150, piso 12, dpto. 3, Rosario',
|
||||||
|
'coordinates' => [-32.946820, -60.639320],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ([$sonder, $fiesta] as $tenant) {
|
||||||
|
$helpMenus = $tenant->menues()
|
||||||
|
->where(fn ($query) => $query
|
||||||
|
->where('menues.code', 'help')
|
||||||
|
->orWhere('menues.parent_menu_code', 'help'))
|
||||||
|
->get();
|
||||||
|
|
||||||
|
$this->assertCount(6, $helpMenus);
|
||||||
|
$this->assertEquals(
|
||||||
|
$expectedQuestions,
|
||||||
|
$helpMenus->firstWhere('code', 'help.faq')->pivot->static_content
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
$expectedContact,
|
||||||
|
$helpMenus->firstWhere('code', 'help.contact')->pivot->static_content
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->assertFalse(
|
||||||
|
$otherTenant->menues()->where('menues.code', 'help')->exists()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createTenant(string $code): Tenant
|
||||||
|
{
|
||||||
|
$headerLogo = $this->createAttachment("{$code}-header.png");
|
||||||
|
$footerLogo = $this->createAttachment("{$code}-footer.png");
|
||||||
|
|
||||||
|
return Tenant::query()->create([
|
||||||
|
'codigo' => $code,
|
||||||
|
'nombre' => $code,
|
||||||
|
'dominio' => "{$code}.example.com",
|
||||||
|
'primary_color' => '#111111',
|
||||||
|
'secondary_color' => '#222222',
|
||||||
|
'danger_color' => '#333333',
|
||||||
|
'success_color' => '#444444',
|
||||||
|
'header_bg_color' => '#ffffff',
|
||||||
|
'footer_bg_color' => '#ffffff',
|
||||||
|
'header_logo_id' => $headerLogo->id,
|
||||||
|
'footer_logo_id' => $footerLogo->id,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createAttachment(string $filename): Attachment
|
||||||
|
{
|
||||||
|
return Attachment::query()->create([
|
||||||
|
'path' => "test/{$filename}",
|
||||||
|
'filename' => $filename,
|
||||||
|
'type' => AttachmentType::Image,
|
||||||
|
'mime_type' => 'image/png',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@ namespace Tests\Feature\Seeders;
|
|||||||
|
|
||||||
use App\Domains\Attachable\Enums\AttachmentType;
|
use App\Domains\Attachable\Enums\AttachmentType;
|
||||||
use App\Domains\Attachable\Models\Attachment;
|
use App\Domains\Attachable\Models\Attachment;
|
||||||
|
use App\Domains\Catalog\Enums\GroupLayout;
|
||||||
use App\Domains\Catalog\Enums\ProductLayout;
|
use App\Domains\Catalog\Enums\ProductLayout;
|
||||||
use App\Domains\Catalog\Models\CatalogItem;
|
use App\Domains\Catalog\Models\CatalogItem;
|
||||||
use App\Domains\Catalog\Models\FeaturedGroup;
|
use App\Domains\Catalog\Models\FeaturedGroup;
|
||||||
@@ -20,7 +21,7 @@ class ProductCatalogFromImagesSeederTest extends TestCase
|
|||||||
{
|
{
|
||||||
use RefreshDatabase;
|
use RefreshDatabase;
|
||||||
|
|
||||||
public function test_it_features_every_sonder_product_in_a_single_image_column(): void
|
public function test_it_creates_paginated_and_random_carousel_groups_for_sonder(): void
|
||||||
{
|
{
|
||||||
Storage::fake('s3');
|
Storage::fake('s3');
|
||||||
|
|
||||||
@@ -51,18 +52,44 @@ class ProductCatalogFromImagesSeederTest extends TestCase
|
|||||||
ProductCatalogFromImagesSeeder::class,
|
ProductCatalogFromImagesSeeder::class,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$group = FeaturedGroup::query()
|
$groups = FeaturedGroup::query()
|
||||||
->where('tenant_code', $tenant->codigo)
|
->where('tenant_code', $tenant->codigo)
|
||||||
->with('featuredItems.catalogItem')
|
->with('featuredItems.catalogItem')
|
||||||
->sole();
|
->orderBy('group_order')
|
||||||
|
->get()
|
||||||
|
->keyBy('group_name');
|
||||||
|
|
||||||
$this->assertSame('Productos', $group->group_name);
|
$paginatedGroup = $groups->get('Productos');
|
||||||
$this->assertSame(ProductLayout::ColumnWithImage, $group->product_layout);
|
$carouselGroup = $groups->get('Productos destacados');
|
||||||
$this->assertSame(0, $group->group_order);
|
$catalogItemIds = CatalogItem::query()
|
||||||
|
->where('tenant_code', $tenant->codigo)
|
||||||
|
->orderBy('id')
|
||||||
|
->pluck('id');
|
||||||
|
|
||||||
|
$this->assertNotNull($paginatedGroup);
|
||||||
|
$this->assertSame(ProductLayout::ColumnWithImage, $paginatedGroup->product_layout);
|
||||||
|
$this->assertSame(GroupLayout::Paginated, $paginatedGroup->group_layout);
|
||||||
|
$this->assertSame(0, $paginatedGroup->group_order);
|
||||||
$this->assertSame(
|
$this->assertSame(
|
||||||
CatalogItem::query()->where('tenant_code', $tenant->codigo)->orderBy('id')->pluck('slug')->all(),
|
CatalogItem::query()->where('tenant_code', $tenant->codigo)->orderBy('id')->pluck('slug')->all(),
|
||||||
$group->featuredItems->pluck('catalogItem.slug')->all(),
|
$paginatedGroup->featuredItems->pluck('catalogItem.slug')->all(),
|
||||||
|
);
|
||||||
|
$this->assertCount(10, $paginatedGroup->featuredItems);
|
||||||
|
|
||||||
|
$this->assertNotNull($carouselGroup);
|
||||||
|
$this->assertSame(ProductLayout::ColumnWithImage, $carouselGroup->product_layout);
|
||||||
|
$this->assertSame(GroupLayout::Carousel, $carouselGroup->group_layout);
|
||||||
|
$this->assertSame(1, $carouselGroup->group_order);
|
||||||
|
$this->assertCount(5, $carouselGroup->featuredItems);
|
||||||
|
$this->assertCount(
|
||||||
|
5,
|
||||||
|
$carouselGroup->featuredItems->pluck('catalog_item_id')->unique(),
|
||||||
|
);
|
||||||
|
$this->assertCount(
|
||||||
|
0,
|
||||||
|
$carouselGroup->featuredItems
|
||||||
|
->pluck('catalog_item_id')
|
||||||
|
->diff($catalogItemIds),
|
||||||
);
|
);
|
||||||
$this->assertCount(10, $group->featuredItems);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
52
tests/Feature/Seeders/SocialMediaSeederTest.php
Normal file
52
tests/Feature/Seeders/SocialMediaSeederTest.php
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\Seeders;
|
||||||
|
|
||||||
|
use App\Domains\Tenant\Models\SocialMedia;
|
||||||
|
use Database\Seeders\SocialMediaSeeder;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class SocialMediaSeederTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase;
|
||||||
|
|
||||||
|
public function test_it_seeds_the_supported_social_media_with_font_awesome_icons(): void
|
||||||
|
{
|
||||||
|
$this->seed(SocialMediaSeeder::class);
|
||||||
|
|
||||||
|
$this->assertSame([
|
||||||
|
[
|
||||||
|
'code' => 'facebook',
|
||||||
|
'icon' => 'fa-brands fa-facebook',
|
||||||
|
'name' => 'Facebook',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'code' => 'instagram',
|
||||||
|
'icon' => 'fa-brands fa-instagram',
|
||||||
|
'name' => 'Instagram',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'code' => 'linkedin',
|
||||||
|
'icon' => 'fa-brands fa-linkedin-in',
|
||||||
|
'name' => 'LinkedIn',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'code' => 'whatsapp',
|
||||||
|
'icon' => 'fa-brands fa-whatsapp',
|
||||||
|
'name' => 'WhatsApp',
|
||||||
|
],
|
||||||
|
], SocialMedia::query()
|
||||||
|
->orderBy('code')
|
||||||
|
->get(['code', 'icon', 'name'])
|
||||||
|
->toArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_it_can_run_more_than_once_without_creating_duplicates(): void
|
||||||
|
{
|
||||||
|
$this->seed(SocialMediaSeeder::class);
|
||||||
|
$this->seed(SocialMediaSeeder::class);
|
||||||
|
|
||||||
|
$this->assertSame(4, SocialMedia::query()->count());
|
||||||
|
}
|
||||||
|
}
|
||||||
72
tests/Feature/Seeders/TenantSeederTest.php
Normal file
72
tests/Feature/Seeders/TenantSeederTest.php
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\Seeders;
|
||||||
|
|
||||||
|
use App\Domains\Tenant\Models\Tenant;
|
||||||
|
use Database\Seeders\SocialMediaSeeder;
|
||||||
|
use Database\Seeders\TenantSeeder;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class TenantSeederTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase;
|
||||||
|
|
||||||
|
public function test_it_loads_the_sonder_main_carousel_images_in_order(): void
|
||||||
|
{
|
||||||
|
Storage::fake('s3');
|
||||||
|
|
||||||
|
$this->seed([
|
||||||
|
SocialMediaSeeder::class,
|
||||||
|
TenantSeeder::class,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$tenant = Tenant::query()->where('codigo', 'sonder')->firstOrFail();
|
||||||
|
$images = $tenant->mainCarouselImages()->get();
|
||||||
|
|
||||||
|
$this->assertSame([
|
||||||
|
'01-urban-team.png',
|
||||||
|
'02-running-shoes.png',
|
||||||
|
'03-streetwear.png',
|
||||||
|
'04-football-training.png',
|
||||||
|
'05-activewear-essentials.png',
|
||||||
|
'06-city-runners.png',
|
||||||
|
], $images->pluck('filename')->all());
|
||||||
|
$this->assertSame([0, 1, 2, 3, 4, 5], $images->pluck('pivot.orden')->all());
|
||||||
|
|
||||||
|
foreach ($images as $image) {
|
||||||
|
Storage::disk('s3')->assertExists($image->path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_it_assigns_social_media_to_both_tenants_in_order(): void
|
||||||
|
{
|
||||||
|
Storage::fake('s3');
|
||||||
|
|
||||||
|
$this->seed([
|
||||||
|
SocialMediaSeeder::class,
|
||||||
|
TenantSeeder::class,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$expectedCodes = ['instagram', 'facebook', 'linkedin', 'whatsapp'];
|
||||||
|
$expectedUrls = [
|
||||||
|
'https://www.instagram.com/sonderargentina/',
|
||||||
|
'https://www.facebook.com/SonderArgentina/',
|
||||||
|
'https://www.linkedin.com/company/35664983/',
|
||||||
|
'https://wa.me/5493412602222',
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach (['sonder', 'fiesta_futbol_infantil'] as $tenantCode) {
|
||||||
|
$socialMedia = Tenant::query()
|
||||||
|
->where('codigo', $tenantCode)
|
||||||
|
->firstOrFail()
|
||||||
|
->socialMedia()
|
||||||
|
->get();
|
||||||
|
|
||||||
|
$this->assertSame($expectedCodes, $socialMedia->pluck('code')->all());
|
||||||
|
$this->assertSame($expectedUrls, $socialMedia->pluck('pivot.url')->all());
|
||||||
|
$this->assertSame([0, 1, 2, 3], $socialMedia->pluck('pivot.orden')->all());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
namespace Tests\Feature\Tenant;
|
namespace Tests\Feature\Tenant;
|
||||||
|
|
||||||
|
use App\Domains\Attachable\Enums\AttachmentType;
|
||||||
|
use App\Domains\Attachable\Models\Attachment;
|
||||||
|
use App\Domains\Menu\Models\Menu;
|
||||||
use App\Domains\Tenant\Models\Tenant;
|
use App\Domains\Tenant\Models\Tenant;
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
use Illuminate\Http\UploadedFile;
|
use Illuminate\Http\UploadedFile;
|
||||||
@@ -18,18 +21,18 @@ class BootstrapTenantControllerTest extends TestCase
|
|||||||
$hdrKey = (string) Str::uuid();
|
$hdrKey = (string) Str::uuid();
|
||||||
$ftrKey = (string) Str::uuid();
|
$ftrKey = (string) Str::uuid();
|
||||||
|
|
||||||
$headerAttachment = \App\Domains\Attachable\Models\Attachment::create([
|
$headerAttachment = Attachment::create([
|
||||||
'key' => $hdrKey,
|
'key' => $hdrKey,
|
||||||
'path' => 'tenants/' . $hdrKey . '.png',
|
'path' => 'tenants/'.$hdrKey.'.png',
|
||||||
'filename' => 'logo_header.png',
|
'filename' => 'logo_header.png',
|
||||||
'type' => \App\Domains\Attachable\Enums\AttachmentType::Image,
|
'type' => AttachmentType::Image,
|
||||||
'mime_type' => 'image/png',
|
'mime_type' => 'image/png',
|
||||||
]);
|
]);
|
||||||
$footerAttachment = \App\Domains\Attachable\Models\Attachment::create([
|
$footerAttachment = Attachment::create([
|
||||||
'key' => $ftrKey,
|
'key' => $ftrKey,
|
||||||
'path' => 'tenants/' . $ftrKey . '.png',
|
'path' => 'tenants/'.$ftrKey.'.png',
|
||||||
'filename' => 'logo_footer.png',
|
'filename' => 'logo_footer.png',
|
||||||
'type' => \App\Domains\Attachable\Enums\AttachmentType::Image,
|
'type' => AttachmentType::Image,
|
||||||
'mime_type' => 'image/png',
|
'mime_type' => 'image/png',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@@ -99,6 +102,78 @@ class BootstrapTenantControllerTest extends TestCase
|
|||||||
$response->assertNotFound();
|
$response->assertNotFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_it_returns_tenant_menus_as_a_clean_hierarchy(): void
|
||||||
|
{
|
||||||
|
$tenant = $this->createTenant();
|
||||||
|
$parent = Menu::query()->create([
|
||||||
|
'code' => 'help',
|
||||||
|
'label' => 'Ayuda',
|
||||||
|
'content_type' => Menu::CONTENT_TYPE_DYNAMIC,
|
||||||
|
'route' => '/ayuda',
|
||||||
|
]);
|
||||||
|
$staticChild = Menu::query()->create([
|
||||||
|
'code' => 'help.faq',
|
||||||
|
'label' => 'Preguntas frecuentes',
|
||||||
|
'parent_menu_code' => $parent->code,
|
||||||
|
'content_type' => Menu::CONTENT_TYPE_STATIC,
|
||||||
|
'static_content_schema' => [
|
||||||
|
'*.question' => 'required|string',
|
||||||
|
'*.answer' => 'required|string',
|
||||||
|
],
|
||||||
|
'route' => '/ayuda/preguntas-frecuentes',
|
||||||
|
]);
|
||||||
|
$dynamicChild = Menu::query()->create([
|
||||||
|
'code' => 'help.shipping',
|
||||||
|
'label' => 'Envíos',
|
||||||
|
'parent_menu_code' => $parent->code,
|
||||||
|
'content_type' => Menu::CONTENT_TYPE_DYNAMIC,
|
||||||
|
'route' => '/ayuda/envios',
|
||||||
|
]);
|
||||||
|
$staticContent = [
|
||||||
|
[
|
||||||
|
'question' => '¿Cómo compro?',
|
||||||
|
'answer' => 'Desde el catálogo.',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
$tenant->menues()->sync([
|
||||||
|
$parent->code,
|
||||||
|
$staticChild->code => ['static_content' => $staticContent],
|
||||||
|
$dynamicChild->code,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response = $this->getJson('/api/tenants/bootstrap/acme.com');
|
||||||
|
|
||||||
|
$response
|
||||||
|
->assertOk()
|
||||||
|
->assertJsonCount(1, 'data.menues')
|
||||||
|
->assertJsonCount(2, 'data.menues.0.submenues')
|
||||||
|
->assertJsonPath('data.menues.0.code', 'help')
|
||||||
|
->assertJsonPath('data.menues.0.label', 'Ayuda')
|
||||||
|
->assertJsonPath('data.menues.0.parent_menu_code', null)
|
||||||
|
->assertJsonPath('data.menues.0.submenues.0.code', 'help.faq')
|
||||||
|
->assertJsonPath('data.menues.0.submenues.0.label', 'Preguntas frecuentes')
|
||||||
|
->assertJsonPath('data.menues.0.submenues.0.parent_menu_code', 'help')
|
||||||
|
->assertJsonPath('data.menues.0.submenues.1.code', 'help.shipping');
|
||||||
|
|
||||||
|
$assertCleanMenu = function (array $menu) use (&$assertCleanMenu): void {
|
||||||
|
$this->assertArrayNotHasKey('created_at', $menu);
|
||||||
|
$this->assertArrayNotHasKey('updated_at', $menu);
|
||||||
|
$this->assertArrayNotHasKey('pivot', $menu);
|
||||||
|
$this->assertArrayNotHasKey('static_content_schema', $menu);
|
||||||
|
|
||||||
|
foreach ($menu['submenues'] as $submenu) {
|
||||||
|
$assertCleanMenu($submenu);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
$menus = $response->json('data.menues');
|
||||||
|
$this->assertEquals($staticContent, $menus[0]['submenues'][0]['static_content']);
|
||||||
|
$assertCleanMenu($menus[0]);
|
||||||
|
$this->assertArrayNotHasKey('static_content', $menus[0]);
|
||||||
|
$this->assertArrayNotHasKey('static_content', $menus[0]['submenues'][1]);
|
||||||
|
}
|
||||||
|
|
||||||
public function test_it_rejects_duplicate_domains_after_normalization_when_storing(): void
|
public function test_it_rejects_duplicate_domains_after_normalization_when_storing(): void
|
||||||
{
|
{
|
||||||
$base64Image = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==';
|
$base64Image = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==';
|
||||||
@@ -191,18 +266,18 @@ class BootstrapTenantControllerTest extends TestCase
|
|||||||
$hdrUuid = (string) Str::uuid();
|
$hdrUuid = (string) Str::uuid();
|
||||||
$ftrUuid = (string) Str::uuid();
|
$ftrUuid = (string) Str::uuid();
|
||||||
|
|
||||||
$hdrAttachment = \App\Domains\Attachable\Models\Attachment::create([
|
$hdrAttachment = Attachment::create([
|
||||||
'key' => $hdrUuid,
|
'key' => $hdrUuid,
|
||||||
'path' => 'tenants/' . $hdrUuid . '.png',
|
'path' => 'tenants/'.$hdrUuid.'.png',
|
||||||
'filename' => 'hdr.png',
|
'filename' => 'hdr.png',
|
||||||
'type' => \App\Domains\Attachable\Enums\AttachmentType::Image,
|
'type' => AttachmentType::Image,
|
||||||
'mime_type' => 'image/png',
|
'mime_type' => 'image/png',
|
||||||
]);
|
]);
|
||||||
$ftrAttachment = \App\Domains\Attachable\Models\Attachment::create([
|
$ftrAttachment = Attachment::create([
|
||||||
'key' => $ftrUuid,
|
'key' => $ftrUuid,
|
||||||
'path' => 'tenants/' . $ftrUuid . '.png',
|
'path' => 'tenants/'.$ftrUuid.'.png',
|
||||||
'filename' => 'ftr.png',
|
'filename' => 'ftr.png',
|
||||||
'type' => \App\Domains\Attachable\Enums\AttachmentType::Image,
|
'type' => AttachmentType::Image,
|
||||||
'mime_type' => 'image/png',
|
'mime_type' => 'image/png',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@@ -429,18 +504,18 @@ class BootstrapTenantControllerTest extends TestCase
|
|||||||
$hdrKey = (string) Str::uuid();
|
$hdrKey = (string) Str::uuid();
|
||||||
$ftrKey = (string) Str::uuid();
|
$ftrKey = (string) Str::uuid();
|
||||||
|
|
||||||
$headerAttachment = \App\Domains\Attachable\Models\Attachment::create([
|
$headerAttachment = Attachment::create([
|
||||||
'key' => $hdrKey,
|
'key' => $hdrKey,
|
||||||
'path' => 'tenants/' . $hdrKey . '.png',
|
'path' => 'tenants/'.$hdrKey.'.png',
|
||||||
'filename' => 'logo_header.png',
|
'filename' => 'logo_header.png',
|
||||||
'type' => \App\Domains\Attachable\Enums\AttachmentType::Image,
|
'type' => AttachmentType::Image,
|
||||||
'mime_type' => 'image/png',
|
'mime_type' => 'image/png',
|
||||||
]);
|
]);
|
||||||
$footerAttachment = \App\Domains\Attachable\Models\Attachment::create([
|
$footerAttachment = Attachment::create([
|
||||||
'key' => $ftrKey,
|
'key' => $ftrKey,
|
||||||
'path' => 'tenants/' . $ftrKey . '.png',
|
'path' => 'tenants/'.$ftrKey.'.png',
|
||||||
'filename' => 'logo_footer.png',
|
'filename' => 'logo_footer.png',
|
||||||
'type' => \App\Domains\Attachable\Enums\AttachmentType::Image,
|
'type' => AttachmentType::Image,
|
||||||
'mime_type' => 'image/png',
|
'mime_type' => 'image/png',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@@ -466,11 +541,11 @@ class BootstrapTenantControllerTest extends TestCase
|
|||||||
$base64Image = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==';
|
$base64Image = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==';
|
||||||
|
|
||||||
$ftrUuid = (string) Str::uuid();
|
$ftrUuid = (string) Str::uuid();
|
||||||
$footerAttachment = \App\Domains\Attachable\Models\Attachment::create([
|
$footerAttachment = Attachment::create([
|
||||||
'key' => $ftrUuid,
|
'key' => $ftrUuid,
|
||||||
'path' => 'tenants/' . $ftrUuid . '.png',
|
'path' => 'tenants/'.$ftrUuid.'.png',
|
||||||
'filename' => 'logo_footer.png',
|
'filename' => 'logo_footer.png',
|
||||||
'type' => \App\Domains\Attachable\Enums\AttachmentType::Image,
|
'type' => AttachmentType::Image,
|
||||||
'mime_type' => 'image/png',
|
'mime_type' => 'image/png',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|||||||
191
tests/Feature/Tenant/TenantMainCarouselImagesTest.php
Normal file
191
tests/Feature/Tenant/TenantMainCarouselImagesTest.php
Normal file
@@ -0,0 +1,191 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\Tenant;
|
||||||
|
|
||||||
|
use App\Domains\Attachable\Enums\AttachmentType;
|
||||||
|
use App\Domains\Attachable\Models\Attachment;
|
||||||
|
use App\Domains\Tenant\Models\Tenant;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Illuminate\Http\UploadedFile;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class TenantMainCarouselImagesTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase;
|
||||||
|
|
||||||
|
public function test_a_tenant_has_ordered_main_carousel_images(): void
|
||||||
|
{
|
||||||
|
$tenant = $this->createTenant();
|
||||||
|
$firstAttachment = $this->createAttachment('first.png');
|
||||||
|
$secondAttachment = $this->createAttachment('second.png');
|
||||||
|
|
||||||
|
$tenant->mainCarouselImages()->attach([
|
||||||
|
$secondAttachment->id => ['orden' => 2],
|
||||||
|
$firstAttachment->id => ['orden' => 1],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$attachments = $tenant->mainCarouselImages()->get();
|
||||||
|
|
||||||
|
$this->assertCount(2, $attachments);
|
||||||
|
$this->assertTrue($attachments[0]->is($firstAttachment));
|
||||||
|
$this->assertTrue($attachments[1]->is($secondAttachment));
|
||||||
|
$this->assertSame([1, 2], $attachments->pluck('pivot.orden')->all());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_bootstrap_returns_all_main_carousel_image_urls_in_order(): void
|
||||||
|
{
|
||||||
|
$tenant = $this->createTenant();
|
||||||
|
$firstAttachment = $this->createAttachment('first.png');
|
||||||
|
$secondAttachment = $this->createAttachment('second.png');
|
||||||
|
|
||||||
|
$tenant->mainCarouselImages()->attach([
|
||||||
|
$secondAttachment->id => ['orden' => 20],
|
||||||
|
$firstAttachment->id => ['orden' => 10],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response = $this->getJson('/api/tenants/bootstrap/acme.com');
|
||||||
|
|
||||||
|
$response
|
||||||
|
->assertOk()
|
||||||
|
->assertJsonCount(2, 'data.main_carousel_images');
|
||||||
|
|
||||||
|
$urls = $response->json('data.main_carousel_images');
|
||||||
|
|
||||||
|
$this->assertStringContainsString($firstAttachment->key, $urls[0]);
|
||||||
|
$this->assertStringContainsString($secondAttachment->key, $urls[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_show_returns_an_empty_main_carousel_images_array_when_the_tenant_has_no_images(): void
|
||||||
|
{
|
||||||
|
$tenant = $this->createTenant();
|
||||||
|
|
||||||
|
$this->getJson("/api/tenants/{$tenant->codigo}")
|
||||||
|
->assertOk()
|
||||||
|
->assertJsonPath('data.main_carousel_images', []);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_store_uploads_and_attaches_main_carousel_images_in_request_order(): void
|
||||||
|
{
|
||||||
|
Storage::fake('s3');
|
||||||
|
|
||||||
|
$headerLogo = $this->createAttachment('header.png');
|
||||||
|
$footerLogo = $this->createAttachment('footer.png');
|
||||||
|
|
||||||
|
$response = $this
|
||||||
|
->withHeader('Accept', 'application/json')
|
||||||
|
->post('/api/tenants', [
|
||||||
|
...$this->tenantPayload(),
|
||||||
|
'header_logo' => $headerLogo->key,
|
||||||
|
'footer_logo' => $footerLogo->key,
|
||||||
|
'main_carousel_images' => [
|
||||||
|
UploadedFile::fake()->image('first-carousel.png', 1200, 300),
|
||||||
|
UploadedFile::fake()->image('second-carousel.png', 1200, 300),
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response
|
||||||
|
->assertCreated()
|
||||||
|
->assertJsonCount(2, 'data.main_carousel_images');
|
||||||
|
|
||||||
|
$tenant = Tenant::query()->where('codigo', 'new-acme')->firstOrFail();
|
||||||
|
$images = $tenant->mainCarouselImages()->get();
|
||||||
|
|
||||||
|
$this->assertSame(
|
||||||
|
['first-carousel.png', 'second-carousel.png'],
|
||||||
|
$images->pluck('filename')->all()
|
||||||
|
);
|
||||||
|
$this->assertSame([0, 1], $images->pluck('pivot.orden')->all());
|
||||||
|
Storage::disk('s3')->assertExists($images[0]->path);
|
||||||
|
Storage::disk('s3')->assertExists($images[1]->path);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_update_replaces_and_can_clear_main_carousel_images(): void
|
||||||
|
{
|
||||||
|
$tenant = $this->createTenant();
|
||||||
|
$oldImage = $this->createAttachment('old.png');
|
||||||
|
$firstImage = $this->createAttachment('first.png');
|
||||||
|
$secondImage = $this->createAttachment('second.png');
|
||||||
|
|
||||||
|
$tenant->mainCarouselImages()->attach($oldImage->id, ['orden' => 0]);
|
||||||
|
|
||||||
|
$this->putJson("/api/tenants/{$tenant->codigo}", [
|
||||||
|
'main_carousel_images' => [$secondImage->key, $firstImage->key],
|
||||||
|
])
|
||||||
|
->assertOk()
|
||||||
|
->assertJsonCount(2, 'data.main_carousel_images');
|
||||||
|
|
||||||
|
$this->assertSame(
|
||||||
|
[$secondImage->id, $firstImage->id],
|
||||||
|
$tenant->mainCarouselImages()->pluck('attachments.id')->all()
|
||||||
|
);
|
||||||
|
$this->assertDatabaseMissing('tenant_main_carousel_images', [
|
||||||
|
'tenant_id' => $tenant->id,
|
||||||
|
'attachment_id' => $oldImage->id,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->putJson("/api/tenants/{$tenant->codigo}", [
|
||||||
|
'main_carousel_images' => [],
|
||||||
|
])
|
||||||
|
->assertOk()
|
||||||
|
->assertJsonPath('data.main_carousel_images', []);
|
||||||
|
|
||||||
|
$this->assertDatabaseMissing('tenant_main_carousel_images', [
|
||||||
|
'tenant_id' => $tenant->id,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<string, string>
|
||||||
|
*/
|
||||||
|
private function tenantPayload(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'codigo' => 'new-acme',
|
||||||
|
'nombre' => 'New Acme',
|
||||||
|
'dominio' => 'new-acme.com',
|
||||||
|
'primary_color' => '#111111',
|
||||||
|
'secondary_color' => '#222222',
|
||||||
|
'danger_color' => '#333333',
|
||||||
|
'success_color' => '#444444',
|
||||||
|
'header_bg_color' => '#ffffff',
|
||||||
|
'footer_bg_color' => '#ffffff',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createTenant(): Tenant
|
||||||
|
{
|
||||||
|
$headerLogo = $this->createAttachment('header.png');
|
||||||
|
$footerLogo = $this->createAttachment('footer.png');
|
||||||
|
|
||||||
|
return Tenant::query()->create([
|
||||||
|
'codigo' => 'acme',
|
||||||
|
'nombre' => 'Acme',
|
||||||
|
'dominio' => 'acme.com',
|
||||||
|
'primary_color' => '#111111',
|
||||||
|
'secondary_color' => '#222222',
|
||||||
|
'danger_color' => '#333333',
|
||||||
|
'success_color' => '#444444',
|
||||||
|
'header_bg_color' => '#ffffff',
|
||||||
|
'footer_bg_color' => '#ffffff',
|
||||||
|
'header_logo_id' => $headerLogo->id,
|
||||||
|
'footer_logo_id' => $footerLogo->id,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createAttachment(string $filename): Attachment
|
||||||
|
{
|
||||||
|
$key = (string) Str::uuid();
|
||||||
|
|
||||||
|
return Attachment::query()->create([
|
||||||
|
'key' => $key,
|
||||||
|
'path' => "tenants/main-carousel/{$key}.png",
|
||||||
|
'filename' => $filename,
|
||||||
|
'type' => AttachmentType::Image,
|
||||||
|
'mime_type' => 'image/png',
|
||||||
|
'extension' => 'png',
|
||||||
|
'size' => 100,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
259
tests/Feature/Tenant/TenantSocialMediaTest.php
Normal file
259
tests/Feature/Tenant/TenantSocialMediaTest.php
Normal file
@@ -0,0 +1,259 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\Tenant;
|
||||||
|
|
||||||
|
use App\Domains\Attachable\Enums\AttachmentType;
|
||||||
|
use App\Domains\Attachable\Models\Attachment;
|
||||||
|
use App\Domains\Tenant\Models\SocialMedia;
|
||||||
|
use App\Domains\Tenant\Models\Tenant;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class TenantSocialMediaTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase;
|
||||||
|
|
||||||
|
public function test_social_media_tables_have_the_expected_columns(): void
|
||||||
|
{
|
||||||
|
$this->assertEqualsCanonicalizing([
|
||||||
|
'id',
|
||||||
|
'code',
|
||||||
|
'icon',
|
||||||
|
'name',
|
||||||
|
'created_at',
|
||||||
|
'updated_at',
|
||||||
|
], Schema::getColumnListing('social_media'));
|
||||||
|
|
||||||
|
$this->assertEqualsCanonicalizing([
|
||||||
|
'id',
|
||||||
|
'tenant_code',
|
||||||
|
'social_media_code',
|
||||||
|
'url',
|
||||||
|
'orden',
|
||||||
|
'created_at',
|
||||||
|
'updated_at',
|
||||||
|
], Schema::getColumnListing('tenant_social_media'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_a_tenant_can_have_social_media_with_its_own_url(): void
|
||||||
|
{
|
||||||
|
$tenant = $this->createTenant();
|
||||||
|
$instagram = SocialMedia::query()->create([
|
||||||
|
'code' => 'instagram',
|
||||||
|
'icon' => 'instagram',
|
||||||
|
'name' => 'Instagram',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$tenant->socialMedia()->attach($instagram->code, [
|
||||||
|
'url' => 'https://instagram.com/acme',
|
||||||
|
'orden' => 3,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertTrue($tenant->socialMedia()->firstOrFail()->is($instagram));
|
||||||
|
$this->assertSame(
|
||||||
|
'https://instagram.com/acme',
|
||||||
|
$tenant->socialMedia()->firstOrFail()->pivot->url
|
||||||
|
);
|
||||||
|
$this->assertSame(3, $tenant->socialMedia()->firstOrFail()->pivot->orden);
|
||||||
|
$this->assertTrue($instagram->tenants()->firstOrFail()->is($tenant));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_deleting_a_social_media_deletes_its_tenant_associations(): void
|
||||||
|
{
|
||||||
|
$tenant = $this->createTenant();
|
||||||
|
$instagram = SocialMedia::query()->create([
|
||||||
|
'code' => 'instagram',
|
||||||
|
'icon' => 'instagram',
|
||||||
|
'name' => 'Instagram',
|
||||||
|
]);
|
||||||
|
$tenant->socialMedia()->attach($instagram->code, [
|
||||||
|
'url' => 'https://instagram.com/acme',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$instagram->delete();
|
||||||
|
|
||||||
|
$this->assertDatabaseMissing('tenant_social_media', [
|
||||||
|
'tenant_code' => $tenant->codigo,
|
||||||
|
'social_media_code' => $instagram->code,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_tenant_update_synchronizes_social_media_and_returns_pivot_urls(): void
|
||||||
|
{
|
||||||
|
$tenant = $this->createTenant();
|
||||||
|
$instagram = $this->createSocialMedia('instagram', 'Instagram');
|
||||||
|
$facebook = $this->createSocialMedia('facebook', 'Facebook');
|
||||||
|
|
||||||
|
$tenant->socialMedia()->attach($facebook->code, [
|
||||||
|
'url' => 'https://facebook.com/old-acme',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->putJson("/api/tenants/{$tenant->codigo}", [
|
||||||
|
'social_media' => [
|
||||||
|
[
|
||||||
|
'code' => $instagram->code,
|
||||||
|
'url' => 'https://instagram.com/acme',
|
||||||
|
'orden' => 4,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
])
|
||||||
|
->assertOk()
|
||||||
|
->assertJsonPath('data.social_media.0.code', 'instagram')
|
||||||
|
->assertJsonPath('data.social_media.0.icon', 'instagram')
|
||||||
|
->assertJsonPath('data.social_media.0.name', 'Instagram')
|
||||||
|
->assertJsonPath('data.social_media.0.url', 'https://instagram.com/acme')
|
||||||
|
->assertJsonCount(1, 'data.social_media');
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('tenant_social_media', [
|
||||||
|
'tenant_code' => $tenant->codigo,
|
||||||
|
'social_media_code' => $instagram->code,
|
||||||
|
'url' => 'https://instagram.com/acme',
|
||||||
|
'orden' => 4,
|
||||||
|
]);
|
||||||
|
$this->assertDatabaseMissing('tenant_social_media', [
|
||||||
|
'tenant_code' => $tenant->codigo,
|
||||||
|
'social_media_code' => $facebook->code,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_tenant_social_media_are_returned_in_configured_order(): void
|
||||||
|
{
|
||||||
|
$tenant = $this->createTenant();
|
||||||
|
$instagram = $this->createSocialMedia('instagram', 'Instagram');
|
||||||
|
$facebook = $this->createSocialMedia('facebook', 'Facebook');
|
||||||
|
|
||||||
|
$this->putJson("/api/tenants/{$tenant->codigo}", [
|
||||||
|
'social_media' => [
|
||||||
|
[
|
||||||
|
'code' => $instagram->code,
|
||||||
|
'url' => 'https://instagram.com/acme',
|
||||||
|
'orden' => 20,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'code' => $facebook->code,
|
||||||
|
'url' => 'https://facebook.com/acme',
|
||||||
|
'orden' => 10,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
])
|
||||||
|
->assertOk()
|
||||||
|
->assertJsonPath('data.social_media.0.code', 'facebook')
|
||||||
|
->assertJsonPath('data.social_media.1.code', 'instagram')
|
||||||
|
->assertJsonMissingPath('data.social_media.0.orden')
|
||||||
|
->assertJsonMissingPath('data.social_media.1.orden');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_tenant_store_synchronizes_social_media(): void
|
||||||
|
{
|
||||||
|
$instagram = $this->createSocialMedia('instagram', 'Instagram');
|
||||||
|
$headerLogo = $this->createAttachment('new-header.png');
|
||||||
|
$footerLogo = $this->createAttachment('new-footer.png');
|
||||||
|
|
||||||
|
$this->postJson('/api/tenants', [
|
||||||
|
'codigo' => 'new-acme',
|
||||||
|
'nombre' => 'New Acme',
|
||||||
|
'dominio' => 'new-acme.com',
|
||||||
|
'primary_color' => '#111111',
|
||||||
|
'secondary_color' => '#222222',
|
||||||
|
'danger_color' => '#333333',
|
||||||
|
'success_color' => '#444444',
|
||||||
|
'header_bg_color' => '#ffffff',
|
||||||
|
'footer_bg_color' => '#ffffff',
|
||||||
|
'header_logo' => $headerLogo->key,
|
||||||
|
'footer_logo' => $footerLogo->key,
|
||||||
|
'social_media' => [
|
||||||
|
[
|
||||||
|
'code' => $instagram->code,
|
||||||
|
'url' => 'https://instagram.com/new-acme',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
])
|
||||||
|
->assertCreated()
|
||||||
|
->assertJsonPath('data.social_media.0.code', 'instagram')
|
||||||
|
->assertJsonPath('data.social_media.0.url', 'https://instagram.com/new-acme');
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('tenant_social_media', [
|
||||||
|
'tenant_code' => 'new-acme',
|
||||||
|
'social_media_code' => $instagram->code,
|
||||||
|
'url' => 'https://instagram.com/new-acme',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_tenant_update_can_clear_social_media(): void
|
||||||
|
{
|
||||||
|
$tenant = $this->createTenant();
|
||||||
|
$instagram = $this->createSocialMedia('instagram', 'Instagram');
|
||||||
|
$tenant->socialMedia()->attach($instagram->code, [
|
||||||
|
'url' => 'https://instagram.com/acme',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->putJson("/api/tenants/{$tenant->codigo}", [
|
||||||
|
'social_media' => [],
|
||||||
|
])
|
||||||
|
->assertOk()
|
||||||
|
->assertJsonPath('data.social_media', []);
|
||||||
|
|
||||||
|
$this->assertDatabaseMissing('tenant_social_media', [
|
||||||
|
'tenant_code' => $tenant->codigo,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_tenant_update_validates_social_media_codes_and_urls(): void
|
||||||
|
{
|
||||||
|
$tenant = $this->createTenant();
|
||||||
|
|
||||||
|
$this->putJson("/api/tenants/{$tenant->codigo}", [
|
||||||
|
'social_media' => [
|
||||||
|
[
|
||||||
|
'code' => 'unknown',
|
||||||
|
'url' => 'not-a-url',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
])
|
||||||
|
->assertUnprocessable()
|
||||||
|
->assertJsonValidationErrors([
|
||||||
|
'social_media.0.code',
|
||||||
|
'social_media.0.url',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createTenant(): Tenant
|
||||||
|
{
|
||||||
|
$headerLogo = $this->createAttachment('header.png');
|
||||||
|
$footerLogo = $this->createAttachment('footer.png');
|
||||||
|
|
||||||
|
return Tenant::query()->create([
|
||||||
|
'codigo' => 'acme',
|
||||||
|
'nombre' => 'Acme',
|
||||||
|
'dominio' => 'acme.com',
|
||||||
|
'primary_color' => '#111111',
|
||||||
|
'secondary_color' => '#222222',
|
||||||
|
'danger_color' => '#333333',
|
||||||
|
'success_color' => '#444444',
|
||||||
|
'header_bg_color' => '#ffffff',
|
||||||
|
'footer_bg_color' => '#ffffff',
|
||||||
|
'header_logo_id' => $headerLogo->id,
|
||||||
|
'footer_logo_id' => $footerLogo->id,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createAttachment(string $filename): Attachment
|
||||||
|
{
|
||||||
|
return Attachment::query()->create([
|
||||||
|
'path' => "test/{$filename}",
|
||||||
|
'filename' => $filename,
|
||||||
|
'type' => AttachmentType::Image,
|
||||||
|
'mime_type' => 'image/png',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createSocialMedia(string $code, string $name): SocialMedia
|
||||||
|
{
|
||||||
|
return SocialMedia::query()->create([
|
||||||
|
'code' => $code,
|
||||||
|
'icon' => $code,
|
||||||
|
'name' => $name,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,6 +7,7 @@ use App\Domains\Attachable\Models\Attachment;
|
|||||||
use App\Domains\Auth\Models\User;
|
use App\Domains\Auth\Models\User;
|
||||||
use App\Domains\Catalog\Enums\CatalogItemType;
|
use App\Domains\Catalog\Enums\CatalogItemType;
|
||||||
use App\Domains\Catalog\Models\CatalogItem;
|
use App\Domains\Catalog\Models\CatalogItem;
|
||||||
|
use App\Domains\Notification\Events\TicketsAvailable;
|
||||||
use App\Domains\Purchase\Models\Purchase;
|
use App\Domains\Purchase\Models\Purchase;
|
||||||
use App\Domains\Tenant\Models\Tenant;
|
use App\Domains\Tenant\Models\Tenant;
|
||||||
use App\Domains\Ticket\Exceptions\TicketGenerationException;
|
use App\Domains\Ticket\Exceptions\TicketGenerationException;
|
||||||
@@ -14,6 +15,8 @@ use App\Domains\Ticket\Services\TicketGeneratorService;
|
|||||||
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
|
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
use Illuminate\Support\Carbon;
|
use Illuminate\Support\Carbon;
|
||||||
|
use Illuminate\Support\Facades\Event;
|
||||||
|
use Illuminate\Support\Facades\Queue;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
@@ -32,6 +35,7 @@ class TicketGeneratorServiceTest extends TestCase
|
|||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
Carbon::setTestNow('2026-07-21 10:00:00');
|
Carbon::setTestNow('2026-07-21 10:00:00');
|
||||||
|
Queue::fake();
|
||||||
$this->service = app(TicketGeneratorService::class);
|
$this->service = app(TicketGeneratorService::class);
|
||||||
$this->tenant = $this->createTenant();
|
$this->tenant = $this->createTenant();
|
||||||
$this->user = User::factory()->create();
|
$this->user = User::factory()->create();
|
||||||
@@ -128,6 +132,7 @@ class TicketGeneratorServiceTest extends TestCase
|
|||||||
|
|
||||||
public function test_marking_a_purchase_as_paid_generates_its_tickets_once(): void
|
public function test_marking_a_purchase_as_paid_generates_its_tickets_once(): void
|
||||||
{
|
{
|
||||||
|
Event::fake([TicketsAvailable::class]);
|
||||||
$item = $this->createTicketableItem('paid-ticket');
|
$item = $this->createTicketableItem('paid-ticket');
|
||||||
$purchase = $this->createPurchase($item, 2);
|
$purchase = $this->createPurchase($item, 2);
|
||||||
$purchase->setRelation('items', new EloquentCollection);
|
$purchase->setRelation('items', new EloquentCollection);
|
||||||
@@ -136,10 +141,12 @@ class TicketGeneratorServiceTest extends TestCase
|
|||||||
|
|
||||||
$this->assertSame(Purchase::STATUS_PAID, $purchase->status);
|
$this->assertSame(Purchase::STATUS_PAID, $purchase->status);
|
||||||
$this->assertDatabaseCount('tickets', 2);
|
$this->assertDatabaseCount('tickets', 2);
|
||||||
|
Event::assertDispatchedTimes(TicketsAvailable::class, 1);
|
||||||
|
|
||||||
$purchase->markAsPaid();
|
$purchase->markAsPaid();
|
||||||
|
|
||||||
$this->assertDatabaseCount('tickets', 2);
|
$this->assertDatabaseCount('tickets', 2);
|
||||||
|
Event::assertDispatchedTimes(TicketsAvailable::class, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_a_ticket_generated_from_a_purchase_keeps_its_source_ids(): void
|
public function test_a_ticket_generated_from_a_purchase_keeps_its_source_ids(): void
|
||||||
@@ -157,6 +164,7 @@ class TicketGeneratorServiceTest extends TestCase
|
|||||||
|
|
||||||
public function test_marking_a_purchase_as_paid_ignores_items_without_tickets(): void
|
public function test_marking_a_purchase_as_paid_ignores_items_without_tickets(): void
|
||||||
{
|
{
|
||||||
|
Event::fake([TicketsAvailable::class]);
|
||||||
$item = $this->createTicketableItem('regular-product');
|
$item = $this->createTicketableItem('regular-product');
|
||||||
$item->update(['has_tickets' => false]);
|
$item->update(['has_tickets' => false]);
|
||||||
$purchase = $this->createPurchase($item->fresh(), 1);
|
$purchase = $this->createPurchase($item->fresh(), 1);
|
||||||
@@ -165,6 +173,7 @@ class TicketGeneratorServiceTest extends TestCase
|
|||||||
|
|
||||||
$this->assertSame(Purchase::STATUS_PAID, $purchase->status);
|
$this->assertSame(Purchase::STATUS_PAID, $purchase->status);
|
||||||
$this->assertDatabaseCount('tickets', 0);
|
$this->assertDatabaseCount('tickets', 0);
|
||||||
|
Event::assertNotDispatched(TicketsAvailable::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_paid_status_is_rolled_back_when_ticket_generation_fails(): void
|
public function test_paid_status_is_rolled_back_when_ticket_generation_fails(): void
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ namespace Tests\Unit\Catalog;
|
|||||||
|
|
||||||
use App\Domains\Attachable\Models\Attachment;
|
use App\Domains\Attachable\Models\Attachment;
|
||||||
use App\Domains\Catalog\Enums\CatalogItemType;
|
use App\Domains\Catalog\Enums\CatalogItemType;
|
||||||
|
use App\Domains\Catalog\Enums\GroupLayout;
|
||||||
use App\Domains\Catalog\Enums\InventoryPolicy;
|
use App\Domains\Catalog\Enums\InventoryPolicy;
|
||||||
use App\Domains\Catalog\Enums\ProductLayout;
|
use App\Domains\Catalog\Enums\ProductLayout;
|
||||||
use App\Domains\Catalog\Models\Attribute;
|
use App\Domains\Catalog\Models\Attribute;
|
||||||
@@ -25,6 +26,16 @@ use Tests\TestCase;
|
|||||||
|
|
||||||
class CatalogModelsTest extends TestCase
|
class CatalogModelsTest extends TestCase
|
||||||
{
|
{
|
||||||
|
public function test_group_layout_has_all_supported_values(): void
|
||||||
|
{
|
||||||
|
$this->assertSame([
|
||||||
|
'paginated',
|
||||||
|
'simple',
|
||||||
|
'simple_vertical',
|
||||||
|
'carousel',
|
||||||
|
], GroupLayout::values());
|
||||||
|
}
|
||||||
|
|
||||||
public function test_attribute_maps_its_values_and_relations(): void
|
public function test_attribute_maps_its_values_and_relations(): void
|
||||||
{
|
{
|
||||||
$attribute = new Attribute;
|
$attribute = new Attribute;
|
||||||
@@ -83,6 +94,7 @@ class CatalogModelsTest extends TestCase
|
|||||||
$group = new FeaturedGroup;
|
$group = new FeaturedGroup;
|
||||||
$group->setRawAttributes([
|
$group->setRawAttributes([
|
||||||
'product_layout' => ProductLayout::ColumnWithImage->value,
|
'product_layout' => ProductLayout::ColumnWithImage->value,
|
||||||
|
'group_layout' => GroupLayout::SimpleVertical->value,
|
||||||
'group_order' => '2',
|
'group_order' => '2',
|
||||||
]);
|
]);
|
||||||
$featuredItem = new FeaturedItem;
|
$featuredItem = new FeaturedItem;
|
||||||
@@ -95,6 +107,7 @@ class CatalogModelsTest extends TestCase
|
|||||||
$this->assertSame('featured_groups', $group->getTable());
|
$this->assertSame('featured_groups', $group->getTable());
|
||||||
$this->assertFalse($group->usesTimestamps());
|
$this->assertFalse($group->usesTimestamps());
|
||||||
$this->assertSame(ProductLayout::ColumnWithImage, $group->product_layout);
|
$this->assertSame(ProductLayout::ColumnWithImage, $group->product_layout);
|
||||||
|
$this->assertSame(GroupLayout::SimpleVertical, $group->group_layout);
|
||||||
$this->assertSame(2, $group->group_order);
|
$this->assertSame(2, $group->group_order);
|
||||||
$this->assertInstanceOf(Tenant::class, $group->tenant()->getRelated());
|
$this->assertInstanceOf(Tenant::class, $group->tenant()->getRelated());
|
||||||
$this->assertInstanceOf(FeaturedItem::class, $group->featuredItems()->getRelated());
|
$this->assertInstanceOf(FeaturedItem::class, $group->featuredItems()->getRelated());
|
||||||
|
|||||||
Reference in New Issue
Block a user