Compare commits
2 Commits
14c81fec1b
...
v1.0.0
| Author | SHA1 | Date | |
|---|---|---|---|
| fcb8386735 | |||
| 6d077647ba |
@@ -3,6 +3,7 @@
|
||||
namespace App\Domains\Commerce\Purchase\Resources;
|
||||
|
||||
use App\Domains\Commerce\Purchase\Models\PurchaseItem;
|
||||
use App\Domains\Core\Tenant\Models\StorefrontWebsiteType;
|
||||
use App\Domains\Core\Tenant\Models\Tenant;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
@@ -14,7 +15,11 @@ class PurchaseItemResource extends JsonResource
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
$tenant = $request->route('tenant');
|
||||
$displayImage = ! $tenant instanceof Tenant || $tenant->display_cart_item_images;
|
||||
$usesEventSummary = $tenant instanceof Tenant
|
||||
&& $tenant->storefrontWebsiteType?->checkout_summary_type
|
||||
=== StorefrontWebsiteType::CHECKOUT_SUMMARY_EVENT;
|
||||
$displayImage = ! $tenant instanceof Tenant
|
||||
|| (! $usesEventSummary && $tenant->display_cart_item_images);
|
||||
|
||||
$imageUrl = $displayImage
|
||||
? $this->imageAttachment?->getTemporaryUrl(1440)
|
||||
@@ -31,7 +36,7 @@ class PurchaseItemResource extends JsonResource
|
||||
'nombre' => $this->item_nombre,
|
||||
'descripcion' => $this->descripcion,
|
||||
'slug' => $this->slug,
|
||||
'imagen' => $imageUrl,
|
||||
'imagen' => $this->when(! $usesEventSummary, $imageUrl),
|
||||
'attributes' => $this->variant_attributes ?? [],
|
||||
],
|
||||
];
|
||||
|
||||
@@ -5,6 +5,9 @@ namespace App\Domains\Commerce\Purchase\Resources;
|
||||
use App\Domains\Commerce\Purchase\Models\Purchase;
|
||||
use App\Domains\Commerce\Purchase\Models\PurchaseItem;
|
||||
use App\Domains\Commerce\Purchase\Models\TelepagosPaymentCandidate;
|
||||
use App\Domains\Core\Tenant\Models\StorefrontWebsiteType;
|
||||
use App\Domains\Core\Tenant\Models\Tenant;
|
||||
use App\Domains\Ticketing\Event\Models\Event;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
@@ -27,6 +30,18 @@ class PurchaseResource extends JsonResource
|
||||
? (int) $this->resource->getAttribute('tickets_count')
|
||||
: null;
|
||||
$paymentVerification = $this->resolvePaymentVerification();
|
||||
$tenant = $request->route('tenant');
|
||||
$usesEventSummary = $tenant instanceof Tenant
|
||||
&& $tenant->storefrontWebsiteType?->checkout_summary_type
|
||||
=== StorefrontWebsiteType::CHECKOUT_SUMMARY_EVENT;
|
||||
/** @var Event|null $checkoutEvent */
|
||||
$checkoutEvent = $usesEventSummary
|
||||
? $items
|
||||
->map(fn (PurchaseItem $item) => $item->sourceCatalogItem?->event)
|
||||
->filter()
|
||||
->unique('id')
|
||||
->first()
|
||||
: null;
|
||||
|
||||
$subtotal = $items->isNotEmpty()
|
||||
? $items->reduce(
|
||||
@@ -64,6 +79,13 @@ class PurchaseResource extends JsonResource
|
||||
'email' => $this->email,
|
||||
'items_source' => $items->isNotEmpty() ? 'purchase' : null,
|
||||
'items' => PurchaseItemResource::collection($items),
|
||||
'event' => $this->when($usesEventSummary, fn () => $checkoutEvent === null
|
||||
? null
|
||||
: [
|
||||
'id' => $checkoutEvent->id,
|
||||
'title' => $checkoutEvent->title,
|
||||
'image' => $checkoutEvent->attachment?->getTemporaryUrl(1440),
|
||||
]),
|
||||
'tickets_count' => $this->when($ticketsCount !== null, $ticketsCount),
|
||||
'has_generated_tickets' => $this->when($ticketsCount !== null, $ticketsCount > 0),
|
||||
'payment_verification' => $this->when($paymentVerification !== null, $paymentVerification),
|
||||
|
||||
@@ -3,12 +3,24 @@
|
||||
namespace App\Domains\Commerce\Purchase\Services\Checkout;
|
||||
|
||||
use App\Domains\Commerce\Purchase\Models\Purchase;
|
||||
use App\Domains\Core\Tenant\Models\StorefrontWebsiteType;
|
||||
|
||||
class PurchaseResponseLoader
|
||||
{
|
||||
public function load(Purchase $purchase): Purchase
|
||||
{
|
||||
$relations = ['tenant', 'items.imageAttachment', 'stockReservation'];
|
||||
$purchase->loadMissing('tenant.storefrontWebsiteType');
|
||||
$usesEventSummary = $purchase->tenant?->storefrontWebsiteType?->checkout_summary_type
|
||||
=== StorefrontWebsiteType::CHECKOUT_SUMMARY_EVENT;
|
||||
$relations = [
|
||||
'tenant',
|
||||
'items.sourceCatalogItem.event.attachment',
|
||||
'stockReservation',
|
||||
];
|
||||
|
||||
if (! $usesEventSummary) {
|
||||
$relations[] = 'items.imageAttachment';
|
||||
}
|
||||
|
||||
if (
|
||||
$purchase->status === Purchase::STATUS_IN_REVIEW
|
||||
|
||||
@@ -7,13 +7,21 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
#[Fillable(['codigo', 'nombre', 'header_type'])]
|
||||
#[Fillable(['codigo', 'nombre', 'header_type', 'checkout_summary_type'])]
|
||||
class StorefrontWebsiteType extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
public const CHECKOUT_SUMMARY_DEFAULT = 'default';
|
||||
|
||||
public const CHECKOUT_SUMMARY_EVENT = 'event';
|
||||
|
||||
protected $table = 'storefront_website_types';
|
||||
|
||||
protected $attributes = [
|
||||
'checkout_summary_type' => self::CHECKOUT_SUMMARY_DEFAULT,
|
||||
];
|
||||
|
||||
/** @return HasMany<StorefrontWebsiteTypeExtra, $this> */
|
||||
public function extras(): HasMany
|
||||
{
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\Domains\Core\Tenant\Resources;
|
||||
|
||||
use App\Domains\Commerce\Catalog\Models\Category;
|
||||
use App\Domains\Core\Menu\Models\Menu;
|
||||
use App\Domains\Core\Tenant\Models\StorefrontWebsiteType;
|
||||
use App\Domains\Core\Tenant\Models\Tenant;
|
||||
use App\Domains\Ticketing\Event\Models\Event;
|
||||
use App\Domains\Ticketing\Event\Models\EventDate;
|
||||
@@ -50,6 +51,8 @@ class TenantResource extends JsonResource
|
||||
'admin_website_type_code' => $this->admin_website_type_code,
|
||||
'storefront_website_type_code' => $this->storefront_website_type_code,
|
||||
'header_type' => $this->storefrontWebsiteType?->header_type ?? 'standard',
|
||||
'checkout_summary_type' => $this->storefrontWebsiteType?->checkout_summary_type
|
||||
?? StorefrontWebsiteType::CHECKOUT_SUMMARY_DEFAULT,
|
||||
'active_event_id' => $this->active_event_id,
|
||||
'event' => $this->whenLoaded('activeEvent', fn () => $this->activeEvent === null
|
||||
? null : $this->formatEvent($this->activeEvent, $eventDateChanges)),
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
namespace App\Domains\Core\Tenant\Services;
|
||||
|
||||
use App\Shared\Attachable\Models\Attachment;
|
||||
use App\Domains\Core\Tenant\Models\Tenant;
|
||||
use App\Domains\Core\Tenant\Models\WebsiteExtra;
|
||||
use App\Shared\Attachable\Models\Attachment;
|
||||
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
@@ -16,6 +16,7 @@ class TenantInformationService
|
||||
'favicon',
|
||||
'headerBackgroundImage',
|
||||
'footerBackgroundImage',
|
||||
'storefrontWebsiteType',
|
||||
'socialMedia',
|
||||
'websiteExtras.websiteTypeExtra',
|
||||
'activeEvent.dates',
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('storefront_website_types', function (Blueprint $table): void {
|
||||
$table->string('checkout_summary_type')->default('default')->after('header_type');
|
||||
});
|
||||
|
||||
DB::table('storefront_website_types')
|
||||
->where('codigo', 'onticket_multi_event')
|
||||
->update(['checkout_summary_type' => 'event']);
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('storefront_website_types', function (Blueprint $table): void {
|
||||
$table->dropColumn('checkout_summary_type');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Domains\Core\Tenant\Services\AdminWebsiteTypeService;
|
||||
use App\Domains\Core\Tenant\Models\StorefrontWebsiteType;
|
||||
use App\Domains\Core\Tenant\Services\AdminWebsiteTypeService;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use RuntimeException;
|
||||
@@ -56,7 +56,11 @@ class WebsiteTypeSeeder extends Seeder
|
||||
|
||||
$shopItStorefront = StorefrontWebsiteType::query()->updateOrCreate(
|
||||
['codigo' => 'shopit'],
|
||||
['nombre' => 'ShopIt', 'header_type' => 'standard'],
|
||||
[
|
||||
'nombre' => 'ShopIt',
|
||||
'header_type' => 'standard',
|
||||
'checkout_summary_type' => StorefrontWebsiteType::CHECKOUT_SUMMARY_DEFAULT,
|
||||
],
|
||||
);
|
||||
|
||||
$shopItStorefront->extras()->updateOrCreate(
|
||||
@@ -85,12 +89,20 @@ class WebsiteTypeSeeder extends Seeder
|
||||
|
||||
$onTicketStorefront = StorefrontWebsiteType::query()->updateOrCreate(
|
||||
['codigo' => 'onticket'],
|
||||
['nombre' => 'OnTicket - evento único', 'header_type' => 'standard'],
|
||||
[
|
||||
'nombre' => 'OnTicket - evento único',
|
||||
'header_type' => 'standard',
|
||||
'checkout_summary_type' => StorefrontWebsiteType::CHECKOUT_SUMMARY_DEFAULT,
|
||||
],
|
||||
);
|
||||
|
||||
$multiEventStorefront = StorefrontWebsiteType::query()->updateOrCreate(
|
||||
['codigo' => 'onticket_multi_event'],
|
||||
['nombre' => 'OnTicket - múltiples eventos', 'header_type' => 'immersive'],
|
||||
[
|
||||
'nombre' => 'OnTicket - múltiples eventos',
|
||||
'header_type' => 'immersive',
|
||||
'checkout_summary_type' => StorefrontWebsiteType::CHECKOUT_SUMMARY_EVENT,
|
||||
],
|
||||
);
|
||||
|
||||
$multiEventStorefront->extras()->updateOrCreate(
|
||||
|
||||
@@ -2,14 +2,16 @@
|
||||
|
||||
namespace Tests\Feature\Purchase;
|
||||
|
||||
use App\Shared\Attachable\Enums\AttachmentType;
|
||||
use App\Shared\Attachable\Models\Attachment;
|
||||
use App\Domains\Core\Auth\Models\User;
|
||||
use App\Domains\Commerce\Cart\Models\Cart;
|
||||
use App\Domains\Commerce\Catalog\Models\CatalogItem;
|
||||
use App\Domains\Commerce\Catalog\Models\Inventory;
|
||||
use App\Domains\Commerce\Purchase\Services\CheckoutService;
|
||||
use App\Domains\Core\Auth\Models\User;
|
||||
use App\Domains\Core\Tenant\Models\StorefrontWebsiteType;
|
||||
use App\Domains\Core\Tenant\Models\Tenant;
|
||||
use App\Domains\Ticketing\Event\Models\Event;
|
||||
use App\Shared\Attachable\Enums\AttachmentType;
|
||||
use App\Shared\Attachable\Models\Attachment;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
@@ -117,6 +119,70 @@ class PurchaseCatalogItemTest extends TestCase
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_multi_event_checkout_returns_only_the_event_image(): void
|
||||
{
|
||||
Storage::fake('s3');
|
||||
Storage::disk('s3')->buildTemporaryUrlsUsing(
|
||||
fn (string $path): string => "https://snapshots.test/{$path}",
|
||||
);
|
||||
|
||||
StorefrontWebsiteType::query()->create([
|
||||
'codigo' => 'onticket_multi_event',
|
||||
'nombre' => 'OnTicket - múltiples eventos',
|
||||
'header_type' => 'immersive',
|
||||
'checkout_summary_type' => StorefrontWebsiteType::CHECKOUT_SUMMARY_EVENT,
|
||||
]);
|
||||
$tenant = $this->createTenant();
|
||||
$tenant->update(['storefront_website_type_code' => 'onticket_multi_event']);
|
||||
$user = User::factory()->create();
|
||||
|
||||
$eventImage = $this->createAttachment('checkout-event');
|
||||
$productImage = $this->createAttachment('checkout-product');
|
||||
Storage::disk('s3')->put($eventImage->path, 'event-image');
|
||||
Storage::disk('s3')->put($productImage->path, 'product-image');
|
||||
|
||||
$event = Event::query()->create([
|
||||
'tenant_code' => $tenant->codigo,
|
||||
'title' => 'Festival de prueba',
|
||||
'published_at' => now(),
|
||||
'attachment_id' => $eventImage->id,
|
||||
]);
|
||||
$inventory = Inventory::query()->create(['real_stock' => 10]);
|
||||
$catalogItem = CatalogItem::query()->create([
|
||||
'tenant_code' => $tenant->codigo,
|
||||
'inventory_id' => $inventory->id,
|
||||
'slug' => 'entrada-general',
|
||||
'nombre' => 'Entrada general',
|
||||
'precio' => 10000,
|
||||
]);
|
||||
$catalogItem->event_id = $event->id;
|
||||
$catalogItem->save();
|
||||
$catalogItem->attachments()->attach($productImage->id, ['orden' => 0]);
|
||||
|
||||
$cart = Cart::query()->create([
|
||||
'tenant_codigo' => $tenant->codigo,
|
||||
'user_id' => $user->id,
|
||||
'status' => 'active',
|
||||
]);
|
||||
$cart->addItem($catalogItem->id, null, 1);
|
||||
|
||||
$purchase = app(CheckoutService::class)->startCheckout($tenant, $user->id, [
|
||||
'cart_id' => $cart->id,
|
||||
'dni' => '12345678',
|
||||
'telefono' => '123456789',
|
||||
'nombre_apellido' => 'Test User',
|
||||
'email' => 'test@example.com',
|
||||
]);
|
||||
|
||||
$this->actingAs($user, 'sanctum')
|
||||
->getJson("/api/tenants/{$tenant->codigo}/compras/{$purchase->id}")
|
||||
->assertOk()
|
||||
->assertJsonMissingPath('data.items.0.item_details.imagen')
|
||||
->assertJsonPath('data.event.id', $event->id)
|
||||
->assertJsonPath('data.event.title', 'Festival de prueba')
|
||||
->assertJsonPath('data.event.image', "https://snapshots.test/{$eventImage->path}");
|
||||
}
|
||||
|
||||
private function createTenant(): Tenant
|
||||
{
|
||||
$headerLogo = $this->createAttachment('purchase-header');
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
namespace Tests\Feature\Seeders;
|
||||
|
||||
use App\Shared\Attachable\Models\Attachment;
|
||||
use App\Domains\Core\Tenant\Models\AdminWebsiteType;
|
||||
use App\Domains\Core\Tenant\Models\StorefrontWebsiteType;
|
||||
use App\Shared\Attachable\Models\Attachment;
|
||||
use Database\Seeders\WebsiteTypeSeeder;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
@@ -54,6 +54,7 @@ class WebsiteTypeSeederTest extends TestCase
|
||||
Storage::disk('s3')->assertExists($shopIt->favicon->path);
|
||||
$shopItStorefront = StorefrontWebsiteType::query()->where('codigo', 'shopit')->with('extras')->sole();
|
||||
$this->assertSame('standard', $shopItStorefront->header_type);
|
||||
$this->assertSame(StorefrontWebsiteType::CHECKOUT_SUMMARY_DEFAULT, $shopItStorefront->checkout_summary_type);
|
||||
$this->assertSame(['carousel'], $shopItStorefront->extras->pluck('codigo')->all());
|
||||
$this->assertSame('Carrusel principal', $shopItStorefront->extras->sole()->nombre);
|
||||
$this->assertSame([
|
||||
@@ -87,8 +88,10 @@ class WebsiteTypeSeederTest extends TestCase
|
||||
$this->assertSame('onticket_favicon.svg', $onTicket->favicon->filename);
|
||||
$onTicketStorefront = StorefrontWebsiteType::query()->where('codigo', 'onticket')->with('extras')->sole();
|
||||
$this->assertSame('standard', $onTicketStorefront->header_type);
|
||||
$this->assertSame(StorefrontWebsiteType::CHECKOUT_SUMMARY_DEFAULT, $onTicketStorefront->checkout_summary_type);
|
||||
$multiEventStorefront = StorefrontWebsiteType::query()->where('codigo', 'onticket_multi_event')->with('extras')->sole();
|
||||
$this->assertSame('immersive', $multiEventStorefront->header_type);
|
||||
$this->assertSame(StorefrontWebsiteType::CHECKOUT_SUMMARY_EVENT, $multiEventStorefront->checkout_summary_type);
|
||||
$this->assertEqualsCanonicalizing(['immersiveHeroCarousel', 'immersiveHero'], $multiEventStorefront->extras->pluck('codigo')->all());
|
||||
$this->assertSame($shopItStorefront->extras->sole()->config_schema, $multiEventStorefront->extras->firstWhere('codigo', 'immersiveHeroCarousel')->config_schema);
|
||||
$this->assertEqualsCanonicalizing(
|
||||
|
||||
@@ -37,7 +37,8 @@ class BootstrapTenantControllerTest extends TestCase
|
||||
->assertJsonCount(1, 'data.event_categories')
|
||||
->assertJsonPath('data.event_categories.0.id', $eventCategory->id)
|
||||
->assertJsonPath('data.event_categories.0.nombre', 'Música')
|
||||
->assertJsonPath('data.event_categories.0.subcategories', []);
|
||||
->assertJsonPath('data.event_categories.0.subcategories', [])
|
||||
->assertJsonPath('data.checkout_summary_type', StorefrontWebsiteType::CHECKOUT_SUMMARY_EVENT);
|
||||
}
|
||||
|
||||
public function test_it_bootstraps_a_tenant_by_domain(): void
|
||||
@@ -125,6 +126,7 @@ class BootstrapTenantControllerTest extends TestCase
|
||||
->assertJsonPath('data.checkout_editing_policy.allow_delete', false)
|
||||
->assertJsonPath('data.checkout_editing_policy.allow_update_quantity', false)
|
||||
->assertJsonPath('data.checkout_editing_policy.allow_update_variant', false)
|
||||
->assertJsonPath('data.checkout_summary_type', StorefrontWebsiteType::CHECKOUT_SUMMARY_DEFAULT)
|
||||
->assertJsonPath('data.display_cart_item_images', false)
|
||||
->assertJsonPath('data.header_bg_color', '#ffffff')->assertJsonPath('data.footer_bg_color', '#ffffff');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user