Merge branch 'some-fixes' into 'nettoyage'

Some fixes

See merge request ldc-web/projets/boutique-cnc!23
This commit is contained in:
Vincent BRIDIER 2025-06-27 09:22:28 +00:00
commit dfc999b9a9
17 changed files with 801 additions and 1008 deletions

View file

@ -65,7 +65,7 @@ class OrderController extends Controller
'reference',
'email',
);
}//end if
} //end if
$this->sortQuery($orders);
$searchFields = trans('Réference,Email,Pay.Ref');
@ -136,7 +136,7 @@ class OrderController extends Controller
return \back()->with('bo.errors', \trans('Il faut choisir un statut pour cette commande.'));
default:
throw new \RuntimeException("Unhandled status `{$request->validation_status}`");
}//end switch
} //end switch
});
}
@ -171,7 +171,7 @@ class OrderController extends Controller
->where('payment_mode', PaymentModeEnum::inShop())
->latest()->first();
$paidTransactions = $order->transactions()->where('type', TransactionType::debit())
->where('status', TransactionStatus::validated())->count();
->where('status', TransactionStatus::validated())->count();
// * Check if there are not paid transactions then
// * we should have one pending inShop transaction.
if (!$paidTransactions and !$inShopTransaction) {
@ -196,7 +196,7 @@ class OrderController extends Controller
));
default:
throw new \RuntimeException("Unhandled status `{$request->delivery_status}`");
}//end switch
} //end switch
});
}
@ -289,11 +289,11 @@ class OrderController extends Controller
} //end if
$transaction->items = $refundedTransactionsItems->map(function (object $basketItem) {
$basketItem->tax = $basketItem->tax * -1;
$basketItem->price = $basketItem->price * -1;
$basketItem->subtotal = $basketItem->subtotal * -1;
$basketItem->options->price_ttc = $basketItem->options->price_ttc * -1;
$basketItem->options->undiscounted_price_ttc =
$basketItem->tax = $basketItem->tax * -1;
$basketItem->price = $basketItem->price * -1;
$basketItem->subtotal = $basketItem->subtotal * -1;
$basketItem->options->price_ttc = $basketItem->options->price_ttc * -1;
$basketItem->options->undiscounted_price_ttc =
$basketItem->options->undiscounted_price_ttc * -1;
return $basketItem;
});
@ -302,9 +302,11 @@ class OrderController extends Controller
// ? The resolution means a complete refund ?
if ($order->isCompleteRefundWithTransaction($transaction)) {
// * Calculate unrefunded tax
$unRefundedTax = \abs(\intval(\collect($order->getRemainingUnrefundedItems())->sum(function (object $item) {
return $item->tax * $item->qty;
})));
$unRefundedTax = \abs(
\intval(\collect($order->getRemainingUnrefundedItems())->sum(function (object $item) {
return $item->tax * $item->qty;
}))
);
// * Calculate justified items tax
$justifiedItemTax = \abs(\intval(\collect($transaction->items)->sum(function (object $item) {
@ -448,11 +450,11 @@ class OrderController extends Controller
$order->total_ttc - $order->total_refund,
// * Negate all items prices (already refunded)
$order->getRemainingUnrefundedItems()->map(function (object $basketItem) {
$basketItem->tax = $basketItem->tax * -1;
$basketItem->price = $basketItem->price * -1;
$basketItem->subtotal = $basketItem->subtotal * -1;
$basketItem->options->price_ttc = $basketItem->options->price_ttc * -1;
$basketItem->options->undiscounted_price_ttc =
$basketItem->tax = $basketItem->tax * -1;
$basketItem->price = $basketItem->price * -1;
$basketItem->subtotal = $basketItem->subtotal * -1;
$basketItem->options->price_ttc = $basketItem->options->price_ttc * -1;
$basketItem->options->undiscounted_price_ttc =
$basketItem->options->undiscounted_price_ttc * -1;
return $basketItem;
})
@ -482,11 +484,11 @@ class OrderController extends Controller
$refundedTransactionsItems->sum('subtotal'),
// * Negate all items prices (already refunded)
$refundedTransactionsItems->map(function (object $basketItem) {
$basketItem->tax = $basketItem->tax * -1;
$basketItem->price = $basketItem->price * -1;
$basketItem->subtotal = $basketItem->subtotal * -1;
$basketItem->options->price_ttc = $basketItem->options->price_ttc * -1;
$basketItem->options->undiscounted_price_ttc =
$basketItem->tax = $basketItem->tax * -1;
$basketItem->price = $basketItem->price * -1;
$basketItem->subtotal = $basketItem->subtotal * -1;
$basketItem->options->price_ttc = $basketItem->options->price_ttc * -1;
$basketItem->options->undiscounted_price_ttc =
$basketItem->options->undiscounted_price_ttc * -1;
return $basketItem;
})

View file

@ -24,6 +24,7 @@ use App\Models\Customer\Customer;
use App\Models\Payment\Transaction;
use App\Models\Shop\DeliveryMode;
use App\Models\Shop\Order;
use App\Models\Shop\PaymentMode;
use App\Models\Shop\Shop;
use App\Models\Shop\Timeslot;
use Carbon\Carbon;
@ -224,11 +225,11 @@ class OrderController extends Controller
/** @var \App\Models\Customer\Customer */
$customer = auth('frontend')->user();
return \view('theme::pages.order-tunnel.shipping', [
'order' => $order, 'customer_info' => $customer->api_data
]);
'order' => $order, 'customer_info' => $customer->api_data
]);
default:
throw new \RuntimeException('Unhandled delivery mode ');
}//end switch
} //end switch
throw new \RuntimeException('This should never happen');
}
@ -430,12 +431,12 @@ class OrderController extends Controller
// * Get Transaction
$transaction = clone (Transaction::getCurrentTransaction() ??
Transaction::getNewInstance(
$paymentMode,
TransactionType::debit(),
$order->basket,
$order->total_ttc,
));
Transaction::getNewInstance(
$paymentMode,
TransactionType::debit(),
$order->basket,
$order->total_ttc,
));
if ($transaction->exists) {
$transaction->refresh();
}
@ -476,7 +477,7 @@ class OrderController extends Controller
Transaction::query()->whereHas('order', function (Builder $q) use ($order) {
$q->where('id', $order->id);
})->where('status', TransactionStatus::pending())->where('id', '!=', $transaction->id)
->where('payment_mode', PaymentModeEnum::inShop())->delete();
->where('payment_mode', PaymentModeEnum::inShop())->delete();
}
// * If payment mode is boutique just use the previous transaction if there was one.
@ -513,7 +514,7 @@ class OrderController extends Controller
*/
private function checkoutSucceeded(): \Closure
{
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed, Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed
return function (Customer $customer, Order $order, Transaction $transaction): void {
// * Associate transaction to order
$transaction->order()->associate($order);
@ -556,16 +557,16 @@ class OrderController extends Controller
if (!$customer or !$order or !$sessionTransaction) {
\redirect()->route('order-tunnel.review')
->with('warning', trans('La session est requise'))
->throwResponse();
->with('warning', trans('La session est requise'))
->throwResponse();
}
// ? Mismatch between url transaction and session transaction ?
// * Needed for stripe IP in route anyway.
if ($sessionTransaction->id !== $transaction->id) {
\redirect()->route('order-tunnel.review')
->with('error', trans('Erreur mauvaise transaction'))
->throwResponse();
->with('error', trans('Erreur mauvaise transaction'))
->throwResponse();
}
// * Force clone here to prevent session save model state (If something goes wrong).
@ -607,8 +608,8 @@ class OrderController extends Controller
$this->assertDoesHaveCurrentTransaction();
if (!$this->checkThatActualProcessStepIs(OrderProcess::paymentReview())) {
\redirect()->route('order-tunnel.review')
->with('warning', trans('Étape précédente requise'))
->throwResponse();
->with('warning', trans('Étape précédente requise'))
->throwResponse();
}
return DB::transaction(function () {
@ -633,8 +634,8 @@ class OrderController extends Controller
!$transaction->status->equals(TransactionStatus::validated())
) {
\redirect()->route('order-tunnel.review')
->with('error', trans('Le payment n\'as pu être validé'))
->throwResponse();
->with('error', trans('Le payment n\'as pu être validé'))
->throwResponse();
}
if ($transaction->payment_mode->equals(PaymentModeEnum::stripe())) {
@ -745,8 +746,8 @@ class OrderController extends Controller
if (!$basket->count()) {
\redirect()->route('home')
->with('warning', trans('Vous n\'avez aucun produit dans votre panier'))
->throwResponse();
->with('warning', trans('Vous n\'avez aucun produit dans votre panier'))
->throwResponse();
}
}
@ -768,8 +769,8 @@ class OrderController extends Controller
if ($session_finger_print !== $actual_finger_print) {
$this->allowTimeSlotSelect(true);
\redirect()->route('order-tunnel.basket.recap')
->with('warning', trans('Votre panier à été modifié'))
->throwResponse();
->with('warning', trans('Votre panier à été modifié'))
->throwResponse();
}
}
@ -790,9 +791,9 @@ class OrderController extends Controller
});
if ($sampleOrder->total_ttc < $minAmountForTransaction) {
\redirect()->route('home')
->with('warning', trans('Le montant minimal pour une commande est de :minAmount', [
'minAmount' => ToolboxHelper::fmtCurrency($minAmountForTransaction)
]))->throwResponse();
->with('warning', trans('Le montant minimal pour une commande est de :minAmount', [
'minAmount' => ToolboxHelper::fmtCurrency($minAmountForTransaction)
]))->throwResponse();
}
}
@ -811,8 +812,8 @@ class OrderController extends Controller
)
) {
\redirect()->route('order-tunnel.review')
->with('warning', trans('La transaction a échoué'))
->throwResponse();
->with('warning', trans('La transaction a échoué'))
->throwResponse();
}
}
@ -827,8 +828,8 @@ class OrderController extends Controller
if (!Gate::check('orderUsingDeliveryMode', $order)) {
$this->allowTimeSlotSelect(true);
\redirect()->route('order-tunnel.shipping-mode')
->with('warning', trans('Le mode de livraison n\'est pas disponible'))
->throwResponse();
->with('warning', trans('Le mode de livraison n\'est pas disponible'))
->throwResponse();
}
}

View file

@ -29,7 +29,7 @@ class ChangeOrderDeliveryStatusRequest extends FormRequest
'delivery_status' => [
'required',
new EnumIsValidRule(DeliveryStatus::class),
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed, Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed
function ($attribute, $value, $fail) {
$deliveryStatus = DeliveryStatus::make(\intval($this->delivery_status));
// * Ignorer commande en préparation.

View file

@ -95,7 +95,7 @@ class ResolveOrderRequest extends FormRequest
'items' => 'present',
'items.*' => 'array',
'items.*.index' => [
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed, Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed
'required', function ($attribute, $inputValue, $fail) {
if (!$this->transactionModel) {
return;

View file

@ -61,7 +61,7 @@ class StoreSlideRequest extends FormRequest
return \array_merge([
'title' => 'required|string|min:3|max:25',
'text' => [
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed, Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed
'nullable', 'string', function ($attribute, $value, $fail) {
$max = 170;
if ((\strlen(\strip_tags($value)) - 1) > $max) {

View file

@ -70,7 +70,7 @@ class UpdateTimeslotRequest extends FormRequest
// phpcs:ignore Generic.Files.LineLength.TooLong
'required_with_all:plages.*.morning_start,plages.*.morning_end,plages.*.afternoon_start,plages.*.afternoon_end',
'regex:/[0-9]{2}\:[0-9]{2}/',
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed, Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed
function ($attribute, $value, $fail) {
try {
$interval = CarbonInterval::createFromFormat('h:i', $value);

View file

@ -31,7 +31,7 @@ class ContactFormRequest extends FormRequest
'subject' => 'required|min:2|max:255',
'email' => 'required|email:rfc,dns,spoof|max:255',
'message' => 'required|min:20|max:1900',
'order_number' => 'nullable|max:255',
'order_number' => 'nullable|integer',
'file' => 'nullable|mimes:jpg,jpeg,png,pdf|max:2048',
'ok_cgv' => 'accepted',
];

View file

@ -52,7 +52,7 @@ class CreateAccountRequest extends FormRequest
'email' => [
'required', 'email:rfc,dns,spoof', 'max:255',
// * Does email already exists in CRM ?
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed, Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed
function (string $attribute, $value, \Closure $fail) {
if (CrmCustomer::findWithEmail(\strval($value))) {
$fail('Un compte existe déjà avec cette adresse.');

View file

@ -35,7 +35,7 @@ class UpdateEmailRequest extends FormRequest
'email' => [
'required', 'email:rfc,dns,spoof', 'max:255', 'unique:customers,email',
// * Does email already exists in CRM ?
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed, Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed
function (string $attribute, $value, \Closure $fail) {
if (CrmCustomer::findWithEmail(\strval($value))) {
$fail('Un compte existe déjà avec cette adresse.');

View file

@ -49,7 +49,7 @@ class CheckoutRequest extends FormRequest
return [
'mode' => [
'required', new EnumIsValidRule(PaymentModeEnum::class),
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed, Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed
function ($attribute, $value, $fail) {
if (!$this->modeEnum or !Gate::check('isAvailable', [PaymentMode::class, $this->modeEnum])) {
$fail(\trans('Ce mode de paiement n\'est pas disponible.'));

View file

@ -37,7 +37,7 @@ class ShippingModeFormRequest extends FormRequest
return [
'mode' => [
'required', new EnumIsValidRule(DeliveryModeEnum::class),
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed, Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed
function ($attribute, $value, $fail) use ($mode) {
if (!DeliveryMode::availables()->where('mode', $mode)->first()) {
$fail(trans('Mode de livraison non disponible'));

1561
composer.lock generated

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,41 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
if (!Schema::hasTable('customers')) {
Schema::create('customers', function (Blueprint $table) {
$table->id();
$table->bigInteger('crm_id')->unsigned()->unique();
$table->string('email')->unique();
$table->string('hashcode')->unique();
$table->rememberToken();
$table->timestamps();
});
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('customers');
}
};

View file

@ -1,40 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
// @phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
class CreateCustomersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('customers', function (Blueprint $table) {
$table->id();
$table->bigInteger('crm_id')->unsigned()->unique();
$table->string('email')->unique();
$table->string('hashcode')->unique();
$table->rememberToken();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('customers');
}
}

View file

@ -38,7 +38,7 @@ class FixDatabaseEncode extends Migration
$databaseName = config("database.connections.{$defaultConnection}.database");
// Change default charset and collation.
DB::unprepared("ALTER SCHEMA {$databaseName} DEFAULT CHARACTER SET {$charset} DEFAULT COLLATE {$collation};");
DB::unprepared("ALTER SCHEMA `{$databaseName}` DEFAULT CHARACTER SET {$charset} DEFAULT COLLATE {$collation};");
// Get the list of all tables.
$tableNames = DB::table('information_schema.tables')
@ -46,7 +46,7 @@ class FixDatabaseEncode extends Migration
// Iterate through the list and alter each table.
foreach ($tableNames as $tableName) {
DB::unprepared("ALTER TABLE {$tableName} CONVERT TO CHARACTER SET {$charset} COLLATE {$collation};");
DB::unprepared("ALTER TABLE `{$tableName}` CONVERT TO CHARACTER SET {$charset} COLLATE {$collation};");
}
// Get the list of all columns that have a collation.
@ -66,7 +66,7 @@ class FixDatabaseEncode extends Migration
$null = 'NOT NULL';
}
$sql = "ALTER TABLE {$tableName}
$sql = "ALTER TABLE `{$tableName}`
CHANGE `{$columnName}` `{$columnName}`
{$columnType}
CHARACTER SET {$charset}

View file

@ -14,6 +14,8 @@ class AddShowBannerToStaticPages extends Migration
public function up()
{
Schema::table('static_pages', function (Blueprint $table) {
$table->boolean('show_title')->after('title')
->comment('Afficher le titre ou non en front');
$table->boolean('show_banner')->after('show_title')
->comment('Afficher la banniere ou non en front');
});
@ -28,6 +30,7 @@ class AddShowBannerToStaticPages extends Migration
{
Schema::table('static_pages', function (Blueprint $table) {
$table->dropColumn('show_banner');
$table->dropColumn('show_title');
});
}
}

View file

@ -1,33 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddShowTitleToStaticPages extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('static_pages', function (Blueprint $table) {
$table->boolean('show_title')->after('title')
->comment('Afficher le titre ou non en front');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('static_pages', function (Blueprint $table) {
$table->dropColumn('show_title');
});
}
}