Compare commits
5 Commits
f9a766dee1
...
6775fb110c
| Author | SHA1 | Date | |
|---|---|---|---|
| 6775fb110c | |||
| 9c46eff880 | |||
| c8ce3b0da3 | |||
| d36a929f8c | |||
| 2de02dfd31 |
@@ -2214,7 +2214,7 @@
|
|||||||
},
|
},
|
||||||
"body": {
|
"body": {
|
||||||
"mode": "raw",
|
"mode": "raw",
|
||||||
"raw": "{\n \"client_id\": {{client_id}},\n \"codigo\": \"{{tenant_code}}\",\n \"nombre\": \"Tenant Demo\",\n \"dominio\": \"{{tenant_domain}}\",\n \"site_title\": \"ShopIt Demo\",\n \"primary_color\": \"#111827\",\n \"secondary_color\": \"#2563EB\",\n \"danger_color\": \"#DC2626\",\n \"success_color\": \"#16A34A\",\n \"header_bg_color\": \"#FFFFFF\",\n \"footer_bg_color\": \"#111827\",\n \"header_logo\": \"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==\",\n \"footer_logo\": \"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==\",\n \"search_product_layout\": \"column_with_image\",\n \"search_group_layout\": \"paginated\",\n \"search_items_per_page\": 12,\n \"display_categories\": true,\n \"display_seach_bar\": true,\n \"display_cart\": true,\n \"cart_editing_policy\": \"full\",\n \"website_type_code\": \"shopit\"\n}",
|
"raw": "{\n \"client_id\": {{client_id}},\n \"codigo\": \"{{tenant_code}}\",\n \"nombre\": \"Tenant Demo\",\n \"dominio\": \"{{tenant_domain}}\",\n \"site_title\": \"ShopIt Demo\",\n \"primary_color\": \"#111827\",\n \"secondary_color\": \"#2563EB\",\n \"danger_color\": \"#DC2626\",\n \"success_color\": \"#16A34A\",\n \"header_bg_color\": \"#FFFFFF\",\n \"footer_bg_color\": \"#111827\",\n \"header_logo\": \"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==\",\n \"footer_logo\": \"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==\",\n \"search_product_layout\": \"column_with_image\",\n \"search_group_layout\": \"paginated\",\n \"search_items_per_page\": 12,\n \"display_categories\": true,\n \"display_seach_bar\": true,\n \"display_cart\": true,\n \"cart_editing_policy\": \"full\",\n \"checkout_editing_policy\": \"full\",\n \"website_type_code\": \"shopit\"\n}",
|
||||||
"options": {
|
"options": {
|
||||||
"raw": {
|
"raw": {
|
||||||
"language": "json"
|
"language": "json"
|
||||||
@@ -2280,7 +2280,7 @@
|
|||||||
},
|
},
|
||||||
"body": {
|
"body": {
|
||||||
"mode": "raw",
|
"mode": "raw",
|
||||||
"raw": "{\n \"nombre\": \"Tenant Demo Actualizado\",\n \"site_title\": \"ShopIt Demo\",\n \"primary_color\": \"#111827\",\n \"cart_editing_policy\": \"full\"\n}",
|
"raw": "{\n \"nombre\": \"Tenant Demo Actualizado\",\n \"site_title\": \"ShopIt Demo\",\n \"primary_color\": \"#111827\",\n \"cart_editing_policy\": \"full\",\n \"checkout_editing_policy\": \"full\"\n}",
|
||||||
"options": {
|
"options": {
|
||||||
"raw": {
|
"raw": {
|
||||||
"language": "json"
|
"language": "json"
|
||||||
@@ -2320,7 +2320,7 @@
|
|||||||
},
|
},
|
||||||
"body": {
|
"body": {
|
||||||
"mode": "raw",
|
"mode": "raw",
|
||||||
"raw": "{\n \"nombre\": \"Tenant Demo Actualizado\",\n \"site_title\": \"ShopIt Demo\",\n \"primary_color\": \"#111827\",\n \"cart_editing_policy\": \"full\"\n}",
|
"raw": "{\n \"nombre\": \"Tenant Demo Actualizado\",\n \"site_title\": \"ShopIt Demo\",\n \"primary_color\": \"#111827\",\n \"cart_editing_policy\": \"full\",\n \"checkout_editing_policy\": \"full\"\n}",
|
||||||
"options": {
|
"options": {
|
||||||
"raw": {
|
"raw": {
|
||||||
"language": "json"
|
"language": "json"
|
||||||
|
|||||||
@@ -117,4 +117,23 @@ class CartController extends Controller
|
|||||||
'message' => __('api.cart.item_removed'),
|
'message' => __('api.cart.item_removed'),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function removeCheckoutItem(
|
||||||
|
Request $request,
|
||||||
|
Tenant $tenant,
|
||||||
|
Cart $cart,
|
||||||
|
CartItem $cartItem,
|
||||||
|
): CartResource {
|
||||||
|
return CartResource::make(
|
||||||
|
$this->cartService->removeCheckoutItem(
|
||||||
|
$tenant,
|
||||||
|
$request,
|
||||||
|
$cart,
|
||||||
|
$cartItem->getKey(),
|
||||||
|
),
|
||||||
|
)->additional([
|
||||||
|
'code' => 'cart.item_removed',
|
||||||
|
'message' => __('api.cart.item_removed'),
|
||||||
|
]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Domains\Cart\Resources;
|
namespace App\Domains\Cart\Resources;
|
||||||
|
|
||||||
|
use App\Domains\Cart\Models\Cart;
|
||||||
use App\Domains\Cart\Models\CartItem;
|
use App\Domains\Cart\Models\CartItem;
|
||||||
use App\Domains\Catalog\Enums\InventoryPolicy;
|
use App\Domains\Catalog\Enums\InventoryPolicy;
|
||||||
use App\Domains\Catalog\Models\Variant;
|
use App\Domains\Catalog\Models\Variant;
|
||||||
@@ -22,9 +23,13 @@ class CartItemResource extends JsonResource
|
|||||||
$selectedItem = $this->selectedItem();
|
$selectedItem = $this->selectedItem();
|
||||||
$imageUrl = null;
|
$imageUrl = null;
|
||||||
$tenant = $request->route('tenant');
|
$tenant = $request->route('tenant');
|
||||||
|
$checkoutCart = $request->route('cart');
|
||||||
$displayImage = ! $tenant instanceof Tenant || $tenant->display_cart_item_images;
|
$displayImage = ! $tenant instanceof Tenant || $tenant->display_cart_item_images;
|
||||||
$includeVariants = $tenant instanceof Tenant
|
$includeVariants = $tenant instanceof Tenant
|
||||||
&& $tenant->cart_editing_policy->allowsVariantChanges();
|
&& ($checkoutCart instanceof Cart
|
||||||
|
? $tenant->checkout_editing_policy
|
||||||
|
: $tenant->cart_editing_policy)
|
||||||
|
->allowsVariantChanges();
|
||||||
|
|
||||||
if ($displayImage && $selectedItem?->relationLoaded('attachments')) {
|
if ($displayImage && $selectedItem?->relationLoaded('attachments')) {
|
||||||
$imageUrl = $selectedItem->attachments->first()?->getTemporaryUrl(1440);
|
$imageUrl = $selectedItem->attachments->first()?->getTemporaryUrl(1440);
|
||||||
|
|||||||
@@ -161,7 +161,26 @@ class CartService
|
|||||||
|| ($updateVariant && $cartItem->variant_id !== $variantId);
|
|| ($updateVariant && $cartItem->variant_id !== $variantId);
|
||||||
|
|
||||||
if (! $hasChanges) {
|
if (! $hasChanges) {
|
||||||
return $this->loadCart($checkoutCart);
|
return $this->loadCart($checkoutCart, $tenant, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
(int) $cartItem->cantidad !== $quantity
|
||||||
|
&& ! $tenant->checkout_editing_policy->allowsQuantityChanges()
|
||||||
|
) {
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'cantidad' => __('api.cart.editing_disabled'),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
$updateVariant
|
||||||
|
&& $cartItem->variant_id !== $variantId
|
||||||
|
&& ! $tenant->checkout_editing_policy->allowsVariantChanges()
|
||||||
|
) {
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'variant_id' => __('api.cart.variant_change_disabled'),
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$checkoutCart->updateItem(
|
$checkoutCart->updateItem(
|
||||||
@@ -184,7 +203,7 @@ class CartService
|
|||||||
]);
|
]);
|
||||||
$this->reservations->syncPurchaseExpiration($purchase);
|
$this->reservations->syncPurchaseExpiration($purchase);
|
||||||
|
|
||||||
return $this->loadCart($checkoutCart);
|
return $this->loadCart($checkoutCart, $tenant, true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -203,6 +222,78 @@ class CartService
|
|||||||
return $this->loadCart($cart, $tenant);
|
return $this->loadCart($cart, $tenant);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function removeCheckoutItem(
|
||||||
|
Tenant $tenant,
|
||||||
|
Request $request,
|
||||||
|
Cart $cart,
|
||||||
|
int $cartItemId,
|
||||||
|
): Cart {
|
||||||
|
if (! $tenant->checkout_editing_policy->allowsRemoval()) {
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'cart_item' => __('api.cart.editing_disabled'),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$user = $request->user() ?? Auth::guard('sanctum')->user();
|
||||||
|
|
||||||
|
if (! $user instanceof User) {
|
||||||
|
throw new NotFoundHttpException('Checkout cart not found.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return DB::transaction(function () use ($tenant, $user, $cart, $cartItemId): Cart {
|
||||||
|
/** @var Purchase|null $purchase */
|
||||||
|
$purchase = Purchase::query()
|
||||||
|
->where('cart_id', $cart->getKey())
|
||||||
|
->where('tenant_codigo', $tenant->codigo)
|
||||||
|
->where('user_id', $user->getKey())
|
||||||
|
->whereIn('status', [
|
||||||
|
Purchase::STATUS_CREATED,
|
||||||
|
Purchase::STATUS_PENDING_PAYMENT,
|
||||||
|
])
|
||||||
|
->whereDoesntHave('items')
|
||||||
|
->lockForUpdate()
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if ($purchase === null) {
|
||||||
|
throw new NotFoundHttpException('Checkout cart not found.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($purchase->expires_at !== null && $purchase->expires_at->isPast()) {
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'cart' => __('api.purchase.not_editable'),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var Cart|null $checkoutCart */
|
||||||
|
$checkoutCart = Cart::query()
|
||||||
|
->whereKey($cart->getKey())
|
||||||
|
->where('tenant_codigo', $tenant->codigo)
|
||||||
|
->where('user_id', $user->getKey())
|
||||||
|
->where('status', 'checkout')
|
||||||
|
->lockForUpdate()
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if ($checkoutCart === null) {
|
||||||
|
throw new NotFoundHttpException('Checkout cart not found.');
|
||||||
|
}
|
||||||
|
|
||||||
|
$checkoutCart->removeItem($cartItemId);
|
||||||
|
$purchase->telepagosQr()->delete();
|
||||||
|
$purchase->update([
|
||||||
|
'status' => Purchase::STATUS_CREATED,
|
||||||
|
'payment_method' => null,
|
||||||
|
'transfer_payer_dni' => null,
|
||||||
|
'total' => $checkoutCart->getTotalAmount(),
|
||||||
|
'expires_at' => now()->addMinutes(
|
||||||
|
max(1, (int) config('purchase.checkout_expiration_minutes', 30)),
|
||||||
|
),
|
||||||
|
]);
|
||||||
|
$this->reservations->syncPurchaseExpiration($purchase);
|
||||||
|
|
||||||
|
return $this->loadCart($checkoutCart, $tenant, true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public function makeGuestTokenCookie(string $guestToken): Cookie
|
public function makeGuestTokenCookie(string $guestToken): Cookie
|
||||||
{
|
{
|
||||||
return cookie(
|
return cookie(
|
||||||
@@ -230,7 +321,7 @@ class CartService
|
|||||||
return $cart;
|
return $cart;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function loadCart(Cart $cart, Tenant $tenant): Cart
|
protected function loadCart(Cart $cart, Tenant $tenant, bool $isCheckout = false): Cart
|
||||||
{
|
{
|
||||||
$relations = [
|
$relations = [
|
||||||
'items.catalogItem.attachments',
|
'items.catalogItem.attachments',
|
||||||
@@ -243,7 +334,11 @@ class CartService
|
|||||||
'items.variant.eventDate',
|
'items.variant.eventDate',
|
||||||
];
|
];
|
||||||
|
|
||||||
if ($tenant->cart_editing_policy->allowsVariantChanges()) {
|
$editingPolicy = $isCheckout
|
||||||
|
? $tenant->checkout_editing_policy
|
||||||
|
: $tenant->cart_editing_policy;
|
||||||
|
|
||||||
|
if ($editingPolicy->allowsVariantChanges()) {
|
||||||
$relations = [
|
$relations = [
|
||||||
...$relations,
|
...$relations,
|
||||||
'items.catalogItem.variants' => fn ($query) => $query->orderBy('id'),
|
'items.catalogItem.variants' => fn ($query) => $query->orderBy('id'),
|
||||||
|
|||||||
@@ -15,4 +15,5 @@ Route::prefix('tenants/{tenant:codigo}')
|
|||||||
->middleware('auth:sanctum')
|
->middleware('auth:sanctum')
|
||||||
->group(function (): void {
|
->group(function (): void {
|
||||||
Route::patch('checkout-carts/{cart}/items/{cartItem}', [CartController::class, 'updateCheckoutItem']);
|
Route::patch('checkout-carts/{cart}/items/{cartItem}', [CartController::class, 'updateCheckoutItem']);
|
||||||
|
Route::delete('checkout-carts/{cart}/items/{cartItem}', [CartController::class, 'removeCheckoutItem']);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -11,9 +11,11 @@ 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\BelongsTo;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
#[Fillable([
|
#[Fillable([
|
||||||
'tenant_code',
|
'tenant_code',
|
||||||
|
'code',
|
||||||
'source_type',
|
'source_type',
|
||||||
'category_id',
|
'category_id',
|
||||||
'product_layout',
|
'product_layout',
|
||||||
@@ -33,6 +35,29 @@ class FeaturedGroup extends Model
|
|||||||
'source_type' => FeaturedGroupSource::Manual->value,
|
'source_type' => FeaturedGroupSource::Manual->value,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
protected static function booted(): void
|
||||||
|
{
|
||||||
|
static::creating(function (FeaturedGroup $featuredGroup): void {
|
||||||
|
if (filled($featuredGroup->code)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$baseCode = Str::slug($featuredGroup->group_name) ?: 'group';
|
||||||
|
$code = $baseCode;
|
||||||
|
$suffix = 2;
|
||||||
|
|
||||||
|
while (static::query()
|
||||||
|
->where('tenant_code', $featuredGroup->tenant_code)
|
||||||
|
->where('code', $code)
|
||||||
|
->exists()) {
|
||||||
|
$code = "{$baseCode}-{$suffix}";
|
||||||
|
$suffix++;
|
||||||
|
}
|
||||||
|
|
||||||
|
$featuredGroup->code = $code;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
protected function casts(): array
|
protected function casts(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ class OnTicketFeaturedGroupResource extends JsonResource
|
|||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'id' => $this->id,
|
'id' => $this->id,
|
||||||
|
'code' => $this->code,
|
||||||
'category_id' => $this->category_id,
|
'category_id' => $this->category_id,
|
||||||
'category_name' => $this->category->nombre,
|
'category_name' => $this->category->nombre,
|
||||||
'group_name' => $this->group_name,
|
'group_name' => $this->group_name,
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ class CatalogFeaturedGroupResource extends JsonResource
|
|||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'id' => $this->id,
|
'id' => $this->id,
|
||||||
|
'code' => $this->code,
|
||||||
'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_layout' => $this->group_layout->value,
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ namespace App\Domains\Purchase\Controllers;
|
|||||||
|
|
||||||
use App\Domains\Integration\Services\TelepagosIntegrationService;
|
use App\Domains\Integration\Services\TelepagosIntegrationService;
|
||||||
use App\Domains\Purchase\Models\Purchase;
|
use App\Domains\Purchase\Models\Purchase;
|
||||||
|
use App\Domains\Purchase\Models\PurchaseItem;
|
||||||
use App\Domains\Purchase\Requests\PaymentIntentRequest;
|
use App\Domains\Purchase\Requests\PaymentIntentRequest;
|
||||||
use App\Domains\Purchase\Requests\StartCheckoutRequest;
|
use App\Domains\Purchase\Requests\StartCheckoutRequest;
|
||||||
use App\Domains\Purchase\Requests\UpdatePurchaseCustomerRequest;
|
use App\Domains\Purchase\Requests\UpdatePurchaseCustomerRequest;
|
||||||
@@ -104,6 +105,33 @@ class PurchaseController extends Controller
|
|||||||
Tenant $tenant,
|
Tenant $tenant,
|
||||||
Purchase $compra,
|
Purchase $compra,
|
||||||
CheckoutService $checkoutService,
|
CheckoutService $checkoutService,
|
||||||
|
): PurchaseResource {
|
||||||
|
$compra = $this->resolveScopedPurchase($tenant, $request->user()->id, $compra);
|
||||||
|
|
||||||
|
return PurchaseResource::make(
|
||||||
|
$checkoutService->prepareItemEditing($compra),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function removeItem(
|
||||||
|
Request $request,
|
||||||
|
Tenant $tenant,
|
||||||
|
Purchase $compra,
|
||||||
|
PurchaseItem $item,
|
||||||
|
CheckoutService $checkoutService,
|
||||||
|
): PurchaseResource {
|
||||||
|
$compra = $this->resolveScopedPurchase($tenant, $request->user()->id, $compra);
|
||||||
|
|
||||||
|
return PurchaseResource::make(
|
||||||
|
$checkoutService->removeItem($compra, $item),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function paymentIntent(
|
||||||
|
PaymentIntentRequest $request,
|
||||||
|
Tenant $tenant,
|
||||||
|
Purchase $compra,
|
||||||
|
CheckoutService $checkoutService,
|
||||||
): JsonResponse {
|
): JsonResponse {
|
||||||
$compra = $this->resolveScopedPurchase($tenant, $request->user()->id, $compra);
|
$compra = $this->resolveScopedPurchase($tenant, $request->user()->id, $compra);
|
||||||
$method = $request->validated('method');
|
$method = $request->validated('method');
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ class PurchaseItemResource extends JsonResource
|
|||||||
? $this->sourceCatalogItem
|
? $this->sourceCatalogItem
|
||||||
: null;
|
: null;
|
||||||
$includeVariants = $tenant instanceof Tenant
|
$includeVariants = $tenant instanceof Tenant
|
||||||
&& $tenant->cart_editing_policy->allowsVariantChanges()
|
&& $tenant->checkout_editing_policy->allowsVariantChanges()
|
||||||
&& $catalogItem !== null
|
&& $catalogItem !== null
|
||||||
&& $catalogItem->relationLoaded('variants');
|
&& $catalogItem->relationLoaded('variants');
|
||||||
|
|
||||||
@@ -67,6 +67,9 @@ class PurchaseItemResource extends JsonResource
|
|||||||
$imageUrl = $displayImage
|
$imageUrl = $displayImage
|
||||||
? $this->resolveImageUrl($selectedItem, $catalogItem)
|
? $this->resolveImageUrl($selectedItem, $catalogItem)
|
||||||
: null;
|
: null;
|
||||||
|
$includeVariants = $tenant instanceof Tenant
|
||||||
|
&& $tenant->checkout_editing_policy->allowsVariantChanges()
|
||||||
|
&& $catalogItem?->relationLoaded('variants');
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'id' => $this->id,
|
'id' => $this->id,
|
||||||
@@ -82,6 +85,16 @@ class PurchaseItemResource extends JsonResource
|
|||||||
'imagen' => $imageUrl,
|
'imagen' => $imageUrl,
|
||||||
'attributes' => $variant === null ? [] : $this->resolveAttributes($variant),
|
'attributes' => $variant === null ? [] : $this->resolveAttributes($variant),
|
||||||
],
|
],
|
||||||
|
'variants' => $this->when(
|
||||||
|
$includeVariants,
|
||||||
|
fn () => $catalogItem
|
||||||
|
->visibleVariants($this->variant_id)
|
||||||
|
->map(fn (Variant $availableVariant): array => $this->variantData(
|
||||||
|
$catalogItem,
|
||||||
|
$availableVariant,
|
||||||
|
))
|
||||||
|
->values(),
|
||||||
|
),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -61,13 +61,13 @@ class EditCheckoutService
|
|||||||
$tenant = $purchase->tenant()->firstOrFail();
|
$tenant = $purchase->tenant()->firstOrFail();
|
||||||
$finalQuantity = $quantity ?? (int) $purchaseItem->cantidad;
|
$finalQuantity = $quantity ?? (int) $purchaseItem->cantidad;
|
||||||
|
|
||||||
if ($quantity !== null && ! $tenant->cart_editing_policy->allowsQuantityChanges()) {
|
if ($quantity !== null && ! $tenant->checkout_editing_policy->allowsQuantityChanges()) {
|
||||||
throw ValidationException::withMessages([
|
throw ValidationException::withMessages([
|
||||||
'quantity' => __('api.cart.editing_disabled'),
|
'quantity' => __('api.cart.editing_disabled'),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($updateVariant && ! $tenant->cart_editing_policy->allowsVariantChanges()) {
|
if ($updateVariant && ! $tenant->checkout_editing_policy->allowsVariantChanges()) {
|
||||||
throw ValidationException::withMessages([
|
throw ValidationException::withMessages([
|
||||||
'variant_id' => __('api.purchase.variant_change_disabled'),
|
'variant_id' => __('api.purchase.variant_change_disabled'),
|
||||||
]);
|
]);
|
||||||
@@ -184,7 +184,7 @@ class EditCheckoutService
|
|||||||
$purchase = $this->lockPurchase($purchase);
|
$purchase = $this->lockPurchase($purchase);
|
||||||
$this->assertEditable($purchase);
|
$this->assertEditable($purchase);
|
||||||
|
|
||||||
if (! $purchase->tenant()->firstOrFail()->cart_editing_policy->allowsModification()) {
|
if (! $purchase->tenant()->firstOrFail()->checkout_editing_policy->allowsModification()) {
|
||||||
throw ValidationException::withMessages([
|
throw ValidationException::withMessages([
|
||||||
'purchase' => __('api.cart.editing_disabled'),
|
'purchase' => __('api.cart.editing_disabled'),
|
||||||
]);
|
]);
|
||||||
@@ -204,6 +204,31 @@ class EditCheckoutService
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function removeItem(Purchase $purchase, PurchaseItem $purchaseItem): Purchase
|
||||||
|
{
|
||||||
|
return DB::transaction(function () use ($purchase, $purchaseItem): Purchase {
|
||||||
|
$purchase = $this->lockPurchase($purchase);
|
||||||
|
$this->assertEditable($purchase);
|
||||||
|
|
||||||
|
if (! $purchase->tenant()->firstOrFail()->checkout_editing_policy->allowsRemoval()) {
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'item' => __('api.cart.editing_disabled'),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$purchaseItem = $this->lockPurchaseItem($purchase, $purchaseItem);
|
||||||
|
$selection = $this->selections->resolvePurchaseItem($purchase->tenant, $purchaseItem);
|
||||||
|
$this->inventory->release($selection, (int) $purchaseItem->cantidad);
|
||||||
|
$this->sourceCart->removeItem($purchase, $purchaseItem);
|
||||||
|
$purchaseItem->delete();
|
||||||
|
$purchase->update([
|
||||||
|
'total' => $purchase->calculateCurrentTotalAmount(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
return $this->loadPurchase($purchase);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private function adjustReservation(
|
private function adjustReservation(
|
||||||
Purchase $purchase,
|
Purchase $purchase,
|
||||||
PurchaseItem $purchaseItem,
|
PurchaseItem $purchaseItem,
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ class PurchaseResponseLoader
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $purchase->tenant->cart_editing_policy->allowsVariantChanges()) {
|
if (! $purchase->tenant->checkout_editing_policy->allowsVariantChanges()) {
|
||||||
return $purchase;
|
return $purchase;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,6 +35,13 @@ class PurchaseResponseLoader
|
|||||||
'items.sourceCatalogItem.variants.definitions.itemAttribute.attribute.options',
|
'items.sourceCatalogItem.variants.definitions.itemAttribute.attribute.options',
|
||||||
'items.sourceCatalogItem.variants.eventDates',
|
'items.sourceCatalogItem.variants.eventDates',
|
||||||
'items.sourceCatalogItem.variants.eventDate',
|
'items.sourceCatalogItem.variants.eventDate',
|
||||||
|
'cart.items.catalogItem.itemAttributes.attribute',
|
||||||
|
'cart.items.catalogItem.variants' => fn ($query) => $query->orderBy('id'),
|
||||||
|
'cart.items.catalogItem.variants.inventory',
|
||||||
|
'cart.items.catalogItem.variants.definitions' => fn ($query) => $query->orderBy('id'),
|
||||||
|
'cart.items.catalogItem.variants.definitions.itemAttribute.attribute.options',
|
||||||
|
'cart.items.catalogItem.variants.eventDates',
|
||||||
|
'cart.items.catalogItem.variants.eventDate',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return $purchase;
|
return $purchase;
|
||||||
|
|||||||
@@ -6,28 +6,29 @@ use App\Domains\Catalog\Models\StockReservation;
|
|||||||
use App\Domains\Catalog\Services\StockReservationService;
|
use App\Domains\Catalog\Services\StockReservationService;
|
||||||
use App\Domains\Purchase\Models\Purchase;
|
use App\Domains\Purchase\Models\Purchase;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
use Illuminate\Validation\ValidationException;
|
use Illuminate\Validation\ValidationException;
|
||||||
|
use Throwable;
|
||||||
|
|
||||||
class ReleaseCheckoutService
|
class ReleaseCheckoutService
|
||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly StockReservationService $reservations,
|
private readonly StockReservationService $reservations,
|
||||||
private readonly SourceCartService $sourceCart,
|
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
public function cancel(Purchase $purchase): Purchase
|
public function cancel(Purchase $purchase): Purchase
|
||||||
{
|
{
|
||||||
return $this->release($purchase, Purchase::STATUS_CANCELLED, restoreCart: true);
|
return $this->release($purchase, Purchase::STATUS_CANCELLED);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function cancelWithoutRestoringCart(Purchase $purchase): Purchase
|
public function cancelWithoutRestoringCart(Purchase $purchase): Purchase
|
||||||
{
|
{
|
||||||
return $this->release($purchase, Purchase::STATUS_CANCELLED, restoreCart: false);
|
return $this->release($purchase, Purchase::STATUS_CANCELLED);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function expire(Purchase $purchase): Purchase
|
public function expire(Purchase $purchase): Purchase
|
||||||
{
|
{
|
||||||
return $this->release($purchase, Purchase::STATUS_EXPIRED, restoreCart: true);
|
return $this->release($purchase, Purchase::STATUS_EXPIRED);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function expireOverdue(): int
|
public function expireOverdue(): int
|
||||||
@@ -40,7 +41,21 @@ class ReleaseCheckoutService
|
|||||||
->where('expires_at', '<=', now())
|
->where('expires_at', '<=', now())
|
||||||
->orderBy('id')
|
->orderBy('id')
|
||||||
->eachById(function (Purchase $purchase) use (&$expiredCount): void {
|
->eachById(function (Purchase $purchase) use (&$expiredCount): void {
|
||||||
$purchase = $this->expire($purchase);
|
try {
|
||||||
|
$purchase = $this->expire($purchase);
|
||||||
|
} catch (Throwable $exception) {
|
||||||
|
Log::channel('commands')->error('Failed to expire overdue purchase.', [
|
||||||
|
'command' => 'reservations:expire',
|
||||||
|
'purchase_id' => $purchase->getKey(),
|
||||||
|
'tenant_codigo' => $purchase->tenant_codigo,
|
||||||
|
'cart_id' => $purchase->cart_id,
|
||||||
|
'status' => $purchase->status,
|
||||||
|
'expires_at' => $purchase->expires_at,
|
||||||
|
'exception' => $exception,
|
||||||
|
]);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if ($purchase->status === Purchase::STATUS_EXPIRED) {
|
if ($purchase->status === Purchase::STATUS_EXPIRED) {
|
||||||
$expiredCount++;
|
$expiredCount++;
|
||||||
@@ -50,9 +65,9 @@ class ReleaseCheckoutService
|
|||||||
return $expiredCount;
|
return $expiredCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function release(Purchase $purchase, string $targetStatus, bool $restoreCart): Purchase
|
private function release(Purchase $purchase, string $targetStatus): Purchase
|
||||||
{
|
{
|
||||||
return DB::transaction(function () use ($purchase, $targetStatus, $restoreCart): Purchase {
|
return DB::transaction(function () use ($purchase, $targetStatus): Purchase {
|
||||||
$purchase = $this->lockPurchase($purchase);
|
$purchase = $this->lockPurchase($purchase);
|
||||||
|
|
||||||
if ($purchase->status === Purchase::STATUS_PAID) {
|
if ($purchase->status === Purchase::STATUS_PAID) {
|
||||||
@@ -82,8 +97,7 @@ class ReleaseCheckoutService
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$reservationReturnedToCart = $restoreCart && $this->sourceCart->restore($purchase);
|
$this->releaseCartReservations($purchase, $targetStatus);
|
||||||
$this->releaseCartReservations($purchase, $reservationReturnedToCart, $targetStatus);
|
|
||||||
|
|
||||||
$purchase->update(['status' => $targetStatus]);
|
$purchase->update(['status' => $targetStatus]);
|
||||||
|
|
||||||
@@ -93,15 +107,8 @@ class ReleaseCheckoutService
|
|||||||
|
|
||||||
private function releaseCartReservations(
|
private function releaseCartReservations(
|
||||||
Purchase $purchase,
|
Purchase $purchase,
|
||||||
bool $reservationReturnedToCart,
|
|
||||||
string $targetStatus,
|
string $targetStatus,
|
||||||
): void {
|
): void {
|
||||||
if ($reservationReturnedToCart) {
|
|
||||||
$this->reservations->detachFromPurchase($purchase);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$cart = $purchase->cart()->withTrashed()->lockForUpdate()->first();
|
$cart = $purchase->cart()->withTrashed()->lockForUpdate()->first();
|
||||||
if ($cart === null) {
|
if ($cart === null) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -3,65 +3,10 @@
|
|||||||
namespace App\Domains\Purchase\Services\Checkout;
|
namespace App\Domains\Purchase\Services\Checkout;
|
||||||
|
|
||||||
use App\Domains\Cart\Models\Cart;
|
use App\Domains\Cart\Models\Cart;
|
||||||
use App\Domains\Cart\Models\CartItem;
|
|
||||||
use App\Domains\Catalog\Services\StockReservationService;
|
|
||||||
use App\Domains\Purchase\Models\Purchase;
|
use App\Domains\Purchase\Models\Purchase;
|
||||||
|
|
||||||
class SourceCartService
|
class SourceCartService
|
||||||
{
|
{
|
||||||
public function __construct(
|
|
||||||
private readonly StockReservationService $reservations,
|
|
||||||
) {}
|
|
||||||
|
|
||||||
public function restore(Purchase $purchase): bool
|
|
||||||
{
|
|
||||||
$sourceCart = $this->findSourceCart($purchase);
|
|
||||||
|
|
||||||
if ($sourceCart === null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($sourceCart->origin === Cart::ORIGIN_DIRECT_CHECKOUT) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @var Cart|null $activeCart */
|
|
||||||
$activeCart = Cart::query()
|
|
||||||
->where('tenant_codigo', $purchase->tenant_codigo)
|
|
||||||
->where('user_id', $purchase->user_id)
|
|
||||||
->where('status', 'active')
|
|
||||||
->where('id', '!=', $sourceCart->getKey())
|
|
||||||
->lockForUpdate()
|
|
||||||
->first();
|
|
||||||
|
|
||||||
if ($activeCart !== null) {
|
|
||||||
$this->mergeIntoActiveCart($sourceCart, $activeCart);
|
|
||||||
|
|
||||||
$sourceCart->update([
|
|
||||||
'status' => 'converted',
|
|
||||||
'guest_token' => null,
|
|
||||||
]);
|
|
||||||
|
|
||||||
if (! $sourceCart->trashed()) {
|
|
||||||
$sourceCart->delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($sourceCart->trashed()) {
|
|
||||||
$sourceCart->restore();
|
|
||||||
}
|
|
||||||
|
|
||||||
$sourceCart->update([
|
|
||||||
'status' => 'active',
|
|
||||||
'user_id' => $purchase->user_id,
|
|
||||||
'guest_token' => null,
|
|
||||||
]);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function syncItemQuantity(
|
public function syncItemQuantity(
|
||||||
Purchase $purchase,
|
Purchase $purchase,
|
||||||
PurchaseItem $purchaseItem,
|
PurchaseItem $purchaseItem,
|
||||||
@@ -130,6 +75,20 @@ class SourceCartService
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function removeItem(Purchase $purchase, PurchaseItem $purchaseItem): void
|
||||||
|
{
|
||||||
|
$sourceCart = $this->findSourceCart($purchase);
|
||||||
|
|
||||||
|
if ($sourceCart === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sourceCart->items()
|
||||||
|
->where('catalog_item_id', $purchaseItem->source_catalog_item_id)
|
||||||
|
->where('variant_id', $purchaseItem->source_variant_id)
|
||||||
|
->delete();
|
||||||
|
}
|
||||||
|
|
||||||
public function finalize(Purchase $purchase): void
|
public function finalize(Purchase $purchase): void
|
||||||
{
|
{
|
||||||
$sourceCart = $this->findSourceCart($purchase);
|
$sourceCart = $this->findSourceCart($purchase);
|
||||||
@@ -157,30 +116,4 @@ class SourceCartService
|
|||||||
->lockForUpdate()
|
->lockForUpdate()
|
||||||
->first();
|
->first();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function mergeIntoActiveCart(Cart $sourceCart, Cart $activeCart): void
|
|
||||||
{
|
|
||||||
$sourceItems = $sourceCart->items()->lockForUpdate()->get();
|
|
||||||
|
|
||||||
foreach ($sourceItems as $sourceItem) {
|
|
||||||
/** @var CartItem|null $activeItem */
|
|
||||||
$activeItem = $activeCart->items()
|
|
||||||
->where('catalog_item_id', $sourceItem->catalog_item_id)
|
|
||||||
->where('variant_id', $sourceItem->variant_id)
|
|
||||||
->lockForUpdate()
|
|
||||||
->first();
|
|
||||||
|
|
||||||
if ($activeItem === null) {
|
|
||||||
$activeItem = $activeCart->items()->create([
|
|
||||||
'catalog_item_id' => $sourceItem->catalog_item_id,
|
|
||||||
'variant_id' => $sourceItem->variant_id,
|
|
||||||
'cantidad' => $sourceItem->cantidad,
|
|
||||||
]);
|
|
||||||
} else {
|
|
||||||
$activeItem->increment('cantidad', (int) $sourceItem->cantidad);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->reservations->transfer($sourceItem, $activeItem);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ namespace App\Domains\Purchase\Services;
|
|||||||
|
|
||||||
use App\Domains\Catalog\Services\StockReservationService;
|
use App\Domains\Catalog\Services\StockReservationService;
|
||||||
use App\Domains\Purchase\Models\Purchase;
|
use App\Domains\Purchase\Models\Purchase;
|
||||||
|
use App\Domains\Purchase\Models\PurchaseItem;
|
||||||
use App\Domains\Purchase\Services\Checkout\CompleteCheckoutService;
|
use App\Domains\Purchase\Services\Checkout\CompleteCheckoutService;
|
||||||
use App\Domains\Purchase\Services\Checkout\EditCheckoutService;
|
use App\Domains\Purchase\Services\Checkout\EditCheckoutService;
|
||||||
use App\Domains\Purchase\Services\Checkout\ReleaseCheckoutService;
|
use App\Domains\Purchase\Services\Checkout\ReleaseCheckoutService;
|
||||||
@@ -69,6 +70,11 @@ class CheckoutService
|
|||||||
return $this->editor->prepareItemEditing($purchase);
|
return $this->editor->prepareItemEditing($purchase);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function removeItem(Purchase $purchase, PurchaseItem $purchaseItem): Purchase
|
||||||
|
{
|
||||||
|
return $this->editor->removeItem($purchase, $purchaseItem);
|
||||||
|
}
|
||||||
|
|
||||||
public function confirmPurchase(Purchase $purchase): void
|
public function confirmPurchase(Purchase $purchase): void
|
||||||
{
|
{
|
||||||
$this->completer->confirm($purchase);
|
$this->completer->confirm($purchase);
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ Implementa el ciclo de compra y checkout: crea la cabecera de compra desde un ca
|
|||||||
- `EditCheckoutService`: modifica los datos del comprador antes del cierre.
|
- `EditCheckoutService`: modifica los datos del comprador antes del cierre.
|
||||||
- `CompleteCheckoutService`: completa, envía a revisión o materializa los `PurchaseItem` al confirmar el pago.
|
- `CompleteCheckoutService`: completa, envía a revisión o materializa los `PurchaseItem` al confirmar el pago.
|
||||||
- `ReleaseCheckoutService`: cancela, vence y procesa vencimientos pendientes.
|
- `ReleaseCheckoutService`: cancela, vence y procesa vencimientos pendientes.
|
||||||
- `SourceCartService`: restaura o finaliza el carrito fuente.
|
- `SourceCartService`: sincroniza o finaliza el carrito de checkout asociado a la compra.
|
||||||
- `CatalogSelectionResolver` y `PurchaseItemSnapshotFactory`: resuelven selecciones y generan snapshots.
|
- `CatalogSelectionResolver` y `PurchaseItemSnapshotFactory`: resuelven selecciones y generan snapshots.
|
||||||
|
|
||||||
Durante `created` y `pending_payment`, `PurchaseResource` publica las líneas del carrito con `items_source=cart`; una compra materializada publica `items_source=purchase`. Los datos descriptivos y económicos del checkout se resuelven siempre desde el catálogo vigente.
|
Durante `created` y `pending_payment`, `PurchaseResource` publica las líneas del carrito con `items_source=cart`; una compra materializada publica `items_source=purchase`. Los datos descriptivos y económicos del checkout se resuelven siempre desde el catálogo vigente.
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ Route::prefix('tenants/{tenant:codigo}')->middleware('auth:sanctum')->group(func
|
|||||||
Route::get('compras/{compra}', [PurchaseController::class, 'show']);
|
Route::get('compras/{compra}', [PurchaseController::class, 'show']);
|
||||||
Route::post('compras/{compra}/edit-items', [PurchaseController::class, 'prepareItemEditing']);
|
Route::post('compras/{compra}/edit-items', [PurchaseController::class, 'prepareItemEditing']);
|
||||||
Route::patch('compras/{compra}/items/{item}', [PurchaseController::class, 'updateItem']);
|
Route::patch('compras/{compra}/items/{item}', [PurchaseController::class, 'updateItem']);
|
||||||
|
Route::delete('compras/{compra}/items/{item}', [PurchaseController::class, 'removeItem']);
|
||||||
Route::patch('compras/{compra}/customer-data', [PurchaseController::class, 'updateCustomerData']);
|
Route::patch('compras/{compra}/customer-data', [PurchaseController::class, 'updateCustomerData']);
|
||||||
Route::post('compras/{compra}/payment-intent', [PurchaseController::class, 'paymentIntent']);
|
Route::post('compras/{compra}/payment-intent', [PurchaseController::class, 'paymentIntent']);
|
||||||
Route::post('compras/{compra}/complete', [PurchaseController::class, 'complete']);
|
Route::post('compras/{compra}/complete', [PurchaseController::class, 'complete']);
|
||||||
|
|||||||
@@ -2,10 +2,12 @@
|
|||||||
|
|
||||||
namespace App\Domains\Sale\Resources\AdminApp;
|
namespace App\Domains\Sale\Resources\AdminApp;
|
||||||
|
|
||||||
|
use App\Domains\Cart\Models\CartItem;
|
||||||
use App\Domains\Purchase\Models\Purchase;
|
use App\Domains\Purchase\Models\Purchase;
|
||||||
use App\Domains\Purchase\Models\PurchaseItem;
|
use App\Domains\Purchase\Models\PurchaseItem;
|
||||||
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 Purchase */
|
/** @mixin Purchase */
|
||||||
class SaleDetailResource extends JsonResource
|
class SaleDetailResource extends JsonResource
|
||||||
@@ -13,23 +15,44 @@ class SaleDetailResource extends JsonResource
|
|||||||
/** @return array<string, mixed> */
|
/** @return array<string, mixed> */
|
||||||
public function toArray(Request $request): array
|
public function toArray(Request $request): array
|
||||||
{
|
{
|
||||||
|
$items = $this->saleItems();
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'id' => $this->id,
|
'id' => $this->id,
|
||||||
'items' => $this->items->map(fn (PurchaseItem $item): array => [
|
'items' => $items->map(fn (PurchaseItem|CartItem $item): array => [
|
||||||
'id' => $item->id,
|
'id' => $item->id,
|
||||||
'product' => $item->item_nombre,
|
'product' => $item instanceof PurchaseItem
|
||||||
|
? $item->item_nombre
|
||||||
|
: $item->selectedItem()?->getName(),
|
||||||
'event_dates' => $this->eventDates($item),
|
'event_dates' => $this->eventDates($item),
|
||||||
'quantity' => (int) $item->cantidad,
|
'quantity' => (int) $item->cantidad,
|
||||||
'unit_price' => $this->formatMoney($item->precio_unitario),
|
'unit_price' => $this->formatMoney($this->unitPrice($item)),
|
||||||
'total' => $this->formatMoney($item->total),
|
'total' => $this->formatMoney($this->lineTotal($item)),
|
||||||
])->values(),
|
])->values(),
|
||||||
'total' => $this->formatMoney($this->total),
|
'total' => $this->formatMoney($this->total),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return list<string> */
|
/** @return Collection<int, PurchaseItem|CartItem> */
|
||||||
private function eventDates(PurchaseItem $item): array
|
private function saleItems(): Collection
|
||||||
{
|
{
|
||||||
|
if ($this->items->isNotEmpty()) {
|
||||||
|
return $this->items;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->cart?->items ?? collect();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return list<string> */
|
||||||
|
private function eventDates(PurchaseItem|CartItem $item): array
|
||||||
|
{
|
||||||
|
if ($item instanceof CartItem) {
|
||||||
|
return $item->variant?->selectedEventDates()
|
||||||
|
->map(fn ($eventDate): string => $eventDate->date->format('Y-m-d'))
|
||||||
|
->values()
|
||||||
|
->all() ?? [];
|
||||||
|
}
|
||||||
|
|
||||||
return collect($item->variant_attributes ?? [])
|
return collect($item->variant_attributes ?? [])
|
||||||
->filter(fn (mixed $attribute): bool => is_array($attribute)
|
->filter(fn (mixed $attribute): bool => is_array($attribute)
|
||||||
&& mb_strtolower(trim((string) ($attribute['name'] ?? ''))) === 'fecha')
|
&& mb_strtolower(trim((string) ($attribute['name'] ?? ''))) === 'fecha')
|
||||||
@@ -43,6 +66,20 @@ class SaleDetailResource extends JsonResource
|
|||||||
->all();
|
->all();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function unitPrice(PurchaseItem|CartItem $item): float|int|string|null
|
||||||
|
{
|
||||||
|
return $item instanceof PurchaseItem
|
||||||
|
? $item->precio_unitario
|
||||||
|
: $item->selectedItem()?->getPrice();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function lineTotal(PurchaseItem|CartItem $item): float|int|string|null
|
||||||
|
{
|
||||||
|
return $item instanceof PurchaseItem
|
||||||
|
? $item->total
|
||||||
|
: ($item->selectedItem()?->getPrice() ?? 0) * $item->cantidad;
|
||||||
|
}
|
||||||
|
|
||||||
private function formatMoney(float|int|string|null $amount): string
|
private function formatMoney(float|int|string|null $amount): string
|
||||||
{
|
{
|
||||||
return number_format((float) ($amount ?? 0), 2, '.', '');
|
return number_format((float) ($amount ?? 0), 2, '.', '');
|
||||||
|
|||||||
@@ -51,7 +51,13 @@ class AdminAppSaleService
|
|||||||
{
|
{
|
||||||
return Purchase::query()
|
return Purchase::query()
|
||||||
->where('tenant_codigo', $tenant->codigo)
|
->where('tenant_codigo', $tenant->codigo)
|
||||||
->with('items')
|
->with([
|
||||||
|
'items',
|
||||||
|
'cart.items.catalogItem',
|
||||||
|
'cart.items.variant.catalogItem',
|
||||||
|
'cart.items.variant.eventDates',
|
||||||
|
'cart.items.variant.eventDate',
|
||||||
|
])
|
||||||
->findOrFail($saleId);
|
->findOrFail($saleId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ use Illuminate\Support\Facades\Schema;
|
|||||||
'dominio',
|
'dominio',
|
||||||
'base_path',
|
'base_path',
|
||||||
'site_title',
|
'site_title',
|
||||||
|
'address',
|
||||||
|
'phone',
|
||||||
'primary_color',
|
'primary_color',
|
||||||
'secondary_color',
|
'secondary_color',
|
||||||
'danger_color',
|
'danger_color',
|
||||||
@@ -46,6 +48,7 @@ use Illuminate\Support\Facades\Schema;
|
|||||||
'display_seach_bar',
|
'display_seach_bar',
|
||||||
'display_cart',
|
'display_cart',
|
||||||
'cart_editing_policy',
|
'cart_editing_policy',
|
||||||
|
'checkout_editing_policy',
|
||||||
'display_cart_item_images',
|
'display_cart_item_images',
|
||||||
'scanner_category_validation_enabled',
|
'scanner_category_validation_enabled',
|
||||||
'event_title',
|
'event_title',
|
||||||
@@ -65,6 +68,7 @@ class Tenant extends Model
|
|||||||
'display_seach_bar' => true,
|
'display_seach_bar' => true,
|
||||||
'display_cart' => true,
|
'display_cart' => true,
|
||||||
'cart_editing_policy' => CartEditingPolicy::Full->value,
|
'cart_editing_policy' => CartEditingPolicy::Full->value,
|
||||||
|
'checkout_editing_policy' => CartEditingPolicy::Disabled->value,
|
||||||
'display_cart_item_images' => true,
|
'display_cart_item_images' => true,
|
||||||
'scanner_category_validation_enabled' => true,
|
'scanner_category_validation_enabled' => true,
|
||||||
];
|
];
|
||||||
@@ -116,6 +120,7 @@ class Tenant extends Model
|
|||||||
'display_seach_bar' => 'boolean',
|
'display_seach_bar' => 'boolean',
|
||||||
'display_cart' => 'boolean',
|
'display_cart' => 'boolean',
|
||||||
'cart_editing_policy' => CartEditingPolicy::class,
|
'cart_editing_policy' => CartEditingPolicy::class,
|
||||||
|
'checkout_editing_policy' => CartEditingPolicy::class,
|
||||||
'display_cart_item_images' => 'boolean',
|
'display_cart_item_images' => 'boolean',
|
||||||
'scanner_category_validation_enabled' => 'boolean',
|
'scanner_category_validation_enabled' => 'boolean',
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -82,6 +82,8 @@ class StoreTenantRequest extends FormRequest
|
|||||||
->where('dominio', $this->input('dominio')),
|
->where('dominio', $this->input('dominio')),
|
||||||
],
|
],
|
||||||
'site_title' => ['sometimes', 'nullable', 'string', 'max:255'],
|
'site_title' => ['sometimes', 'nullable', 'string', 'max:255'],
|
||||||
|
'address' => ['sometimes', 'nullable', 'string', 'max:255'],
|
||||||
|
'phone' => ['sometimes', 'nullable', 'string', 'max:255'],
|
||||||
'primary_color' => ['required', 'string', 'regex:/^#([a-fA-F0-9]{3,4}|[a-fA-F0-9]{6}|[a-fA-F0-9]{8})$/'],
|
'primary_color' => ['required', 'string', 'regex:/^#([a-fA-F0-9]{3,4}|[a-fA-F0-9]{6}|[a-fA-F0-9]{8})$/'],
|
||||||
'secondary_color' => ['required', 'string', 'regex:/^#([a-fA-F0-9]{3,4}|[a-fA-F0-9]{6}|[a-fA-F0-9]{8})$/'],
|
'secondary_color' => ['required', 'string', 'regex:/^#([a-fA-F0-9]{3,4}|[a-fA-F0-9]{6}|[a-fA-F0-9]{8})$/'],
|
||||||
'danger_color' => ['required', 'string', 'regex:/^#([a-fA-F0-9]{3,4}|[a-fA-F0-9]{6}|[a-fA-F0-9]{8})$/'],
|
'danger_color' => ['required', 'string', 'regex:/^#([a-fA-F0-9]{3,4}|[a-fA-F0-9]{6}|[a-fA-F0-9]{8})$/'],
|
||||||
@@ -109,6 +111,7 @@ class StoreTenantRequest extends FormRequest
|
|||||||
'display_seach_bar' => ['sometimes', 'boolean'],
|
'display_seach_bar' => ['sometimes', 'boolean'],
|
||||||
'display_cart' => ['sometimes', 'boolean'],
|
'display_cart' => ['sometimes', 'boolean'],
|
||||||
'cart_editing_policy' => ['sometimes', Rule::enum(CartEditingPolicy::class)],
|
'cart_editing_policy' => ['sometimes', Rule::enum(CartEditingPolicy::class)],
|
||||||
|
'checkout_editing_policy' => ['sometimes', Rule::enum(CartEditingPolicy::class)],
|
||||||
'display_cart_item_images' => ['sometimes', 'boolean'],
|
'display_cart_item_images' => ['sometimes', 'boolean'],
|
||||||
'scanner_category_validation_enabled' => ['sometimes', 'boolean'],
|
'scanner_category_validation_enabled' => ['sometimes', 'boolean'],
|
||||||
'website_type_code' => [
|
'website_type_code' => [
|
||||||
|
|||||||
@@ -103,6 +103,8 @@ class UpdateTenantRequest extends FormRequest
|
|||||||
->ignore($tenant?->id),
|
->ignore($tenant?->id),
|
||||||
],
|
],
|
||||||
'site_title' => ['sometimes', 'nullable', 'string', 'max:255'],
|
'site_title' => ['sometimes', 'nullable', 'string', 'max:255'],
|
||||||
|
'address' => ['sometimes', 'nullable', 'string', 'max:255'],
|
||||||
|
'phone' => ['sometimes', 'nullable', 'string', 'max:255'],
|
||||||
'primary_color' => ['nullable', 'string', 'regex:/^#([a-fA-F0-9]{3,4}|[a-fA-F0-9]{6}|[a-fA-F0-9]{8})$/'],
|
'primary_color' => ['nullable', 'string', 'regex:/^#([a-fA-F0-9]{3,4}|[a-fA-F0-9]{6}|[a-fA-F0-9]{8})$/'],
|
||||||
'secondary_color' => ['nullable', 'string', 'regex:/^#([a-fA-F0-9]{3,4}|[a-fA-F0-9]{6}|[a-fA-F0-9]{8})$/'],
|
'secondary_color' => ['nullable', 'string', 'regex:/^#([a-fA-F0-9]{3,4}|[a-fA-F0-9]{6}|[a-fA-F0-9]{8})$/'],
|
||||||
'danger_color' => ['nullable', 'string', 'regex:/^#([a-fA-F0-9]{3,4}|[a-fA-F0-9]{6}|[a-fA-F0-9]{8})$/'],
|
'danger_color' => ['nullable', 'string', 'regex:/^#([a-fA-F0-9]{3,4}|[a-fA-F0-9]{6}|[a-fA-F0-9]{8})$/'],
|
||||||
@@ -130,6 +132,7 @@ class UpdateTenantRequest extends FormRequest
|
|||||||
'display_seach_bar' => ['sometimes', 'boolean'],
|
'display_seach_bar' => ['sometimes', 'boolean'],
|
||||||
'display_cart' => ['sometimes', 'boolean'],
|
'display_cart' => ['sometimes', 'boolean'],
|
||||||
'cart_editing_policy' => ['sometimes', Rule::enum(CartEditingPolicy::class)],
|
'cart_editing_policy' => ['sometimes', Rule::enum(CartEditingPolicy::class)],
|
||||||
|
'checkout_editing_policy' => ['sometimes', Rule::enum(CartEditingPolicy::class)],
|
||||||
'display_cart_item_images' => ['sometimes', 'boolean'],
|
'display_cart_item_images' => ['sometimes', 'boolean'],
|
||||||
'scanner_category_validation_enabled' => ['sometimes', 'boolean'],
|
'scanner_category_validation_enabled' => ['sometimes', 'boolean'],
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -32,6 +32,8 @@ class TenantResource extends JsonResource
|
|||||||
'site_title' => $this->site_title
|
'site_title' => $this->site_title
|
||||||
?? $this->websiteType?->site_title
|
?? $this->websiteType?->site_title
|
||||||
?? 'ShopitFront',
|
?? 'ShopitFront',
|
||||||
|
'address' => $this->address,
|
||||||
|
'phone' => $this->phone,
|
||||||
'favicon' => ($this->favicon ?? $this->websiteType?->favicon)
|
'favicon' => ($this->favicon ?? $this->websiteType?->favicon)
|
||||||
?->getTemporaryUrl(1440),
|
?->getTemporaryUrl(1440),
|
||||||
'primary_color' => $this->primary_color,
|
'primary_color' => $this->primary_color,
|
||||||
@@ -76,6 +78,7 @@ class TenantResource extends JsonResource
|
|||||||
'display_seach_bar' => $this->display_seach_bar,
|
'display_seach_bar' => $this->display_seach_bar,
|
||||||
'display_cart' => $this->display_cart,
|
'display_cart' => $this->display_cart,
|
||||||
'cart_editing_policy' => CartEditingPolicyResource::make($this->cart_editing_policy),
|
'cart_editing_policy' => CartEditingPolicyResource::make($this->cart_editing_policy),
|
||||||
|
'checkout_editing_policy' => CartEditingPolicyResource::make($this->checkout_editing_policy),
|
||||||
'display_cart_item_images' => $this->display_cart_item_images,
|
'display_cart_item_images' => $this->display_cart_item_images,
|
||||||
'scanner_category_validation_enabled' => $this->scanner_category_validation_enabled,
|
'scanner_category_validation_enabled' => $this->scanner_category_validation_enabled,
|
||||||
'social_media' => $this->whenLoaded(
|
'social_media' => $this->whenLoaded(
|
||||||
|
|||||||
@@ -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('tenants', function (Blueprint $table): void {
|
||||||
|
$table->string('checkout_editing_policy')
|
||||||
|
->default('disabled')
|
||||||
|
->after('cart_editing_policy');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('tenants', function (Blueprint $table): void {
|
||||||
|
$table->dropColumn('checkout_editing_policy');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<?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('tenants', function (Blueprint $table): void {
|
||||||
|
$table->string('address')->nullable()->after('site_title');
|
||||||
|
$table->string('phone')->nullable()->after('address');
|
||||||
|
});
|
||||||
|
|
||||||
|
DB::table('tenants')->update([
|
||||||
|
'address' => 'Av. San Lorenzo 1542, Rosario',
|
||||||
|
'phone' => '54 9 (0341) 6658247',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('tenants', function (Blueprint $table): void {
|
||||||
|
$table->dropColumn(['address', 'phone']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
<?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
|
||||||
|
{
|
||||||
|
Schema::table('featured_groups', function (Blueprint $table): void {
|
||||||
|
$table->string('code')->nullable()->after('tenant_code');
|
||||||
|
});
|
||||||
|
|
||||||
|
$usedCodes = [];
|
||||||
|
|
||||||
|
DB::table('featured_groups')
|
||||||
|
->select(['id', 'tenant_code', 'group_name'])
|
||||||
|
->orderBy('id')
|
||||||
|
->get()
|
||||||
|
->each(function (object $group) use (&$usedCodes): void {
|
||||||
|
$baseCode = Str::slug($group->group_name) ?: "group-{$group->id}";
|
||||||
|
$code = $baseCode;
|
||||||
|
$suffix = 2;
|
||||||
|
|
||||||
|
while (isset($usedCodes[$group->tenant_code][$code])) {
|
||||||
|
$code = "{$baseCode}-{$suffix}";
|
||||||
|
$suffix++;
|
||||||
|
}
|
||||||
|
|
||||||
|
$usedCodes[$group->tenant_code][$code] = true;
|
||||||
|
|
||||||
|
DB::table('featured_groups')
|
||||||
|
->where('id', $group->id)
|
||||||
|
->update(['code' => $code]);
|
||||||
|
});
|
||||||
|
|
||||||
|
Schema::table('featured_groups', function (Blueprint $table): void {
|
||||||
|
$table->string('code')->nullable(false)->change();
|
||||||
|
$table->unique(['tenant_code', 'code']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('featured_groups', function (Blueprint $table): void {
|
||||||
|
$table->dropUnique(['tenant_code', 'code']);
|
||||||
|
$table->dropColumn('code');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -75,6 +75,7 @@ class DesfilePuraTendenciaSeeder extends Seeder
|
|||||||
'display_seach_bar' => false,
|
'display_seach_bar' => false,
|
||||||
'display_cart' => true,
|
'display_cart' => true,
|
||||||
'cart_editing_policy' => 'disabled',
|
'cart_editing_policy' => 'disabled',
|
||||||
|
'checkout_editing_policy' => 'disabled',
|
||||||
'display_cart_item_images' => false,
|
'display_cart_item_images' => false,
|
||||||
'scanner_category_validation_enabled' => false,
|
'scanner_category_validation_enabled' => false,
|
||||||
'website_type_code' => 'onticket',
|
'website_type_code' => 'onticket',
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ class TenantSeeder extends Seeder
|
|||||||
'display_seach_bar' => true,
|
'display_seach_bar' => true,
|
||||||
'display_cart' => true,
|
'display_cart' => true,
|
||||||
'cart_editing_policy' => 'quantity_and_remove',
|
'cart_editing_policy' => 'quantity_and_remove',
|
||||||
|
'checkout_editing_policy' => 'disabled',
|
||||||
'header_logo' => $this->uploadedImage('images/tennants/sonder/sonder_header.png', 'sonder_header.png'),
|
'header_logo' => $this->uploadedImage('images/tennants/sonder/sonder_header.png', 'sonder_header.png'),
|
||||||
'footer_logo' => $this->uploadedImage('images/tennants/sonder/sonder_footer.png', 'sonder_footer.png'),
|
'footer_logo' => $this->uploadedImage('images/tennants/sonder/sonder_footer.png', 'sonder_footer.png'),
|
||||||
'social_media' => self::SOCIAL_MEDIA,
|
'social_media' => self::SOCIAL_MEDIA,
|
||||||
@@ -133,6 +134,7 @@ class TenantSeeder extends Seeder
|
|||||||
'display_seach_bar' => false,
|
'display_seach_bar' => false,
|
||||||
'display_cart' => true,
|
'display_cart' => true,
|
||||||
'cart_editing_policy' => 'full',
|
'cart_editing_policy' => 'full',
|
||||||
|
'checkout_editing_policy' => 'disabled',
|
||||||
'header_logo' => $this->uploadedImage(
|
'header_logo' => $this->uploadedImage(
|
||||||
'images/tennants/fiesta_futbol_infantil/futbol_infantil_header.png',
|
'images/tennants/fiesta_futbol_infantil/futbol_infantil_header.png',
|
||||||
'futbol_infantil_header.png',
|
'futbol_infantil_header.png',
|
||||||
|
|||||||
@@ -81,6 +81,7 @@ class OnTicketFeaturedGroupControllerTest extends TestCase
|
|||||||
'is_featured' => true,
|
'is_featured' => true,
|
||||||
])
|
])
|
||||||
->assertCreated()
|
->assertCreated()
|
||||||
|
->assertJsonPath('data.code', 'food')
|
||||||
->assertJsonPath('data.category_name', 'Food')
|
->assertJsonPath('data.category_name', 'Food')
|
||||||
->assertJsonPath('data.group_name', 'Food')
|
->assertJsonPath('data.group_name', 'Food')
|
||||||
->assertJsonPath('data.is_featured', true)
|
->assertJsonPath('data.is_featured', true)
|
||||||
@@ -96,6 +97,7 @@ class OnTicketFeaturedGroupControllerTest extends TestCase
|
|||||||
]);
|
]);
|
||||||
$this->assertDatabaseHas('featured_groups', [
|
$this->assertDatabaseHas('featured_groups', [
|
||||||
'tenant_code' => $tenant->codigo,
|
'tenant_code' => $tenant->codigo,
|
||||||
|
'code' => 'food',
|
||||||
'source_type' => 'category',
|
'source_type' => 'category',
|
||||||
'category_id' => $categoryId,
|
'category_id' => $categoryId,
|
||||||
'product_layout' => 'row',
|
'product_layout' => 'row',
|
||||||
@@ -130,6 +132,7 @@ class OnTicketFeaturedGroupControllerTest extends TestCase
|
|||||||
'is_featured' => true,
|
'is_featured' => true,
|
||||||
])
|
])
|
||||||
->assertOk()
|
->assertOk()
|
||||||
|
->assertJsonPath('data.code', 'old-name')
|
||||||
->assertJsonPath('data.category_name', 'New name')
|
->assertJsonPath('data.category_name', 'New name')
|
||||||
->assertJsonPath('data.group_name', 'New name')
|
->assertJsonPath('data.group_name', 'New name')
|
||||||
->assertJsonPath('data.is_featured', true)
|
->assertJsonPath('data.is_featured', true)
|
||||||
@@ -142,6 +145,7 @@ class OnTicketFeaturedGroupControllerTest extends TestCase
|
|||||||
]);
|
]);
|
||||||
$this->assertDatabaseHas('featured_groups', [
|
$this->assertDatabaseHas('featured_groups', [
|
||||||
'id' => $group->id,
|
'id' => $group->id,
|
||||||
|
'code' => 'old-name',
|
||||||
'group_name' => 'New name',
|
'group_name' => 'New name',
|
||||||
'product_layout' => 'row',
|
'product_layout' => 'row',
|
||||||
'group_layout' => 'paginated',
|
'group_layout' => 'paginated',
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Feature\Migrations;
|
||||||
|
|
||||||
|
use App\Domains\Tenant\Models\Tenant;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Tests\TestCase;
|
||||||
|
|
||||||
|
class AddCheckoutEditingPolicyToTenantsTest extends TestCase
|
||||||
|
{
|
||||||
|
use RefreshDatabase;
|
||||||
|
|
||||||
|
public function test_it_disables_checkout_editing_for_every_tenant(): void
|
||||||
|
{
|
||||||
|
Tenant::query()->where('codigo', 'sonder')->update([
|
||||||
|
'cart_editing_policy' => 'disabled',
|
||||||
|
]);
|
||||||
|
Tenant::query()->where('codigo', 'fiesta_futbol_infantil')->update([
|
||||||
|
'cart_editing_policy' => 'quantity_and_remove',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$migration = require database_path(
|
||||||
|
'migrations/2026_08_20_000000_add_checkout_editing_policy_to_tenants.php'
|
||||||
|
);
|
||||||
|
|
||||||
|
$migration->down();
|
||||||
|
$migration->up();
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('tenants', [
|
||||||
|
'codigo' => 'sonder',
|
||||||
|
'cart_editing_policy' => 'disabled',
|
||||||
|
'checkout_editing_policy' => 'disabled',
|
||||||
|
]);
|
||||||
|
$this->assertDatabaseHas('tenants', [
|
||||||
|
'codigo' => 'fiesta_futbol_infantil',
|
||||||
|
'cart_editing_policy' => 'quantity_and_remove',
|
||||||
|
'checkout_editing_policy' => 'disabled',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -412,7 +412,7 @@ class StorePurchaseTest extends TestCase
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_it_restores_the_source_cart_when_checkout_is_cancelled(): void
|
public function test_it_releases_and_closes_the_checkout_cart_when_purchase_is_cancelled(): void
|
||||||
{
|
{
|
||||||
$this->createTenant('sonder', 'Sonder', 'sonder.com.ar');
|
$this->createTenant('sonder', 'Sonder', 'sonder.com.ar');
|
||||||
$user = User::factory()->create();
|
$user = User::factory()->create();
|
||||||
@@ -430,11 +430,10 @@ class StorePurchaseTest extends TestCase
|
|||||||
->assertOk()
|
->assertOk()
|
||||||
->assertJsonPath('data.status', Purchase::STATUS_CANCELLED);
|
->assertJsonPath('data.status', Purchase::STATUS_CANCELLED);
|
||||||
|
|
||||||
$this->assertDatabaseHas('carritos', [
|
$this->assertSoftDeleted('carritos', [
|
||||||
'id' => $purchase->cart_id,
|
'id' => $purchase->cart_id,
|
||||||
'user_id' => $user->id,
|
'user_id' => $user->id,
|
||||||
'status' => 'active',
|
'status' => 'converted',
|
||||||
'deleted_at' => null,
|
|
||||||
]);
|
]);
|
||||||
$this->assertDatabaseHas('carrito_items', [
|
$this->assertDatabaseHas('carrito_items', [
|
||||||
'cart_id' => $purchase->cart_id,
|
'cart_id' => $purchase->cart_id,
|
||||||
@@ -444,11 +443,16 @@ class StorePurchaseTest extends TestCase
|
|||||||
]);
|
]);
|
||||||
$this->assertDatabaseHas('inventories', [
|
$this->assertDatabaseHas('inventories', [
|
||||||
'id' => $variant->inventory_id,
|
'id' => $variant->inventory_id,
|
||||||
'reserved_stock' => 3,
|
'reserved_stock' => 0,
|
||||||
|
]);
|
||||||
|
$this->assertDatabaseHas('stock_reservations', [
|
||||||
|
'purchase_id' => $purchase->id,
|
||||||
|
'quantity' => 0,
|
||||||
|
'status' => 'released',
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_it_merges_the_checkout_cart_when_the_user_created_another_active_cart(): void
|
public function test_it_keeps_a_new_active_cart_separate_when_checkout_is_cancelled(): void
|
||||||
{
|
{
|
||||||
$this->createTenant('sonder', 'Sonder', 'sonder.com.ar');
|
$this->createTenant('sonder', 'Sonder', 'sonder.com.ar');
|
||||||
$user = User::factory()->create();
|
$user = User::factory()->create();
|
||||||
@@ -480,11 +484,15 @@ class StorePurchaseTest extends TestCase
|
|||||||
'cart_id' => $activeCartId,
|
'cart_id' => $activeCartId,
|
||||||
'catalog_item_id' => $variant->catalog_item_id,
|
'catalog_item_id' => $variant->catalog_item_id,
|
||||||
'variant_id' => $variant->id,
|
'variant_id' => $variant->id,
|
||||||
'cantidad' => 3,
|
'cantidad' => 1,
|
||||||
|
]);
|
||||||
|
$this->assertSoftDeleted('carritos', [
|
||||||
|
'id' => $purchase->cart_id,
|
||||||
|
'status' => 'converted',
|
||||||
]);
|
]);
|
||||||
$this->assertDatabaseHas('inventories', [
|
$this->assertDatabaseHas('inventories', [
|
||||||
'id' => $variant->inventory_id,
|
'id' => $variant->inventory_id,
|
||||||
'reserved_stock' => 3,
|
'reserved_stock' => 1,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -565,7 +573,8 @@ class StorePurchaseTest extends TestCase
|
|||||||
|
|
||||||
public function test_it_updates_a_checkout_cart_item_quantity_and_its_stock_reservation(): void
|
public function test_it_updates_a_checkout_cart_item_quantity_and_its_stock_reservation(): void
|
||||||
{
|
{
|
||||||
$this->createTenant('sonder', 'Sonder', 'sonder.com.ar');
|
$tenant = $this->createTenant('sonder', 'Sonder', 'sonder.com.ar');
|
||||||
|
$tenant->update(['checkout_editing_policy' => 'full']);
|
||||||
$user = User::factory()->create();
|
$user = User::factory()->create();
|
||||||
$variant = $this->createVariantForTenant('sonder', 10, '50.00');
|
$variant = $this->createVariantForTenant('sonder', 10, '50.00');
|
||||||
$purchase = $this->createCheckoutPurchase($user, 'sonder', $variant, 2);
|
$purchase = $this->createCheckoutPurchase($user, 'sonder', $variant, 2);
|
||||||
@@ -609,10 +618,61 @@ class StorePurchaseTest extends TestCase
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_checkout_cart_editing_uses_checkout_policy_independently_from_cart_policy(): void
|
||||||
|
{
|
||||||
|
$tenant = $this->createTenant('sonder', 'Sonder', 'sonder.com.ar');
|
||||||
|
$tenant->update([
|
||||||
|
'cart_editing_policy' => 'full',
|
||||||
|
'checkout_editing_policy' => 'disabled',
|
||||||
|
]);
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$variant = $this->createVariantForTenant('sonder', 10, '50.00');
|
||||||
|
$purchase = $this->createCheckoutPurchase($user, 'sonder', $variant, 2);
|
||||||
|
$itemId = $purchase->cart->items->firstOrFail()->id;
|
||||||
|
|
||||||
|
$this->actingAs($user, 'sanctum')
|
||||||
|
->patchJson("/api/tenants/sonder/checkout-carts/{$purchase->cart_id}/items/{$itemId}", [
|
||||||
|
'cantidad' => 4,
|
||||||
|
])
|
||||||
|
->assertUnprocessable()
|
||||||
|
->assertJsonValidationErrors('cantidad');
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('carrito_items', [
|
||||||
|
'id' => $itemId,
|
||||||
|
'cantidad' => 2,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_it_removes_an_item_from_the_checkout_cart_when_the_policy_allows_it(): void
|
||||||
|
{
|
||||||
|
$tenant = $this->createTenant('sonder', 'Sonder', 'sonder.com.ar');
|
||||||
|
$tenant->update(['checkout_editing_policy' => 'quantity_and_remove']);
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$variant = $this->createVariantForTenant('sonder', 10, '50.00');
|
||||||
|
$purchase = $this->createCheckoutPurchase($user, 'sonder', $variant, 2);
|
||||||
|
$itemId = $purchase->cart->items->firstOrFail()->id;
|
||||||
|
|
||||||
|
$this->actingAs($user, 'sanctum')
|
||||||
|
->deleteJson("/api/tenants/sonder/checkout-carts/{$purchase->cart_id}/items/{$itemId}")
|
||||||
|
->assertOk()
|
||||||
|
->assertJsonPath('data.items', [])
|
||||||
|
->assertJsonPath('data.subtotal', '0.00');
|
||||||
|
|
||||||
|
$this->assertDatabaseMissing('carrito_items', ['id' => $itemId]);
|
||||||
|
$this->assertDatabaseHas('compras', [
|
||||||
|
'id' => $purchase->id,
|
||||||
|
'total' => '0.00',
|
||||||
|
]);
|
||||||
|
$this->assertDatabaseHas('inventories', [
|
||||||
|
'id' => $variant->inventory_id,
|
||||||
|
'reserved_stock' => 0,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
public function test_it_changes_a_checkout_item_variant_and_moves_its_reservation(): void
|
public function test_it_changes_a_checkout_item_variant_and_moves_its_reservation(): void
|
||||||
{
|
{
|
||||||
$tenant = $this->createTenant('sonder', 'Sonder', 'sonder.com.ar');
|
$tenant = $this->createTenant('sonder', 'Sonder', 'sonder.com.ar');
|
||||||
$tenant->update(['cart_editing_policy' => 'full']);
|
$tenant->update(['checkout_editing_policy' => 'full']);
|
||||||
$user = User::factory()->create();
|
$user = User::factory()->create();
|
||||||
$firstVariant = $this->createVariantForTenant('sonder', 10, '50.00');
|
$firstVariant = $this->createVariantForTenant('sonder', 10, '50.00');
|
||||||
$secondInventory = Inventory::query()->create(['real_stock' => 10]);
|
$secondInventory = Inventory::query()->create(['real_stock' => 10]);
|
||||||
@@ -659,7 +719,7 @@ class StorePurchaseTest extends TestCase
|
|||||||
public function test_it_rejects_checkout_variant_changes_when_the_policy_does_not_allow_them(): void
|
public function test_it_rejects_checkout_variant_changes_when_the_policy_does_not_allow_them(): void
|
||||||
{
|
{
|
||||||
$tenant = $this->createTenant('sonder', 'Sonder', 'sonder.com.ar');
|
$tenant = $this->createTenant('sonder', 'Sonder', 'sonder.com.ar');
|
||||||
$tenant->update(['cart_editing_policy' => 'quantity_and_remove']);
|
$tenant->update(['checkout_editing_policy' => 'quantity_and_remove']);
|
||||||
$user = User::factory()->create();
|
$user = User::factory()->create();
|
||||||
$firstVariant = $this->createVariantForTenant('sonder', 10, '50.00');
|
$firstVariant = $this->createVariantForTenant('sonder', 10, '50.00');
|
||||||
$secondInventory = Inventory::query()->create(['real_stock' => 10]);
|
$secondInventory = Inventory::query()->create(['real_stock' => 10]);
|
||||||
@@ -694,7 +754,7 @@ class StorePurchaseTest extends TestCase
|
|||||||
public function test_checkout_variant_change_rolls_back_when_the_target_has_insufficient_stock(): void
|
public function test_checkout_variant_change_rolls_back_when_the_target_has_insufficient_stock(): void
|
||||||
{
|
{
|
||||||
$tenant = $this->createTenant('sonder', 'Sonder', 'sonder.com.ar');
|
$tenant = $this->createTenant('sonder', 'Sonder', 'sonder.com.ar');
|
||||||
$tenant->update(['cart_editing_policy' => 'full']);
|
$tenant->update(['checkout_editing_policy' => 'full']);
|
||||||
$user = User::factory()->create();
|
$user = User::factory()->create();
|
||||||
$firstVariant = $this->createVariantForTenant('sonder', 10, '50.00');
|
$firstVariant = $this->createVariantForTenant('sonder', 10, '50.00');
|
||||||
$secondInventory = Inventory::query()->create(['real_stock' => 1]);
|
$secondInventory = Inventory::query()->create(['real_stock' => 1]);
|
||||||
@@ -736,7 +796,7 @@ class StorePurchaseTest extends TestCase
|
|||||||
public function test_changing_to_an_existing_checkout_variant_merges_purchase_and_cart_rows(): void
|
public function test_changing_to_an_existing_checkout_variant_merges_purchase_and_cart_rows(): void
|
||||||
{
|
{
|
||||||
$tenant = $this->createTenant('sonder', 'Sonder', 'sonder.com.ar');
|
$tenant = $this->createTenant('sonder', 'Sonder', 'sonder.com.ar');
|
||||||
$tenant->update(['cart_editing_policy' => 'full']);
|
$tenant->update(['checkout_editing_policy' => 'full']);
|
||||||
$user = User::factory()->create();
|
$user = User::factory()->create();
|
||||||
$firstVariant = $this->createVariantForTenant('sonder', 10, '50.00');
|
$firstVariant = $this->createVariantForTenant('sonder', 10, '50.00');
|
||||||
$secondInventory = Inventory::query()->create(['real_stock' => 10]);
|
$secondInventory = Inventory::query()->create(['real_stock' => 10]);
|
||||||
@@ -787,7 +847,8 @@ class StorePurchaseTest extends TestCase
|
|||||||
|
|
||||||
public function test_it_rejects_a_quantity_update_above_the_user_purchase_limit(): void
|
public function test_it_rejects_a_quantity_update_above_the_user_purchase_limit(): void
|
||||||
{
|
{
|
||||||
$this->createTenant('sonder', 'Sonder', 'sonder.com.ar');
|
$tenant = $this->createTenant('sonder', 'Sonder', 'sonder.com.ar');
|
||||||
|
$tenant->update(['checkout_editing_policy' => 'full']);
|
||||||
$user = User::factory()->create();
|
$user = User::factory()->create();
|
||||||
$variant = $this->createVariantForTenant('sonder', 10, '50.00');
|
$variant = $this->createVariantForTenant('sonder', 10, '50.00');
|
||||||
$variant->catalogItem->update(['max_units_per_user' => 3]);
|
$variant->catalogItem->update(['max_units_per_user' => 3]);
|
||||||
@@ -813,7 +874,8 @@ class StorePurchaseTest extends TestCase
|
|||||||
|
|
||||||
public function test_it_invalidates_a_pending_payment_when_the_checkout_cart_changes(): void
|
public function test_it_invalidates_a_pending_payment_when_the_checkout_cart_changes(): void
|
||||||
{
|
{
|
||||||
$this->createTenant('sonder', 'Sonder', 'sonder.com.ar');
|
$tenant = $this->createTenant('sonder', 'Sonder', 'sonder.com.ar');
|
||||||
|
$tenant->update(['checkout_editing_policy' => 'full']);
|
||||||
$user = User::factory()->create();
|
$user = User::factory()->create();
|
||||||
$variant = $this->createVariantForTenant('sonder', 10, '50.00');
|
$variant = $this->createVariantForTenant('sonder', 10, '50.00');
|
||||||
$purchase = $this->createCheckoutPurchase($user, 'sonder', $variant, 2);
|
$purchase = $this->createCheckoutPurchase($user, 'sonder', $variant, 2);
|
||||||
@@ -1015,7 +1077,7 @@ class StorePurchaseTest extends TestCase
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_it_expires_an_abandoned_purchase_and_restores_its_cart(): void
|
public function test_it_expires_an_abandoned_purchase_and_releases_its_checkout_cart(): void
|
||||||
{
|
{
|
||||||
$this->createTenant('sonder', 'Sonder', 'sonder.com.ar');
|
$this->createTenant('sonder', 'Sonder', 'sonder.com.ar');
|
||||||
$user = User::factory()->create();
|
$user = User::factory()->create();
|
||||||
@@ -1041,21 +1103,20 @@ class StorePurchaseTest extends TestCase
|
|||||||
]);
|
]);
|
||||||
$this->assertDatabaseMissing('compra_items', ['compra_id' => $purchase->id]);
|
$this->assertDatabaseMissing('compra_items', ['compra_id' => $purchase->id]);
|
||||||
$this->assertDatabaseHas('stock_reservations', [
|
$this->assertDatabaseHas('stock_reservations', [
|
||||||
'purchase_id' => null,
|
'purchase_id' => $purchase->id,
|
||||||
'quantity' => 3,
|
'quantity' => 0,
|
||||||
'status' => 'active',
|
'status' => 'expired',
|
||||||
]);
|
]);
|
||||||
$this->assertDatabaseHas('inventories', [
|
$this->assertDatabaseHas('inventories', [
|
||||||
'id' => $variant->inventory_id,
|
'id' => $variant->inventory_id,
|
||||||
'real_stock' => 10,
|
'real_stock' => 10,
|
||||||
'reserved_stock' => 3,
|
'reserved_stock' => 0,
|
||||||
'sold_units' => 0,
|
'sold_units' => 0,
|
||||||
]);
|
]);
|
||||||
$this->assertDatabaseHas('carritos', [
|
$this->assertSoftDeleted('carritos', [
|
||||||
'id' => $purchase->cart_id,
|
'id' => $purchase->cart_id,
|
||||||
'user_id' => $user->id,
|
'user_id' => $user->id,
|
||||||
'status' => 'active',
|
'status' => 'converted',
|
||||||
'deleted_at' => null,
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->artisan('reservations:expire')
|
$this->artisan('reservations:expire')
|
||||||
@@ -1064,6 +1125,43 @@ class StorePurchaseTest extends TestCase
|
|||||||
->assertSuccessful();
|
->assertSuccessful();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_it_continues_expiring_purchases_after_an_inconsistent_reservation(): void
|
||||||
|
{
|
||||||
|
$this->createTenant('sonder', 'Sonder', 'sonder.com.ar');
|
||||||
|
$user = User::factory()->create();
|
||||||
|
$variant = $this->createVariantForTenant('sonder', 10, '50.00');
|
||||||
|
$inconsistentPurchase = $this->createCheckoutPurchase($user, 'sonder', $variant, 1);
|
||||||
|
$validPurchase = $this->createCheckoutPurchase($user, 'sonder', $variant, 1);
|
||||||
|
|
||||||
|
$inconsistentPurchase->items()->create([
|
||||||
|
'source_catalog_item_id' => $variant->catalog_item_id,
|
||||||
|
'source_variant_id' => $variant->id,
|
||||||
|
'nombre' => 'Inconsistent item',
|
||||||
|
'slug' => 'inconsistent-item',
|
||||||
|
'cantidad' => 1,
|
||||||
|
'precio_unitario' => '50.00',
|
||||||
|
'discount_total' => '0.00',
|
||||||
|
'tax_total' => '0.00',
|
||||||
|
'total' => '50.00',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->travel(31)->minutes();
|
||||||
|
|
||||||
|
$this->artisan('reservations:expire')
|
||||||
|
->expectsOutput('Expired purchases: 1')
|
||||||
|
->expectsOutput('Expired cart items: 0')
|
||||||
|
->assertSuccessful();
|
||||||
|
|
||||||
|
$this->assertDatabaseHas('compras', [
|
||||||
|
'id' => $inconsistentPurchase->id,
|
||||||
|
'status' => Purchase::STATUS_CREATED,
|
||||||
|
]);
|
||||||
|
$this->assertDatabaseHas('compras', [
|
||||||
|
'id' => $validPurchase->id,
|
||||||
|
'status' => Purchase::STATUS_EXPIRED,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
public function test_purchase_detail_uses_cart_items_for_created_purchase(): void
|
public function test_purchase_detail_uses_cart_items_for_created_purchase(): void
|
||||||
{
|
{
|
||||||
$this->createTenant('sonder', 'Sonder', 'sonder.com.ar');
|
$this->createTenant('sonder', 'Sonder', 'sonder.com.ar');
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ namespace Tests\Feature\Sale;
|
|||||||
use App\Domains\Auth\Models\User;
|
use App\Domains\Auth\Models\User;
|
||||||
use App\Domains\Authorization\Enums\RoleCode;
|
use App\Domains\Authorization\Enums\RoleCode;
|
||||||
use App\Domains\Cart\Models\Cart;
|
use App\Domains\Cart\Models\Cart;
|
||||||
|
use App\Domains\Cart\Models\CartItem;
|
||||||
use App\Domains\Catalog\Models\CatalogItem;
|
use App\Domains\Catalog\Models\CatalogItem;
|
||||||
use App\Domains\Purchase\Events\PurchasePaid;
|
use App\Domains\Purchase\Events\PurchasePaid;
|
||||||
use App\Domains\Purchase\Models\Purchase;
|
use App\Domains\Purchase\Models\Purchase;
|
||||||
@@ -71,6 +72,44 @@ class AdminAppSaleControllerTest extends TestCase
|
|||||||
->assertJsonPath('data.total', '40000.00');
|
->assertJsonPath('data.total', '40000.00');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_an_adminapp_user_can_read_cart_items_from_an_unconfirmed_sale(): void
|
||||||
|
{
|
||||||
|
$tenant = $this->createTenant('acme');
|
||||||
|
Sanctum::actingAs($this->createAdminAppUser($tenant));
|
||||||
|
|
||||||
|
$catalogItem = CatalogItem::query()->create([
|
||||||
|
'tenant_code' => $tenant->codigo,
|
||||||
|
'slug' => 'entrada-general',
|
||||||
|
'nombre' => 'Entrada general',
|
||||||
|
'descripcion' => 'Acceso general',
|
||||||
|
'precio' => '12500.00',
|
||||||
|
]);
|
||||||
|
$cart = Cart::query()->create([
|
||||||
|
'tenant_codigo' => $tenant->codigo,
|
||||||
|
'status' => 'checkout',
|
||||||
|
]);
|
||||||
|
$cartItem = CartItem::query()->create([
|
||||||
|
'cart_id' => $cart->id,
|
||||||
|
'catalog_item_id' => $catalogItem->id,
|
||||||
|
'cantidad' => 2,
|
||||||
|
]);
|
||||||
|
$purchase = Purchase::query()->create([
|
||||||
|
'cart_id' => $cart->id,
|
||||||
|
'tenant_codigo' => $tenant->codigo,
|
||||||
|
'status' => Purchase::STATUS_PENDING_PAYMENT,
|
||||||
|
'total' => '25000.00',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->getJson("/api/v1/adminapp/tenant/sales/{$purchase->id}")
|
||||||
|
->assertOk()
|
||||||
|
->assertJsonPath('data.items.0.id', $cartItem->id)
|
||||||
|
->assertJsonPath('data.items.0.product', 'Entrada general')
|
||||||
|
->assertJsonPath('data.items.0.event_dates', [])
|
||||||
|
->assertJsonPath('data.items.0.quantity', 2)
|
||||||
|
->assertJsonPath('data.items.0.unit_price', '12500.00')
|
||||||
|
->assertJsonPath('data.items.0.total', '25000.00');
|
||||||
|
}
|
||||||
|
|
||||||
public function test_an_adminapp_user_cannot_read_a_sale_from_another_tenant(): void
|
public function test_an_adminapp_user_cannot_read_a_sale_from_another_tenant(): void
|
||||||
{
|
{
|
||||||
$tenant = $this->createTenant('acme');
|
$tenant = $this->createTenant('acme');
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ class DesfilePuraTendenciaSeederTest extends TestCase
|
|||||||
'display_categories' => false,
|
'display_categories' => false,
|
||||||
'display_seach_bar' => false,
|
'display_seach_bar' => false,
|
||||||
'cart_editing_policy' => 'disabled',
|
'cart_editing_policy' => 'disabled',
|
||||||
|
'checkout_editing_policy' => 'disabled',
|
||||||
'display_cart_item_images' => false,
|
'display_cart_item_images' => false,
|
||||||
'site_title' => 'Desfile Pura Tendencia',
|
'site_title' => 'Desfile Pura Tendencia',
|
||||||
]);
|
]);
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ class TenantSeederTest extends TestCase
|
|||||||
|
|
||||||
$this->assertSame('shopit', $sonder->website_type_code);
|
$this->assertSame('shopit', $sonder->website_type_code);
|
||||||
$this->assertSame('quantity_and_remove', $sonder->cart_editing_policy->value);
|
$this->assertSame('quantity_and_remove', $sonder->cart_editing_policy->value);
|
||||||
|
$this->assertSame('disabled', $sonder->checkout_editing_policy->value);
|
||||||
|
|
||||||
$carousel = $sonder->websiteExtras
|
$carousel = $sonder->websiteExtras
|
||||||
->firstWhere('websiteTypeExtra.codigo', 'carousel');
|
->firstWhere('websiteTypeExtra.codigo', 'carousel');
|
||||||
@@ -83,6 +84,7 @@ class TenantSeederTest extends TestCase
|
|||||||
|
|
||||||
$this->assertSame('onticket', $fiesta->website_type_code);
|
$this->assertSame('onticket', $fiesta->website_type_code);
|
||||||
$this->assertSame('full', $fiesta->cart_editing_policy->value);
|
$this->assertSame('full', $fiesta->cart_editing_policy->value);
|
||||||
|
$this->assertSame('disabled', $fiesta->checkout_editing_policy->value);
|
||||||
|
|
||||||
$extras = $fiesta->websiteExtras->keyBy('websiteTypeExtra.codigo');
|
$extras = $fiesta->websiteExtras->keyBy('websiteTypeExtra.codigo');
|
||||||
$this->assertEqualsCanonicalizing(
|
$this->assertEqualsCanonicalizing(
|
||||||
|
|||||||
@@ -59,6 +59,8 @@ class BootstrapTenantControllerTest extends TestCase
|
|||||||
'codigo' => 'acme',
|
'codigo' => 'acme',
|
||||||
'nombre' => 'Acme',
|
'nombre' => 'Acme',
|
||||||
'dominio' => 'acme.com',
|
'dominio' => 'acme.com',
|
||||||
|
'address' => 'Calle Test 123, Rosario',
|
||||||
|
'phone' => '+54 341 555 1234',
|
||||||
'primary_color' => '#ff0000',
|
'primary_color' => '#ff0000',
|
||||||
'secondary_color' => '#00ff00',
|
'secondary_color' => '#00ff00',
|
||||||
'danger_color' => '#0000ff',
|
'danger_color' => '#0000ff',
|
||||||
@@ -74,6 +76,7 @@ class BootstrapTenantControllerTest extends TestCase
|
|||||||
'display_seach_bar' => false,
|
'display_seach_bar' => false,
|
||||||
'display_cart' => false,
|
'display_cart' => false,
|
||||||
'cart_editing_policy' => 'disabled',
|
'cart_editing_policy' => 'disabled',
|
||||||
|
'checkout_editing_policy' => 'quantity_and_remove',
|
||||||
'display_cart_item_images' => false,
|
'display_cart_item_images' => false,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@@ -83,6 +86,8 @@ class BootstrapTenantControllerTest extends TestCase
|
|||||||
->assertOk()
|
->assertOk()
|
||||||
->assertJsonPath('data.codigo', 'acme')
|
->assertJsonPath('data.codigo', 'acme')
|
||||||
->assertJsonPath('data.dominio', 'acme.com')
|
->assertJsonPath('data.dominio', 'acme.com')
|
||||||
|
->assertJsonPath('data.address', 'Calle Test 123, Rosario')
|
||||||
|
->assertJsonPath('data.phone', '+54 341 555 1234')
|
||||||
->assertJsonPath('data.primary_color', '#ff0000')
|
->assertJsonPath('data.primary_color', '#ff0000')
|
||||||
->assertJsonPath('data.secondary_color', '#00ff00')
|
->assertJsonPath('data.secondary_color', '#00ff00')
|
||||||
->assertJsonPath('data.danger_color', '#0000ff')
|
->assertJsonPath('data.danger_color', '#0000ff')
|
||||||
@@ -96,6 +101,11 @@ class BootstrapTenantControllerTest extends TestCase
|
|||||||
->assertJsonPath('data.cart_editing_policy.allow_delete', false)
|
->assertJsonPath('data.cart_editing_policy.allow_delete', false)
|
||||||
->assertJsonPath('data.cart_editing_policy.allow_update_quantity', false)
|
->assertJsonPath('data.cart_editing_policy.allow_update_quantity', false)
|
||||||
->assertJsonPath('data.cart_editing_policy.allow_update_variant', false)
|
->assertJsonPath('data.cart_editing_policy.allow_update_variant', false)
|
||||||
|
->assertJsonPath('data.checkout_editing_policy.code', 'quantity_and_remove')
|
||||||
|
->assertJsonPath('data.checkout_editing_policy.allow_modify', true)
|
||||||
|
->assertJsonPath('data.checkout_editing_policy.allow_delete', true)
|
||||||
|
->assertJsonPath('data.checkout_editing_policy.allow_update_quantity', true)
|
||||||
|
->assertJsonPath('data.checkout_editing_policy.allow_update_variant', false)
|
||||||
->assertJsonPath('data.display_cart_item_images', false)
|
->assertJsonPath('data.display_cart_item_images', false)
|
||||||
->assertJsonPath('data.header_bg_color', '#ffffff')->assertJsonPath('data.footer_bg_color', '#ffffff');
|
->assertJsonPath('data.header_bg_color', '#ffffff')->assertJsonPath('data.footer_bg_color', '#ffffff');
|
||||||
|
|
||||||
@@ -763,6 +773,7 @@ class BootstrapTenantControllerTest extends TestCase
|
|||||||
$response = $this->putJson("/api/tenants/{$tenant->codigo}", [
|
$response = $this->putJson("/api/tenants/{$tenant->codigo}", [
|
||||||
'primary_color' => '#000000',
|
'primary_color' => '#000000',
|
||||||
'cart_editing_policy' => 'quantity_and_remove',
|
'cart_editing_policy' => 'quantity_and_remove',
|
||||||
|
'checkout_editing_policy' => 'disabled',
|
||||||
'display_cart_item_images' => false,
|
'display_cart_item_images' => false,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@@ -776,6 +787,8 @@ class BootstrapTenantControllerTest extends TestCase
|
|||||||
->assertJsonPath('data.cart_editing_policy.allow_delete', true)
|
->assertJsonPath('data.cart_editing_policy.allow_delete', true)
|
||||||
->assertJsonPath('data.cart_editing_policy.allow_update_quantity', true)
|
->assertJsonPath('data.cart_editing_policy.allow_update_quantity', true)
|
||||||
->assertJsonPath('data.cart_editing_policy.allow_update_variant', false)
|
->assertJsonPath('data.cart_editing_policy.allow_update_variant', false)
|
||||||
|
->assertJsonPath('data.checkout_editing_policy.code', 'disabled')
|
||||||
|
->assertJsonPath('data.checkout_editing_policy.allow_modify', false)
|
||||||
->assertJsonPath('data.display_cart_item_images', false);
|
->assertJsonPath('data.display_cart_item_images', false);
|
||||||
|
|
||||||
$this->assertDatabaseHas('tenants', [
|
$this->assertDatabaseHas('tenants', [
|
||||||
@@ -784,6 +797,7 @@ class BootstrapTenantControllerTest extends TestCase
|
|||||||
'nombre' => 'Acme',
|
'nombre' => 'Acme',
|
||||||
'primary_color' => '#000000',
|
'primary_color' => '#000000',
|
||||||
'cart_editing_policy' => 'quantity_and_remove',
|
'cart_editing_policy' => 'quantity_and_remove',
|
||||||
|
'checkout_editing_policy' => 'disabled',
|
||||||
'display_cart_item_images' => false,
|
'display_cart_item_images' => false,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
namespace Tests\Unit\Sale;
|
namespace Tests\Unit\Sale;
|
||||||
|
|
||||||
|
use App\Domains\Cart\Models\Cart;
|
||||||
|
use App\Domains\Cart\Models\CartItem;
|
||||||
|
use App\Domains\Catalog\Models\CatalogItem;
|
||||||
use App\Domains\Purchase\Models\Purchase;
|
use App\Domains\Purchase\Models\Purchase;
|
||||||
use App\Domains\Purchase\Models\PurchaseItem;
|
use App\Domains\Purchase\Models\PurchaseItem;
|
||||||
use App\Domains\Sale\Resources\AdminApp\SaleDetailResource;
|
use App\Domains\Sale\Resources\AdminApp\SaleDetailResource;
|
||||||
@@ -38,4 +41,39 @@ class SaleDetailResourceTest extends TestCase
|
|||||||
$this->assertSame('30000.00', $data['items'][0]['total']);
|
$this->assertSame('30000.00', $data['items'][0]['total']);
|
||||||
$this->assertSame('30000.00', $data['total']);
|
$this->assertSame('30000.00', $data['total']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_it_uses_the_associated_cart_items_when_the_purchase_has_no_items(): void
|
||||||
|
{
|
||||||
|
$catalogItem = (new CatalogItem)->forceFill([
|
||||||
|
'id' => 21,
|
||||||
|
'nombre' => 'Entrada general',
|
||||||
|
'precio' => '12500.00',
|
||||||
|
]);
|
||||||
|
$cartItem = (new CartItem)->forceFill([
|
||||||
|
'id' => 34,
|
||||||
|
'catalog_item_id' => $catalogItem->id,
|
||||||
|
'cantidad' => 2,
|
||||||
|
]);
|
||||||
|
$cartItem->setRelation('catalogItem', $catalogItem);
|
||||||
|
$cartItem->setRelation('variant', null);
|
||||||
|
|
||||||
|
$cart = new Cart;
|
||||||
|
$cart->setRelation('items', collect([$cartItem]));
|
||||||
|
|
||||||
|
$purchase = (new Purchase)->forceFill([
|
||||||
|
'id' => 16,
|
||||||
|
'total' => '25000.00',
|
||||||
|
]);
|
||||||
|
$purchase->setRelation('items', collect());
|
||||||
|
$purchase->setRelation('cart', $cart);
|
||||||
|
|
||||||
|
$data = (new SaleDetailResource($purchase))->resolve(Request::create('/'));
|
||||||
|
|
||||||
|
$this->assertSame(34, $data['items'][0]['id']);
|
||||||
|
$this->assertSame('Entrada general', $data['items'][0]['product']);
|
||||||
|
$this->assertSame([], $data['items'][0]['event_dates']);
|
||||||
|
$this->assertSame(2, $data['items'][0]['quantity']);
|
||||||
|
$this->assertSame('12500.00', $data['items'][0]['unit_price']);
|
||||||
|
$this->assertSame('25000.00', $data['items'][0]['total']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user