Compare commits
101 commits
evolutionV
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
972ce0cf6f | ||
|
|
033ce42b42 | ||
|
|
481b39d856 | ||
|
|
262ea2871c | ||
|
|
8ba5feff18 | ||
|
|
a247dba2b2 | ||
|
|
4873cd7fc2 | ||
|
|
69ce45d5cb | ||
|
|
a6d0e1ae2d | ||
|
|
d8464a34ac | ||
|
|
4359c85b8c | ||
|
|
7ba2c3b2fe | ||
|
|
1f235efebe | ||
|
|
6eef17a390 | ||
|
|
5872d670fe | ||
|
|
0c22695c77 | ||
|
|
1aceb54b0e | ||
|
|
e9085b681a | ||
|
|
e8d1669bae | ||
|
|
9e7fad8ebb | ||
|
|
6b3145eb8f | ||
|
|
30e53b81b3 | ||
|
|
1cca69c933 | ||
|
|
11dad23fe2 | ||
|
|
9b5a68c121 | ||
|
|
6f14d1d975 | ||
|
|
039587d1e3 | ||
|
|
825d47797b | ||
|
|
e1820ba1ac | ||
|
|
b72988b20c | ||
|
|
8235f134cf | ||
|
|
3000e1663f | ||
|
|
f30c6cff18 | ||
|
|
d48c9aa99b | ||
|
|
64868010d4 | ||
|
|
b7c0e12429 | ||
|
|
2d65de573c | ||
|
|
2534188942 | ||
|
|
16213ac4e4 | ||
|
|
6e359d3c41 | ||
|
|
1d2300ba57 | ||
|
|
1fc4d97657 | ||
|
|
4bbb98e3c8 | ||
|
|
80d426f470 | ||
|
|
78b5a223a7 | ||
|
|
7ffa7f67a6 | ||
|
|
3ee9fa91dc | ||
|
|
02da9c7b7d | ||
|
|
b932825760 | ||
|
|
869c56445c | ||
|
|
7d593ec5ac | ||
|
|
02cfc1982b | ||
|
|
3e9428d122 | ||
|
|
e4f00ae71c | ||
|
|
2bb67dd42d | ||
|
|
89fd1b8516 | ||
|
|
ce21e69af8 | ||
|
|
25783cdd77 | ||
|
|
31fed252d6 | ||
|
|
e26f3afb69 | ||
|
|
3b77148e72 | ||
|
|
27f02c7b89 | ||
|
|
fd1bdc1222 | ||
|
|
8bf0255747 | ||
|
|
69af67ff83 | ||
|
|
bc3be757d6 | ||
|
|
ee894b925a | ||
|
|
50a3495ee1 | ||
|
|
6a8676600f | ||
|
|
5ade814cb5 | ||
|
|
01979430fa | ||
|
|
652d8430f5 | ||
|
|
b7786019df | ||
|
|
9db7691ac2 | ||
|
|
a20816e0bf | ||
|
|
351023e4d3 | ||
|
|
81db3a3a92 | ||
|
|
6edb8757f3 | ||
|
|
68e3e47a5c | ||
|
|
9b0e1db5d1 | ||
|
|
0d3d61877b | ||
|
|
4efed5f5b3 | ||
|
|
ec49fd6e8d | ||
|
|
a7882b75bd | ||
|
|
5cf76c2f0d | ||
|
|
2328c79611 | ||
|
|
31e6752a17 | ||
|
|
a5ca89e3b2 | ||
|
|
2cc5215e2a | ||
|
|
b962678684 | ||
|
|
c33b3c55b5 | ||
|
|
9f8b28e64f | ||
|
|
0a33c08c6e | ||
|
|
d4860ac6dc | ||
|
|
5f2edbec2c | ||
|
|
c4cb2da2af | ||
|
|
1b2dc4b34f | ||
|
|
a3ebe93e90 | ||
|
|
ee4f404328 | ||
|
|
ce39a598f3 | ||
|
|
d5722b5835 |
176 changed files with 6438 additions and 87653 deletions
43
.env.example
43
.env.example
|
|
@ -1,19 +1,19 @@
|
|||
APP_NAME=Laravel
|
||||
APP_NAME="ENV-Boutique LDC"
|
||||
APP_ENV=local
|
||||
APP_KEY=
|
||||
APP_DEBUG=true
|
||||
APP_URL=http://localhost
|
||||
APP_URL=
|
||||
APP_THEME=basic
|
||||
|
||||
LOG_CHANNEL=stack
|
||||
LOG_CHANNEL=daily
|
||||
LOG_LEVEL=debug
|
||||
|
||||
DB_CONNECTION=mysql
|
||||
DB_HOST=127.0.0.1
|
||||
DB_HOST=dev-mariadb
|
||||
DB_PORT=3306
|
||||
DB_DATABASE=laravel
|
||||
DB_DATABASE=
|
||||
DB_USERNAME=root
|
||||
DB_PASSWORD=
|
||||
DB_PASSWORD=secret
|
||||
|
||||
BROADCAST_DRIVER=log
|
||||
CACHE_DRIVER=file
|
||||
|
|
@ -21,28 +21,23 @@ QUEUE_CONNECTION=sync
|
|||
SESSION_DRIVER=file
|
||||
SESSION_LIFETIME=120
|
||||
|
||||
REDIS_HOST=127.0.0.1
|
||||
REDIS_PASSWORD=null
|
||||
REDIS_PORT=6379
|
||||
|
||||
MAIL_MAILER=smtp
|
||||
MAIL_HOST=smtp.mailtrap.io
|
||||
MAIL_PORT=2525
|
||||
MAIL_HOST=dev-mailhog
|
||||
MAIL_PORT=1025
|
||||
MAIL_USERNAME=null
|
||||
MAIL_PASSWORD=null
|
||||
MAIL_ENCRYPTION=null
|
||||
MAIL_FROM_ADDRESS=null
|
||||
MAIL_FROM_ADDRESS=equipe.web@ldc.fr
|
||||
MAIL_FROM_NAME="${APP_NAME}"
|
||||
|
||||
AWS_ACCESS_KEY_ID=
|
||||
AWS_SECRET_ACCESS_KEY=
|
||||
AWS_DEFAULT_REGION=us-east-1
|
||||
AWS_BUCKET=
|
||||
MAIL_LIST_SERVICEWEB=equipe.web@ldc.fr
|
||||
MAIL_LIST_INVALIDINCO=equipe.web@ldc.fr,vincent.pierre@ldc.fr,christelle.manceau@ldc.fr
|
||||
|
||||
PUSHER_APP_ID=
|
||||
PUSHER_APP_KEY=
|
||||
PUSHER_APP_SECRET=
|
||||
PUSHER_APP_CLUSTER=mt1
|
||||
|
||||
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
|
||||
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
|
||||
# CRM
|
||||
CRM_ENDPOINT=https://ldcldccrm:K5cJmTsG@dev.ldc-crm.fr
|
||||
# Service boutique
|
||||
CRM_TOKEN=
|
||||
# LDC Web Status Checker
|
||||
PROJECT_UUID=
|
||||
# Google Analytics
|
||||
ANALYTICS_GOOGLE_ID=
|
||||
|
|
|
|||
4
.gitignore
vendored
4
.gitignore
vendored
|
|
@ -5,6 +5,8 @@
|
|||
/public/images/gammes
|
||||
/public/images/produits
|
||||
/public/images/slides
|
||||
/public/b-o/
|
||||
/public/mix-manifest.json
|
||||
/storage/*.key
|
||||
/vendor
|
||||
.env
|
||||
|
|
@ -16,3 +18,5 @@ Homestead.json
|
|||
Homestead.yaml
|
||||
npm-debug.log
|
||||
yarn-error.log
|
||||
auth.json
|
||||
.vscode
|
||||
|
|
|
|||
46
.gitlab-ci.yml
Normal file
46
.gitlab-ci.yml
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
image: $CI_REGISTRY/service-web-lab/ldc-web-images-docker/ldcweb-qa:php7.3-1.0
|
||||
|
||||
stages:
|
||||
- Security
|
||||
- CodingStandards
|
||||
|
||||
composer-security:
|
||||
stage: Security
|
||||
script:
|
||||
- local-php-security-checker --format=json --path=./composer.lock > composer-security-checker-report.json
|
||||
artifacts:
|
||||
when: on_failure
|
||||
expose_as: 'composer-security-checker'
|
||||
paths:
|
||||
- composer-security-checker-report.json
|
||||
allow_failure: true
|
||||
|
||||
npm-security:
|
||||
stage: Security
|
||||
script:
|
||||
- audit-ci -p npm -o json > npm-security-checker-report.json
|
||||
artifacts:
|
||||
when: on_failure
|
||||
expose_as: 'npm-security-checker'
|
||||
paths:
|
||||
- npm-security-checker-report.json
|
||||
allow_failure: true
|
||||
|
||||
phpcs:
|
||||
stage: CodingStandards
|
||||
before_script:
|
||||
- composer config gitlab-token.gitlab.com $CI_DEPLOY_USER $CI_DEPLOY_PASSWORD
|
||||
- composer install
|
||||
cache:
|
||||
paths:
|
||||
- vendor/
|
||||
script:
|
||||
- vendor/bin/phpcs --report=junit --report-file=phpcs-report.xml
|
||||
artifacts:
|
||||
when: on_failure
|
||||
expose_as: 'phpcs'
|
||||
paths:
|
||||
- phpcs-report.xml
|
||||
reports:
|
||||
junit: phpcs-report.xml
|
||||
allow_failure: false
|
||||
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
|
|
@ -16,7 +16,8 @@
|
|||
"titleBar.activeBackground": "#630856",
|
||||
"titleBar.activeForeground": "#e7e7e7",
|
||||
"titleBar.inactiveBackground": "#63085699",
|
||||
"titleBar.inactiveForeground": "#e7e7e799"
|
||||
"titleBar.inactiveForeground": "#e7e7e799",
|
||||
"commandCenter.border": "#e7e7e799"
|
||||
},
|
||||
"peacock.remoteColor": "#630856"
|
||||
}
|
||||
|
|
|
|||
17
CHANGELOG.md
17
CHANGELOG.md
|
|
@ -1,7 +1,20 @@
|
|||
## 1.0.1
|
||||
- Change LDC CRM Client repository
|
||||
- composer update
|
||||
- Update .gitignore
|
||||
- Delete compiled assets
|
||||
- Replace informatique.internet -> equipe.web
|
||||
- Complete README.md
|
||||
- Delete credentials from front folder..
|
||||
- Delete tests folder and PHPUnit file
|
||||
- Update PHPCS file
|
||||
- Add mix() for assets
|
||||
- PHPCBF
|
||||
## 1.0.0
|
||||
Init versioning
|
||||
## 19-03-2022
|
||||
|
||||
* legal RGPD routes always accessible
|
||||
* privatisable routes
|
||||
* quickorder route
|
||||
* quickorder route
|
||||
* quickorder route activated by theme settings
|
||||
* improved tooltip for product reference wher regate orders are active
|
||||
|
|
|
|||
44
README.md
44
README.md
|
|
@ -1,23 +1,38 @@
|
|||
## Boutique Click N Collect
|
||||
|
||||
## Required systems
|
||||
|
||||
* supervisor
|
||||
|
||||
# Boutique Click N Collect
|
||||
## Installation
|
||||
|
||||
```
|
||||
composer install
|
||||
php artisan storage:link
|
||||
cd /ressources/views/front/
|
||||
mkdir <theme-folder>
|
||||
cd <theme-folder>
|
||||
git clone <theme-repo> .
|
||||
cd ../../../.../
|
||||
npm install && npm run prod
|
||||
|
||||
cp .env.example .env
|
||||
php artisan key:generate
|
||||
```
|
||||
Edit .env file then :
|
||||
```
|
||||
php artisan migrate --seed
|
||||
```
|
||||
|
||||
## Theme
|
||||
```
|
||||
cd resources/views/front/
|
||||
git clone [REPO_URL] --branch=[THEME_BRANCH_NAME] [THEME_NAME]
|
||||
```
|
||||
Ex:
|
||||
```
|
||||
git clone [REPO_URL] --branch=develop-mairet mairet
|
||||
```
|
||||
Update APP_THEME value in .env :
|
||||
```
|
||||
APP_THEME=[THEME_NAME]
|
||||
```
|
||||
Ex:
|
||||
```
|
||||
APP_THEME=mairet
|
||||
```
|
||||
Project root :
|
||||
```
|
||||
npm install && npm run prod
|
||||
```
|
||||
## Back-Office
|
||||
|
||||
Création de compte
|
||||
|
|
@ -27,3 +42,6 @@ php artisan create:admin
|
|||
```
|
||||
|
||||
URL : /bo
|
||||
## Required systems
|
||||
|
||||
* supervisor
|
||||
|
|
|
|||
|
|
@ -23,35 +23,25 @@ class CreateAdmin extends Command
|
|||
protected $description = 'creates an admin user upon password entry';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$firstname = $this->ask('What is the firstname?','Equipe');
|
||||
$lastname = $this->ask('What is the lastname?','Web');
|
||||
$email = $this->ask('What is the email?', 'equipe.web@ldc.fr');
|
||||
$pwd = $this->secret('What is the password?');
|
||||
$firstname = $this->ask('What is the firstname?', 'Equipe');
|
||||
$lastname = $this->ask('What is the lastname?', 'Web');
|
||||
$email = $this->ask('What is the email?', 'equipe.web@ldc.fr');
|
||||
$pwd = $this->secret('What is the password?');
|
||||
|
||||
$user = new User();
|
||||
$user->firstname = $firstname;
|
||||
$user->lastname = $lastname;
|
||||
$user->date_of_birth = now();
|
||||
$user->email = $email;
|
||||
$user->password = Hash::make($pwd);
|
||||
$user = new User();
|
||||
$user->firstname = $firstname;
|
||||
$user->lastname = $lastname;
|
||||
$user->date_of_birth = now();
|
||||
$user->email = $email;
|
||||
$user->password = Hash::make($pwd);
|
||||
$user->email_verified_at = now();
|
||||
$user->role = 1;
|
||||
$user->role = 1;
|
||||
$user->save();
|
||||
|
||||
$this->info('User created.');
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ use App\Jobs\CsvSalariesReader as JobCsvSalarieReader;
|
|||
|
||||
class ImportSalaries extends Command
|
||||
{
|
||||
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
|
|
@ -22,29 +21,17 @@ class ImportSalaries extends Command
|
|||
*/
|
||||
protected $description = 'Import Salaries, pour provision des clients';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->info('Running the Job, this could take some time.');
|
||||
$job = new JobCsvSalarieReader();
|
||||
$job = new JobCsvSalarieReader();
|
||||
$job->console = $this;
|
||||
$job->handle();
|
||||
$this->info('Job completed');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
<?php
|
||||
/*
|
||||
* Command Name: LDC Web Status Checker
|
||||
* Description: Envoi des infos Serveur/Laravel vers LDC Web
|
||||
* Version: 1.0
|
||||
* Author: Vincent BRIDIER
|
||||
* Author URI: vincent.bridier@ldc.fr
|
||||
*/
|
||||
|
||||
/**
|
||||
* Command Name: LDC Web Status Checker
|
||||
* Description: Envoi des infos Serveur/Laravel vers LDC Web
|
||||
* Version: 1.0
|
||||
* Author: Vincent BRIDIER
|
||||
* Author URI: vincent.bridier@ldc.fr
|
||||
*/
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
|
|
@ -27,16 +28,6 @@ class LDCWebStatusChecker extends Command
|
|||
*/
|
||||
protected $description = 'Envoi des infos Serveur/Laravel vers LDC Web';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
|
|
@ -44,28 +35,28 @@ class LDCWebStatusChecker extends Command
|
|||
*/
|
||||
public function handle()
|
||||
{
|
||||
$data = [];
|
||||
$data = [];
|
||||
$data['uuid'] = config('ldcweb.project_uuid');
|
||||
|
||||
// Sitemap.xml ?
|
||||
if (file_exists(public_path() . '/sitemap.xml')) {
|
||||
$data['sitemap'] = 'true';
|
||||
}else{
|
||||
} else {
|
||||
$data['sitemap'] = 'false';
|
||||
}
|
||||
|
||||
// Robots.txt ?
|
||||
if (file_exists(public_path() . '/robots.txt')) {
|
||||
$data['robots'] = 'true';
|
||||
}else{
|
||||
} else {
|
||||
$data['robots'] = 'false';
|
||||
}
|
||||
|
||||
//Check logs
|
||||
// Check logs.
|
||||
$data['logs'] = 0;
|
||||
$patherror = storage_path('/logs');
|
||||
$files = glob($patherror.'/*.log');
|
||||
if(count($files) > 0){
|
||||
$patherror = storage_path('/logs');
|
||||
$files = glob($patherror . '/*.log');
|
||||
if (count($files) > 0) {
|
||||
foreach ($files as $file) {
|
||||
$data['logs'] = $data['logs'] + filesize($file);
|
||||
}
|
||||
|
|
@ -73,9 +64,9 @@ class LDCWebStatusChecker extends Command
|
|||
|
||||
$data['code']['version'] = app()->version();
|
||||
|
||||
// Send by cURL
|
||||
$url = 'https://ldc-web.ldc.fr/api/status-checker';
|
||||
$ch = curl_init($url);
|
||||
// Send by cURL.
|
||||
$url = 'https://ldc-web.ldc.fr/api/status-checker';
|
||||
$ch = curl_init($url);
|
||||
$payload = ['token' => 'CE8S52Qq7stf5k8frF4T', 'datas' => json_encode($data)];
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ use Illuminate\Console\Command;
|
|||
|
||||
class RefreshSiteMap extends Command
|
||||
{
|
||||
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
|
|
@ -25,12 +24,12 @@ class RefreshSiteMap extends Command
|
|||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$this->info('Running the Job, this could take some time.');
|
||||
$job = new JobsRefreshSiteMap();
|
||||
$job = new JobsRefreshSiteMap();
|
||||
$job->console = $this;
|
||||
$job->handle();
|
||||
$this->info('Job completed');
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ use Illuminate\Console\Command;
|
|||
|
||||
class XmlIncoReader extends Command
|
||||
{
|
||||
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
|
|
@ -30,7 +29,7 @@ class XmlIncoReader extends Command
|
|||
public function handle()
|
||||
{
|
||||
$this->info('Running the Job, this could take some time.');
|
||||
$job = new JobsXmlIncoReader();
|
||||
$job = new JobsXmlIncoReader();
|
||||
$job->console = $this;
|
||||
$job->handle();
|
||||
$this->info('Job completed');
|
||||
|
|
|
|||
|
|
@ -14,13 +14,12 @@ class Kernel extends ConsoleKernel
|
|||
* @var array
|
||||
*/
|
||||
protected $commands = [
|
||||
//
|
||||
];
|
||||
];
|
||||
|
||||
/**
|
||||
* Define the application's command schedule.
|
||||
*
|
||||
* @param \Illuminate\Console\Scheduling\Schedule $schedule
|
||||
* @param \Illuminate\Console\Scheduling\Schedule $schedule
|
||||
* @return void
|
||||
*/
|
||||
protected function schedule(Schedule $schedule)
|
||||
|
|
@ -28,7 +27,6 @@ class Kernel extends ConsoleKernel
|
|||
$schedule->command('sitemap:refresh')->dailyAt('16:13');
|
||||
$schedule->command('ldcweb:statuschecker')->everyFifteenMinutes();
|
||||
$schedule->job(JobsXmlIncoReader::class)->name('xml-inco-reader')->onOneServer()->dailyAt('15:00');
|
||||
//$schedule->job(new XmlIncoReader)->weeklyOn(1, '8:00');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -38,7 +36,7 @@ class Kernel extends ConsoleKernel
|
|||
*/
|
||||
protected function commands()
|
||||
{
|
||||
$this->load(__DIR__.'/Commands');
|
||||
$this->load(__DIR__ . '/Commands');
|
||||
|
||||
require base_path('routes/console.php');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,11 @@ use Kwaadpepper\Enum\BaseEnum;
|
|||
*/
|
||||
final class InvoicingUnit extends BaseEnum
|
||||
{
|
||||
/**
|
||||
* Enum values
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected static function values(): array
|
||||
{
|
||||
return [
|
||||
|
|
@ -20,6 +25,11 @@ final class InvoicingUnit extends BaseEnum
|
|||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Enum labels
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected static function labels(): array
|
||||
{
|
||||
return [
|
||||
|
|
@ -29,6 +39,10 @@ final class InvoicingUnit extends BaseEnum
|
|||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the value as a string
|
||||
* @return string
|
||||
*/
|
||||
public function __toString(): string
|
||||
{
|
||||
return (string)$this->label;
|
||||
|
|
|
|||
|
|
@ -11,6 +11,11 @@ use Kwaadpepper\Enum\BaseEnum;
|
|||
*/
|
||||
final class OrderUnit extends BaseEnum
|
||||
{
|
||||
/**
|
||||
* Enum values
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected static function values(): array
|
||||
{
|
||||
return [
|
||||
|
|
@ -20,6 +25,11 @@ final class OrderUnit extends BaseEnum
|
|||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Enum labels
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected static function labels(): array
|
||||
{
|
||||
return [
|
||||
|
|
@ -29,6 +39,10 @@ final class OrderUnit extends BaseEnum
|
|||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the value as a string
|
||||
* @return string
|
||||
*/
|
||||
public function __toString(): string
|
||||
{
|
||||
return (string)$this->label;
|
||||
|
|
|
|||
|
|
@ -14,6 +14,11 @@ use Kwaadpepper\Enum\BaseEnumRoutable;
|
|||
*/
|
||||
class PriceShowingMode extends BaseEnumRoutable
|
||||
{
|
||||
/**
|
||||
* Enum values
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected static function values(): array
|
||||
{
|
||||
return [
|
||||
|
|
@ -22,6 +27,11 @@ class PriceShowingMode extends BaseEnumRoutable
|
|||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Enum labels
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected static function labels(): array
|
||||
{
|
||||
return [
|
||||
|
|
|
|||
|
|
@ -11,6 +11,11 @@ use Kwaadpepper\Enum\BaseEnum;
|
|||
*/
|
||||
final class SellUnit extends BaseEnum
|
||||
{
|
||||
/**
|
||||
* Enum values
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected static function values(): array
|
||||
{
|
||||
return [
|
||||
|
|
@ -20,6 +25,11 @@ final class SellUnit extends BaseEnum
|
|||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Enum labels
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected static function labels(): array
|
||||
{
|
||||
return [
|
||||
|
|
@ -29,6 +39,10 @@ final class SellUnit extends BaseEnum
|
|||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the value as a string
|
||||
* @return string
|
||||
*/
|
||||
public function __toString(): string
|
||||
{
|
||||
return (string)$this->label;
|
||||
|
|
|
|||
|
|
@ -10,6 +10,11 @@ use Kwaadpepper\Enum\BaseEnum;
|
|||
*/
|
||||
final class SettingRegisterMode extends BaseEnum
|
||||
{
|
||||
/**
|
||||
* Enum values
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected static function values(): array
|
||||
{
|
||||
return [
|
||||
|
|
@ -18,6 +23,11 @@ final class SettingRegisterMode extends BaseEnum
|
|||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Enum labels
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected static function labels(): array
|
||||
{
|
||||
return [
|
||||
|
|
@ -26,6 +36,10 @@ final class SettingRegisterMode extends BaseEnum
|
|||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the value as a string
|
||||
* @return string
|
||||
*/
|
||||
public function __toString(): string
|
||||
{
|
||||
return (string)$this->label;
|
||||
|
|
|
|||
|
|
@ -11,6 +11,11 @@ use Kwaadpepper\Enum\BaseEnum;
|
|||
*/
|
||||
final class WeightUnit extends BaseEnum
|
||||
{
|
||||
/**
|
||||
* Enum values
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected static function values(): array
|
||||
{
|
||||
return [
|
||||
|
|
@ -20,6 +25,11 @@ final class WeightUnit extends BaseEnum
|
|||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Enum labels
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected static function labels(): array
|
||||
{
|
||||
return [
|
||||
|
|
@ -29,6 +39,12 @@ final class WeightUnit extends BaseEnum
|
|||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* conversion values
|
||||
* base kg()
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function convert(): array
|
||||
{
|
||||
return [
|
||||
|
|
@ -38,6 +54,10 @@ final class WeightUnit extends BaseEnum
|
|||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the value as a string
|
||||
* @return string
|
||||
*/
|
||||
public function __toString(): string
|
||||
{
|
||||
return (string)$this->label;
|
||||
|
|
|
|||
|
|
@ -6,5 +6,4 @@ use Exception;
|
|||
|
||||
class AbortCsvImportException extends Exception
|
||||
{
|
||||
//
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,10 +4,6 @@ namespace App\Exceptions;
|
|||
|
||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||
use Illuminate\Auth\AuthenticationException;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use RuntimeException;
|
||||
use Throwable;
|
||||
|
||||
class Handler extends ExceptionHandler
|
||||
{
|
||||
|
|
@ -16,9 +12,7 @@ class Handler extends ExceptionHandler
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $dontReport = [
|
||||
//
|
||||
];
|
||||
protected $dontReport = [];
|
||||
|
||||
/**
|
||||
* A list of the inputs that are never flashed for validation exceptions.
|
||||
|
|
@ -37,9 +31,21 @@ class Handler extends ExceptionHandler
|
|||
*/
|
||||
public function register()
|
||||
{
|
||||
//
|
||||
$this->reportable(function (\Throwable $e) {
|
||||
if (app()->bound('sentry')) {
|
||||
app('sentry')->captureException($e);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle unauthenticated as exception
|
||||
*
|
||||
* @param mixed $request
|
||||
* @param AuthenticationException $exception
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
protected function unauthenticated($request, AuthenticationException $exception)
|
||||
{
|
||||
if ($request->expectsJson()) {
|
||||
|
|
@ -54,47 +60,9 @@ class Handler extends ExceptionHandler
|
|||
$login = 'auth.login';
|
||||
break;
|
||||
}
|
||||
//cf. issue https://stackoverflow.com/questions/52417438/laravel-unauthenticated-redirect-issue-with-multiple-authentication
|
||||
//Session::forget('url.intented');
|
||||
// Cf. issue :
|
||||
// Https://stackoverflow.com/questions/52417438/laravel-unauthenticated-redirect-issue-with-multiple-authentication.
|
||||
// Session::forget('url.intented'); .
|
||||
return redirect()->guest(route($login));
|
||||
}
|
||||
|
||||
/**
|
||||
* Report or log an exception.
|
||||
*
|
||||
* @param \Throwable $exception
|
||||
* @return void
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function report(Throwable $e)
|
||||
{
|
||||
if (get_class($e) == RedirectTo::class) {
|
||||
abort(redirect($e->url));
|
||||
}
|
||||
try {
|
||||
if (config('app.debug') === false) {
|
||||
if ($this->shouldntReport($e)) {
|
||||
return;
|
||||
}
|
||||
Mail::send([
|
||||
'html' => 'emails.exception',
|
||||
'text' => 'emails.exception-plain'
|
||||
], [
|
||||
'exception' => $e,
|
||||
'appName' => config('app.name')
|
||||
], function ($m) {
|
||||
$m->to(
|
||||
config('mail.contactsList.serviceweb'),
|
||||
sprintf('%s Exception Handler', config('app.name'))
|
||||
)->subject('Need help !, an error occured in your application, please check Logs ASAP');
|
||||
});
|
||||
}
|
||||
// phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch
|
||||
} catch (RuntimeException $e) {
|
||||
// do nothing, mail send error, let laravel only handle this
|
||||
} finally {
|
||||
parent::report($e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,11 +8,27 @@ use Illuminate\Support\Facades\Auth;
|
|||
|
||||
class LoginController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display login form
|
||||
*
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*
|
||||
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
// @phpcs:enable
|
||||
return view('auth.login-bo');
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute login form
|
||||
*
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*
|
||||
*/
|
||||
public function login(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
|
|
@ -37,8 +53,17 @@ class LoginController extends Controller
|
|||
return view('auth.login')->withErrors('Informations incorrectes.');
|
||||
}
|
||||
|
||||
/**
|
||||
* logout
|
||||
*
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*
|
||||
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
|
||||
*/
|
||||
public function logout(Request $request)
|
||||
{
|
||||
// @phpcs:enable
|
||||
Auth::logout();
|
||||
return redirect()->route('home');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,11 +10,27 @@ use Illuminate\Support\Facades\Hash;
|
|||
|
||||
class RegisterController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display register form
|
||||
*
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*
|
||||
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
// @phpcs:enable
|
||||
return view('auth.register');
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute regioster form
|
||||
*
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*
|
||||
*/
|
||||
public function register(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
|
|
@ -34,8 +50,7 @@ class RegisterController extends Controller
|
|||
'role' => 3
|
||||
]);
|
||||
|
||||
// Envoi mail activation
|
||||
|
||||
// Envoi mail activation.
|
||||
return redirect()->route('auth.register')->with('success', 'Mail envoyé pour confirmation');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,8 +7,17 @@ use Illuminate\Http\Request;
|
|||
|
||||
class ResetPasswordController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display reset password form
|
||||
*
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*
|
||||
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
// @phpcs:enable
|
||||
return view('auth.reset-password');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,11 +12,15 @@ class BasketController extends Controller
|
|||
{
|
||||
/**
|
||||
* ajout de produit au panier
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function addToCart(Request $request)
|
||||
{
|
||||
$instance = $request->instance ?? "panier";
|
||||
$product = Product::find($request->id);
|
||||
$product = Product::find($request->id);
|
||||
Cart::instance($instance);
|
||||
Cart::add($product, $request->qty);
|
||||
return $this->getCart($instance);
|
||||
|
|
@ -24,13 +28,17 @@ class BasketController extends Controller
|
|||
|
||||
/**
|
||||
* ajout de plusieurs produits au panier
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function addToCartLot(Request $request)
|
||||
{
|
||||
$instance = $request->instance ?? "panier";
|
||||
Cart::instance($instance);
|
||||
$lot = $request->items;
|
||||
foreach($lot as $item) {
|
||||
foreach ($lot as $item) {
|
||||
$product = Product::find($item["cartItem"]["id"]);
|
||||
Cart::add($product, $item["cartItem"]["qty"]);
|
||||
}
|
||||
|
|
@ -39,11 +47,15 @@ class BasketController extends Controller
|
|||
|
||||
/**
|
||||
* suppression de produit du panier
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function removeFromCart(Request $request)
|
||||
{
|
||||
$instance = $request->instance ?? "panier";
|
||||
$rowId = $request->rowId;
|
||||
$rowId = $request->rowId;
|
||||
Cart::instance($instance);
|
||||
Cart::remove($rowId);
|
||||
return $this->getCart($instance);
|
||||
|
|
@ -51,8 +63,13 @@ class BasketController extends Controller
|
|||
|
||||
/**
|
||||
* vidage de panier
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function emptyCart(Request $request) {
|
||||
public function emptyCart(Request $request)
|
||||
{
|
||||
$instance = $request->instance ?? "panier";
|
||||
Cart::instance($instance);
|
||||
Cart::destroy();
|
||||
|
|
@ -61,6 +78,10 @@ class BasketController extends Controller
|
|||
|
||||
/**
|
||||
* récupération du panier
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCartRequest(Request $request)
|
||||
{
|
||||
|
|
@ -69,14 +90,19 @@ class BasketController extends Controller
|
|||
return $this->getCart($instance);
|
||||
}
|
||||
|
||||
|
||||
public function getCart($instance = "panier")
|
||||
/**
|
||||
* return cart data array
|
||||
*
|
||||
* @param string $instance
|
||||
* @return array
|
||||
*/
|
||||
public function getCart(string $instance = "panier")
|
||||
{
|
||||
Cart::instance($instance);
|
||||
$dbpanier = new Collection();
|
||||
foreach (Cart::content() as $row) {
|
||||
$product = $row->model;
|
||||
//$product->additionnalProductInfo = $product->additionnalProductInfo($product->product_type);
|
||||
|
||||
$product->calculatedPrices = $product->getCalcPrices();
|
||||
|
||||
$row->setTaxRate($product->tax->rate);
|
||||
|
|
@ -91,30 +117,42 @@ class BasketController extends Controller
|
|||
|
||||
$cartInfos = array(
|
||||
"totalTTC" => Cart::total(),
|
||||
'totalTVA' => Cart::tax(), //total des taxes
|
||||
'totalHT' => Cart::subtotal(), //total sans les taxes
|
||||
'totalweight' => Cart::weight(), //poids total des items
|
||||
'totalHTbefore' => Cart::priceTotal(), //total avant taxes et remises
|
||||
'totaldiscount' => Cart::discount(), //total des remises
|
||||
'countItems' => Cart::count(), //nb de produits dans le cart
|
||||
// Total des taxes.
|
||||
'totalTVA' => Cart::tax(),
|
||||
// Total sans les taxes.
|
||||
'totalHT' => Cart::subtotal(),
|
||||
// Poids total des items.
|
||||
'totalweight' => Cart::weight(),
|
||||
// Total avant taxes et remises.
|
||||
'totalHTbefore' => Cart::priceTotal(),
|
||||
// Total des remises.
|
||||
'totaldiscount' => Cart::discount(),
|
||||
// Nb de produits dans le cart.
|
||||
'countItems' => Cart::count(),
|
||||
);
|
||||
|
||||
$cartInfosNoPrice = array(
|
||||
"totalTTC" => "-.--",
|
||||
'totalTVA' => "-.--", //total des taxes
|
||||
'totalHT' => "-.--", //total sans les taxes
|
||||
'totalweight' => Cart::weight(), //poids total des items
|
||||
'totalHTbefore' => "-.--", //total avant taxes et remises
|
||||
'totaldiscount' => "-.--", //total des remises
|
||||
'countItems' => Cart::count(), //nb de produits dans le cart
|
||||
// Total des taxes.
|
||||
'totalTVA' => "-.--",
|
||||
// Total sans les taxes.
|
||||
'totalHT' => "-.--",
|
||||
// Poids total des items.
|
||||
'totalweight' => Cart::weight(),
|
||||
// Total avant taxes et remises.
|
||||
'totalHTbefore' => "-.--",
|
||||
// Total des remises.
|
||||
'totaldiscount' => "-.--",
|
||||
// Nb de produits dans le cart.
|
||||
'countItems' => Cart::count(),
|
||||
);
|
||||
|
||||
$cartReturn = array($dbpanier,$cartInfosNoPrice);
|
||||
if (config('bosettings.show_prices_authenticated') == "authenticated") {
|
||||
{
|
||||
if (Auth::guard('customer')->check()) {
|
||||
$cartReturn = array($dbpanier,$cartInfos);
|
||||
}
|
||||
if (Auth::guard('customer')->check()) {
|
||||
$cartReturn = array($dbpanier,$cartInfos);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (config('bosettings.show_prices_guest') == "guest") {
|
||||
|
|
|
|||
|
|
@ -8,14 +8,22 @@ use Illuminate\Http\Request;
|
|||
|
||||
class ContentController extends Controller
|
||||
{
|
||||
public function manage(Request $request, $key)
|
||||
/**
|
||||
* Manage content page
|
||||
*
|
||||
* @param Request $request
|
||||
* @param string $key
|
||||
* @return \Illuminate\Http\Response
|
||||
*
|
||||
*/
|
||||
public function manage(Request $request, string $key)
|
||||
{
|
||||
$content = Content::where('key', $key)->first();
|
||||
|
||||
if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
||||
$banner = $request->banner;
|
||||
$title = $request->title;
|
||||
$chapeau = $request->chapeau;
|
||||
$banner = $request->banner;
|
||||
$title = $request->title;
|
||||
$chapeau = $request->chapeau;
|
||||
$maintext = $request->value;
|
||||
|
||||
$request->validate([
|
||||
|
|
@ -34,14 +42,14 @@ class ContentController extends Controller
|
|||
$content->banner = $imageName;
|
||||
}
|
||||
|
||||
$content->title = $title;
|
||||
$content->title = $title;
|
||||
$content->chapeau = $chapeau;
|
||||
$content->value = $maintext;
|
||||
$content->value = $maintext;
|
||||
$content->save();
|
||||
|
||||
return redirect()->route('bo.content', ['key' => $content->key, 'content' => $content])
|
||||
->with('success', 'Modifications enregistrés !');
|
||||
}
|
||||
}//end if
|
||||
|
||||
return view('bo.content.manage', compact('content'));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,46 +9,69 @@ use Illuminate\Http\Request;
|
|||
|
||||
class CreneauxController extends Controller
|
||||
{
|
||||
public function settings(Request $request,$id)
|
||||
/**
|
||||
* Display creneaux settings form
|
||||
*
|
||||
* @param Request $request
|
||||
* @param integer $id
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*
|
||||
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
|
||||
*/
|
||||
public function settings(Request $request, int $id)
|
||||
{
|
||||
|
||||
$magasin = Magasin::findOrFail($id);
|
||||
$timeslotSettings = $magasin->timeslotSettings;
|
||||
// @phpcs:enable
|
||||
$magasin = Magasin::findOrFail($id);
|
||||
$timeslotSettings = $magasin->timeslotSettings;
|
||||
if ($timeslotSettings->count() === 0) {
|
||||
//Aucun settings pour ce magasin
|
||||
// Aucun settings pour ce magasin.
|
||||
$timeslotSettings = $this->makeCreneauxSettings($id);
|
||||
}
|
||||
|
||||
return view('bo.creneaux.settings', compact('timeslotSettings', 'magasin'));
|
||||
}
|
||||
|
||||
public function makeCreneauxSettings($id) {
|
||||
for ($i=0;$i<7;$i++) {
|
||||
$dayset = new TimeslotSetting();
|
||||
/**
|
||||
* Retrieve creneaux settings
|
||||
*
|
||||
* @param integer $id
|
||||
* @return mixed
|
||||
*/
|
||||
public function makeCreneauxSettings(int $id)
|
||||
{
|
||||
for ($i = 0; $i < 7; $i++) {
|
||||
$dayset = new TimeslotSetting();
|
||||
$dayset->magasin_id = $id;
|
||||
$dayset->day_index = ''.$i;
|
||||
$dayset->day_index = '' . $i;
|
||||
$dayset->save();
|
||||
}
|
||||
return Magasin::findOrFail($id)->timeslotSettings;
|
||||
}
|
||||
|
||||
public function updateSettings(Request $request,$id)
|
||||
/**
|
||||
* save settings
|
||||
*
|
||||
* @param Request $request
|
||||
* @param integer $id
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function updateSettings(Request $request, int $id)
|
||||
{
|
||||
$plage = $request->plage;
|
||||
$plage = $request->plage;
|
||||
$magasin_id = $id;
|
||||
|
||||
foreach($plage as $index => $day) {
|
||||
$setting = TimeslotSetting::where('day_index', ''.$index)
|
||||
foreach ($plage as $index => $day) {
|
||||
$setting = TimeslotSetting::where('day_index', '' . $index)
|
||||
->where('magasin_id', $magasin_id)
|
||||
->firstOrFail();
|
||||
//$setting->magasin_id = $magasin_id; ne doit pas changer
|
||||
$setting->morning_start = $day['morning_start'];
|
||||
$setting->morning_end = $day['morning_end'];
|
||||
$setting->afternoon_start = $day['afternoon_start'];
|
||||
$setting->afternoon_end = $day['afternoon_end'];
|
||||
$setting->interval = $day['interval'];
|
||||
// $setting->magasin_id = $magasin_id; ne doit pas changer
|
||||
$setting->morning_start = $day['morning_start'];
|
||||
$setting->morning_end = $day['morning_end'];
|
||||
$setting->afternoon_start = $day['afternoon_start'];
|
||||
$setting->afternoon_end = $day['afternoon_end'];
|
||||
$setting->interval = $day['interval'];
|
||||
$setting->max_orders_per_interval = $day['max_orders_per_interval'];
|
||||
$setting->min_order_preparation = $day['min_order_preparation'];
|
||||
$setting->min_order_preparation = $day['min_order_preparation'];
|
||||
$setting->save();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,11 @@ use App\Http\Controllers\Controller;
|
|||
|
||||
class DashboardController extends Controller
|
||||
{
|
||||
/**
|
||||
* Dashboard Page
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return view('bo.dashboard');
|
||||
|
|
|
|||
|
|
@ -8,24 +8,41 @@ use Illuminate\Http\Request;
|
|||
|
||||
class FaqController extends Controller
|
||||
{
|
||||
public function index() {
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$faq = Faq::all();
|
||||
return view('bo.faq.index', compact('faq'));
|
||||
}
|
||||
|
||||
public function saveDatas(Request $request) {
|
||||
/**
|
||||
* Update faq data.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function saveDatas(Request $request)
|
||||
{
|
||||
$faq = $request->faq;
|
||||
|
||||
for ($i = 0; $i < count($faq); $i++) {
|
||||
$looplimit = count($faq);
|
||||
for ($i = 0; $i < $looplimit; $i++) {
|
||||
$faqToInsert = !empty($faq[$i]["question"]) && !empty($faq[$i]["answer"]);
|
||||
if (isset($faq[$i]["id"]) && $faq[$i]["id"] !== null && $faqToInsert) {
|
||||
$f = Faq::findOrFail($faq[$i]["id"]);
|
||||
$f = Faq::findOrFail($faq[$i]["id"]);
|
||||
$f->question = $faq[$i]["question"];
|
||||
$f->answer = $faq[$i]["answer"];
|
||||
$f->answer = $faq[$i]["answer"];
|
||||
$f->save();
|
||||
} else {
|
||||
if ($faqToInsert) {
|
||||
$c = Faq::updateOrCreate(['question' => $faq[$i]["question"], 'answer' => $faq[$i]["answer"]]);
|
||||
$c = Faq::updateOrCreate([
|
||||
'question' => $faq[$i]["question"],
|
||||
'answer' => $faq[$i]["answer"]
|
||||
]);
|
||||
$faq[$i]["id"] = $c->id;
|
||||
} else {
|
||||
unset($faq[$i]);
|
||||
|
|
@ -37,7 +54,14 @@ class FaqController extends Controller
|
|||
return $faq;
|
||||
}
|
||||
|
||||
public function destroy(Request $request) {
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy(Request $request)
|
||||
{
|
||||
$faq = Faq::findOrFail($request->id);
|
||||
$faq->delete();
|
||||
|
||||
|
|
|
|||
|
|
@ -33,13 +33,15 @@ class MagasinsController extends Controller
|
|||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'name' => 'required|string|max:255',
|
||||
'email_contact' => 'required|email:rfc,dns,spoof|max:255',
|
||||
'email_confirm' => 'nullable|email:rfc,dns,spoof|max:255',
|
||||
'address' => 'required|string|max:255',
|
||||
'postcode' => 'required',
|
||||
'city' => 'required|string|max:255',
|
||||
|
|
@ -49,26 +51,15 @@ class MagasinsController extends Controller
|
|||
return redirect()->route('bo.magasins.edit', $shop->id)->with('success', 'Nouveau Magasin enregistré !');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @param integer $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
public function edit(int $id)
|
||||
{
|
||||
$magasin = Magasin::findOrFail($id);
|
||||
$magasin = Magasin::findOrFail($id);
|
||||
$exceptionsCollecte = $magasin->collecteExceptions()->orderBy('date')->get();
|
||||
return view('bo.magasins.edit', compact('magasin', 'exceptionsCollecte'));
|
||||
}
|
||||
|
|
@ -76,14 +67,16 @@ class MagasinsController extends Controller
|
|||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param integer $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
public function update(Request $request, int $id)
|
||||
{
|
||||
$request->validate([
|
||||
'name' => 'required|string|max:255',
|
||||
'email_contact' => 'required|email:rfc,dns,spoof|max:255',
|
||||
'email_confirm' => 'nullable|email:rfc,dns,spoof|max:255',
|
||||
'address' => 'required|string|max:255',
|
||||
'postcode' => 'required',
|
||||
'city' => 'required|string|max:255',
|
||||
|
|
@ -97,20 +90,19 @@ class MagasinsController extends Controller
|
|||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @param integer $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id)
|
||||
public function destroy(int $id)
|
||||
{
|
||||
$shop = Magasin::findOrFail($id);
|
||||
|
||||
$count = Magasin::count();
|
||||
|
||||
if ($count === 1) {
|
||||
return redirect()->back()->withErrors("Suppression impossible : Vous devez conserver au moins 1 point de retrait.");
|
||||
return redirect()->back()
|
||||
->withErrors("Suppression impossible : Vous devez conserver au moins 1 point de retrait.");
|
||||
}
|
||||
// @todo : controller les crenaux settings liés
|
||||
|
||||
$shop->delete();
|
||||
return redirect()->route('bo.magasins.index');
|
||||
}
|
||||
|
|
@ -118,15 +110,19 @@ class MagasinsController extends Controller
|
|||
/**
|
||||
* bo
|
||||
* ajx : affichage d'infos sur un magasin
|
||||
*
|
||||
* @param integer $id
|
||||
* @param string|null $mode
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function getMagasinInfo($id, $mode = null)
|
||||
public function getMagasinInfo(int $id, string $mode = null)
|
||||
{
|
||||
$magasin = Magasin::findOrFail($id);
|
||||
if(!is_null($mode)) {
|
||||
if($mode=="tippy") {
|
||||
if (!is_null($mode)) {
|
||||
if ($mode == "tippy") {
|
||||
return view('bo.magasins.tippy-card', compact('magasin'));
|
||||
}
|
||||
if($mode=="json") {
|
||||
if ($mode == "json") {
|
||||
return $magasin;
|
||||
}
|
||||
return view('bo.magasins.info-card', compact('magasin'));
|
||||
|
|
@ -134,54 +130,74 @@ class MagasinsController extends Controller
|
|||
return view('bo.magasins.info-popup', compact('magasin'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Save collect exceptions
|
||||
*
|
||||
* @param Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function saveExceptions(Request $request)
|
||||
{
|
||||
$collecteException = $request->collecte_exception;
|
||||
|
||||
for ($i = 0; $i < count($collecteException); $i++) {
|
||||
$looplimit = count($collecteException);
|
||||
for ($i = 0; $i < $looplimit; $i++) {
|
||||
$collecteExceptionToInsert = !empty($collecteException[$i]["date"]);
|
||||
if (isset($collecteException[$i]["id"]) && $collecteException[$i]["id"] !== null && $collecteExceptionToInsert) {
|
||||
$ce = CollecteException::findOrFail($collecteException[$i]["id"]);
|
||||
$ce->date = $collecteException[$i]["date"];
|
||||
$ce->comment = $collecteException[$i]["comment"];
|
||||
if (
|
||||
isset($collecteException[$i]["id"]) &&
|
||||
$collecteException[$i]["id"] !== null &&
|
||||
$collecteExceptionToInsert
|
||||
) {
|
||||
$ce = CollecteException::findOrFail($collecteException[$i]["id"]);
|
||||
$ce->date = $collecteException[$i]["date"];
|
||||
$ce->comment = $collecteException[$i]["comment"];
|
||||
$ce->magasin_id = $collecteException[$i]["magasin_id"];
|
||||
$ce->save();
|
||||
} else {
|
||||
if ($collecteExceptionToInsert) {
|
||||
$ce = CollecteException::updateOrCreate([
|
||||
$ce = CollecteException::updateOrCreate([
|
||||
'date' => $collecteException[$i]["date"],
|
||||
'comment' => $collecteException[$i]["comment"],
|
||||
'magasin_id' => $collecteException[$i]["magasin_id"]
|
||||
]);
|
||||
$collecteException[$i]["id"] = $ce->id;
|
||||
|
||||
} else {
|
||||
unset($collecteException[$i]);
|
||||
$i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}//end for
|
||||
|
||||
//remet dans l'ordre avant de renvoyer
|
||||
//$collecteException = CollecteException::where('magasin_id',)->orderBy('date')->get();
|
||||
// Remet dans l'ordre avant de renvoyer.
|
||||
$this->arraySortByColumn($collecteException, "date");
|
||||
return $collecteException;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* helper function
|
||||
*
|
||||
* @param array $array
|
||||
* @param string $column
|
||||
* @param integer $direction
|
||||
* @return void
|
||||
*/
|
||||
public function arraySortByColumn(&$array, $column, $direction = SORT_ASC) {
|
||||
public function arraySortByColumn(array &$array, string $column, int $direction = SORT_ASC)
|
||||
{
|
||||
$reference_array = array();
|
||||
|
||||
foreach($array as $key => $row) {
|
||||
foreach ($array as $key => $row) {
|
||||
$reference_array[$key] = $row[$column];
|
||||
}
|
||||
|
||||
array_multisort($reference_array, $direction, $array);
|
||||
}
|
||||
|
||||
/**
|
||||
* delete collecte exception
|
||||
*
|
||||
* @param Request $request
|
||||
* @return string
|
||||
*/
|
||||
public function destroyExceptions(Request $request)
|
||||
{
|
||||
$collecteException = CollecteException::findOrFail($request->id);
|
||||
|
|
|
|||
|
|
@ -16,56 +16,89 @@ use App\Mail\OrderConfirmMail;
|
|||
use App\Mail\OrderConfirmAdminMail;
|
||||
use App\Jobs\CsvOrderWrite;
|
||||
use App\Models\Customers;
|
||||
use App\Models\OrdersStatus;
|
||||
use App\Models\Setting;
|
||||
use Carbon\Carbon;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Carbon\CarbonInterval;
|
||||
use Gloudemans\Shoppingcart\Facades\Cart;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use Exception;
|
||||
|
||||
class OrdersController extends Controller
|
||||
{
|
||||
/**
|
||||
* index of orders (Bo)
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @param \App\Http\Requests\SortOrders $request
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function index(SortOrders $request)
|
||||
{
|
||||
//$orders = Order::orderBy('date', 'DESC')->get();
|
||||
|
||||
$orders = $this->filterOrders($request);
|
||||
|
||||
$status_orders = OrdersStatus::all();
|
||||
$magasins = Magasin::all();
|
||||
|
||||
$filter_status_order = $request->query('filter_status_order');
|
||||
$filter_magasin = $request->query('filter_magasin');
|
||||
$filter_reference = $request->query('filter_reference');
|
||||
|
||||
if (!empty($filter_status_order)) {
|
||||
$orders = $orders->where('status_id', $filter_status_order);
|
||||
}
|
||||
if (!empty($filter_magasin)) {
|
||||
$orders = $orders->whereHas(
|
||||
'timeslot',
|
||||
function (Builder $q) use ($filter_magasin) {
|
||||
$q->where('timeslots.magasin_id', $filter_magasin);
|
||||
}
|
||||
);
|
||||
}
|
||||
if (!empty($filter_reference)) {
|
||||
$orders = $orders->where('reference', 'like', "%{$filter_reference}%");
|
||||
}
|
||||
$orders = $orders->paginate(10);
|
||||
|
||||
return view('bo.orders.index', compact('orders'));
|
||||
return view(
|
||||
'bo.orders.index',
|
||||
compact('orders', 'status_orders', 'magasins', 'filter_status_order', 'filter_magasin', 'filter_reference')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* orders that ship today
|
||||
*
|
||||
* @param SortOrders $request
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function today(SortOrders $request)
|
||||
{
|
||||
//$orders = Order::orderBy('date', 'DESC')->get();
|
||||
|
||||
$orders = $this->filterOrders($request);
|
||||
|
||||
//filter today
|
||||
// Filter today.
|
||||
$today = CarbonImmutable::now()->startOfDay();
|
||||
$orders = $orders->whereHas('timeslot', function ($q) use ($today) {
|
||||
$q->where('day', '=', $today->format('d/m/Y'));
|
||||
});
|
||||
|
||||
|
||||
$orders = $orders->get(); //paginate(20);
|
||||
|
||||
$orders = $orders->get();
|
||||
return view('bo.orders.index', compact('orders', 'today'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter orders
|
||||
*
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
protected function filterOrders(Request $request)
|
||||
{
|
||||
$orders = Order::query();
|
||||
|
||||
|
||||
if ($request->rst) {
|
||||
Session::remove('orders.sort_col');
|
||||
Session::remove('orders.sort_way');
|
||||
|
|
@ -102,8 +135,10 @@ class OrdersController extends Controller
|
|||
case 'customer_id':
|
||||
$orders = $orders->orderBy('customer_id', Session::get('orders.sort_way'));
|
||||
break;
|
||||
}
|
||||
}
|
||||
} //end switch
|
||||
} else {
|
||||
$orders->orderByDesc('date');
|
||||
}//end if
|
||||
|
||||
return $orders;
|
||||
}
|
||||
|
|
@ -111,41 +146,47 @@ class OrdersController extends Controller
|
|||
/**
|
||||
* action de changement de statut vers l'avant
|
||||
* envoi de mails transctionnels
|
||||
* @param String $reference reference de la commande
|
||||
*
|
||||
* @param string $reference Reference de la commande.
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function changeStatus($reference)
|
||||
public function changeStatus(string $reference)
|
||||
{
|
||||
$order = Order::where('reference', $reference)->first();
|
||||
$order->status_id = $order->status_id + 1;
|
||||
$order->save();
|
||||
|
||||
//send confirm mail
|
||||
// Send confirm mail.
|
||||
Mail::to($order->customer->email)->send(new OrderStatusMail($order));
|
||||
Mail::mailer('smtp2')->to($order->customer->email)->send(new OrderStatusMail($order));
|
||||
|
||||
//return redirect()->route('bo.orders')->with('success', "Changement de status enregistré pour la commande " . $order->reference . ".");
|
||||
return back()->with('success', "Changement de status enregistré pour la commande " . $order->reference . ".");
|
||||
}
|
||||
|
||||
/**
|
||||
* mise au statut annulé d'une commande
|
||||
*
|
||||
* @param string $reference
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function cancelOrder($reference)
|
||||
public function cancelOrder(string $reference)
|
||||
{
|
||||
$order = Order::where('reference', $reference)->first();
|
||||
$order->status_id = 7;
|
||||
$order->save();
|
||||
|
||||
//return redirect()->route('bo.orders')->with('success', "La commande à été annulée.");
|
||||
return back()->with('success', "La commande " . $order->reference . " à été annulée.");
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* @deprecated Supprimer cette méthode qui repose sur un modèle de donnée osolète.
|
||||
* ajout de produits à la commande
|
||||
* @todo : supprimer cette méthode qui repose sur un modèle de donnée osolète
|
||||
*
|
||||
* @param string $orderReference
|
||||
* @param integer $productId
|
||||
* @param integer $quantity
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function addProduct($orderReference, $productId, $quantity)
|
||||
public function addProduct(string $orderReference, int $productId, int $quantity)
|
||||
{
|
||||
$product = Product::findOrFail($productId);
|
||||
$order = Order::where('reference', $orderReference)->first();
|
||||
|
|
@ -164,7 +205,8 @@ class OrdersController extends Controller
|
|||
/**
|
||||
* front
|
||||
* récap panier du tunnel de commande
|
||||
* @todo : déplacer vers le controller idoine
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function recapOrder()
|
||||
{
|
||||
|
|
@ -174,12 +216,18 @@ class OrdersController extends Controller
|
|||
|
||||
$cartInfos = array(
|
||||
"totalTTC" => Cart::total(),
|
||||
'totalTVA' => Cart::tax(), //total des taxes
|
||||
'totalHT' => Cart::subtotal(), //total sans les taxes
|
||||
'totalweight' => Cart::weight(), //poids total des items
|
||||
'totalHTbefore' => Cart::priceTotal(), //total avant taxes et remises
|
||||
'totaldiscount' => Cart::discount(), //total des remises
|
||||
'countItems' => Cart::count(), //nb de produits dans le cart
|
||||
// Total des taxes.
|
||||
'totalTVA' => Cart::tax(),
|
||||
// Total sans les taxes.
|
||||
'totalHT' => Cart::subtotal(),
|
||||
// Poids total des items.
|
||||
'totalweight' => Cart::weight(),
|
||||
// Total avant taxes et remises.
|
||||
'totalHTbefore' => Cart::priceTotal(),
|
||||
// Total des remises.
|
||||
'totaldiscount' => Cart::discount(),
|
||||
// Nb de produits dans le cart.
|
||||
'countItems' => Cart::count(),
|
||||
);
|
||||
|
||||
return view('sales.recap', compact('activestep', 'cart', 'cartInfos'));
|
||||
|
|
@ -188,13 +236,15 @@ class OrdersController extends Controller
|
|||
/**
|
||||
* front
|
||||
* Storing order from sales tunnel
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function store()
|
||||
{
|
||||
//save
|
||||
// Save.
|
||||
Cart::instance('panier');
|
||||
$order = new Order();
|
||||
//generate order ref
|
||||
// Generate order ref.
|
||||
$order->reference = $this->generateOrderRef();
|
||||
$order->date = Carbon::now();
|
||||
$order->status_id = 1;
|
||||
|
|
@ -203,7 +253,7 @@ class OrdersController extends Controller
|
|||
|
||||
$order->save();
|
||||
|
||||
//order_id
|
||||
// Order_id.
|
||||
Cart::instance('panier');
|
||||
$cart = Cart::content();
|
||||
foreach ($cart as $cartItem) {
|
||||
|
|
@ -211,47 +261,48 @@ class OrdersController extends Controller
|
|||
$order_line->order_id = $order->id;
|
||||
$order_line->product_id = $cartItem->model->id;
|
||||
$order_line->quantity = $cartItem->qty;
|
||||
//gross unit price
|
||||
// Gross unit price.
|
||||
$order_line->unit_price = $cartItem->model->priceHt;
|
||||
//discount per unit
|
||||
// Discount per unit.
|
||||
$order_line->unit_discount = $cartItem->model->discountAmount;
|
||||
//tax rate for this line
|
||||
// Tax rate for this line.
|
||||
$order_line->tax_rate = $cartItem->taxRate;
|
||||
//tax amount par unit
|
||||
$order_line->unit_tax = round(( ($order_line->unit_price - $order_line->unit_discount) * ($order_line->tax_rate / 100) ) * 100) / 100;
|
||||
//discount amount for the line
|
||||
// Tax amount par unit.
|
||||
$order_line->unit_tax = round(
|
||||
(($order_line->unit_price - $order_line->unit_discount) * ($order_line->tax_rate / 100)) * 100
|
||||
) / 100;
|
||||
// Discount amount for the line.
|
||||
$order_line->total_discount = $order_line->unit_discount * $order_line->quantity;
|
||||
//gross amount for the line
|
||||
// Gross amount for the line.
|
||||
$order_line->total_ht = ($order_line->unit_price - $order_line->unit_discount) * $order_line->quantity;
|
||||
//tax amount for the line
|
||||
// Tax amount for the line.
|
||||
$order_line->total_tax = $order_line->unit_tax * $order_line->quantity;
|
||||
//total TTC avec remises de la ligne
|
||||
// Total TTC avec remises de la ligne.
|
||||
$order_line->total_ttc = $order_line->total_ht + $order_line->total_tax;
|
||||
|
||||
$order_line->save();
|
||||
}
|
||||
}//end foreach
|
||||
|
||||
//empty cart
|
||||
// Empty cart.
|
||||
Cart::destroy();
|
||||
//then redirect
|
||||
// Then redirect.
|
||||
return redirect()->route('sales.pick-slot', ['reference' => $order->reference]);
|
||||
}
|
||||
|
||||
/**
|
||||
* generate order Reference
|
||||
* for a new order
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function generateOrderRef()
|
||||
{
|
||||
|
||||
//Avant
|
||||
//Str::uuid();
|
||||
//maintenant
|
||||
//format : YYYYMMDDHHMM000
|
||||
// Format : YYYYMMDDHHMM000.
|
||||
$now = Carbon::now();
|
||||
//count todays orders
|
||||
// Count todays orders.
|
||||
$countorders = Order::whereDate('created_at', Carbon::today())->count();
|
||||
//add one
|
||||
// Add one.
|
||||
$countorders++;
|
||||
$ref = $now->isoFormat('YYYYMMDDHHmm') . str_pad($countorders, 3, "0", STR_PAD_LEFT);
|
||||
return $ref;
|
||||
|
|
@ -259,8 +310,11 @@ class OrdersController extends Controller
|
|||
|
||||
/**
|
||||
* front tunnel de commande étape 3 : choix de créneau
|
||||
*
|
||||
* @param string $reference
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function timeSlotPick($reference)
|
||||
public function timeSlotPick(string $reference)
|
||||
{
|
||||
$activestep = 3;
|
||||
if (config('theme.multi_relay')) {
|
||||
|
|
@ -270,26 +324,81 @@ class OrdersController extends Controller
|
|||
}
|
||||
|
||||
$availCreneaux = array();
|
||||
//plus besoin car chargé par le composant vue.
|
||||
//$availCreneaux = $this->getAvailableCreneauxByShop($magasin->id);
|
||||
|
||||
$order = Order::where('reference', '=', $reference)->firstOrFail();
|
||||
$order = Order::where('reference', '=', $reference)->firstOrFail();
|
||||
|
||||
return view('sales.pick-slot', compact('activestep', 'availCreneaux', 'order', 'magasin'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
* add timeslot by interval between start and end hour
|
||||
*
|
||||
* @param array $plage
|
||||
* @param integer $weekDay
|
||||
* @param CarbonImmutable $current
|
||||
* @param Magasin $magasin
|
||||
* @param CarbonImmutable $now
|
||||
* @param CarbonImmutable $today
|
||||
* @param CarbonInterval $delaiPrepa
|
||||
* @param CarbonInterval $interval
|
||||
* @param Carbon $currentTime
|
||||
* @param Carbon $endTime
|
||||
* @return array
|
||||
*/
|
||||
public function getAvailableCreneauxByShop($id)
|
||||
private function addCreneaux(
|
||||
array $plage,
|
||||
int $weekDay,
|
||||
CarbonImmutable $current,
|
||||
Magasin $magasin,
|
||||
CarbonImmutable $now,
|
||||
CarbonImmutable $today,
|
||||
CarbonInterval $delaiPrepa,
|
||||
CarbonInterval $interval,
|
||||
Carbon $currentTime,
|
||||
Carbon $endTime
|
||||
) {
|
||||
$retArray = array();
|
||||
do {
|
||||
$creneau = $currentTime->format('H:i');
|
||||
$nbtakens = $magasin->timeslots()
|
||||
->where('day', $current->format('d/m/Y'))
|
||||
->where('time', $creneau)->count();
|
||||
|
||||
if ($nbtakens >= $plage[$weekDay]['max_orders_per_interval']) {
|
||||
$isDispo = false;
|
||||
} else {
|
||||
$isDispo = true;
|
||||
}
|
||||
|
||||
if (
|
||||
$current->addHours($currentTime->format('H'))->addMinutes($currentTime->format('i')) <
|
||||
$now->add($delaiPrepa)
|
||||
) {
|
||||
$isDispo = false;
|
||||
}
|
||||
// Attention si la date est passée (today mais avant maintenant) : pas de créneau.
|
||||
if ($current > $today || $currentTime >= $now) {
|
||||
$retArray[] = array($creneau, $isDispo);
|
||||
}
|
||||
$currentTime->add($interval);
|
||||
} while ($currentTime <= $endTime);
|
||||
return $retArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* give array of available crenaux
|
||||
*
|
||||
* @param integer $id
|
||||
* @return array
|
||||
*/
|
||||
public function getAvailableCreneauxByShop(int $id)
|
||||
{
|
||||
//setting à stocker et réutiliser
|
||||
// Setting à stocker et réutiliser.
|
||||
$plage_days = Setting::where('key', 'order_withdrawal_period')->firstOrFail()->value;
|
||||
|
||||
$magasin = Magasin::findOrFail($id);
|
||||
$timeslotSettings = $magasin->timeslotSettings;
|
||||
//$timeslotSettings = TimeslotSetting::all();
|
||||
//fabriquons un tableau recap
|
||||
// $timeslotSettings = TimeslotSetting::all();
|
||||
// Fabriquons un tableau recap.
|
||||
$plage = array();
|
||||
foreach ($timeslotSettings as $day) {
|
||||
$plage[$day->day_index] = array(
|
||||
|
|
@ -303,18 +412,14 @@ class OrdersController extends Controller
|
|||
);
|
||||
}
|
||||
|
||||
//génération des plages
|
||||
//start today
|
||||
// Génération des plages.
|
||||
// Start today.
|
||||
$today = CarbonImmutable::now()->startOfDay();
|
||||
$weekDay = $today->weekday();
|
||||
//final boundary (permet de limiter la liste des jours d'exception)
|
||||
// Final boundary (permet de limiter la liste des jours d'exception).
|
||||
$finalday = $today->add($plage_days, 'day');
|
||||
$now = CarbonImmutable::now();
|
||||
//jours exceptions
|
||||
// $noCollectDays = CollecteException::where('magasin_id',$magasin->id)
|
||||
// ->whereDate('date', '>', $now)
|
||||
// ->whereDate('date', '<=', $finalday)
|
||||
// ->orderBy('date')->get();
|
||||
// Jours exceptions.
|
||||
$noCollectDays = $magasin->collecteExceptions()
|
||||
->whereDate('date', '>', $now)
|
||||
->whereDate('date', '<=', $finalday)
|
||||
|
|
@ -325,12 +430,11 @@ class OrdersController extends Controller
|
|||
$availCreneaux = array();
|
||||
|
||||
for ($i = 0; $i < $plage_days; $i++) {
|
||||
/** @var Carbon */
|
||||
$current = $today->add($i, 'day');
|
||||
$weekDay = $current->weekday();
|
||||
$interval = CarbonInterval::createFromFormat('h:i', $plage[$weekDay]['interval'] ?? '00:15');
|
||||
|
||||
//si c'est un jour exception skip
|
||||
// Si c'est un jour exception skip.
|
||||
$skip = false;
|
||||
foreach ($noCollectDays as $not_today) {
|
||||
if ($current->isSameDay($not_today->date)) {
|
||||
|
|
@ -340,64 +444,63 @@ class OrdersController extends Controller
|
|||
if ($skip) {
|
||||
continue;
|
||||
}
|
||||
//matinée
|
||||
$availCreneaux[$current->format('d/m/Y')] = array();
|
||||
// Matinée.
|
||||
if (!empty($plage[$weekDay]['morning_start'])) {
|
||||
$currentTime = Carbon::createFromTimeString($plage[$weekDay]['morning_start']);
|
||||
$endTime = Carbon::createFromTimeString($plage[$weekDay]['morning_end']);
|
||||
do {
|
||||
$creneau = $currentTime->format('H:i');
|
||||
$nbtakens = $magasin->timeslots()
|
||||
->where('day', $current->format('d/m/Y'))
|
||||
->where('time', $creneau)->count();
|
||||
|
||||
// $nbtakens = Timeslot::where('day', $current->format('d/m/Y'))
|
||||
// ->where('time', $creneau)->count();
|
||||
$morningCreneaux = $this->addCreneaux(
|
||||
$plage,
|
||||
$weekDay,
|
||||
$current,
|
||||
$magasin,
|
||||
$now,
|
||||
$today,
|
||||
$delaiPrepa,
|
||||
$interval,
|
||||
$currentTime,
|
||||
$endTime
|
||||
);
|
||||
|
||||
if ($nbtakens >= $plage[$weekDay]['max_orders_per_interval']) {
|
||||
$isDispo = false;
|
||||
} else {
|
||||
$isDispo = true;
|
||||
}
|
||||
|
||||
if ($current->addHours($currentTime->format('H'))->addMinutes($currentTime->format('i')) < $now->add($delaiPrepa)) {
|
||||
$isDispo = false;
|
||||
}
|
||||
//attention si la date est passée (today mais avant maintenant) : pas de créneau
|
||||
if ($current > $today || $currentTime >= $now) {
|
||||
$availCreneaux[$current->format('d/m/Y')][] = array($creneau,$isDispo);
|
||||
}
|
||||
$currentTime->add($interval);
|
||||
} while ($currentTime <= $endTime);
|
||||
}
|
||||
//aprem
|
||||
$availCreneaux[$current->format('d/m/Y')] = array_merge(
|
||||
$availCreneaux[$current->format('d/m/Y')],
|
||||
$morningCreneaux
|
||||
);
|
||||
} //end if
|
||||
// Aprem.
|
||||
if (!empty($plage[$weekDay]['afternoon_start'])) {
|
||||
$currentTime = Carbon::createFromTimeString($plage[$weekDay]['afternoon_start']);
|
||||
$endTime = Carbon::createFromTimeString($plage[$weekDay]['afternoon_end']);
|
||||
do {
|
||||
$creneau = $currentTime->format('H:i');
|
||||
$nbtakens = Timeslot::where('day', $current->format('d/m/Y'))->where('time', $creneau)->count();
|
||||
if ($nbtakens >= $plage[$weekDay]['max_orders_per_interval']) {
|
||||
$isDispo = false;
|
||||
} else {
|
||||
$isDispo = true;
|
||||
}
|
||||
|
||||
if ($current->addHours($currentTime->format('H'))->addMinutes($currentTime->format('i')) < $now->add($delaiPrepa)) {
|
||||
$isDispo = false;
|
||||
}
|
||||
$afternoonCreneaux = $this->addCreneaux(
|
||||
$plage,
|
||||
$weekDay,
|
||||
$current,
|
||||
$magasin,
|
||||
$now,
|
||||
$today,
|
||||
$delaiPrepa,
|
||||
$interval,
|
||||
$currentTime,
|
||||
$endTime
|
||||
);
|
||||
|
||||
//attention si la date est passée (today mais avant maintenant) : pas de créneau
|
||||
if ($current > $today || $currentTime >= $now) {
|
||||
$availCreneaux[$current->format('d/m/Y')][] = array($creneau,$isDispo);
|
||||
}
|
||||
$currentTime->add($interval);
|
||||
} while ($currentTime <= $endTime);
|
||||
}
|
||||
}
|
||||
$availCreneaux[$current->format('d/m/Y')] = array_merge(
|
||||
$availCreneaux[$current->format('d/m/Y')],
|
||||
$afternoonCreneaux
|
||||
);
|
||||
} //end if
|
||||
}//end for
|
||||
return $availCreneaux;
|
||||
}
|
||||
|
||||
//call ajax pour le composant vue de timeslots
|
||||
/**
|
||||
* Call ajax pour le composant vue de timeslots.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function getAvailableCreneaux(Request $request)
|
||||
{
|
||||
return $this->getAvailableCreneauxByShop($request->id);
|
||||
|
|
@ -407,6 +510,10 @@ class OrdersController extends Controller
|
|||
* front
|
||||
* enregistrement du créneau de collect
|
||||
* et validation de la commande
|
||||
*
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @throws \RuntimeException If email missing.
|
||||
*/
|
||||
public function setTimeSlot(Request $request)
|
||||
{
|
||||
|
|
@ -416,7 +523,6 @@ class OrdersController extends Controller
|
|||
'ok_cgv' => 'accepted',
|
||||
]);
|
||||
|
||||
$time_slot = Carbon::createFromFormat('d/m/Y-H:i', $request->selectedcreneau);
|
||||
$tsday = explode('-', $request->selectedcreneau)[0];
|
||||
$tstime = explode('-', $request->selectedcreneau)[1];
|
||||
$magasin_id = $request->selectedmagasin;
|
||||
|
|
@ -424,8 +530,8 @@ class OrdersController extends Controller
|
|||
$order = Order::where('reference', '=', $reference)->firstOrFail();
|
||||
|
||||
if ($order->status_id == 1) {
|
||||
// on ne traite l'enregistrement que pour les commandes en attente venant de l'étape de récap
|
||||
//save timeslot
|
||||
// On ne traite l'enregistrement que pour les commandes en attente venant de l'étape de récap.
|
||||
// Save timeslot.
|
||||
$timeslot = Timeslot::firstOrNew(['order_id' => $order->id]);
|
||||
$timeslot->order_id = $order->id;
|
||||
$timeslot->magasin_id = $magasin_id;
|
||||
|
|
@ -433,35 +539,53 @@ class OrdersController extends Controller
|
|||
$timeslot->time = $tstime;
|
||||
$timeslot->save();
|
||||
|
||||
//save order status
|
||||
// Save order status.
|
||||
$order->status_id = 3;
|
||||
$order->save();
|
||||
|
||||
//send confirm mail
|
||||
// Send confirm mail.
|
||||
Mail::to($order->customer->email)->queue(new OrderConfirmMail($order));
|
||||
Mail::mailer('smtp2')->to($order->customer->email)->queue(new OrderConfirmMail($order));
|
||||
|
||||
//envoi du mail de confirmation aux admins site
|
||||
$toMailSetting = Setting::where('key', 'send_order_confirm_mail_to')->first();
|
||||
if (empty($toMailSetting->value)) {
|
||||
$toMail = config('mail.from.address');
|
||||
// Envoi du mail de confirmation aux admins site.
|
||||
/** @var \App\Model\Magasin|null */
|
||||
$shop = Magasin::where('id', $magasin_id)->first();
|
||||
|
||||
if ($shop and $shop->email_confirm) {
|
||||
/** @var string */
|
||||
$toMail = $shop->email_confirm;
|
||||
} else {
|
||||
$toMail = $toMailSetting->value;
|
||||
/** @var string|null */
|
||||
$toMail = \optional(Setting::where('key', 'send_order_confirm_mail_to')->first())->value;
|
||||
if (!$toMail) {
|
||||
/** @var string|null */
|
||||
$toMail = config('mail.from.address');
|
||||
}
|
||||
}
|
||||
Mail::to($toMail)->queue(new OrderConfirmAdminMail($order));
|
||||
Mail::mailer('smtp2')->to($toMail)->queue(new OrderConfirmAdminMail($order));
|
||||
|
||||
//export commande
|
||||
if (!$toMail) {
|
||||
throw new \RuntimeException('Impossible de trouver un mail');
|
||||
}
|
||||
|
||||
Mail::to($toMail)->queue(new OrderConfirmAdminMail($order));
|
||||
|
||||
// Export commande.
|
||||
if (config('bosettings.regate_orders')) {
|
||||
CsvOrderWrite::dispatch($order);
|
||||
}
|
||||
}
|
||||
}//end if
|
||||
|
||||
//redirect to final confirmation
|
||||
// Redirect to final confirmation.
|
||||
return redirect()->route('sales.confirm', ['reference' => $order->reference]);
|
||||
}
|
||||
|
||||
public function generateOrder($reference)
|
||||
/**
|
||||
* generate Order
|
||||
* Test method
|
||||
*
|
||||
* @param string $reference
|
||||
* @return void
|
||||
*/
|
||||
public function generateOrder(string $reference)
|
||||
{
|
||||
$order = Order::where('reference', '=', $reference)->with('lines')->firstOrFail();
|
||||
$job = new CsvOrderWrite($order);
|
||||
|
|
@ -472,15 +596,18 @@ class OrdersController extends Controller
|
|||
/**
|
||||
* front
|
||||
* page de confirmation de commande
|
||||
*
|
||||
* @param string $reference
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function confirmOrder($reference)
|
||||
public function confirmOrder(string $reference)
|
||||
{
|
||||
$activestep = 4;
|
||||
|
||||
$idcommande = Session::get('idcommande');
|
||||
$order = Order::where('reference', '=', $reference)->firstOrFail();
|
||||
|
||||
//1 seul magasin en base pour le moment
|
||||
// 1 seul magasin en base pour le moment
|
||||
$magasin = Magasin::find($order->timeslot->magasin->id);
|
||||
|
||||
return view('sales.confirm', compact('activestep', 'order', 'magasin'));
|
||||
|
|
@ -489,9 +616,12 @@ class OrdersController extends Controller
|
|||
/**
|
||||
* bo
|
||||
* ajx : affichage d'infos sur un client
|
||||
* @todo : déplacer dans le controller idoine
|
||||
*
|
||||
* @param integer $id
|
||||
* @param string|null $mode
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function getCustomerInfo($id, $mode = null)
|
||||
public function getCustomerInfo(int $id, string $mode = null)
|
||||
{
|
||||
$cust = Customers::findOrFail($id);
|
||||
if (!is_null($mode)) {
|
||||
|
|
@ -499,7 +629,7 @@ class OrdersController extends Controller
|
|||
return view('bo.customer.tippy-card', compact('cust'));
|
||||
}
|
||||
if ($mode == "json") {
|
||||
return $cust;
|
||||
return $cust->apiData;
|
||||
}
|
||||
return view('bo.customer.info-card', compact('cust'));
|
||||
}
|
||||
|
|
@ -507,9 +637,12 @@ class OrdersController extends Controller
|
|||
}
|
||||
|
||||
/**
|
||||
* bo : page détatil commande
|
||||
* bo : page détail commande
|
||||
*
|
||||
* @param string $reference
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function orderDetail($reference)
|
||||
public function orderDetail(string $reference)
|
||||
{
|
||||
$order = Order::where('reference', '=', $reference)->firstOrFail();
|
||||
return view('bo.orders.detail', compact('order'));
|
||||
|
|
|
|||
|
|
@ -21,7 +21,10 @@ use Illuminate\Support\Facades\File;
|
|||
class ProductsController extends Controller
|
||||
{
|
||||
/**
|
||||
* Bo index page for products
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
|
|
@ -40,13 +43,12 @@ class ProductsController extends Controller
|
|||
}
|
||||
$products = $products->paginate(10);
|
||||
|
||||
//ici récupération des infos additionnelles pour affichage dans la liste
|
||||
// @todo : parametrer l'occurence de ces affichages car ça n'aura aucun sens selon le type de produit
|
||||
// Ici récupération des infos additionnelles pour affichage dans la liste.
|
||||
foreach ($products as &$product) {
|
||||
if(!empty($product->product_type)) {
|
||||
if (!empty($product->product_type)) {
|
||||
$product->additionnalProductInfo = $product->additionnalProductInfo($product->product_type);
|
||||
if ($product->additionnalProductInfo === null) {
|
||||
//n'existe pas on renseigne un vide
|
||||
// N'existe pas on renseigne un vide.
|
||||
$product_type = $product->product_type;
|
||||
$modelClass = 'App\Models\\' . ucfirst($product_type);
|
||||
$product->$product_type = new $modelClass();
|
||||
|
|
@ -58,32 +60,34 @@ class ProductsController extends Controller
|
|||
}
|
||||
|
||||
/**
|
||||
* create à product
|
||||
* Show the form for creating a new resource.
|
||||
* @param string $product_type
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create($product_type = null)
|
||||
public function create(string $product_type = null)
|
||||
{
|
||||
if (!empty($product_type) && !array_key_exists($product_type, config('theme.enum_product_types'))) {
|
||||
abort(404, "Cette page n'existe pas.");
|
||||
//return redirect()->route('bo.products.index');
|
||||
}
|
||||
$modelClass = 'App\Models\\' . ucfirst($product_type);
|
||||
$product = new Product();
|
||||
if(!empty($product_type)) {
|
||||
$modelClass = 'App\Models\\' . ucfirst($product_type);
|
||||
$product = new Product();
|
||||
if (!empty($product_type)) {
|
||||
$product->$product_type = new $modelClass();
|
||||
}
|
||||
$ranges = Range::all();
|
||||
$taxes = TaxRate::all();
|
||||
$ranges = Range::all();
|
||||
$taxes = TaxRate::all();
|
||||
return view('bo.products.create', compact('product_type', 'product', 'ranges', 'taxes'));
|
||||
}
|
||||
|
||||
/**
|
||||
* store a new product
|
||||
* @todo : manage tags and associated products
|
||||
* @todo : enregistrer unité de vente, poids et unité de poids
|
||||
*
|
||||
* @param ProductRequest $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(ProductRequest $request)
|
||||
{
|
||||
//products fields
|
||||
// Products fields.
|
||||
$name = $request->name;
|
||||
$description = $request->description;
|
||||
$picture = $request->picture;
|
||||
|
|
@ -98,15 +102,17 @@ class ProductsController extends Controller
|
|||
$weight = $request->weight;
|
||||
$weight_unit = $request->weight_unit;
|
||||
$status = $request->status === null ? 0 : 1;
|
||||
$orderable_start = $request->orderable_start_date === null ? null : $request->orderable_start_date . " " . $request->orderable_start_time;
|
||||
$orderable_end = $request->orderable_end_date === null ? null : $request->orderable_end_date . " " . $request->orderable_end_time;
|
||||
$orderable_start = $request->orderable_start_date === null ? null
|
||||
: $request->orderable_start_date . " " . $request->orderable_start_time;
|
||||
$orderable_end = $request->orderable_end_date === null ? null
|
||||
: $request->orderable_end_date . " " . $request->orderable_end_time;
|
||||
$star = $request->star === null ? 0 : 1;
|
||||
$slug = Str::slug($name);
|
||||
$rangeId = $request->range_id;
|
||||
$taxRateId = $request->tax_rate_id;
|
||||
|
||||
|
||||
// Check si le slug existe déjà dans cette gamme de produits
|
||||
// Check si le slug existe déjà dans cette gamme de produits.
|
||||
$slugExist = Product::where([
|
||||
['range_id', $rangeId],
|
||||
['slug', $slug]
|
||||
|
|
@ -140,7 +146,7 @@ class ProductsController extends Controller
|
|||
$product->tax_rate_id = $taxRateId;
|
||||
$product->save();
|
||||
|
||||
// Check si le slug existe dans la table old_slugs, auquel cas il est attribué a ce nouveau produit
|
||||
// Check si le slug existe dans la table old_slugs, auquel cas il est attribué a ce nouveau produit.
|
||||
$oldSlug = OldSlug::where('slug', $slug)->first();
|
||||
if ($oldSlug && $oldSlug->product_id !== $product->id) {
|
||||
$oldSlug->product_id = $product->id;
|
||||
|
|
@ -163,7 +169,7 @@ class ProductsController extends Controller
|
|||
$product->save();
|
||||
}
|
||||
|
||||
//ajout des infos additionnelles
|
||||
// Ajout des infos additionnelles.
|
||||
$product_type = $request->product_type;
|
||||
|
||||
if ($product_type !== null) {
|
||||
|
|
@ -174,23 +180,27 @@ class ProductsController extends Controller
|
|||
}
|
||||
|
||||
|
||||
//additionnal product info (foodProduct)
|
||||
// Additionnal product info (foodProduct).
|
||||
return redirect()->route('bo.products.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* edit an existing product
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param integer $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
public function edit(int $id)
|
||||
{
|
||||
$product = Product::findOrFail($id);
|
||||
if(!empty($product->product_type)) {
|
||||
if (!empty($product->product_type)) {
|
||||
$product->additionnalProductInfo = $product->additionnalProductInfo($product->product_type);
|
||||
//above lines equivalent to :
|
||||
//$product = Product::with('additionnalProductInfo')->findOrFail($id);
|
||||
|
||||
/**
|
||||
* Above lines equivalent to
|
||||
* $product = Product::with('additionnalProductInfo')->findOrFail($id);
|
||||
*/
|
||||
if ($product->additionnalProductInfo === null) {
|
||||
//n'existe pas on renseigne un vide
|
||||
// N'existe pas on renseigne un vide.
|
||||
$product_type = $product->product_type;
|
||||
$modelClass = 'App\Models\\' . ucfirst($product_type);
|
||||
$product->$product_type = new $modelClass();
|
||||
|
|
@ -206,23 +216,30 @@ class ProductsController extends Controller
|
|||
$selectedProds = $product->products;
|
||||
$existingProds = $existingProds->diff($selectedProds);
|
||||
|
||||
return view('bo.products.edit', compact('product', 'ranges', 'taxes', 'existingTags', 'selectedtags', 'existingProds', 'selectedProds'));
|
||||
return view('bo.products.edit', compact(
|
||||
'product',
|
||||
'ranges',
|
||||
'taxes',
|
||||
'existingTags',
|
||||
'selectedtags',
|
||||
'existingProds',
|
||||
'selectedProds'
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* update an existing product
|
||||
* Update the specified resource.
|
||||
*
|
||||
* @param \App\Models\Product $product
|
||||
* @param ProductRequest $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Product $product, ProductRequest $request)
|
||||
{
|
||||
|
||||
//$product = Product::findOrFail($id);
|
||||
|
||||
$orderable_end_time = $request->orderable_end_time === null ? "23:59" : $request->orderable_end_time;
|
||||
|
||||
$name = $request->name;
|
||||
$description = $request->description;
|
||||
$picture = $request->picture;
|
||||
$picture_large = $request->picture_large;
|
||||
$price = $request->price;
|
||||
$invoicing_unit = $request->invoicing_unit;
|
||||
$priceBuy = $request->price_buy;
|
||||
|
|
@ -233,59 +250,22 @@ class ProductsController extends Controller
|
|||
$weight = $request->weight;
|
||||
$weight_unit = $request->weight_unit;
|
||||
$status = $request->status === null ? 0 : 1;
|
||||
$orderable_start = $request->orderable_start_date === null ? null : $request->orderable_start_date . " " . $request->orderable_start_time;
|
||||
$orderable_end = $request->orderable_end_date === null ? null : $request->orderable_end_date . " " . $orderable_end_time;
|
||||
$orderable_start = $request->orderable_start_date === null ? null
|
||||
: $request->orderable_start_date . " " . $request->orderable_start_time;
|
||||
$orderable_end = $request->orderable_end_date === null ? null
|
||||
: $request->orderable_end_date . " " . $orderable_end_time;
|
||||
$star = $request->star === null ? 0 : 1;
|
||||
$slug = Str::slug($name);
|
||||
$rangeId = $request->range_id;
|
||||
$taxRateId = $request->tax_rate_id;
|
||||
$tags = $request->tags;
|
||||
|
||||
// Check si le slug existe déjà dans cette gamme de produits
|
||||
$slugExist = Product::where([
|
||||
['range_id', $rangeId],
|
||||
['slug', $slug],
|
||||
['id', '<>', $product->id]
|
||||
])->first();
|
||||
$this->checkSlugExistsWithinRange($request, $rangeId, $slug, $product->id);
|
||||
|
||||
if ($slugExist) {
|
||||
return redirect()->back()
|
||||
->withInput($request->input())
|
||||
->withErrors("Erreur : un produit avec le slug d'accès \"" . $slug .
|
||||
"\" éxiste déjà. Veuillez changer le nom du produit.");
|
||||
}
|
||||
|
||||
$str_random = Str::random(5);
|
||||
|
||||
if ($picture !== null) {
|
||||
if ($product->picture !== null && file_exists(public_path('images/produits/') . $product->picture)) {
|
||||
unlink(public_path('images/produits/') . $product->picture);
|
||||
}
|
||||
$imageName = $product->id . '_' . $str_random . '.' . $picture->extension();
|
||||
$picture->move(public_path('images/produits'), $imageName);
|
||||
$product->picture = $imageName;
|
||||
}
|
||||
|
||||
if ($picture_large !== null) {
|
||||
if ($product->picture_large !== null && file_exists(public_path('images/produits/') . $product->picture_large)) {
|
||||
unlink(public_path('images/produits/') . $product->picture_large);
|
||||
}
|
||||
$imageName = $product->id . '_' . $str_random . '_large.' . $picture_large->extension();
|
||||
$picture_large->move(public_path('images/produits'), $imageName);
|
||||
$product->picture_large = $imageName;
|
||||
}
|
||||
$this->manageProductImages($request->picture, $product, $request->picture_large);
|
||||
|
||||
$product->name = $name;
|
||||
|
||||
if ($product->slug != $slug) {
|
||||
$exist = OldSlug::where('slug', $product->slug)->first();
|
||||
if ($exist === null) {
|
||||
$oldSlug = new OldSlug();
|
||||
$oldSlug->product_id = $product->id;
|
||||
$oldSlug->slug = $product->slug;
|
||||
$oldSlug->save();
|
||||
}
|
||||
}
|
||||
$this->saveNewSlugForProduct($product, $slug);
|
||||
|
||||
$product->description = $description;
|
||||
$product->price = $price;
|
||||
|
|
@ -306,65 +286,189 @@ class ProductsController extends Controller
|
|||
$product->tax_rate_id = $taxRateId;
|
||||
$product->save();
|
||||
|
||||
// Check si le slug existe dans la table old_slug, auquel cas il est attribué a ce nouveau produit
|
||||
$oldSlug = OldSlug::where('slug', $slug)->first();
|
||||
if ($oldSlug) {
|
||||
$oldSlug->delete();
|
||||
}
|
||||
// Check si le slug existe dans la table old_slug, auquel cas il est attribué a ce nouveau produit.
|
||||
$this->cleanOldSlug($slug);
|
||||
|
||||
//ajout des infos additionnelles
|
||||
// Ajout des infos additionnelles.
|
||||
$product_type = $request->product_type;
|
||||
|
||||
//save additionnal
|
||||
// Save additionnal.
|
||||
if ($product_type !== null) {
|
||||
$methodName = "save" . ucfirst($product_type);
|
||||
$this->$methodName($request, $product->id);
|
||||
}
|
||||
|
||||
//tags associés
|
||||
if (!empty($tags)) {
|
||||
$arTagIds = array();
|
||||
foreach ($tags as $tag) {
|
||||
$oTag = json_decode($tag);
|
||||
if (empty($oTag->id)) {
|
||||
//we need a new tag
|
||||
$arTagIds[] = $this->storeTag($oTag);
|
||||
} else {
|
||||
$arTagIds[] = $oTag->id;
|
||||
}
|
||||
}
|
||||
//prise en charge de la liaison avec les produits
|
||||
$product->tags()->sync($arTagIds);
|
||||
} else {
|
||||
$product->tags()->sync(array());
|
||||
}
|
||||
// Tags associés.
|
||||
$this->syncTags($request->tags, $product);
|
||||
|
||||
//produits associés
|
||||
if (!empty($request->prods)) {
|
||||
$productIds = explode(",", $request->prods);
|
||||
//prise en charge de la liaison avec les produits
|
||||
$product->products()->sync($productIds);
|
||||
} else {
|
||||
$product->products()->sync(array());
|
||||
}
|
||||
// Produits associés.
|
||||
$this->syncProduitsAssocies($request->prods, $product);
|
||||
|
||||
return redirect()->route('bo.products.edit', $product->id)->with('success', 'Modifications enregistrés !');
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if slug already exists, if so redirect
|
||||
*
|
||||
* @param Request $request
|
||||
* @param integer $rangeId
|
||||
* @param string $slug
|
||||
* @param integer|null $productId
|
||||
* @return \Illuminate\Http\RedirectResponse|void
|
||||
*/
|
||||
private function checkSlugExistsWithinRange(Request $request, int $rangeId, string $slug, int $productId = null)
|
||||
{
|
||||
// Check si le slug existe déjà dans cette gamme de produits.
|
||||
$slugExist = Product::where([
|
||||
['range_id', $rangeId],
|
||||
['slug', $slug],
|
||||
['id', '<>', $productId]
|
||||
])->first();
|
||||
|
||||
if ($slugExist) {
|
||||
return redirect()->back()
|
||||
->withInput($request->input())
|
||||
->withErrors("Erreur : un produit avec le slug d'accès \"" . $slug .
|
||||
"\" éxiste déjà. Veuillez changer le nom du produit.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If new slug for product then save oldslug
|
||||
*
|
||||
* @param Product $product
|
||||
* @param string $slug
|
||||
* @return void
|
||||
*/
|
||||
private function saveNewSlugForProduct(Product $product, string $slug)
|
||||
{
|
||||
if ($product->slug != $slug) {
|
||||
$exist = OldSlug::where('slug', $product->slug)->first();
|
||||
if ($exist === null) {
|
||||
$oldSlug = new OldSlug();
|
||||
$oldSlug->product_id = $product->id;
|
||||
$oldSlug->slug = $product->slug;
|
||||
$oldSlug->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* clean oldslug if exists
|
||||
*
|
||||
* @param string $slug
|
||||
* @return void
|
||||
*/
|
||||
private function cleanOldSlug(string $slug)
|
||||
{
|
||||
// Check si le slug existe dans la table old_slug, auquel cas il est attribué a ce nouveau produit.
|
||||
$oldSlug = OldSlug::where('slug', $slug)->first();
|
||||
if ($oldSlug) {
|
||||
$oldSlug->delete();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Store and update saved images on product
|
||||
*
|
||||
* @param UploadedFile|null $picture
|
||||
* @param Product $product
|
||||
* @param UploadedFile|null $picture_large
|
||||
* @return void
|
||||
*/
|
||||
private function manageProductImages($picture, Product &$product, $picture_large)
|
||||
{
|
||||
|
||||
$str_random = Str::random(5);
|
||||
|
||||
if ($picture !== null) {
|
||||
if (
|
||||
$product->picture !== null &&
|
||||
file_exists(public_path('images/produits/') . $product->picture)
|
||||
) {
|
||||
unlink(public_path('images/produits/') . $product->picture);
|
||||
}
|
||||
$imageName = $product->id . '_' . $str_random . '.' . $picture->extension();
|
||||
$picture->move(public_path('images/produits'), $imageName);
|
||||
$product->picture = $imageName;
|
||||
}
|
||||
|
||||
if ($picture_large !== null) {
|
||||
if (
|
||||
$product->picture_large !== null &&
|
||||
file_exists(public_path('images/produits/') . $product->picture_large)
|
||||
) {
|
||||
unlink(public_path('images/produits/') . $product->picture_large);
|
||||
}
|
||||
$imageName = $product->id . '_' . $str_random . '_large.' . $picture_large->extension();
|
||||
$picture_large->move(public_path('images/produits'), $imageName);
|
||||
$product->picture_large = $imageName;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* sync tags to product
|
||||
*
|
||||
* @param array|null $tags
|
||||
* @param Product $product
|
||||
* @return void
|
||||
*/
|
||||
private function syncTags(array $tags = null, Product &$product)
|
||||
{
|
||||
if (!empty($tags)) {
|
||||
$arTagIds = array();
|
||||
foreach ($tags as $tag) {
|
||||
$oTag = json_decode($tag);
|
||||
if (empty($oTag->id)) {
|
||||
// We need a new tag.
|
||||
$arTagIds[] = $this->storeTag($oTag);
|
||||
} else {
|
||||
$arTagIds[] = $oTag->id;
|
||||
}
|
||||
}
|
||||
// Prise en charge de la liaison avec les produits.
|
||||
$product->tags()->sync($arTagIds);
|
||||
} else {
|
||||
$product->tags()->sync(array());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* sync associated products to product
|
||||
*
|
||||
* @param string|null $prods
|
||||
* @param Product $product
|
||||
* @return void
|
||||
*/
|
||||
private function syncProduitsAssocies(string $prods = null, Product $product)
|
||||
{
|
||||
if (!empty($prods)) {
|
||||
$productIds = explode(",", $prods);
|
||||
// Prise en charge de la liaison avec les produits.
|
||||
$product->products()->sync($productIds);
|
||||
} else {
|
||||
$product->products()->sync(array());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to store a new tag if necessary
|
||||
* Otherwise retreive an existing tag to associate its id
|
||||
*
|
||||
* @param \App\Models\Tag $oTag
|
||||
* @return integer
|
||||
*/
|
||||
public function storeTag($oTag)
|
||||
public function storeTag(Tag $oTag)
|
||||
{
|
||||
$slug = Str::slug($oTag->label);
|
||||
$tag = Tag::where('slug', $slug)->first();
|
||||
if ($tag === null) {
|
||||
//si on pas encore ce tag on le crée
|
||||
$tag = new Tag();
|
||||
$tag->label = $oTag->label;
|
||||
$tag->slug = Str::slug($oTag->label);
|
||||
$tag->status = 1; //a new tag is published by default
|
||||
// Si on pas encore ce tag on le crée.
|
||||
$tag = new Tag();
|
||||
$tag->label = $oTag->label;
|
||||
$tag->slug = Str::slug($oTag->label);
|
||||
// A new tag is published by default.
|
||||
$tag->status = 1;
|
||||
$tag->order = TagsController::getLastOrder();
|
||||
$tag->save();
|
||||
}
|
||||
|
|
@ -373,16 +477,21 @@ class ProductsController extends Controller
|
|||
|
||||
/**
|
||||
* destroy a product (soft delete)
|
||||
* @todo : manage liaisons
|
||||
*
|
||||
* @param integer $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id)
|
||||
public function destroy(int $id)
|
||||
{
|
||||
$product = Product::findOrFail($id);
|
||||
|
||||
if ($product->picture !== null && file_exists(public_path('images/produits/') . $product->picture)) {
|
||||
unlink(public_path('images/produits/') . $product->picture);
|
||||
}
|
||||
if ($product->picture_large !== null && file_exists(public_path('images/produits/') . $product->picture_large)) {
|
||||
if (
|
||||
$product->picture_large !== null &&
|
||||
file_exists(public_path('images/produits/') . $product->picture_large)
|
||||
) {
|
||||
unlink(public_path('images/produits/') . $product->picture_large);
|
||||
}
|
||||
|
||||
|
|
@ -394,41 +503,55 @@ class ProductsController extends Controller
|
|||
|
||||
/**
|
||||
* check if inco data exists
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return mixed
|
||||
*/
|
||||
public function checkIncoData(Request $request) {
|
||||
$id = $request->id;
|
||||
public function checkIncoData(Request $request)
|
||||
{
|
||||
$id = $request->id;
|
||||
$xmlInco = XmlInco::find($id);
|
||||
|
||||
if(!empty($xmlInco)) {
|
||||
//we have data
|
||||
$hasInco = __("Des données Inco sont disponibles, souhaitez vous les associer à ce produit ?");
|
||||
if (!empty($xmlInco)) {
|
||||
// We have data.
|
||||
$hasInco = __("Des données Inco sont disponibles, souhaitez vous les associer à ce produit ?");
|
||||
$preparedImages = $this->prepareIncoImages($xmlInco->picture);
|
||||
return view('bo.products.load-inco',compact('hasInco','xmlInco','preparedImages'));
|
||||
return view('bo.products.load-inco', compact('hasInco', 'xmlInco', 'preparedImages'));
|
||||
} else {
|
||||
return array("data"=> array());
|
||||
return array("data" => array());
|
||||
}
|
||||
}
|
||||
|
||||
public function getPrepareIncoImages(Request $request) {
|
||||
$picture = $request->picture;
|
||||
/**
|
||||
* Show prepared images
|
||||
*
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function getPrepareIncoImages(Request $request)
|
||||
{
|
||||
$picture = $request->picture;
|
||||
$preparedImages = $this->prepareIncoImages($picture);
|
||||
return view('bo.products.inco-images', compact('preparedImages'));
|
||||
}
|
||||
|
||||
/**
|
||||
* prepare Inco Images
|
||||
* prepared images
|
||||
*
|
||||
* @param array $picture
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function prepareIncoImages($picture) {
|
||||
|
||||
public function prepareIncoImages(array $picture)
|
||||
{
|
||||
$preparedImages = array();
|
||||
|
||||
foreach ($picture as $incoImage) {
|
||||
//charge
|
||||
if(File::exists(storage_path($incoImage))) {
|
||||
// Charge.
|
||||
if (File::exists(storage_path($incoImage))) {
|
||||
$imagePath = storage_path($incoImage);
|
||||
//redimensionne
|
||||
//create mask
|
||||
//Resize original image into mask
|
||||
// Redimensionne.
|
||||
// Create mask.
|
||||
// Resize original image into mask.
|
||||
$this->resizeImg(
|
||||
$imagePath,
|
||||
config('theme.product_image_large_maxwidth'),
|
||||
|
|
@ -445,15 +568,24 @@ class ProductsController extends Controller
|
|||
|
||||
|
||||
$preparedImages[] = "inco/images/" . File::name($incoImage) . "_large.png";
|
||||
}
|
||||
}
|
||||
}//end if
|
||||
}//end foreach
|
||||
return $preparedImages;
|
||||
}
|
||||
|
||||
/**
|
||||
* redimensionne une image dans un masque
|
||||
*/
|
||||
private function resizeImg($imagePath, $maskWidth, $maskHeight, $resizedName)
|
||||
/**
|
||||
* redimensionne une image dans un masque
|
||||
*
|
||||
* @param string $imagePath
|
||||
* @param integer $maskWidth
|
||||
* @param integer $maskHeight
|
||||
* @param string $resizedName
|
||||
* @return boolean|void
|
||||
*/
|
||||
private function resizeImg(string $imagePath, int $maskWidth, int $maskHeight, string $resizedName)
|
||||
{
|
||||
// ---- création du masque
|
||||
$mask = imagecreatetruecolor($maskWidth, $maskHeight);
|
||||
|
|
@ -479,34 +611,43 @@ class ProductsController extends Controller
|
|||
}
|
||||
|
||||
// ---- Chargement de l'image source
|
||||
$img = $image_create_func($imagePath);
|
||||
$img = $image_create_func($imagePath);
|
||||
list($imgWidth, $imgHeight) = getimagesize($imagePath);
|
||||
|
||||
// ---- Calcul les nouvelles dimensions de l'image
|
||||
if($imgWidth > $imgHeight){
|
||||
$finalWidth = $maskWidth;
|
||||
$finalHeight = ($finalWidth*$imgHeight)/$imgWidth;
|
||||
}else{
|
||||
if ($imgWidth > $imgHeight) {
|
||||
$finalWidth = $maskWidth;
|
||||
$finalHeight = ($finalWidth * $imgHeight) / $imgWidth;
|
||||
} else {
|
||||
$finalHeight = $maskHeight;
|
||||
$finalWidth = ($finalHeight*$imgWidth)/$imgHeight;
|
||||
$finalWidth = ($finalHeight * $imgWidth) / $imgHeight;
|
||||
}
|
||||
|
||||
// ---- Redimensionne l'image source
|
||||
$resizeImg = imagecreatetruecolor($finalWidth, $finalHeight);
|
||||
imagealphablending( $resizeImg, false );
|
||||
imagesavealpha( $resizeImg, true );
|
||||
imagealphablending($resizeImg, false);
|
||||
imagesavealpha($resizeImg, true);
|
||||
imagecopyresampled($resizeImg, $img, 0, 0, 0, 0, $finalWidth, $finalHeight, $imgWidth, $imgHeight);
|
||||
|
||||
// ---- Copie l'image redimensionnée dans le mask
|
||||
imagecopy($mask, $resizeImg, ($maskWidth-$finalWidth)/2, ($maskHeight-$finalHeight)/2, 0, 0, imagesx($resizeImg), imagesy($resizeImg));
|
||||
imagealphablending( $mask, false );
|
||||
imagesavealpha( $mask, true );
|
||||
// Copie l'image redimensionnée dans le mask.
|
||||
imagecopy(
|
||||
$mask,
|
||||
$resizeImg,
|
||||
($maskWidth - $finalWidth) / 2,
|
||||
($maskHeight - $finalHeight) / 2,
|
||||
0,
|
||||
0,
|
||||
imagesx($resizeImg),
|
||||
imagesy($resizeImg)
|
||||
);
|
||||
imagealphablending($mask, false);
|
||||
imagesavealpha($mask, true);
|
||||
|
||||
//écrit dans storage/app/public
|
||||
// ---- Créer le fichier final
|
||||
// Ecrit dans storage/app/public.
|
||||
// Créer le fichier final.
|
||||
imagepng($mask, storage_path('app/public/inco/images/' . $resizedName), 5);
|
||||
|
||||
// ---- Libère la mémoire associée aux images manipulées
|
||||
// Libère la mémoire associée aux images manipulées.
|
||||
imagedestroy($img);
|
||||
imagedestroy($resizeImg);
|
||||
imagedestroy($mask);
|
||||
|
|
@ -515,6 +656,12 @@ class ProductsController extends Controller
|
|||
/**
|
||||
* set une image préparée comme image du produit
|
||||
*/
|
||||
/**
|
||||
* set une image préparée comme image du produit
|
||||
*
|
||||
* @param Request $request
|
||||
* @return \App\Models\Product
|
||||
*/
|
||||
public function setIncoImage(Request $request)
|
||||
{
|
||||
$imagePath = $request->picture;
|
||||
|
|
@ -522,34 +669,37 @@ class ProductsController extends Controller
|
|||
$imagePath = storage_path("app/public/" . $imagePath);
|
||||
|
||||
$product_id = $request->product;
|
||||
$product = Product::findOrFail($product_id);
|
||||
$product = Product::findOrFail($product_id);
|
||||
|
||||
$str_random = Str::random(5);
|
||||
//default is large image
|
||||
// Default is large image.
|
||||
$finalImageName = $product->id . '_' . $str_random . '_large.' . File::extension($imagePath);
|
||||
|
||||
$productimagespath = public_path('images/produits');
|
||||
|
||||
if(!File::isDirectory($productimagespath)) {
|
||||
if (!File::isDirectory($productimagespath)) {
|
||||
File::makeDirectory($productimagespath, 0644, true);
|
||||
}
|
||||
|
||||
File::copy($imagePath, $productimagespath . "/" . $finalImageName);
|
||||
|
||||
//suppression de l'ancien fichier
|
||||
if ($product->picture_large !== null && file_exists(public_path('images/produits/') . $product->picture_large)) {
|
||||
// Suppression de l'ancien fichier.
|
||||
if (
|
||||
$product->picture_large !== null &&
|
||||
file_exists(public_path('images/produits/') . $product->picture_large)
|
||||
) {
|
||||
unlink(public_path('images/produits/') . $product->picture_large);
|
||||
}
|
||||
|
||||
$product->picture_large = $finalImageName;
|
||||
|
||||
|
||||
//now set small image
|
||||
$imagePath = str_replace("_large", "_small", $imagePath);
|
||||
// Now set small image.
|
||||
$imagePath = str_replace("_large", "_small", $imagePath);
|
||||
$finalImageName = $product->id . '_' . $str_random . '.' . File::extension($imagePath);
|
||||
File::copy($imagePath, $productimagespath . "/" . $finalImageName);
|
||||
|
||||
//suppression de l'ancien fichier
|
||||
// Suppression de l'ancien fichier.
|
||||
if ($product->picture !== null && file_exists(public_path('images/produits/') . $product->picture)) {
|
||||
unlink(public_path('images/produits/') . $product->picture);
|
||||
}
|
||||
|
|
@ -558,15 +708,17 @@ class ProductsController extends Controller
|
|||
|
||||
$product->save();
|
||||
|
||||
//@TODO : envoyer une réponse pour maj de l'interface
|
||||
return $product;
|
||||
}
|
||||
|
||||
/**
|
||||
* helper method to update additionnal product info
|
||||
* foodProduct
|
||||
*
|
||||
* @param Request $request
|
||||
* @param integer $product_id
|
||||
* @return void
|
||||
*/
|
||||
public function saveFoodProduct(Request $request, $product_id)
|
||||
public function saveFoodProduct(Request $request, int $product_id)
|
||||
{
|
||||
$foodProduct = FoodProduct::firstOrNew([
|
||||
'product_id' => $product_id,
|
||||
|
|
@ -618,11 +770,17 @@ class ProductsController extends Controller
|
|||
}
|
||||
|
||||
/**
|
||||
* helper method to update additionnal product info
|
||||
* toolProduct
|
||||
* helper method to update toolproduct info
|
||||
*
|
||||
* @param Request $request
|
||||
* @param integer $product_id
|
||||
* @return void
|
||||
*
|
||||
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
|
||||
*/
|
||||
public function saveToolProduct(Request $request, $product_id)
|
||||
public function saveToolProduct(Request $request, int $product_id)
|
||||
{
|
||||
// phpcs:enable
|
||||
$toolProduct = ToolProduct::firstOrNew([
|
||||
'product_id' => $product_id,
|
||||
]);
|
||||
|
|
@ -631,58 +789,50 @@ class ProductsController extends Controller
|
|||
}
|
||||
|
||||
/**
|
||||
* helper method to update additionnal product info
|
||||
* anifoodProduct
|
||||
* helper method to update anifoodProduct info
|
||||
*
|
||||
* @param Request $request
|
||||
* @param integer $product_id
|
||||
* @return void
|
||||
*/
|
||||
public function saveAnifoodProduct(Request $request, $product_id)
|
||||
public function saveAnifoodProduct(Request $request, int $product_id)
|
||||
{
|
||||
$anifoodProduct = AnifoodProduct::firstOrNew([
|
||||
'product_id' => $product_id,
|
||||
]);
|
||||
|
||||
$anifoodProduct->composition = $request->composition;
|
||||
$anifoodProduct->servings = $request->servings;
|
||||
$anifoodProduct->servings = $request->servings;
|
||||
$anifoodProduct->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* helper method to update additionnal product info
|
||||
* garmentProduct
|
||||
* helper method to update garmentProduct info
|
||||
*
|
||||
* @param Request $request
|
||||
* @param integer $product_id
|
||||
* @return void
|
||||
*/
|
||||
public function saveGarmentProduct(Request $request, $product_id)
|
||||
public function saveGarmentProduct(Request $request, int $product_id)
|
||||
{
|
||||
$garmentProduct = GarmentProduct::firstOrNew([
|
||||
'product_id' => $product_id,
|
||||
]);
|
||||
|
||||
$garmentProduct->size = $request->size;
|
||||
$garmentProduct->color = $request->color;
|
||||
$garmentProduct->size = $request->size;
|
||||
$garmentProduct->color = $request->color;
|
||||
$garmentProduct->material = $request->material;
|
||||
$garmentProduct->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* product detail intended for Bo
|
||||
*/
|
||||
public function show()
|
||||
{
|
||||
//not in use
|
||||
}
|
||||
|
||||
/**
|
||||
* index des produits mis en avant
|
||||
*
|
||||
* @return * @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function starred()
|
||||
{
|
||||
$products = Product::where('star', 1)->paginate(10);
|
||||
return view('bo.products.starred', compact('products'));
|
||||
}
|
||||
|
||||
/**
|
||||
* working method to start the mapping of inco fields into foodproduct
|
||||
*/
|
||||
/*
|
||||
public function mapIncoFieldsToFoodProduct () {
|
||||
|
||||
}*/
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,17 +31,15 @@ class PromotionsController extends Controller
|
|||
$discTypes = DiscountType::all();
|
||||
|
||||
$existingProds = Product::all();
|
||||
$promotion = new Promotion();
|
||||
$promotion = new Promotion();
|
||||
$selectedProds = $promotion->products;
|
||||
//$existingProds = $existingProds->diff($selectedProds);
|
||||
|
||||
return view('bo.promotions.create', compact('discTypes', 'existingProds', 'selectedProds'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
|
|
@ -52,42 +50,31 @@ class PromotionsController extends Controller
|
|||
]);
|
||||
|
||||
$productIds = explode(",", $request->product_id);
|
||||
$discType = $request->discount_type_id;
|
||||
$value = $request->discount_value;
|
||||
$discType = $request->discount_type_id;
|
||||
$value = $request->discount_value;
|
||||
$date_start = $request->date_start_date . " " . $request->date_start_time;
|
||||
$date_end = $request->date_end_date . " " . $request->date_end_time;
|
||||
$date_end = $request->date_end_date . " " . $request->date_end_time;
|
||||
|
||||
$promotion = new Promotion();
|
||||
$promotion = new Promotion();
|
||||
$promotion->discount_type_id = $discType;
|
||||
$promotion->discount_value = $value;
|
||||
$promotion->date_start = $date_start;
|
||||
$promotion->date_end = $date_end;
|
||||
$promotion->discount_value = $value;
|
||||
$promotion->date_start = $date_start;
|
||||
$promotion->date_end = $date_end;
|
||||
$promotion->save();
|
||||
|
||||
//prise en charge de la liaison avec les produits
|
||||
// Prise en charge de la liaison avec les produits.
|
||||
$promotion->products()->sync($productIds);
|
||||
|
||||
return redirect()->route('bo.promotions.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @param integer $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
public function edit(int $id)
|
||||
{
|
||||
$promotion = Promotion::findOrFail($id);
|
||||
$discTypes = DiscountType::all();
|
||||
|
|
@ -102,11 +89,11 @@ class PromotionsController extends Controller
|
|||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param integer $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
public function update(Request $request, int $id)
|
||||
{
|
||||
$promotion = Promotion::findOrFail($id);
|
||||
|
||||
|
|
@ -115,35 +102,34 @@ class PromotionsController extends Controller
|
|||
]);
|
||||
|
||||
$productIds = explode(",", $request->product_id);
|
||||
$discType = $request->discount_type_id;
|
||||
$value = $request->discount_value;
|
||||
$discType = $request->discount_type_id;
|
||||
$value = $request->discount_value;
|
||||
$date_start = $request->date_start_date . " " . $request->date_start_time;
|
||||
$date_end = $request->date_end_date . " " . $request->date_end_time;
|
||||
$date_end = $request->date_end_date . " " . $request->date_end_time;
|
||||
|
||||
$promotion->discount_type_id = $discType;
|
||||
$promotion->discount_value = $value;
|
||||
$promotion->date_start = $date_start;
|
||||
$promotion->date_end = $date_end;
|
||||
$promotion->discount_value = $value;
|
||||
$promotion->date_start = $date_start;
|
||||
$promotion->date_end = $date_end;
|
||||
$promotion->save();
|
||||
|
||||
//prise en charge de la liaison avec les produits
|
||||
// Prise en charge de la liaison avec les produits.
|
||||
$promotion->products()->sync($productIds);
|
||||
|
||||
return redirect()->route('bo.promotions.edit', $promotion->id)->with('success', 'Modifications enregistrés !');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @param integer $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id)
|
||||
public function destroy(int $id)
|
||||
{
|
||||
$p = Promotion::findOrFail($id);
|
||||
|
||||
//prise en charge de la liaison avec les produits
|
||||
// Prise en charge de la liaison avec les produits.
|
||||
$p->products()->detach();
|
||||
|
||||
$p->delete();
|
||||
|
|
|
|||
|
|
@ -11,24 +11,40 @@ use Illuminate\Support\Str;
|
|||
|
||||
class RangesController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$ranges = Range::all();
|
||||
return view('bo.ranges.index', compact('ranges'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return view('bo.ranges.create');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$name = $request->name;
|
||||
$slug = Str::slug($name);
|
||||
$name = $request->name;
|
||||
$slug = Str::slug($name);
|
||||
$description = $request->description;
|
||||
$picture = $request->picture;
|
||||
$status = $request->status === null ? 0 : 1;
|
||||
$picture = $request->picture;
|
||||
$status = $request->status === null ? 0 : 1;
|
||||
|
||||
$request->validate([
|
||||
'name' => 'required|string|max:255',
|
||||
|
|
@ -38,11 +54,11 @@ class RangesController extends Controller
|
|||
config('theme.range_image_maxheight'),
|
||||
]);
|
||||
|
||||
$range = new Range();
|
||||
$range->name = $name;
|
||||
$range->slug = $slug;
|
||||
$range = new Range();
|
||||
$range->name = $name;
|
||||
$range->slug = $slug;
|
||||
$range->description = $description;
|
||||
$range->status = $status;
|
||||
$range->status = $status;
|
||||
$range->save();
|
||||
|
||||
if ($picture !== null) {
|
||||
|
|
@ -55,19 +71,32 @@ class RangesController extends Controller
|
|||
return redirect()->route('bo.ranges.index');
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param integer $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit(int $id)
|
||||
{
|
||||
$range = Range::findOrFail($id);
|
||||
return view('bo.ranges.edit', compact('range'));
|
||||
}
|
||||
|
||||
public function update(Request $request, $id)
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param integer $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, int $id)
|
||||
{
|
||||
$name = $request->name;
|
||||
$slug = Str::slug($name);
|
||||
$name = $request->name;
|
||||
$slug = Str::slug($name);
|
||||
$description = $request->description;
|
||||
$picture = $request->picture;
|
||||
$status = $request->status === null ? 0 : 1;
|
||||
$picture = $request->picture;
|
||||
$status = $request->status === null ? 0 : 1;
|
||||
|
||||
$request->validate([
|
||||
'name' => 'required|string|max:255',
|
||||
|
|
@ -80,8 +109,9 @@ class RangesController extends Controller
|
|||
$range = Range::findOrFail($id);
|
||||
|
||||
if ($picture !== null) {
|
||||
if ($range->picture !== null && file_exists(public_path('images/gammes/') . $range->picture))
|
||||
if ($range->picture !== null && file_exists(public_path('images/gammes/') . $range->picture)) {
|
||||
unlink(public_path('images/gammes/') . $range->picture);
|
||||
}
|
||||
$imageName = $range->id . '_' . $slug . '_' . Str::random(5) . '.' . $picture->extension();
|
||||
$picture->move(public_path('images/gammes'), $imageName);
|
||||
}
|
||||
|
|
@ -91,30 +121,38 @@ class RangesController extends Controller
|
|||
if ($range->slug != $slug) {
|
||||
$exist = OldSlug::where('slug', $range->slug)->first();
|
||||
if ($exist === null) {
|
||||
$oldSlug = new OldSlug();
|
||||
$oldSlug = new OldSlug();
|
||||
$oldSlug->range_id = $range->id;
|
||||
$oldSlug->slug = $range->slug;
|
||||
$oldSlug->slug = $range->slug;
|
||||
$oldSlug->save();
|
||||
}
|
||||
}
|
||||
|
||||
$range->slug = $slug;
|
||||
$range->slug = $slug;
|
||||
$range->description = $description;
|
||||
if ($picture !== null)
|
||||
if ($picture !== null) {
|
||||
$range->picture = $imageName;
|
||||
}
|
||||
$range->status = $status;
|
||||
$range->save();
|
||||
|
||||
return redirect()->route('bo.ranges.edit', $range->id)->with('success', 'Modifications enregistrés !');
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param integer $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy(int $id)
|
||||
{
|
||||
$range = Range::findOrFail($id);
|
||||
|
||||
$product = Product::where('range_id', $range->id)->count();
|
||||
if ($product !== 0) {
|
||||
return redirect()->back()->withErrors("Suppression impossible : \"" . $range->name . "\" contient encore des produits.");
|
||||
return redirect()->back()
|
||||
->withErrors("Suppression impossible : \"" . $range->name . "\" contient encore des produits.");
|
||||
}
|
||||
|
||||
if ($range->picture !== null) {
|
||||
|
|
|
|||
|
|
@ -10,9 +10,16 @@ use Illuminate\Support\Facades\Config;
|
|||
|
||||
class SettingsController extends Controller
|
||||
{
|
||||
public function manage(Request $request) {
|
||||
|
||||
$settings = Setting::all();
|
||||
/**
|
||||
* Manage settings page
|
||||
*
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*
|
||||
*/
|
||||
public function manage(Request $request)
|
||||
{
|
||||
$settings = Setting::all();
|
||||
$settingsToPrint = [];
|
||||
foreach ($settings as $setting) {
|
||||
$settingsToPrint[$setting->key] = $setting->value;
|
||||
|
|
@ -21,47 +28,55 @@ class SettingsController extends Controller
|
|||
if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
||||
$input = $request->all();
|
||||
|
||||
//comparer les settingsToPrint (en base) avec les inputs (pour trouver un nouveau)
|
||||
foreach($input as $key=>$value) {
|
||||
if(!isset($settingsToPrint[$key])
|
||||
// Comparer les settingsToPrint (en base) avec les inputs (pour trouver un nouveau).
|
||||
foreach ($input as $key => $value) {
|
||||
if (
|
||||
!isset($settingsToPrint[$key])
|
||||
&& $key != "_method"
|
||||
&& $key != "_token")
|
||||
{
|
||||
//new setting
|
||||
$setting = new Setting();
|
||||
$setting->key = $key;
|
||||
&& $key != "_token"
|
||||
) {
|
||||
// New setting.
|
||||
$setting = new Setting();
|
||||
$setting->key = $key;
|
||||
$setting->value = $value ?? 0;
|
||||
$setting->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for($i = 0; $i < count($settings); $i++) {
|
||||
if(is_array($request->input($settings[$i]->key))) {
|
||||
$looplimit = count($settings);
|
||||
for ($i = 0; $i < $looplimit; $i++) {
|
||||
if (is_array($request->input($settings[$i]->key))) {
|
||||
$settings[$i]->value = implode(',', $request->input($settings[$i]->key));
|
||||
} else {
|
||||
$settings[$i]->value = $request->input($settings[$i]->key) === null ? 0 : $request->input($settings[$i]->key);
|
||||
$settings[$i]->value = $request->input($settings[$i]->key) === null ? 0
|
||||
: $request->input($settings[$i]->key);
|
||||
}
|
||||
$settings[$i]->save();
|
||||
}
|
||||
|
||||
//store redirector to keep flash message from being wipe pby artisan call below
|
||||
// Store redirector to keep flash message from being wipe pby artisan call below.
|
||||
$redirector = redirect()->route('bo.settings')->with('success', 'Modifications enregistrés !');
|
||||
|
||||
//all settings saved : cache routes
|
||||
// All settings saved : cache routes.
|
||||
Artisan::call('route:clear');
|
||||
//programmer un php artisan optimize ? (une fois par jour la nuit par exemple)
|
||||
|
||||
// Programmer un php artisan optimize ? (une fois par jour la nuit par exemple).
|
||||
return $redirector;
|
||||
}
|
||||
}//end if
|
||||
|
||||
return view('bo.settings', compact('settingsToPrint'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage Theme settings page
|
||||
* Management des settings dont la clé est préfixée theme_
|
||||
*
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*
|
||||
*/
|
||||
public function manageTheme(Request $request) {
|
||||
$settings = Setting::where('key', 'LIKE', 'theme_%')->get();
|
||||
public function manageTheme(Request $request)
|
||||
{
|
||||
$settings = Setting::where('key', 'LIKE', 'theme_%')->get();
|
||||
$settingsToPrint = [];
|
||||
foreach ($settings as $setting) {
|
||||
$settingsToPrint[$setting->key] = $setting->value;
|
||||
|
|
@ -69,22 +84,24 @@ class SettingsController extends Controller
|
|||
|
||||
$config_settings = Config::get(('theme.bo_theme_settings'));
|
||||
|
||||
//check if, for each of the theme defined settings we have a database setting
|
||||
// Check if, for each of the theme defined settings we have a database setting.
|
||||
foreach ($config_settings as $onekey => $params) {
|
||||
if (!isset($settingsToPrint['theme_' . $onekey])) {
|
||||
$dbsetting = new Setting();
|
||||
$dbsetting->key = 'theme_' . $onekey;
|
||||
$dbsetting = new Setting();
|
||||
$dbsetting->key = 'theme_' . $onekey;
|
||||
$dbsetting->value = $params['default_value'];
|
||||
$dbsetting->save();
|
||||
//injection dans settings to print
|
||||
// Injection dans settings to print.
|
||||
$settingsToPrint[$dbsetting->key] = $dbsetting->value;
|
||||
}
|
||||
}
|
||||
|
||||
if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
||||
for($i = 0; $i < count($settings); $i++) {
|
||||
//attention pour les booléens/checkbox on enregistre 'on'
|
||||
$settings[$i]->value = $request->input($settings[$i]->key) === null ? 0 : $request->input($settings[$i]->key);
|
||||
$looplimit = count($settings);
|
||||
for ($i = 0; $i < $looplimit; $i++) {
|
||||
// Attention pour les booléens/checkbox on enregistre 'on'.
|
||||
$settings[$i]->value = $request->input($settings[$i]->key) === null ? 0
|
||||
: $request->input($settings[$i]->key);
|
||||
$settings[$i]->save();
|
||||
}
|
||||
return redirect()->route('bo.themesettings')->with('success', 'Modifications enregistrés !');
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ class SlidersController extends Controller
|
|||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
|
|
@ -59,24 +59,13 @@ class SlidersController extends Controller
|
|||
return redirect()->route('bo.sliders.edit', $slider->id)->with('success', 'Slider créé !');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @param integer $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
public function edit(int $id)
|
||||
{
|
||||
$slider = Slider::findOrFail($id);
|
||||
return view('bo.sliders.edit', compact('slider'));
|
||||
|
|
@ -85,11 +74,11 @@ class SlidersController extends Controller
|
|||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param integer $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
public function update(Request $request, int $id)
|
||||
{
|
||||
$slider = Slider::findOrFail($id);
|
||||
$label = $request->label;
|
||||
|
|
@ -113,10 +102,10 @@ class SlidersController extends Controller
|
|||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @param integer $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id)
|
||||
public function destroy(int $id)
|
||||
{
|
||||
$slider = Slider::findOrFail($id);
|
||||
|
||||
|
|
@ -125,8 +114,6 @@ class SlidersController extends Controller
|
|||
if ($count === 1) {
|
||||
return redirect()->back()->withErrors("Suppression impossible : Vous devez conserver au moins 1 Slider");
|
||||
}
|
||||
// @todo : controller les slides liés
|
||||
|
||||
$slider->delete();
|
||||
return redirect()->route('bo.sliders.index');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,9 +35,7 @@ class SlidesController extends Controller
|
|||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @todo : validation des dates
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
|
|
@ -101,24 +99,13 @@ class SlidesController extends Controller
|
|||
return redirect()->route('bo.slides.edit', $slide->id)->with('success', 'Slide créé !');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @param integer $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
public function edit(int $id)
|
||||
{
|
||||
$slide = Slide::findOrFail($id);
|
||||
$sliders = Slider::all();
|
||||
|
|
@ -128,11 +115,11 @@ class SlidesController extends Controller
|
|||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param integer $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
public function update(Request $request, int $id)
|
||||
{
|
||||
$title = $request->title;
|
||||
$picture = $request->picture;
|
||||
|
|
@ -198,10 +185,10 @@ class SlidesController extends Controller
|
|||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @param integer $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id)
|
||||
public function destroy(int $id)
|
||||
{
|
||||
$s = Slide::findOrFail($id);
|
||||
|
||||
|
|
@ -210,8 +197,14 @@ class SlidesController extends Controller
|
|||
return redirect()->route('bo.slides.index');
|
||||
}
|
||||
|
||||
|
||||
public function changeOrder($id, $action)
|
||||
/**
|
||||
* Change Slide Order
|
||||
*
|
||||
* @param integer $id
|
||||
* @param string $action
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function changeOrder(int $id, string $action)
|
||||
{
|
||||
$current = Slide::findOrFail($id);
|
||||
|
||||
|
|
@ -230,11 +223,12 @@ class SlidesController extends Controller
|
|||
$current->save();
|
||||
|
||||
return back();
|
||||
//return redirect()->route('bo.slides.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* retreive order position to put a new slide to
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
private function getLastOrder()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -33,20 +33,20 @@ class TagsController extends Controller
|
|||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$label = $request->label;
|
||||
$slug = Str::slug($label);
|
||||
$label = $request->label;
|
||||
$slug = Str::slug($label);
|
||||
$status = $request->status === null ? 0 : 1;
|
||||
|
||||
$request->validate([
|
||||
'label' => 'required|string|max:255',
|
||||
]);
|
||||
|
||||
$tag = new Tag();
|
||||
$tag = new Tag();
|
||||
$tag->label = $label;
|
||||
$tag->slug = $slug;
|
||||
$tag->status = $status;
|
||||
|
|
@ -56,24 +56,13 @@ class TagsController extends Controller
|
|||
return redirect()->route('bo.tags.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @param integer $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
public function edit(int $id)
|
||||
{
|
||||
$tag = Tag::findOrFail($id);
|
||||
return view('bo.tags.edit', compact('tag'));
|
||||
|
|
@ -82,14 +71,14 @@ class TagsController extends Controller
|
|||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param integer $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
public function update(Request $request, int $id)
|
||||
{
|
||||
$label = $request->label;
|
||||
$slug = Str::slug($label);
|
||||
$label = $request->label;
|
||||
$slug = Str::slug($label);
|
||||
$status = $request->status === null ? 0 : 1;
|
||||
|
||||
$request->validate([
|
||||
|
|
@ -98,8 +87,8 @@ class TagsController extends Controller
|
|||
|
||||
$tag = Tag::findOrFail($id);
|
||||
|
||||
$tag->label = $label;
|
||||
$tag->slug = $slug;
|
||||
$tag->label = $label;
|
||||
$tag->slug = $slug;
|
||||
$tag->status = $status;
|
||||
$tag->save();
|
||||
|
||||
|
|
@ -109,24 +98,31 @@ class TagsController extends Controller
|
|||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @param integer $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id)
|
||||
public function destroy(int $id)
|
||||
{
|
||||
$tag = Tag::findOrFail($id);
|
||||
|
||||
$products = $tag->products()->count();
|
||||
if ($products !== 0) {
|
||||
return redirect()->back()->withErrors("Suppression impossible : \"" . $tag->label . "\" est associé à des produits.");
|
||||
return redirect()->back()
|
||||
->withErrors("Suppression impossible : \"" . $tag->label . "\" est associé à des produits.");
|
||||
}
|
||||
|
||||
$tag->delete();
|
||||
return redirect()->route('bo.tags.index');
|
||||
}
|
||||
|
||||
|
||||
public function changeOrder($id, $action)
|
||||
/**
|
||||
* Change Tag Order
|
||||
*
|
||||
* @param integer $id
|
||||
* @param string $action
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function changeOrder(int $id, string $action)
|
||||
{
|
||||
$current = Tag::findOrFail($id);
|
||||
|
||||
|
|
@ -145,11 +141,17 @@ class TagsController extends Controller
|
|||
$current->save();
|
||||
|
||||
return back();
|
||||
//return redirect()->route('bo.slides.index');
|
||||
}
|
||||
|
||||
public function toggleStatus($id) {
|
||||
$tag = Tag::findOrFail($id);
|
||||
/**
|
||||
* Toggle tag status
|
||||
*
|
||||
* @param integer $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function toggleStatus(int $id)
|
||||
{
|
||||
$tag = Tag::findOrFail($id);
|
||||
$tag->status = !($tag->status);
|
||||
$tag->save();
|
||||
return back();
|
||||
|
|
@ -158,6 +160,8 @@ class TagsController extends Controller
|
|||
|
||||
/**
|
||||
* retreive order position to put a new slide to
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public static function getLastOrder()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -12,30 +12,57 @@ use Illuminate\Http\Request;
|
|||
|
||||
class ContactController extends Controller
|
||||
{
|
||||
/**
|
||||
* legal notice page
|
||||
*
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*
|
||||
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
|
||||
*/
|
||||
public function contact(Request $request)
|
||||
{
|
||||
// @phpcs:enable
|
||||
$status = $request->session()->get('status');
|
||||
|
||||
//1er magasin en base pour le moment
|
||||
$magasin = Magasin::first();
|
||||
$magasin = Magasin::first();
|
||||
$magasins = Magasin::all();
|
||||
|
||||
$content = Content::where('key', 'contact')->first();
|
||||
|
||||
return view('contact', compact('status', 'magasin', 'content'));
|
||||
return view('contact', compact('status', 'magasins', 'magasin', 'content'));
|
||||
}
|
||||
|
||||
/**
|
||||
* submit contact form
|
||||
*
|
||||
* @param ContactFormRequest $request
|
||||
* @return \Illuminate\Http\Response
|
||||
* @throws \RuntimeException If email missing.
|
||||
*/
|
||||
public function contactSubmit(ContactFormRequest $request)
|
||||
{
|
||||
$data = $request->all();
|
||||
/** @var \App\Model\Magasin|null */
|
||||
$shop = Magasin::where('name', $request->shop)->first();
|
||||
|
||||
$toMailSetting = Setting::where('key', 'send_contact_mail_to')->first();
|
||||
if(empty($toMailSetting->value)) {
|
||||
$toMail = config('mail.from.address');
|
||||
if ($shop and $shop->email_contact) {
|
||||
/** @var string */
|
||||
$toMail = $shop->email_contact;
|
||||
} else {
|
||||
$toMail = $toMailSetting->value;
|
||||
/** @var string|null */
|
||||
$toMail = \optional(Setting::where('key', 'send_contact_mail_to')->first())->value;
|
||||
if (!$toMail) {
|
||||
/** @var string|null */
|
||||
$toMail = config('mail.from.address');
|
||||
}
|
||||
}
|
||||
//envoi du mail d'alerte
|
||||
|
||||
if (!$toMail) {
|
||||
throw new \RuntimeException('Impossible de trouver un mail');
|
||||
}
|
||||
|
||||
// Envoi du mail d'alerte.
|
||||
Mail::to($toMail)->send(new SendContactMail($request));
|
||||
Mail::mailer('smtp2')->to($toMail)->send(new SendContactMail($request));
|
||||
|
||||
return back()->with('status', true);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,5 +9,7 @@ use Illuminate\Routing\Controller as BaseController;
|
|||
|
||||
class Controller extends BaseController
|
||||
{
|
||||
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
|
||||
use AuthorizesRequests;
|
||||
use DispatchesJobs;
|
||||
use ValidatesRequests;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ namespace App\Http\Controllers;
|
|||
use App\Http\Requests\CustomerRegisterRequest;
|
||||
use App\Http\Requests\LoginRequest;
|
||||
use App\Http\Requests\UpdateInfosRequest;
|
||||
use App\Mail\OrderCanceledConfirmMail;
|
||||
use App\Mail\PasswordResetMail;
|
||||
use App\Mail\RegisterConfirmMail;
|
||||
use App\Models\Customers;
|
||||
|
|
@ -12,6 +13,7 @@ use App\Models\Magasin;
|
|||
use App\Models\Order;
|
||||
use App\Models\PasswordReset;
|
||||
use App\Models\Salarie;
|
||||
use App\Models\Setting;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
|
@ -31,6 +33,8 @@ class CustomerController extends Controller
|
|||
{
|
||||
/**
|
||||
* Affiche la page d'inscription
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function registerForm()
|
||||
{
|
||||
|
|
@ -77,13 +81,14 @@ class CustomerController extends Controller
|
|||
$crmCustomer->country = Country::france();
|
||||
$crmCustomer->save();
|
||||
|
||||
// * Enrregistrement du Hashcode
|
||||
/** @var \App\Models\Customers $customer */
|
||||
$customer = new Customers($request->all());
|
||||
$customer->hashcode = $crmCustomer->hashcode;
|
||||
$customer->saveOrFail();
|
||||
|
||||
// * liaison éventuelle avec la table salaries
|
||||
if ($request->matricule && $request->code) {
|
||||
/** @var \App\Models\Customers $customer */
|
||||
$customer = new Customers($request->all());
|
||||
$customer->hashcode = $crmCustomer->hashcode;
|
||||
$customer->saveOrFail();
|
||||
|
||||
/** @var \App\Models\Salarie $salarie */
|
||||
$salarie = Salarie::where('matricule', '=', $request->matricule)
|
||||
->where('code', '=', $request->code)
|
||||
|
|
@ -93,8 +98,6 @@ class CustomerController extends Controller
|
|||
}
|
||||
|
||||
Mail::to($request->email)->send(new RegisterConfirmMail($customer, $request->firstname));
|
||||
Mail::mailer('smtp2')->to($request->email)
|
||||
->send(new RegisterConfirmMail($customer, $request->firstname));
|
||||
|
||||
return view('auth.register-success', ['mail' => $request->email]);
|
||||
});
|
||||
|
|
@ -121,6 +124,9 @@ class CustomerController extends Controller
|
|||
|
||||
/**
|
||||
* Retourne la page de connexion
|
||||
*
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function authenticateForm(Request $request)
|
||||
{
|
||||
|
|
@ -190,29 +196,31 @@ class CustomerController extends Controller
|
|||
$crmCustomer = $customer->apiData;
|
||||
if ($crmCustomer->activate()) {
|
||||
return view('auth.activate')
|
||||
->with('message', 'Votre compte a bien été activé, vous pouvez désormais vous connecter.');
|
||||
->with('message', 'Votre compte a bien été activé, vous pouvez désormais vous connecter.');
|
||||
}
|
||||
} catch (ApiErrorException $e) {
|
||||
if ($e->getApiError()->equals(ApiError::customerAlreadyActive())) {
|
||||
// phpcs:disable Generic.Files.LineLength.TooLong
|
||||
return view('auth.activate')
|
||||
->with('message', 'Votre compte est déjà activé, vous pouvez dès à présent vous connecter avec celui-ci.');
|
||||
->with('message', 'Votre compte est déjà activé, vous pouvez dès à présent vous connecter avec celui-ci.');
|
||||
}
|
||||
report($e);
|
||||
// Une erreur critique est survenue avec la CRM.
|
||||
return view('auth.activate')
|
||||
->with('message', 'Une erreur est survenue, merci de réessayer ultérieurement.');
|
||||
->with('message', 'Une erreur est survenue, merci de réessayer ultérieurement.');
|
||||
} catch (CrmException $e) {
|
||||
report($e);
|
||||
// Une erreur critique est survenue avec la CRM.
|
||||
return view('auth.activate')
|
||||
->with('message', 'Une erreur est survenue, merci de réessayer ultérieurement.');
|
||||
->with('message', 'Une erreur est survenue, merci de réessayer ultérieurement.');
|
||||
} //end try
|
||||
return view('auth.activate')->with('message', 'Ce lien d\'activation n\'est pas valide.');
|
||||
}
|
||||
|
||||
/**
|
||||
* deconnexion customer
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function logout()
|
||||
{
|
||||
|
|
@ -224,14 +232,23 @@ class CustomerController extends Controller
|
|||
|
||||
/**
|
||||
* page d'accès à la procédure mdp oublié
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*
|
||||
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
|
||||
*/
|
||||
public function forgotPasswordForm(Request $request)
|
||||
{
|
||||
// @phpcs:enable
|
||||
return view('auth.passwords.forgot');
|
||||
}
|
||||
|
||||
/**
|
||||
* initialisation de la procédure de mdp oublié
|
||||
*
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function passwordReset(Request $request)
|
||||
{
|
||||
|
|
@ -244,7 +261,7 @@ class CustomerController extends Controller
|
|||
$customerExist = Customers::where('email', $email)->count() === 0 ? false : true;
|
||||
|
||||
if ($customerExist) {
|
||||
// Suppression des anciens tokens
|
||||
// Suppression des anciens tokens.
|
||||
PasswordReset::where('email', $email)->delete();
|
||||
|
||||
$token = Str::random(80);
|
||||
|
|
@ -256,9 +273,10 @@ class CustomerController extends Controller
|
|||
$passwordReset->save();
|
||||
|
||||
Mail::to($email)->send(new PasswordResetMail($token));
|
||||
Mail::mailer('smtp2')->to($email)->send(new PasswordResetMail($token));
|
||||
// @phpcs:ignore Generic.Files.LineLength
|
||||
return back()->with('success', __("La procédure pour changer votre mot de passe a été envoyé sur votre email."));
|
||||
return back()->with(
|
||||
'success',
|
||||
__("La procédure pour changer votre mot de passe a été envoyé sur votre email.")
|
||||
);
|
||||
} else {
|
||||
return back()->withErrors(__("Cette adresse email n'est pas enregistrée dans nos services."));
|
||||
}
|
||||
|
|
@ -266,10 +284,10 @@ class CustomerController extends Controller
|
|||
|
||||
/**
|
||||
* Print the view used to change the password of a user when he required it
|
||||
* @param $token Token used to identificate the user to change the password of
|
||||
* @return View The view to print
|
||||
* @param string $token Token used to identificate the user to change the password.
|
||||
* @return \Illuminate\Contracts\View\View The view to print
|
||||
*/
|
||||
public function viewChangePassword($token)
|
||||
public function viewChangePassword(string $token)
|
||||
{
|
||||
$pwdReset = PasswordReset::where('token', $token)->first();
|
||||
if (!$pwdReset) {
|
||||
|
|
@ -335,11 +353,16 @@ class CustomerController extends Controller
|
|||
|
||||
/**
|
||||
* profil client (mon compte)
|
||||
*
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*
|
||||
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
|
||||
*/
|
||||
public function dashboard(Request $request)
|
||||
{
|
||||
|
||||
//show Profile
|
||||
// @phpcs:enable
|
||||
// Show Profile.
|
||||
/** @var \App\Models\Customers|null $customer */
|
||||
$customer = Auth::guard('customer')->user();
|
||||
if (!$customer) {
|
||||
|
|
@ -378,6 +401,9 @@ class CustomerController extends Controller
|
|||
|
||||
/**
|
||||
* changement de mot de passe depuis le profil
|
||||
*
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function changePasswordWhenAuthenticated(Request $request)
|
||||
{
|
||||
|
|
@ -397,18 +423,30 @@ class CustomerController extends Controller
|
|||
|
||||
/**
|
||||
* affichage des commandes du customer connecté
|
||||
*
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*
|
||||
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
|
||||
*/
|
||||
public function myOrders(Request $request)
|
||||
{
|
||||
// @phpcs:enable
|
||||
$orders = Order::where('customer_id', Auth::guard('customer')->user()->id)->orderBy('date', 'DESC')->get();
|
||||
return view('customer.my-orders', compact('orders'));
|
||||
}
|
||||
|
||||
public function orderDetail($reference)
|
||||
/**
|
||||
* Show detail commande
|
||||
*
|
||||
* @param string $reference
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function orderDetail(string $reference)
|
||||
{
|
||||
$order = Order::where('reference', '=', $reference)
|
||||
->where('customer_id', Auth::guard('customer')->user()->id)
|
||||
->firstOrFail();
|
||||
$order = Order::where('reference', '=', $reference)
|
||||
->where('customer_id', Auth::guard('customer')->user()->id)
|
||||
->firstOrFail();
|
||||
|
||||
if ($order->status_id == 1) {
|
||||
$magasin = null;
|
||||
|
|
@ -419,25 +457,50 @@ class CustomerController extends Controller
|
|||
return view('customer.order-detail', compact('order', 'magasin'));
|
||||
}
|
||||
|
||||
public function delete($id)
|
||||
/**
|
||||
* mise au statut annulé d'une commande
|
||||
*
|
||||
* @param string $reference
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @throws \RuntimeException If email missing.
|
||||
*/
|
||||
public function cancelOrder(string $reference)
|
||||
{
|
||||
// TODO : Implémenter la suppression lorsque la CRM sera prête pour le faire aussi
|
||||
die('Not implemented yet');
|
||||
// Suppression d'un compte client
|
||||
$customer = Customers::findOrFail($id);
|
||||
$customer->recipes()->delete();
|
||||
$customer->products()->delete();
|
||||
$customer->answers()->delete();
|
||||
$customer->forums()->delete();
|
||||
|
||||
// TODO : Suppression via la CRM
|
||||
|
||||
if (Auth::guard('customer')->user()->id === $customer->id) {
|
||||
Auth::guard('customer')->logout();
|
||||
/** @var \App\Models\Order|null */
|
||||
$order = Order::where('reference', $reference)->first();
|
||||
if (!$order) {
|
||||
throw new \RuntimeException('Impossible de trouver un enregistrement Order');
|
||||
}
|
||||
$customer->delete();
|
||||
$order->status_id = 7;
|
||||
$order->save();
|
||||
|
||||
return redirect()->route('home');
|
||||
// Envoi du mail d'annulation aux admins site.
|
||||
/** @var string|null */
|
||||
$toMail = \optional(Setting::where('key', 'send_order_confirm_mail_to')->first())->value;
|
||||
if (!$toMail) {
|
||||
/** @var string|null */
|
||||
$toMail = config('mail.from.address');
|
||||
}
|
||||
|
||||
if (!$toMail) {
|
||||
throw new \RuntimeException('Impossible de trouver un mail');
|
||||
}
|
||||
|
||||
Mail::to($toMail)->queue(new OrderCanceledConfirmMail($order));
|
||||
|
||||
return back()->with('success', "La commande " . $order->reference . " à été annulée.");
|
||||
}
|
||||
|
||||
/**
|
||||
* delete customers
|
||||
*
|
||||
* @param integer $id
|
||||
* @return void
|
||||
*/
|
||||
public function delete(int $id)
|
||||
{
|
||||
dump('deleting' . $id);
|
||||
die('Not implemented yet');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -495,7 +558,6 @@ class CustomerController extends Controller
|
|||
}
|
||||
}
|
||||
Mail::to($request->email)->send(new RegisterConfirmMail($customer, null));
|
||||
Mail::mailer('smtp2')->to($request->email)->send(new RegisterConfirmMail($customer, null));
|
||||
return back()
|
||||
->withErrors(
|
||||
trans('Votre compte n\'est pas activé, vérifiez dans vos emails pour y trouver
|
||||
|
|
@ -541,7 +603,6 @@ class CustomerController extends Controller
|
|||
return \redirect()->back();
|
||||
}
|
||||
|
||||
// TODO: Activer le changement d'email quand ce sera possible dans la CRM.
|
||||
/** @var \LDC\LDCCRM\Models\Customer */
|
||||
$crmCustomer = $customer->apiData;
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ use App\Models\Product;
|
|||
use App\Models\Slider;
|
||||
use App\Models\Range;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use LDC\LDCCRM\Enums\ApiError;
|
||||
use LDC\LDCCRM\Exceptions\ApiErrorException;
|
||||
|
|
@ -16,10 +15,19 @@ use LDC\LDCCRM\Models\SingleOptin;
|
|||
|
||||
class HomeController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display homepage
|
||||
*
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*
|
||||
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
// @phpcs:enable
|
||||
$content = Content::where('key', 'accueil')->first();
|
||||
//star products
|
||||
// Star products.
|
||||
$products = Product::where('status', 1)->where('star', 1)->get();
|
||||
|
||||
$slider = Slider::where('slug', 'home')->first();
|
||||
|
|
@ -37,8 +45,10 @@ class HomeController extends Controller
|
|||
|
||||
/**
|
||||
* Call the CRM to add a single optin
|
||||
* @param String $email Email to add as a single optin
|
||||
* @return String Message to print to the customer
|
||||
*
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*
|
||||
*/
|
||||
public function addOptIn(Request $request)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -8,38 +8,64 @@ use Illuminate\Http\Request;
|
|||
|
||||
class IndexController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* deprecated
|
||||
* legal notice page
|
||||
*
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*
|
||||
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
|
||||
*/
|
||||
public function contact(Request $request)
|
||||
{
|
||||
$content = Content::where('key', 'contact')->first();
|
||||
return view('contact', compact('content'));
|
||||
}
|
||||
|
||||
public function legalNotice(Request $request)
|
||||
{
|
||||
// @phpcs:enable
|
||||
$content = Content::where('key', 'legals')->first();
|
||||
return view('legal-notice', compact('content'));
|
||||
}
|
||||
|
||||
/**
|
||||
* terms and conditions page
|
||||
*
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*
|
||||
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
|
||||
*/
|
||||
public function terms(Request $request)
|
||||
{
|
||||
// @phpcs:enable
|
||||
$content = Content::where('key', 'cgv')->first();
|
||||
return view('terms', compact('content'));
|
||||
}
|
||||
|
||||
/**
|
||||
* privacy page
|
||||
*
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*
|
||||
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
|
||||
*/
|
||||
public function privacy(Request $request)
|
||||
{
|
||||
// @phpcs:enable
|
||||
$content = Content::where('key', 'confidentialite')->first();
|
||||
return view('privacy', compact('content'));
|
||||
}
|
||||
|
||||
/**
|
||||
* faq page
|
||||
*
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*
|
||||
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
|
||||
*/
|
||||
public function faq(Request $request)
|
||||
{
|
||||
// @phpcs:enable
|
||||
$content = Content::where('key', 'faq')->first();
|
||||
$faq = Faq::all();
|
||||
return view('faq', compact('faq','content'));
|
||||
$faq = Faq::all();
|
||||
return view('faq', compact('faq', 'content'));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,49 +6,68 @@ use App\Models\Product;
|
|||
use App\Models\Range;
|
||||
use App\Models\Tag;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class ProductsController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* page des gammes
|
||||
* Ranges page
|
||||
*
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*
|
||||
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
|
||||
*/
|
||||
public function ranges(Request $request)
|
||||
{
|
||||
//now in AppServiceProvider
|
||||
//$ranges = Range::all();
|
||||
//return view('ranges', compact('ranges'));
|
||||
// @phpcs:enable
|
||||
// $ranges shared in AppServiceProvider.
|
||||
return view('ranges');
|
||||
}
|
||||
|
||||
/**
|
||||
* page une gamme
|
||||
* One Range page
|
||||
*
|
||||
* @param Request $request
|
||||
* @param string $range_slug
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*
|
||||
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
|
||||
*/
|
||||
public function range(Request $request, $range_slug)
|
||||
public function range(Request $request, string $range_slug)
|
||||
{
|
||||
// @phpcs:enable
|
||||
$range = Range::where('slug', $range_slug)->first();
|
||||
if (!$range || !$range->status) {
|
||||
abort(404);
|
||||
}
|
||||
$products = Product::where('range_id', $range->id)->where('status', 1)->paginate(9);
|
||||
//find promo within range
|
||||
$offres = Product::where('range_id', $range->id)->where('status', 1)->has('promotions')->with('promotions')->get();
|
||||
// Find promo within range.
|
||||
$offres = Product::where('range_id', $range->id)
|
||||
->where('status', 1)
|
||||
->has('promotions')
|
||||
->with('promotions')->get();
|
||||
return view('range', compact('range', 'products', 'offres'));
|
||||
}
|
||||
|
||||
/**
|
||||
* page produit
|
||||
* One product page
|
||||
*
|
||||
* @param Request $request
|
||||
* @param string $product_slug
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*
|
||||
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
|
||||
*/
|
||||
public function product(Request $request, $product_slug)
|
||||
public function product(Request $request, string $product_slug)
|
||||
{
|
||||
// @phpcs:enable
|
||||
$product = Product::where('slug', $product_slug)->first();
|
||||
if (!$product || !$product->status) {
|
||||
abort(404);
|
||||
}
|
||||
$product->additionnalProductInfo = $product->additionnalProductInfo($product->product_type);
|
||||
if ($product->additionnalProductInfo === null && !empty($product_type)) {
|
||||
//n'existe pas on renseigne un vide
|
||||
// N'existe pas on renseigne un vide.
|
||||
$product_type = $product->product_type;
|
||||
$modelClass = 'App\Models\\' . ucfirst($product_type);
|
||||
$product->$product_type = new $modelClass();
|
||||
|
|
@ -62,6 +81,10 @@ class ProductsController extends Controller
|
|||
/**
|
||||
* tous les produits
|
||||
* recherche par nom de produit
|
||||
*
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*
|
||||
*/
|
||||
public function allProducts(Request $request)
|
||||
{
|
||||
|
|
@ -82,10 +105,18 @@ class ProductsController extends Controller
|
|||
}
|
||||
|
||||
/**
|
||||
* produits filtrés par tag (1 tag)
|
||||
* tous les produits
|
||||
* filtrage par tag
|
||||
*
|
||||
* @param Request $request
|
||||
* @param string $tag_slug
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*
|
||||
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
|
||||
*/
|
||||
public function tagFiltered(Request $request, $tag_slug)
|
||||
public function tagFiltered(Request $request, string $tag_slug)
|
||||
{
|
||||
// @phpcs:enable
|
||||
$products = Product::where('status', 1)
|
||||
->whereHas('tags', function ($q) use ($tag_slug) {
|
||||
$q->where('slug', '=', $tag_slug);
|
||||
|
|
|
|||
|
|
@ -7,8 +7,17 @@ use Illuminate\Http\Request;
|
|||
|
||||
class QuickOrderController extends Controller
|
||||
{
|
||||
/**
|
||||
* Quickorder page
|
||||
*
|
||||
* @param Request $request
|
||||
* @return \Illuminate\Contracts\View\View
|
||||
*
|
||||
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
// @phpcs:enable
|
||||
$quickorder_ranges = Range::with('products')->get();
|
||||
foreach ($quickorder_ranges as $range) {
|
||||
foreach ($range->products as $product) {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace App\Http;
|
||||
|
||||
use App\Http\Middleware\isAdmin;
|
||||
use App\Http\Middleware\IsAdmin;
|
||||
use Illuminate\Foundation\Http\Kernel as HttpKernel;
|
||||
|
||||
class Kernel extends HttpKernel
|
||||
|
|
@ -15,7 +15,6 @@ class Kernel extends HttpKernel
|
|||
* @var array
|
||||
*/
|
||||
protected $middleware = [
|
||||
// \App\Http\Middleware\TrustHosts::class,
|
||||
\App\Http\Middleware\TrustProxies::class,
|
||||
\Fruitcake\Cors\HandleCors::class,
|
||||
\App\Http\Middleware\PreventRequestsDuringMaintenance::class,
|
||||
|
|
@ -34,7 +33,6 @@ class Kernel extends HttpKernel
|
|||
\App\Http\Middleware\EncryptCookies::class,
|
||||
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
|
||||
\Illuminate\Session\Middleware\StartSession::class,
|
||||
// \Illuminate\Session\Middleware\AuthenticateSession::class,
|
||||
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
|
||||
\App\Http\Middleware\VerifyCsrfToken::class,
|
||||
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||
|
|
@ -64,6 +62,6 @@ class Kernel extends HttpKernel
|
|||
'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
|
||||
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
|
||||
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
|
||||
'is-admin' => isAdmin::class,
|
||||
'is-admin' => IsAdmin::class,
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ class Authenticate extends Middleware
|
|||
/**
|
||||
* Get the path the user should be redirected to when they are not authenticated.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param mixed $request
|
||||
* @return string|null
|
||||
*/
|
||||
protected function redirectTo($request)
|
||||
|
|
|
|||
|
|
@ -12,6 +12,5 @@ class EncryptCookies extends Middleware
|
|||
* @var array
|
||||
*/
|
||||
protected $except = [
|
||||
//
|
||||
];
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,22 +3,24 @@
|
|||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class isAdmin
|
||||
class IsAdmin
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
public function handle(Request $request, Closure $next)
|
||||
{
|
||||
$role = Auth::user()->role;
|
||||
if ($role === 1 || $role === 2)
|
||||
if ($role === 1 || $role === 2) {
|
||||
return $next($request);
|
||||
}
|
||||
abort(404, "Cette page n'existe pas.");
|
||||
}
|
||||
}
|
||||
|
|
@ -12,6 +12,5 @@ class PreventRequestsDuringMaintenance extends Middleware
|
|||
* @var array
|
||||
*/
|
||||
protected $except = [
|
||||
//
|
||||
];
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,9 +12,9 @@ class RedirectIfAuthenticated
|
|||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @param string|null ...$guards
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @param string|null ...$guards
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle(Request $request, Closure $next, ...$guards)
|
||||
|
|
|
|||
|
|
@ -6,20 +6,21 @@ use App\Models\OldSlug;
|
|||
use App\Models\Product;
|
||||
use App\Models\Range;
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class RedirectOldSlugs
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
public function handle(Request $request, Closure $next)
|
||||
{
|
||||
$productSlug = $request->route('productSlug');
|
||||
$rangeSlug = $request->route('rangeSlug');
|
||||
$rangeSlug = $request->route('rangeSlug');
|
||||
|
||||
if ($productSlug !== null) {
|
||||
$product = Product::where('slug', $productSlug)->first();
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ class TrustProxies extends Middleware
|
|||
/**
|
||||
* The headers that should be used to detect proxies.
|
||||
*
|
||||
* @var int
|
||||
* @var integer
|
||||
*/
|
||||
protected $headers = Request::HEADER_X_FORWARDED_ALL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,5 @@ class VerifyCsrfToken extends Middleware
|
|||
* @var array
|
||||
*/
|
||||
protected $except = [
|
||||
//
|
||||
];
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,8 +2,6 @@
|
|||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use App\Enums\ContactFormCivility;
|
||||
use App\Enums\ContactFormType;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class ContactFormRequest extends FormRequest
|
||||
|
|
@ -11,7 +9,7 @@ class ContactFormRequest extends FormRequest
|
|||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
* @return boolean
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
|
|
@ -28,8 +26,8 @@ class ContactFormRequest extends FormRequest
|
|||
return [
|
||||
'last_name' => 'required|min:2',
|
||||
'first_name' => 'required|min:2',
|
||||
// TODO: The dns and spoof validators require the PHP intl extension. (présent sur prod ?)
|
||||
'email' => 'required|email:rfc,dns,spoof',
|
||||
'shop' => 'present|nullable|string|exists:magasins,name',
|
||||
'subject' => 'required|min:2',
|
||||
'order_ref' => 'sometimes',
|
||||
'message' => 'required|min:20|max:1900',
|
||||
|
|
@ -49,6 +47,7 @@ class ContactFormRequest extends FormRequest
|
|||
'ok_cgv.accepted' => __('You must accept the terms and conditions and the privacy policy'),
|
||||
'file.max' => __('La taille du fichier ne peut pas dépasser :max kilo-octets.'),
|
||||
'file.mimes' => __('Le fichier doit être de type : :values.'),
|
||||
'shop.exists' => __('Le magasin :exists est introuvable.')
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ class ProductRequest extends FormRequest
|
|||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
* @return boolean
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ class SortOrders extends FormRequest
|
|||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
* @return boolean
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -4,16 +4,20 @@ namespace App\Jobs;
|
|||
|
||||
abstract class CsvJobs extends XArcadiaFlux
|
||||
{
|
||||
|
||||
/**
|
||||
* parse csv file
|
||||
*
|
||||
* @param string $csvFile
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function parseCsv($csvFile) {
|
||||
protected function parseCsv(string $csvFile)
|
||||
{
|
||||
$file_handle = fopen($csvFile, 'r');
|
||||
while (!feof($file_handle)) {
|
||||
$line_of_text[] = fgetcsv($file_handle, 0, ";");
|
||||
if(!end($line_of_text)) {
|
||||
//supprime les lignes vides du csv
|
||||
if (!end($line_of_text)) {
|
||||
// Supprime les lignes vides du csv.
|
||||
array_pop($line_of_text);
|
||||
}
|
||||
}
|
||||
|
|
@ -36,10 +40,19 @@ abstract class CsvJobs extends XArcadiaFlux
|
|||
/**
|
||||
* converts an array to a csv stream
|
||||
*
|
||||
* @param array $data
|
||||
* @param string $delimiter
|
||||
* @param string $enclosure
|
||||
* @param string $escape_char
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function array2csv($data, $delimiter = ',', $enclosure = '"', $escape_char = "\\")
|
||||
{
|
||||
protected function array2csv(
|
||||
array $data,
|
||||
string $delimiter = ',',
|
||||
string $enclosure = '"',
|
||||
string $escape_char = "\\"
|
||||
) {
|
||||
$f = fopen('php://memory', 'r+');
|
||||
foreach ($data as $item) {
|
||||
fputcsv($f, $item, $delimiter, $enclosure, $escape_char);
|
||||
|
|
|
|||
|
|
@ -4,20 +4,27 @@ namespace App\Jobs;
|
|||
|
||||
use Illuminate\Support\Carbon;
|
||||
use App\Models\Order;
|
||||
use App\Models\OrderLine;
|
||||
use App\Models\Customers;
|
||||
use App\Models\Timeslot;
|
||||
|
||||
class CsvOrderWrite extends CsvJobs
|
||||
{
|
||||
|
||||
/**
|
||||
* The Laravel disk name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $disk = 'orders';
|
||||
|
||||
/** @var Order */
|
||||
/**
|
||||
* The Order to be exported
|
||||
*
|
||||
* @var Order
|
||||
* */
|
||||
private $order;
|
||||
|
||||
/**
|
||||
* en-têtes
|
||||
* CSV File headers
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $header = [
|
||||
"CodeArt",
|
||||
|
|
@ -34,6 +41,8 @@ class CsvOrderWrite extends CsvJobs
|
|||
|
||||
/**
|
||||
* correspondance unité d'appro/mode de commande
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $mode_commande = [
|
||||
"COLIS" => "UEA",
|
||||
|
|
@ -44,6 +53,8 @@ class CsvOrderWrite extends CsvJobs
|
|||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @param Order $order
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Order $order)
|
||||
|
|
@ -70,44 +81,48 @@ class CsvOrderWrite extends CsvJobs
|
|||
/** @var Timeslot */
|
||||
$timeslot = $this->order->timeslot;
|
||||
|
||||
//insertion de la ligne d'en-têtes
|
||||
// Insertion de la ligne d'en-têtes.
|
||||
$csvlines[] = $this->header;
|
||||
|
||||
foreach ($orderlines as $orderline) {
|
||||
$product = $orderline->product;
|
||||
|
||||
$unité_commande = $product->order_unit ?? 'PCE'; //COLIS, KGM, PCE (faut il introduire un nouveau champs type unité de commande)
|
||||
$code_client = preg_replace('/[^\d]/', '', $customer->salarie->matricule); //matricule rh transmis sans les lettres de l'identifiant windows
|
||||
|
||||
//convert to date object
|
||||
// COLIS, KGM, PCE (faut il introduire un nouveau champs type unité de commande).
|
||||
$unité_commande = $product->order_unit ?? 'PCE';
|
||||
// Matricule rh transmis sans les lettres de l'identifiant windows.
|
||||
$code_client = preg_replace('/[^\d]/', '', $customer->salarie->matricule);
|
||||
// Convert to date object.
|
||||
$datLivraison = Carbon::createFromFormat('d/m/Y H:i', $timeslot->day . " " . $timeslot->time);
|
||||
|
||||
//on enleve un jour pour avoir le produit la veille
|
||||
$datLivraison = $datLivraison->subDay();
|
||||
|
||||
$oneline = [
|
||||
$product->foodProduct->no_art, //21/01/2022 : suppression du pcb ici
|
||||
$product->foodProduct->no_art,
|
||||
// 21/01/2022 : suppression du pcb ici
|
||||
$code_client,
|
||||
$product->reference,
|
||||
"commande ferme",
|
||||
$unité_commande,
|
||||
$this->mode_commande[$unité_commande], //UEA,KGM,UB (respectivement selon le champ précédent)
|
||||
"", //on vide la colonne pcb comme demandé
|
||||
$datLivraison->format('d/m/Y'), //dd/mm/yyyy
|
||||
// UEA,KGM,UB (respectivement selon le champ précédent).
|
||||
$this->mode_commande[$unité_commande],
|
||||
// On vide la colonne pcb comme demandé.
|
||||
"",
|
||||
$datLivraison->format('d/m/Y'),
|
||||
$orderline->quantity,
|
||||
$this->order->reference,
|
||||
];
|
||||
|
||||
$csvlines[] = $oneline;
|
||||
}
|
||||
}//end foreach
|
||||
|
||||
$data = $this->array2csv($csvlines, ";");
|
||||
|
||||
//$outputfilename = date("Ymd_His") . microtime(true) . ".csv";
|
||||
$outputfilename = "BTQ_" . $this->order->reference . "_" . $code_client . "_" . $customer->salarie->nom . "_" . $customer->salarie->prenom . "_" . str_pad($customer->salarie->code_societe, 3, "0", STR_PAD_LEFT) . ".csv";
|
||||
$outputfilename = "BTQ_" .
|
||||
$this->order->reference . "_" .
|
||||
$code_client . "_" .
|
||||
$customer->salarie->nom . "_" .
|
||||
$customer->salarie->prenom . "_" .
|
||||
str_pad($customer->salarie->code_societe, 3, "0", STR_PAD_LEFT) . ".csv";
|
||||
|
||||
$disk->put($outputfilename, $data);
|
||||
|
||||
//send this file by mail
|
||||
// Send this file by mail.
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,17 +8,21 @@ use ErrorException;
|
|||
use TypeError;
|
||||
use Illuminate\Database\QueryException;
|
||||
use App\Exceptions\AbortCsvImportException;
|
||||
use Illuminate\Contracts\Filesystem\Filesystem;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class CsvSalariesReader extends CsvJobs
|
||||
{
|
||||
|
||||
/**
|
||||
* This is for Laravel Console usage
|
||||
* @var \Illuminate\Console\Command|null
|
||||
*/
|
||||
public $console = null;
|
||||
|
||||
/**
|
||||
* The Laravel disk name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $disk = 'salaries';
|
||||
|
||||
/**
|
||||
|
|
@ -28,7 +32,6 @@ class CsvSalariesReader extends CsvJobs
|
|||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -44,7 +47,7 @@ class CsvSalariesReader extends CsvJobs
|
|||
$files = $disk->files();
|
||||
|
||||
$progress = 1;
|
||||
$total = count(array_filter($files, function ($filename) {
|
||||
$total = count(array_filter($files, function ($filename) {
|
||||
if ($this->fileHasToBeIgnored($filename)) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -63,17 +66,17 @@ class CsvSalariesReader extends CsvJobs
|
|||
|
||||
try {
|
||||
$data = $this->parseCsv($filepath);
|
||||
//first line is header (mandatory)
|
||||
// First line is header (mandatory).
|
||||
$header = array_flip(array_shift($data));
|
||||
foreach ($data as $line) {
|
||||
$matricule = $line[$header['matricule']];
|
||||
$prenom = $line[$header['prenom']];
|
||||
$nom = $line[$header['nom']];
|
||||
$salarie = Salarie::firstOrNew(['matricule' => $matricule ]);
|
||||
$matricule = $line[$header['matricule']];
|
||||
$prenom = $line[$header['prenom']];
|
||||
$nom = $line[$header['nom']];
|
||||
$salarie = Salarie::firstOrNew(['matricule' => $matricule ]);
|
||||
$salarie->matricule = $matricule;
|
||||
$salarie->nom = $nom;
|
||||
$salarie->prenom = $prenom;
|
||||
$salarie->code = $salarie->code ?? $this->generateCode();
|
||||
$salarie->nom = $nom;
|
||||
$salarie->prenom = $prenom;
|
||||
$salarie->code = $salarie->code ?? $this->generateCode();
|
||||
$salarie->save();
|
||||
}
|
||||
} catch (ErrorException | TypeError | QueryException $e) {
|
||||
|
|
@ -90,7 +93,8 @@ class CsvSalariesReader extends CsvJobs
|
|||
),
|
||||
LogType::critical()
|
||||
);
|
||||
continue; // ignore the file
|
||||
continue;
|
||||
// Ignore the file.
|
||||
} catch (AbortCsvImportException $e) {
|
||||
$this->log(
|
||||
sprintf(
|
||||
|
|
@ -101,19 +105,23 @@ class CsvSalariesReader extends CsvJobs
|
|||
),
|
||||
LogType::error()
|
||||
);
|
||||
continue; // ignore the file
|
||||
}
|
||||
continue;
|
||||
// Ignore the file.
|
||||
}//end try
|
||||
$this->moveToArchives($filename);
|
||||
}
|
||||
}//end foreach
|
||||
|
||||
// Clear old archives
|
||||
// Clear old archives.
|
||||
$this->clearOldArchives();
|
||||
}
|
||||
|
||||
/**
|
||||
* Génère un code d'inscription
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function generateCode() {
|
||||
protected function generateCode()
|
||||
{
|
||||
return Str::random(5);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,19 +38,15 @@ class RefreshSiteMap implements ShouldQueue
|
|||
'/login',
|
||||
'/bo',
|
||||
'/activer',
|
||||
// '/deconnexion',
|
||||
'/reinitialiser-mdp',
|
||||
// '/le-club-des-gaulois/la-boutique',
|
||||
// '/password/confirm',
|
||||
// '/produit/from-menus',
|
||||
// '/cote-cuisine/sante-et-nutrition/menu-equilibre-j',
|
||||
// '/la-marque/tracabilite/search',
|
||||
// '/frame',
|
||||
// '/map',
|
||||
'/_debugbar', // Hack ignore laravel debug bar
|
||||
'_ignition/health-check', //ignore ignition route
|
||||
'_ignition/scripts/{script}', //ignore ignition route
|
||||
'_ignition/styles/{style}' //ignore ignition route
|
||||
// Hack ignore laravel debug bar.
|
||||
'/_debugbar',
|
||||
// Ignore ignition route.
|
||||
'_ignition/health-check',
|
||||
// Ignore ignition route.
|
||||
'_ignition/scripts/{script}',
|
||||
// Ignore ignition route.
|
||||
'_ignition/styles/{style}'
|
||||
];
|
||||
|
||||
/**
|
||||
|
|
@ -73,13 +69,12 @@ class RefreshSiteMap implements ShouldQueue
|
|||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
*! Ici c'est du sale !!
|
||||
* TODO: mettre tout ça dans un package pour le rendre plus générique
|
||||
*
|
||||
* @return void
|
||||
* @phpcs:disable Generic.Metrics.CyclomaticComplexity.TooHigh
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
// @phpcs:enable
|
||||
$this->assertRouteBinderIsCorrect();
|
||||
|
||||
$siteMap = [];
|
||||
|
|
@ -115,20 +110,20 @@ class RefreshSiteMap implements ShouldQueue
|
|||
/** @var string $pName $parameter name on route uri */
|
||||
$pName = '';
|
||||
|
||||
// If the route has parameters and the controller accepts it
|
||||
// If the route has parameters and the controller accepts it.
|
||||
if (count($pNames) and \array_key_exists($param->getPosition(), $pNames)) {
|
||||
// Get the controller parameter name for the route
|
||||
// Get the controller parameter name for the route.
|
||||
$pName = $pNames[$param->getPosition()];
|
||||
}
|
||||
|
||||
// If We have a custom binder for this route
|
||||
// If We have a custom binder for this route.
|
||||
if ($this->hasRouteBinderParam($route, $pName)) {
|
||||
$hasModels = true;
|
||||
$this->processWithRouteBinderParam($rParams, $route, $pName);
|
||||
continue;
|
||||
}
|
||||
|
||||
// If This route takes a model as param
|
||||
// If This route takes a model as param.
|
||||
if ($name and $name->isSubclassOf(Model::class)) {
|
||||
$hasModels = true;
|
||||
/** @var \string */
|
||||
|
|
@ -136,19 +131,20 @@ class RefreshSiteMap implements ShouldQueue
|
|||
$this->setParamsForModel($rParams, $modelClassName, $pName);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}//end foreach
|
||||
|
||||
// If the route has no dynamic models as parameters
|
||||
// If the route has no dynamic models as parameters.
|
||||
if (!count($params) or !$hasModels) {
|
||||
$siteMap[] = [
|
||||
route($route->getName()),
|
||||
Url::CHANGE_FREQUENCY_MONTHLY,
|
||||
0.1
|
||||
];
|
||||
} else { // If the route has dynamic models as parameters
|
||||
} else {
|
||||
// If the route has dynamic models as parameters.
|
||||
$this->genRoute($route, $siteMap, $rParams);
|
||||
}
|
||||
}
|
||||
}//end foreach
|
||||
|
||||
$sm = Sitemap::create();
|
||||
foreach ($siteMap as $smRules) {
|
||||
|
|
@ -163,9 +159,11 @@ class RefreshSiteMap implements ShouldQueue
|
|||
/**
|
||||
* Process route with binderParam
|
||||
*
|
||||
* @param array $rParams
|
||||
* @param RoutingRoute $route
|
||||
* @param string $pName
|
||||
* @param string $pName
|
||||
* @return void
|
||||
* @throws Exception When unhandled class.
|
||||
*/
|
||||
private function processWithRouteBinderParam(array &$rParams, RoutingRoute $route, string $pName)
|
||||
{
|
||||
|
|
@ -175,7 +173,7 @@ class RefreshSiteMap implements ShouldQueue
|
|||
$modelClassName = $o[0];
|
||||
/** @var \string */
|
||||
$routeParamName = $o[1];
|
||||
$rfLCls = (new ReflectionClass($modelClassName));
|
||||
$rfLCls = (new ReflectionClass($modelClassName));
|
||||
|
||||
switch (true) {
|
||||
case $rfLCls->isSubclassOf(Model::class):
|
||||
|
|
@ -192,7 +190,7 @@ class RefreshSiteMap implements ShouldQueue
|
|||
/**
|
||||
* Set route param Array for Enums
|
||||
*
|
||||
* @param array $rParams
|
||||
* @param array $rParams
|
||||
* @param string $enumClassName
|
||||
* @param string $pName
|
||||
* @return void
|
||||
|
|
@ -210,7 +208,7 @@ class RefreshSiteMap implements ShouldQueue
|
|||
/**
|
||||
* Set route param Array for Models
|
||||
*
|
||||
* @param array $rParams
|
||||
* @param array $rParams
|
||||
* @param string $modelClassName
|
||||
* @param string $pName
|
||||
* @param string $routeParamName
|
||||
|
|
@ -222,16 +220,15 @@ class RefreshSiteMap implements ShouldQueue
|
|||
string $pName,
|
||||
string $routeParamName = null
|
||||
) {
|
||||
$i = 0;
|
||||
$limit = 10;
|
||||
$i = 0;
|
||||
$limit = 10;
|
||||
$modelTable = (new ReflectionClass($modelClassName))->newInstanceWithoutConstructor()->getTable();
|
||||
$q = $modelClassName::query();
|
||||
$q = Schema::hasColumn($modelTable, 'status') ? $q->where('status', true) : $q;
|
||||
$q = Schema::hasColumn($modelTable, 'ocbStatus') ? $q->where('ocbStatus', EleveurOcbStatus::yes()->value) : $q;
|
||||
$q = Schema::hasColumn($modelTable, 'star_moment') ? $q->where('star_moment', true) : $q;
|
||||
$q = $modelClassName::query();
|
||||
$q = Schema::hasColumn($modelTable, 'status') ? $q->where('status', true) : $q;
|
||||
$q = Schema::hasColumn($modelTable, 'star_moment') ? $q->where('star_moment', true) : $q;
|
||||
do {
|
||||
$results = $q->offset($i * $limit)->limit($limit)->get();
|
||||
$length = count($results);
|
||||
$length = count($results);
|
||||
$results->map(function (Model $model) use (&$rParams, $pName, $routeParamName) {
|
||||
if (!array_key_exists($pName, $rParams)) {
|
||||
$rParams[$pName] = [];
|
||||
|
|
@ -250,8 +247,8 @@ class RefreshSiteMap implements ShouldQueue
|
|||
* Recursively generate routes for all params
|
||||
*
|
||||
* @param RoutingRoute $route
|
||||
* @param array $siteMap
|
||||
* @param array $params
|
||||
* @param array $siteMap
|
||||
* @param array $params
|
||||
* @return void
|
||||
*/
|
||||
private function genRoute(RoutingRoute $route, array &$siteMap, array $params)
|
||||
|
|
@ -290,7 +287,7 @@ class RefreshSiteMap implements ShouldQueue
|
|||
* Check if $route exists in routesBinder and has $param
|
||||
*
|
||||
* @param RoutingRoute $route
|
||||
* @param string $param
|
||||
* @param string $param
|
||||
* @return boolean
|
||||
*/
|
||||
private function hasRouteBinderParam(RoutingRoute $route, string $param): bool
|
||||
|
|
@ -316,7 +313,7 @@ class RefreshSiteMap implements ShouldQueue
|
|||
* Get the routeBinder param
|
||||
*
|
||||
* @param RoutingRoute $route
|
||||
* @param string $param
|
||||
* @param string $param
|
||||
* @return array
|
||||
*/
|
||||
private function getRouteBinderParam(RoutingRoute $route, string $param): array
|
||||
|
|
@ -327,7 +324,7 @@ class RefreshSiteMap implements ShouldQueue
|
|||
/**
|
||||
* Assert that routeBinder is correct
|
||||
*
|
||||
* @throws Exception
|
||||
* @throws Exception When route does not exist | incomplrte parameters | parameter is not a model class.
|
||||
* @return void
|
||||
*/
|
||||
private function assertRouteBinderIsCorrect()
|
||||
|
|
@ -367,8 +364,8 @@ class RefreshSiteMap implements ShouldQueue
|
|||
$p[0]
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
}//end foreach
|
||||
}//end foreach
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
namespace App\Jobs;
|
||||
|
||||
use App\Enums\LogType;
|
||||
use Exception;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Filesystem\Filesystem;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
|
|
@ -30,6 +29,7 @@ abstract class XArcadiaFlux implements ShouldQueue
|
|||
|
||||
/**
|
||||
* This is for Laravel Console usage
|
||||
* @var \Illuminate\Console\Command|null
|
||||
*/
|
||||
public $console = null;
|
||||
|
||||
|
|
@ -53,6 +53,7 @@ abstract class XArcadiaFlux implements ShouldQueue
|
|||
* Check if the file extension
|
||||
*
|
||||
* @param string $filename
|
||||
* @param string $extension
|
||||
* @return boolean
|
||||
*/
|
||||
protected function checkExtension(string $filename, string $extension): bool
|
||||
|
|
@ -110,7 +111,7 @@ abstract class XArcadiaFlux implements ShouldQueue
|
|||
*/
|
||||
protected function clearOldArchives(): void
|
||||
{
|
||||
$disk = $this->getDisk();
|
||||
$disk = $this->getDisk();
|
||||
$archives = $disk->files($this->archiveFolderName);
|
||||
|
||||
// /** @var File */
|
||||
|
|
@ -141,9 +142,10 @@ abstract class XArcadiaFlux implements ShouldQueue
|
|||
/**
|
||||
* Logs data
|
||||
*
|
||||
* @param string $message
|
||||
* @param string $message
|
||||
* @param LogType $logtype
|
||||
* @return void
|
||||
* @throws \ErrorException If logtype is not handled.
|
||||
*/
|
||||
protected function log(string $message, LogType $logtype = null): void
|
||||
{
|
||||
|
|
@ -171,17 +173,18 @@ abstract class XArcadiaFlux implements ShouldQueue
|
|||
Log::critical($message);
|
||||
break;
|
||||
default:
|
||||
throw new Exception(sprintf('%s : unhandled log type %s', get_class($this), $logtype->label));
|
||||
}
|
||||
throw new \ErrorException(sprintf('%s : unhandled log type %s', get_class($this), $logtype->label));
|
||||
}//end switch
|
||||
$this->consolePrint($message, $logtype);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints to the console
|
||||
*
|
||||
* @param string $message
|
||||
* @param string $message
|
||||
* @param LogType $logtype
|
||||
* @return void
|
||||
* @throws \ErrorException If logtype is not handled.
|
||||
*/
|
||||
protected function consolePrint(string $message, LogType $logtype): void
|
||||
{
|
||||
|
|
@ -200,7 +203,7 @@ abstract class XArcadiaFlux implements ShouldQueue
|
|||
$this->console->error($message);
|
||||
break;
|
||||
default:
|
||||
throw new Exception(sprintf('%s : unhandled log type %s', get_class($this), $logtype->label));
|
||||
throw new \ErrorException(sprintf('%s : unhandled log type %s', get_class($this), $logtype->label));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,12 +8,26 @@ use SimpleXMLElement;
|
|||
|
||||
class XmlIncoReader extends XmlJobs
|
||||
{
|
||||
|
||||
/**
|
||||
* The Laravel disk name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $disk = 'inco';
|
||||
|
||||
/**
|
||||
* Storage path
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $imagesPath = 'images';
|
||||
|
||||
/**
|
||||
* The columns to take from the XML
|
||||
* subcolumns can be added with a dot
|
||||
*
|
||||
* @var array
|
||||
*
|
||||
* éléments à la racine : nom du noeud
|
||||
* sous éléments d'un noeud PARENT :
|
||||
* d'abord:
|
||||
|
|
@ -29,42 +43,47 @@ class XmlIncoReader extends XmlJobs
|
|||
* 'EXPLOITANT.NOM_SOCIETE' => 'nom_societe',
|
||||
*/
|
||||
protected $takeColumns = [
|
||||
'NO_ART' => 'id', // primary key on model
|
||||
|
||||
//this wil not return anything cf doc above
|
||||
'NO_ART' => 'id',
|
||||
// Primary key on model.
|
||||
// This wil not return anything cf doc above.
|
||||
'ID_SOCIETE' => 'id_societe',
|
||||
'NOM_SOCIETE' => 'nom_societe',
|
||||
|
||||
'PROD_SAISON' => 'prod_saison',
|
||||
'NOM' => 'nom',
|
||||
'NUMERO' => 'numero',
|
||||
'TAILLE_REF' => 'taille_ref', //$poidsRef censé être dans INCO_COMPO (et généralement 100g)
|
||||
'TAILLE_REF' => 'taille_ref',
|
||||
// $poidsRef censé être dans INCO_COMPO (et généralement 100g)
|
||||
'ALLEGATIONS' => 'allegations',
|
||||
'CONSEIL_PREPA' => 'conseil_prepa',
|
||||
'ASTUCES' => 'astuces',
|
||||
'DESCRIPTIF' => 'descriptif', //$descriptif
|
||||
'DESCRIPTIF' => 'descriptif',
|
||||
// $descriptif
|
||||
'ARG_VENTE' => 'arg_vente',
|
||||
'NB_PORTION' => 'nb_portion',
|
||||
'TYP_PORTION' => 'typ_portion',
|
||||
'PDS_MOY_THEO' => 'pds_moy_theo',
|
||||
'LIB_CONSO' => 'lib_conso',
|
||||
'LST_ING' => 'lst_ing', //$ingredients
|
||||
|
||||
// list alergene
|
||||
'LST_ALLERGENE' => 'lst_allergene', // Consider this sub array
|
||||
'LST_ING' => 'lst_ing',
|
||||
// $ingredients
|
||||
// List alergene.
|
||||
'LST_ALLERGENE' => 'lst_allergene',
|
||||
// Consider this sub array.
|
||||
'LST_ALLERGENE.LIB_ALLERGENE' => 'lib_allergene',
|
||||
|
||||
// Allegations
|
||||
// Allegations.
|
||||
'ALLEGAT_SANTE' => 'allegat_sante',
|
||||
'ALLEGAT_NUTRIT' => 'allegat_nutrit',
|
||||
'ALLEGAT_AUTRE' => 'allegat_autre',
|
||||
|
||||
|
||||
'INCO_COMPO' => 'inco_compo', // Consider this sub array
|
||||
'INCO_COMPO' => 'inco_compo',
|
||||
// Consider this sub array.
|
||||
'INCO_COMPO.NOM' => 'nom',
|
||||
'INCO_COMPO.TAILLE_REF' => 'taille_ref',
|
||||
'INCO_COMPO.VAL_ENERG_KJ_NUT' => 'val_energ_kj_nut',
|
||||
'INCO_COMPO.VAL_ENERG_KJ_R' => 'val_energ_kj_r', //_R apports de la taille_ref
|
||||
'INCO_COMPO.VAL_ENERG_KJ_R' => 'val_energ_kj_r',
|
||||
// _R apports de la taille_ref
|
||||
'INCO_COMPO.VAL_ENERG_KCAL_R' => 'val_energ_kcal_r',
|
||||
'INCO_COMPO.VAL_ENERG_KCAL_NUT' => 'val_energ_kcal_nut',
|
||||
'INCO_COMPO.MAT_GRASS_R' => 'mat_grass_r',
|
||||
|
|
@ -85,7 +104,8 @@ class XmlIncoReader extends XmlJobs
|
|||
'INCO_COMPO.ENER_E14_R' => 'ener_e14_r',
|
||||
'INCO_COMPO.FRUITS_R' => 'fruits_r',
|
||||
'INCO_COMPO.FRUITS_COQUE_SECH_R' => 'fruits_coque_sech_r',
|
||||
'INCO_COMPO.POURCENT_APPORT_REF_E14_R' => 'pourcent_apport_ref_e14_r', //POURCENT_*_P apports journaliers par portion
|
||||
'INCO_COMPO.POURCENT_APPORT_REF_E14_R' => 'pourcent_apport_ref_e14_r',
|
||||
// POURCENT_*_P apports journaliers par portion.
|
||||
'INCO_COMPO.ENER_KJO_R' => 'ener_kjo_r',
|
||||
'INCO_COMPO.POURCENT_APPORT_REF_KJO_R' => 'pourcent_apport_ref_kjo_r',
|
||||
'INCO_COMPO.POURCENT_APPORT_REF_FAT_R' => 'pourcent_apport_ref_fat_r',
|
||||
|
|
@ -102,8 +122,10 @@ class XmlIncoReader extends XmlJobs
|
|||
'INCO_COMPO.SALTEQ_R' => 'salteq_r',
|
||||
'INCO_COMPO.POURCENT_APPORT_REF_SALTEQ_R' => 'pourcent_apport_ref_salteq_r',
|
||||
'INCO_COMPO.APPORT_REF' => 'apport_ref',
|
||||
'INCO_COMPO.TAILLE_PORT' => 'taille_port', //$poidsPortion
|
||||
'INCO_COMPO.VAL_ENERG_KJ_P' => 'val_energ_kj_p', //_P apports par portion
|
||||
'INCO_COMPO.TAILLE_PORT' => 'taille_port',
|
||||
// $poidsPortion
|
||||
'INCO_COMPO.VAL_ENERG_KJ_P' => 'val_energ_kj_p',
|
||||
// _P apports par portion
|
||||
'INCO_COMPO.VAL_ENERG_KCAL_P' => 'val_energ_kcal_p',
|
||||
'INCO_COMPO.MAT_GRASS_P' => 'mat_grass_p',
|
||||
'INCO_COMPO.AGS_P' => 'ags_p',
|
||||
|
|
@ -145,8 +167,10 @@ class XmlIncoReader extends XmlJobs
|
|||
'INCO_COMPO.COMPOSANTE_N' => 'composante_n',
|
||||
'INCO_COMPO.COMPOSANTE_P' => 'composante_p',
|
||||
'INCO_COMPO.POURCENT_FRUITS' => 'pourcent_fruits',
|
||||
'INCO_COMPO.SCORE_NUTRI' => 'score_nutri', //du coup nutriscore ?
|
||||
'INCO_COMPO.CLASSEMENT' => 'classement', //$nutriscore mais pas censé être dans INCO_COMPO
|
||||
'INCO_COMPO.SCORE_NUTRI' => 'score_nutri',
|
||||
// Du coup nutriscore ?.
|
||||
'INCO_COMPO.CLASSEMENT' => 'classement',
|
||||
// $nutriscore mais pas censé être dans INCO_COMPO
|
||||
'INCO_COMPO.MAT_GRASS_R_PREC' => 'mat_grass_r_prec',
|
||||
'INCO_COMPO.AGS_R_PREC' => 'ags_r_prec',
|
||||
'INCO_COMPO.GLUCIDES_R_PREC' => 'glucides_r_prec',
|
||||
|
|
@ -159,6 +183,11 @@ class XmlIncoReader extends XmlJobs
|
|||
'INCO_COMPO.FRUITS_COQUE_SECH_R_PREC' => 'fruits_coque_sech_r_prec',
|
||||
];
|
||||
|
||||
/**
|
||||
* The columns allowed to be null
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $nullableFields = [
|
||||
'taille_ref',
|
||||
'conseil_prepa',
|
||||
|
|
@ -272,8 +301,18 @@ class XmlIncoReader extends XmlJobs
|
|||
'inco_compo.fruits_coque_sech_r_prec'
|
||||
];
|
||||
|
||||
/**
|
||||
* Unique keys for updating rows
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $uniqueKeyField = ['id'];
|
||||
|
||||
/**
|
||||
* Columns to merge in
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $mergeColumns = [
|
||||
'allegations' => [
|
||||
'allegat_sante',
|
||||
|
|
@ -379,15 +418,20 @@ class XmlIncoReader extends XmlJobs
|
|||
]
|
||||
];
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
|
||||
$this->parseData('INCO', XmlInco::class, function (SimpleXMLElement $xmlData, array &$line) {
|
||||
|
||||
// merge columns
|
||||
// Merge columns.
|
||||
foreach ($this->mergeColumns as $key => $values) {
|
||||
$line[$key] = [];
|
||||
// merge columns and remove merged columns from line
|
||||
// Merge columns and remove merged columns from line.
|
||||
array_map(function ($kValue) use (&$line, $key) {
|
||||
if (array_key_exists($kValue, $line)) {
|
||||
$line[$key][$kValue] = $line[$kValue];
|
||||
|
|
@ -398,13 +442,9 @@ class XmlIncoReader extends XmlJobs
|
|||
$line[$key] = implode(',', array_filter($line[$key]));
|
||||
$line[$key] = strlen($line[$key]) ? $line[$key] : null;
|
||||
}
|
||||
//json column cast into array in model => no need for encode
|
||||
// if ($key == 'nutritional_values') {
|
||||
// $line[$key] = json_encode($line[$key], \JSON_FORCE_OBJECT);
|
||||
// }
|
||||
}
|
||||
|
||||
// Boolean cast prod_saison
|
||||
// Boolean cast prod_saison.
|
||||
$line['prod_saison'] = isset($line['prod_saison']) ?
|
||||
(strtolower($line['prod_saison']) == 'non' ? false : true) : false;
|
||||
|
||||
|
|
@ -413,52 +453,118 @@ class XmlIncoReader extends XmlJobs
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract Image form XML file
|
||||
*
|
||||
* @param SimpleXMLElement $xmlData
|
||||
* @return array
|
||||
* @throws AbortXmlImportException When media tag does not contain an image.
|
||||
*/
|
||||
private function parseImage(SimpleXMLElement $xmlData)
|
||||
{
|
||||
$images = $xmlData->INCO->MEDIA_VISUEL_EAI->MEDIA_VISUEL_EAI;
|
||||
$list_media = $xmlData->INCO->MEDIA_VISUEL_EAI->MEDIA_VISUEL_EAI;
|
||||
$arImgPaths = array();
|
||||
$index = 1;
|
||||
|
||||
foreach ($images as $image) {
|
||||
foreach ($list_media as $media) {
|
||||
$image = $media->img;
|
||||
$imageData = trim((string)$image);
|
||||
if (strlen($imageData)) {
|
||||
$imageData = base64_decode($imageData);
|
||||
$imgName = strval($xmlData->INCO->INCO_COMPO->TBL_INCO_COMPO->ID_INCO);
|
||||
if(empty($imgName)) {
|
||||
$imgName = strval($xmlData->INCO->INCO_COMPO->TBL_INCO_COMPO->ID_INCO);
|
||||
if (empty($imgName)) {
|
||||
$imgName = strval($xmlData->INCO->NO_ART);
|
||||
}
|
||||
$imgName = $imgName."_".$index;
|
||||
$imgName = $imgName . "_" . $index;
|
||||
$imgNamePath = sprintf('%s/%s', rtrim($this->imagesPath, '/'), $imgName);
|
||||
|
||||
$disk = $this->getDisk();
|
||||
|
||||
$info = getimagesizefromstring($imageData);
|
||||
$mime = $info['mime'];
|
||||
switch ($mime) {
|
||||
case 'image/jpeg':
|
||||
$imgExtension = 'jpg';
|
||||
break;
|
||||
case 'image/png':
|
||||
$imgExtension = 'png';
|
||||
break;
|
||||
case 'image/gif':
|
||||
$imgExtension = 'gif';
|
||||
break;
|
||||
default:
|
||||
throw new AbortXmlImportException(sprintf('Unknown image type %s', $imgName));
|
||||
}
|
||||
if ($info !== false) {
|
||||
$mime = $info['mime'];
|
||||
switch ($mime) {
|
||||
case 'image/jpeg':
|
||||
$imgExtension = 'jpg';
|
||||
break;
|
||||
case 'image/png':
|
||||
$imgExtension = 'png';
|
||||
break;
|
||||
case 'image/gif':
|
||||
$imgExtension = 'gif';
|
||||
break;
|
||||
default:
|
||||
throw new AbortXmlImportException(sprintf('Unknown image type %s', $imgName));
|
||||
}
|
||||
|
||||
$imgNamePath = sprintf('%s.%s', $imgNamePath, $imgExtension);
|
||||
$imgNamePath = sprintf('%s.%s', $imgNamePath, $imgExtension);
|
||||
|
||||
if (!$disk->put($imgNamePath, $imageData)) {
|
||||
throw new AbortXmlImportException(sprintf('The image %s could not be saved', $imgNamePath));
|
||||
}
|
||||
if (!$disk->put($imgNamePath, $imageData)) {
|
||||
throw new AbortXmlImportException(sprintf('The image %s could not be saved', $imgNamePath));
|
||||
}
|
||||
|
||||
$arImgPaths[$index] = sprintf('%s/%s', $this->disk, $imgNamePath);
|
||||
$index++;
|
||||
}
|
||||
}
|
||||
$arImgPaths[$index] = sprintf('%s/%s', $this->disk, $imgNamePath);
|
||||
$index++;
|
||||
}//end if
|
||||
}//end if
|
||||
}//end foreach
|
||||
|
||||
return $arImgPaths;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Recursive extract to array
|
||||
* introduce sort of Hook to transform
|
||||
* <TYP_PORTION>
|
||||
* <code><![CDATA[2]]></code>
|
||||
* <libelle><![CDATA[Approximatif]]></libelle>
|
||||
* </TYP_PORTION>
|
||||
* extracted as "TYP_PORTION" => array:1 [
|
||||
* 0 => array:2 [
|
||||
* "code" => "2"
|
||||
* "libelle" => "Approximatif"
|
||||
* ]
|
||||
* ]
|
||||
* into this
|
||||
* <TYP_PORTION><![CDATA[Approximatif]]></TYP_PORTION>
|
||||
* extracted as "TYP_PORTION" => "Approximatif"
|
||||
*
|
||||
*
|
||||
* @param \SimpleXMLElement|false $sxe
|
||||
* @return array
|
||||
*/
|
||||
protected function extract($sxe = null): array
|
||||
{
|
||||
|
||||
if (!$sxe instanceof SimpleXMLElement) {
|
||||
return array();
|
||||
}
|
||||
$extract = array();
|
||||
foreach ($sxe->children() as $key => $value) {
|
||||
if ($value->count()) {
|
||||
$extraction = $this->extract($value);
|
||||
|
||||
if (
|
||||
count($extraction)
|
||||
&& array_key_exists("code", $extraction)
|
||||
&& array_key_exists("libelle", $extraction)
|
||||
) {
|
||||
$val = strval($extraction['libelle']);
|
||||
$extract[$key] = strlen($val) ? $val : null;
|
||||
continue;
|
||||
}
|
||||
|
||||
$extract[$key][] = $extraction;
|
||||
continue;
|
||||
}
|
||||
$value = strval($value);
|
||||
if (array_key_exists($key, $extract) and is_array($extract[$key])) {
|
||||
$extract[$key][] = strlen($value) ? $value : null;
|
||||
} else {
|
||||
$extract[$key] = strlen($value) ? $value : null;
|
||||
}
|
||||
}//end foreach
|
||||
return $extract;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ use App\Exceptions\AbortXmlImportException;
|
|||
use App\Exceptions\InvalidXmlException;
|
||||
use ErrorException;
|
||||
use Illuminate\Contracts\Filesystem\FileNotFoundException;
|
||||
use Illuminate\Contracts\Filesystem\Filesystem;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
|
@ -20,7 +19,6 @@ use TypeError;
|
|||
|
||||
abstract class XmlJobs extends XArcadiaFlux
|
||||
{
|
||||
|
||||
/**
|
||||
* invalid xml folder
|
||||
*
|
||||
|
|
@ -54,20 +52,24 @@ abstract class XmlJobs extends XArcadiaFlux
|
|||
/**
|
||||
* Parse Data from the XML and gives it to the callback
|
||||
*
|
||||
* @param string $entityName
|
||||
* @param string $modelClass
|
||||
* @param string $entityName
|
||||
* @param string $modelClass
|
||||
* @param callable $callback
|
||||
* @throws InvalidXmlException When xml is invalid.
|
||||
* @return void
|
||||
*
|
||||
* @phpcs:disable Generic.Metrics.CyclomaticComplexity.TooHigh
|
||||
*/
|
||||
// phpcs:ignore Generic.Metrics.CyclomaticComplexity.TooHigh
|
||||
protected function parseData(string $entityName, string $modelClass, callable $callback = null): void
|
||||
{
|
||||
// @phpcs:enable
|
||||
/** @var Filesystem */
|
||||
$disk = $this->getDisk();
|
||||
$this->log('Démarrage du traitement');
|
||||
$files = $disk->files();
|
||||
|
||||
$progress = 1;
|
||||
$total = count(array_filter($files, function ($filename) {
|
||||
$total = count(array_filter($files, function ($filename) {
|
||||
if ($this->fileHasToBeIgnored($filename)) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -96,15 +98,10 @@ abstract class XmlJobs extends XArcadiaFlux
|
|||
|
||||
if ($xmlContent === false) {
|
||||
throw new InvalidXmlException('XML is Invalid (simplexml_load_string returned false)');
|
||||
// $this->log(
|
||||
// sprintf('File %s could not be parsed (simplexml_load_string)', $filename),
|
||||
// LogType::critical()
|
||||
// );
|
||||
// continue; // ignore the file
|
||||
}
|
||||
} catch (ErrorException $e) {
|
||||
throw new InvalidXmlException('XML is Invalid', 0, $e);
|
||||
}
|
||||
}//end try
|
||||
|
||||
$data = $this->extract($xmlContent);
|
||||
|
||||
|
|
@ -117,7 +114,7 @@ abstract class XmlJobs extends XArcadiaFlux
|
|||
$lines[] = $line;
|
||||
}
|
||||
|
||||
// Mise en base des données
|
||||
// Mise en base des données.
|
||||
foreach ($lines as $line) {
|
||||
/** @var array Unique Key columns */
|
||||
$uniqueColumnsKey = [];
|
||||
|
|
@ -128,7 +125,6 @@ abstract class XmlJobs extends XArcadiaFlux
|
|||
[$modelClass, 'updateOrCreate'],
|
||||
[$uniqueColumnsKey, $line]
|
||||
);
|
||||
// @todo : should we put that method in a interface ?
|
||||
$savedData->updateLocalProductInfo();
|
||||
}
|
||||
} catch (InvalidXmlException $e) {
|
||||
|
|
@ -159,7 +155,8 @@ abstract class XmlJobs extends XArcadiaFlux
|
|||
LogType::critical()
|
||||
);
|
||||
$this->sendErrorParseEmailToServiceWeb($e);
|
||||
continue; // ignore the file
|
||||
continue;
|
||||
// Ignore the file.
|
||||
} catch (AbortXmlImportException $e) {
|
||||
$this->log(
|
||||
sprintf(
|
||||
|
|
@ -172,9 +169,10 @@ abstract class XmlJobs extends XArcadiaFlux
|
|||
);
|
||||
$this->sendErrorParseEmailToServiceWeb($e);
|
||||
$this->moveToInvalid($filename);
|
||||
continue; // ignore the file
|
||||
continue;
|
||||
// Ignore the file.
|
||||
} catch (FileNotFoundException | QueryException $e) {
|
||||
// This happens because of concurent xml jobs read
|
||||
// This happens because of concurent xml jobs read.
|
||||
$message = $e->getMessage();
|
||||
if (get_class($e) === QueryException::class) {
|
||||
$message = implode(' ', $e->errorInfo);
|
||||
|
|
@ -188,12 +186,13 @@ abstract class XmlJobs extends XArcadiaFlux
|
|||
),
|
||||
LogType::debug()
|
||||
);
|
||||
continue; // ignore the file
|
||||
}
|
||||
continue;
|
||||
// Ignore the file.
|
||||
}//end try
|
||||
$this->moveToArchives($filename);
|
||||
}
|
||||
}//end foreach
|
||||
|
||||
// Clear old archives
|
||||
// Clear old archives.
|
||||
$this->clearOldArchives();
|
||||
}
|
||||
|
||||
|
|
@ -229,7 +228,7 @@ abstract class XmlJobs extends XArcadiaFlux
|
|||
*
|
||||
* @param array $fields
|
||||
* @return array
|
||||
* @throws AbortXmlImportException
|
||||
* @throws AbortXmlImportException When field should not be null.
|
||||
*/
|
||||
protected function processFields(array $fields): array
|
||||
{
|
||||
|
|
@ -242,7 +241,7 @@ abstract class XmlJobs extends XArcadiaFlux
|
|||
throw new AbortXmlImportException(sprintf('The field %s is not allowed to be null', $key));
|
||||
}
|
||||
if (is_array($field)) {
|
||||
// Flatten data
|
||||
// Flatten data.
|
||||
$it = new RecursiveIteratorIterator(new RecursiveArrayIterator($field));
|
||||
foreach ($it as $k => $f) {
|
||||
$ko = strtolower(sprintf('%s.%s', $key, $k));
|
||||
|
|
@ -261,7 +260,7 @@ abstract class XmlJobs extends XArcadiaFlux
|
|||
} else {
|
||||
$result[$key] = $field;
|
||||
}
|
||||
}
|
||||
}//end foreach
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
|
@ -324,6 +323,12 @@ abstract class XmlJobs extends XArcadiaFlux
|
|||
return $isXml;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send Error Mail
|
||||
*
|
||||
* @param Throwable $e
|
||||
* @return void
|
||||
*/
|
||||
protected function sendErrorParseEmailToServiceWeb(Throwable $e)
|
||||
{
|
||||
Mail::send('emails.exception', [
|
||||
|
|
@ -337,6 +342,13 @@ abstract class XmlJobs extends XArcadiaFlux
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Send Mail Invalid XML
|
||||
*
|
||||
* @param string $filename
|
||||
* @param Throwable $e
|
||||
* @return void
|
||||
*/
|
||||
protected function sendInvalidXmlEmail(string $filename, Throwable $e)
|
||||
{
|
||||
$message = $e->getPrevious()->getMessage();
|
||||
|
|
|
|||
190
app/Lib/ExceptionsHelper.php
Normal file
190
app/Lib/ExceptionsHelper.php
Normal file
|
|
@ -0,0 +1,190 @@
|
|||
<?php
|
||||
|
||||
namespace App\Lib;
|
||||
|
||||
class ExceptionsHelper
|
||||
{
|
||||
/**
|
||||
* Handle sentry event
|
||||
*
|
||||
* @param \Sentry\Event $event
|
||||
* @return null|\Sentry\Event
|
||||
*/
|
||||
public static function sentryEventHandler(\Sentry\Event $event): ?\Sentry\Event
|
||||
{
|
||||
// Remove unwanted reports.
|
||||
$event->setModules([]);
|
||||
$event->setOsContext(null);
|
||||
|
||||
/** @var \Sentry\ExceptionDataBag[] */
|
||||
$exceptionBag = [];
|
||||
foreach ($event->getExceptions() as $exceptionDataBag) {
|
||||
$exceptionBag[] = self::getAnonymizedSentryException($exceptionDataBag);
|
||||
}
|
||||
$event->setExceptions($exceptionBag);
|
||||
return $event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Anonimize Sentry Exception bag
|
||||
*
|
||||
* @param \Sentry\ExceptionDataBag $exceptionDataBag
|
||||
* @return \Sentry\ExceptionDataBag
|
||||
*/
|
||||
private static function getAnonymizedSentryException(
|
||||
\Sentry\ExceptionDataBag $exceptionDataBag
|
||||
): \Sentry\ExceptionDataBag {
|
||||
$exceptionDataBag->setValue(self::getAnonymizedMessage($exceptionDataBag->getValue()));
|
||||
if ($stackTrace = $exceptionDataBag->getStacktrace()) {
|
||||
$exceptionDataBag->setStacktrace(self::getAnonymizedSentryStackTrace($stackTrace));
|
||||
}
|
||||
return $exceptionDataBag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Anonymise sentry stacktrace
|
||||
*
|
||||
* @param \Sentry\Stacktrace $stackTrace
|
||||
* @return \Sentry\Stacktrace
|
||||
*/
|
||||
private static function getAnonymizedSentryStackTrace(\Sentry\Stacktrace $stackTrace): \Sentry\Stacktrace
|
||||
{
|
||||
/** @var \Sentry\Frame[] */
|
||||
$frames = \array_reverse($stackTrace->getFrames(), true);
|
||||
$i = \count($frames) - 1;
|
||||
// * Remove all but keep first (index.php).
|
||||
while ($i-- > 0) {
|
||||
$stackTrace->removeFrame(count($stackTrace->getFrames()) - 1);
|
||||
}
|
||||
foreach ($frames as $index => $frame) {
|
||||
$frame->setPostContext([]);
|
||||
$frame->setPreContext([]);
|
||||
$frame->setContextLine('');
|
||||
$frame->setVars(self::getAnonymizedSentryParams($frame->getVars()));
|
||||
$stackTrace->addFrame($frame);
|
||||
if ($index === 0) {
|
||||
$stackTrace->removeFrame(count($stackTrace->getFrames()) - 1);
|
||||
}
|
||||
}
|
||||
return $stackTrace;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get anonymized sentry params
|
||||
*
|
||||
* @param mixed[] $params
|
||||
* @return string[]
|
||||
*/
|
||||
private static function getAnonymizedSentryParams(array $params): array
|
||||
{
|
||||
foreach ($params as &$param) {
|
||||
$type = \strtolower(\gettype($param));
|
||||
if (\is_string($param)) {
|
||||
$type = \explode(' ', \trim($param))[0] ?? null;
|
||||
}
|
||||
switch ($type) {
|
||||
case 'Lambda':
|
||||
case 'Object':
|
||||
continue 2;
|
||||
case 'array':
|
||||
$param = sprintf('Array(%d)', \count($param));
|
||||
continue 2;
|
||||
default:
|
||||
if (\is_numeric($param)) {
|
||||
$param = \ucfirst($type);
|
||||
continue 2;
|
||||
}
|
||||
if (\is_string($param)) {
|
||||
$param = sprintf('String(%d)', \strlen($param));
|
||||
continue 2;
|
||||
}
|
||||
} //end switch
|
||||
} //end foreach
|
||||
return $params;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Anonymize at least Sql queries
|
||||
*
|
||||
* @param string $message
|
||||
* @return string
|
||||
*/
|
||||
public static function getAnonymizedMessage(string $message): string
|
||||
{
|
||||
$message = \preg_replace('/^(.*)( \(SQL:.*\))$/', '$1', $message) ?? $message;
|
||||
if ($sqlPos = \strpos($message, 'to use near')) {
|
||||
$message = \mb_strcut($message, 0, $sqlPos);
|
||||
}
|
||||
return $message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Anonymize stack trace
|
||||
*
|
||||
* @param \Throwable $e
|
||||
* @return string
|
||||
*/
|
||||
public static function getAnonymizedStackTrace(\Throwable $e): string
|
||||
{
|
||||
$projectPath = \realpath(\sprintf('%s/../', \app_path()));
|
||||
$traceStack = $e->getTrace();
|
||||
$traceStr = '';
|
||||
$maxStackStage = 0;
|
||||
foreach ($traceStack as $stackStage => $stack) {
|
||||
$maxStackStage = $stackStage;
|
||||
$traceStr .= \sprintf(
|
||||
'#%s %s(%d): ',
|
||||
$stackStage,
|
||||
str_replace($projectPath, '', $stack['file'] ?? ''),
|
||||
$stack['line'] ?? ''
|
||||
);
|
||||
if (isset($stack['class'])) {
|
||||
$traceStr .= "{$stack['class']}->{$stack['function']}(";
|
||||
if (isset($stack['args'])) {
|
||||
$traceStr .= self::handleArgs($stack);
|
||||
}
|
||||
$traceStr .= ")\n";
|
||||
} elseif (isset($stack['function'])) {
|
||||
$traceStr .= "{$stack['function']}(";
|
||||
if (isset($stack['args'])) {
|
||||
$traceStr .= self::handleArgs($stack);
|
||||
}
|
||||
$traceStr .= ")\n";
|
||||
}
|
||||
} //end foreach
|
||||
$maxStackStage++;
|
||||
$traceStr .= "#$maxStackStage {main}";
|
||||
return $traceStr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Args
|
||||
*
|
||||
* @param array $stack
|
||||
* @return string
|
||||
*/
|
||||
public static function handleArgs(array $stack): string
|
||||
{
|
||||
$traceArgs = '';
|
||||
$argsCount = count($stack['args']);
|
||||
for ($i = 0; $i < $argsCount; $i++) {
|
||||
$type = \gettype($stack['args'][$i]);
|
||||
switch ($type) {
|
||||
case 'object':
|
||||
$traceArgs .= sprintf('Object(%s)', \get_class($stack['args'][$i]));
|
||||
break;
|
||||
case 'array':
|
||||
$traceArgs .= sprintf('Array(%d)', \count($stack['args'][$i]));
|
||||
break;
|
||||
case 'string':
|
||||
$traceArgs .= sprintf('String(%d)', \strlen($stack['args'][$i]));
|
||||
break;
|
||||
default:
|
||||
$traceArgs .= \gettype($stack['args'][$i]);
|
||||
}
|
||||
$traceArgs .= ($i !== ($argsCount - 1) ? ',' : '');
|
||||
}
|
||||
return $traceArgs;
|
||||
}
|
||||
}
|
||||
|
|
@ -7,13 +7,22 @@ use Gloudemans\Shoppingcart\Contracts\Calculator;
|
|||
|
||||
class CartCalculator implements Calculator
|
||||
{
|
||||
/**
|
||||
* All purpose getter
|
||||
*
|
||||
* @param string $attribute
|
||||
* @param CartItem $cartItem
|
||||
* @return float|void
|
||||
* @phpcs:disable Generic.Metrics.CyclomaticComplexity.TooHigh
|
||||
*/
|
||||
public static function getAttribute(string $attribute, CartItem $cartItem)
|
||||
{
|
||||
// @phpcs:enable
|
||||
$decimals = config('cart.format.decimals', 2);
|
||||
|
||||
switch ($attribute) {
|
||||
case 'discount':
|
||||
return round($cartItem->price * ($cartItem->getDiscountRate() / 100)*100)/100;
|
||||
return round($cartItem->price * ($cartItem->getDiscountRate() / 100) * 100) / 100;
|
||||
case 'tax':
|
||||
return round($cartItem->priceTarget * ($cartItem->taxRate / 100), $decimals);
|
||||
case 'priceTax':
|
||||
|
|
@ -27,16 +36,15 @@ class CartCalculator implements Calculator
|
|||
case 'priceTarget':
|
||||
return round(($cartItem->priceTotal - $cartItem->discountTotal) / $cartItem->qty, $decimals);
|
||||
case 'taxTotal':
|
||||
//taxe pour un item multiplié par la quantité
|
||||
$unit_price = max($cartItem->price - $cartItem->discount,0);
|
||||
$unit_tax = round($unit_price * ($cartItem->taxRate / 100), $decimals);
|
||||
$taxTotal = round($unit_tax * $cartItem->qty, $decimals);
|
||||
//return round($cartItem->subtotal * ($cartItem->taxRate / 100), $decimals);
|
||||
// Taxe pour un item multiplié par la quantité.
|
||||
$unit_price = max($cartItem->price - $cartItem->discount, 0);
|
||||
$unit_tax = round($unit_price * ($cartItem->taxRate / 100), $decimals);
|
||||
$taxTotal = round($unit_tax * $cartItem->qty, $decimals);
|
||||
return $taxTotal;
|
||||
case 'total':
|
||||
return round($cartItem->subtotal + $cartItem->taxTotal, $decimals);
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}//end switch
|
||||
}
|
||||
}
|
||||
|
|
|
|||
47
app/Mail/OrderCanceledConfirmMail.php
Normal file
47
app/Mail/OrderCanceledConfirmMail.php
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
namespace App\Mail;
|
||||
|
||||
use App\Models\Order;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class OrderCanceledConfirmMail extends Mailable
|
||||
{
|
||||
use Queueable;
|
||||
use SerializesModels;
|
||||
|
||||
/**
|
||||
* The Order
|
||||
*
|
||||
* @var \App\Models\Order
|
||||
*/
|
||||
private $order;
|
||||
|
||||
/**
|
||||
* Create a new message instance.
|
||||
*
|
||||
* @param \App\Models\Order $order
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Order $order)
|
||||
{
|
||||
$this->order = $order;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the message.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function build()
|
||||
{
|
||||
$order = $this->order;
|
||||
|
||||
return $this->subject(
|
||||
"Commande " . config('theme.site_name') . " n°" . $order->reference . " a été annulée."
|
||||
)->view('mails.order-canceled-confirm', compact('order'));
|
||||
}
|
||||
}
|
||||
|
|
@ -3,23 +3,31 @@
|
|||
namespace App\Mail;
|
||||
|
||||
use App\Models\Magasin;
|
||||
use App\Models\Order;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class OrderConfirmAdminMail extends Mailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
use Queueable;
|
||||
use SerializesModels;
|
||||
|
||||
/**
|
||||
* The Order
|
||||
*
|
||||
* @var \App\Models\Order
|
||||
*/
|
||||
private $order;
|
||||
|
||||
/**
|
||||
* Create a new message instance.
|
||||
*
|
||||
* @param \App\Models\Order $order
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($order)
|
||||
public function __construct(Order $order)
|
||||
{
|
||||
$this->order = $order;
|
||||
}
|
||||
|
|
@ -34,6 +42,8 @@ class OrderConfirmAdminMail extends Mailable
|
|||
$order = $this->order;
|
||||
$magasin = Magasin::find($order->timeslot->magasin->id);
|
||||
|
||||
return $this->subject("Nouvelle Commande - " . config('theme.site_name'))->view('emails.order-confirm-admin', compact('order', 'magasin'));
|
||||
return $this->subject(
|
||||
"Nouvelle Commande - " . config('theme.site_name')
|
||||
)->view('emails.order-confirm-admin', compact('order', 'magasin'));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,23 +3,31 @@
|
|||
namespace App\Mail;
|
||||
|
||||
use App\Models\Magasin;
|
||||
use App\Models\Order;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class OrderConfirmMail extends Mailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
use Queueable;
|
||||
use SerializesModels;
|
||||
|
||||
/**
|
||||
* The Order
|
||||
*
|
||||
* @var \App\Models\Order
|
||||
*/
|
||||
private $order;
|
||||
|
||||
/**
|
||||
* Create a new message instance.
|
||||
*
|
||||
* @param \App\Models\Order $order
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($order)
|
||||
public function __construct(Order $order)
|
||||
{
|
||||
$this->order = $order;
|
||||
}
|
||||
|
|
@ -34,6 +42,8 @@ class OrderConfirmMail extends Mailable
|
|||
$order = $this->order;
|
||||
$magasin = Magasin::find($order->timeslot->magasin->id);
|
||||
|
||||
return $this->subject("Votre commande - " . config('theme.site_name'))->view('mails.order-confirm', compact('order', 'magasin'));
|
||||
return $this->subject(
|
||||
"Votre commande - " . config('theme.site_name')
|
||||
)->view('mails.order-confirm', compact('order', 'magasin'));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,23 +3,30 @@
|
|||
namespace App\Mail;
|
||||
|
||||
use App\Models\Magasin;
|
||||
use App\Models\Order;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class OrderStatusMail extends Mailable
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
use Queueable;
|
||||
use SerializesModels;
|
||||
|
||||
/**
|
||||
* The Order
|
||||
*
|
||||
* @var \App\Models\Order
|
||||
*/
|
||||
private $order;
|
||||
|
||||
/**
|
||||
* Create a new message instance.
|
||||
*
|
||||
* @param \App\Models\Order $order
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($order)
|
||||
public function __construct(Order $order)
|
||||
{
|
||||
$this->order = $order;
|
||||
}
|
||||
|
|
@ -31,9 +38,11 @@ class OrderStatusMail extends Mailable
|
|||
*/
|
||||
public function build()
|
||||
{
|
||||
$order = $this->order;
|
||||
$order = $this->order;
|
||||
$magasin = Magasin::find($order->timeslot->magasin->id);
|
||||
|
||||
return $this->subject("Votre commande - " . config('theme.site_name'))->view('mails.order-status', compact('order', 'magasin'));
|
||||
return $this->subject(
|
||||
"Votre commande - " . config('theme.site_name')
|
||||
)->view('mails.order-status', compact('order', 'magasin'));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace App\Mail;
|
||||
|
||||
use App\Models\Moments;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Mail\Mailable;
|
||||
|
|
@ -10,16 +9,23 @@ use Illuminate\Queue\SerializesModels;
|
|||
|
||||
class PasswordResetMail extends Mailable implements ShouldQueue
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
use Queueable;
|
||||
use SerializesModels;
|
||||
|
||||
/**
|
||||
* Reset token
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $token;
|
||||
|
||||
/**
|
||||
* Create a new message instance.
|
||||
*
|
||||
* @param string $token
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($token)
|
||||
public function __construct(string $token)
|
||||
{
|
||||
$this->token = $token;
|
||||
}
|
||||
|
|
@ -32,6 +38,8 @@ class PasswordResetMail extends Mailable implements ShouldQueue
|
|||
public function build()
|
||||
{
|
||||
$token = $this->token;
|
||||
return $this->subject("Réinitialiser votre accès - " . config('theme.site_name'))->view('mails.password-reset', compact('token'));
|
||||
return $this->subject(
|
||||
"Réinitialiser votre accès - " . config('theme.site_name')
|
||||
)->view('mails.password-reset', compact('token'));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Mail;
|
||||
|
||||
use App\Models\Customers;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Mail\Mailable;
|
||||
|
|
@ -9,19 +10,34 @@ use Illuminate\Queue\SerializesModels;
|
|||
|
||||
class RegisterConfirmMail extends Mailable implements ShouldQueue
|
||||
{
|
||||
use Queueable, SerializesModels;
|
||||
use Queueable;
|
||||
use SerializesModels;
|
||||
|
||||
private $customer, $firstname;
|
||||
/**
|
||||
* target Customer
|
||||
*
|
||||
* @var \App\Models\Customers
|
||||
*/
|
||||
private $customer;
|
||||
|
||||
/**
|
||||
* Customer's firstname
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $firstname;
|
||||
|
||||
/**
|
||||
* Create a new message instance.
|
||||
*
|
||||
* @param \App\Models\Customers $customer
|
||||
* @param string|null $firstname
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($customer, $firstname)
|
||||
public function __construct(Customers $customer, string $firstname = null)
|
||||
{
|
||||
$this->firstname = $firstname;
|
||||
$this->customer = $customer;
|
||||
$this->customer = $customer;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -31,7 +47,7 @@ class RegisterConfirmMail extends Mailable implements ShouldQueue
|
|||
*/
|
||||
public function build()
|
||||
{
|
||||
$customer = $this->customer;
|
||||
$customer = $this->customer;
|
||||
$firstname = $this->firstname;
|
||||
return $this->subject("Confirmation d'inscription " . config('theme.site_name'))
|
||||
->view('mails.register-ok', compact('customer', 'firstname'));
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
namespace App\Mail;
|
||||
|
||||
use App\Http\Requests\ContactFormRequest;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Mail\Mailable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
|
|
@ -15,6 +15,7 @@ class SendContactMail extends Mailable
|
|||
/**
|
||||
* The form data.
|
||||
*
|
||||
* @var \App\Http\Requests\ContactFormRequest
|
||||
*/
|
||||
protected $data;
|
||||
|
||||
|
|
@ -29,9 +30,10 @@ class SendContactMail extends Mailable
|
|||
/**
|
||||
* Create a new message instance.
|
||||
*
|
||||
* @param \App\Http\Requests\ContactFormRequest $data
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($data)
|
||||
public function __construct(ContactFormRequest $data)
|
||||
{
|
||||
$this->data = $data;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,11 @@ class CollecteException extends Model
|
|||
{
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['date', 'comment', 'magasin_id'];
|
||||
|
||||
/**
|
||||
|
|
@ -21,11 +26,22 @@ class CollecteException extends Model
|
|||
'date' => 'date',
|
||||
];
|
||||
|
||||
/**
|
||||
* Format a date
|
||||
*
|
||||
* @param DateTimeInterface $date
|
||||
* @return string
|
||||
*/
|
||||
protected function serializeDate(DateTimeInterface $date)
|
||||
{
|
||||
return $date->format('Y-m-d');
|
||||
}
|
||||
|
||||
/**
|
||||
* BelongsTo magasin relation
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function magasin()
|
||||
{
|
||||
return $this->belongsTo(Magasin::class);
|
||||
|
|
|
|||
|
|
@ -8,5 +8,4 @@ use Illuminate\Database\Eloquent\Model;
|
|||
class Content extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,11 @@ class Customers extends Authenticatable
|
|||
protected $guard = 'customer';
|
||||
|
||||
|
||||
//possible additionnals
|
||||
/**
|
||||
* hasOne salarie relation
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasOne
|
||||
*/
|
||||
public function salarie()
|
||||
{
|
||||
return $this->hasOne(Salarie::class, 'customer_id');
|
||||
|
|
|
|||
|
|
@ -9,9 +9,20 @@ class DiscountType extends Model
|
|||
{
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* Indicates if the model should be timestamped.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $timestamps = false;
|
||||
|
||||
public function promotions() {
|
||||
/**
|
||||
* hasMany promotions relation
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function promotions()
|
||||
{
|
||||
return $this->hasMany(Promotion::class, 'discount_type_id');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,5 +9,10 @@ class Faq extends Model
|
|||
{
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['question', 'answer'];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,11 +18,23 @@ class FoodProduct extends Model
|
|||
'product_id',
|
||||
];
|
||||
|
||||
public function product() {
|
||||
/**
|
||||
* BelongsTo product relation
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function product()
|
||||
{
|
||||
return $this->belongsTo(Product::class);
|
||||
}
|
||||
|
||||
public function xmlInco() {
|
||||
/**
|
||||
* hasOne product relation
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasOne
|
||||
*/
|
||||
public function xmlInco()
|
||||
{
|
||||
return $this->hasOne(XmlInco::class, 'id', 'no_art');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,21 +9,44 @@ class Magasin extends Model
|
|||
{
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name', 'address', 'postcode', 'city', 'phone',
|
||||
'name', 'email_contact', 'email_confirm', 'address', 'postcode', 'city', 'phone',
|
||||
'latitude', 'longitude',
|
||||
'gmaps_placeid', 'gmaps_embed_href', 'gmaps_link_href',
|
||||
];
|
||||
|
||||
public function timeslotSettings() {
|
||||
/**
|
||||
* hasMany timeslot settings relation
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function timeslotSettings()
|
||||
{
|
||||
return $this->hasMany(TimeslotSetting::class);
|
||||
}
|
||||
|
||||
public function collecteExceptions() {
|
||||
/**
|
||||
* hasMany collecte exceptions relation
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function collecteExceptions()
|
||||
{
|
||||
return $this->hasMany(CollecteException::class);
|
||||
}
|
||||
|
||||
public function timeslots() {
|
||||
/**
|
||||
* hasMany timeslots relation
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function timeslots()
|
||||
{
|
||||
return $this->hasMany(Timeslot::class);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,11 +9,23 @@ class OldSlug extends Model
|
|||
{
|
||||
use HasFactory;
|
||||
|
||||
public function product() {
|
||||
/**
|
||||
* BelongsTo product relation
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function product()
|
||||
{
|
||||
return $this->belongsTo('App\Model\Product', 'product_id');
|
||||
}
|
||||
|
||||
public function range() {
|
||||
/**
|
||||
* BelongsTo range relation
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function range()
|
||||
{
|
||||
return $this->belongsTo('App\Model\Range', 'range_id');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,34 +10,66 @@ class Order extends Model
|
|||
use HasFactory;
|
||||
|
||||
/**
|
||||
* use carefully
|
||||
* BelongsToMany products relation
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
*/
|
||||
public function products() {
|
||||
public function products()
|
||||
{
|
||||
return $this->belongsToMany(Product::class, 'order_lines', 'order_id', 'product_id');
|
||||
}
|
||||
|
||||
//Relations
|
||||
/**
|
||||
* hasMany lines relation
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function lines()
|
||||
{
|
||||
return $this->hasMany(OrderLine::class);
|
||||
}
|
||||
|
||||
public function status() {
|
||||
/**
|
||||
* BelongsTo order_status relation
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function status()
|
||||
{
|
||||
return $this->belongsTo('App\Models\OrdersStatus', 'status_id');
|
||||
}
|
||||
|
||||
public function customer() {
|
||||
/**
|
||||
* BelongsTo customer relation
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function customer()
|
||||
{
|
||||
return $this->belongsTo(Customers::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* hasOne timeslot relation
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasOne
|
||||
*/
|
||||
public function timeslot()
|
||||
{
|
||||
return $this->hasOne(Timeslot::class);
|
||||
}
|
||||
|
||||
//Formattages
|
||||
/**
|
||||
* Custom Attribute
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFormattedTotalTtcAttribute()
|
||||
{
|
||||
return $this->attributes['formattedTotalTtc'] = sprintf('%s €', number_format($this->attributes['total'], 2, ',', ' '));
|
||||
$this->attributes['formattedTotalTtc'] = sprintf(
|
||||
'%s €',
|
||||
number_format($this->attributes['total'], 2, ',', ' ')
|
||||
);
|
||||
return $this->attributes['formattedTotalTtc'];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,20 +9,37 @@ class OrderLine extends Model
|
|||
{
|
||||
use HasFactory;
|
||||
|
||||
//Relations
|
||||
/**
|
||||
* BelongsTo order relation
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function order()
|
||||
{
|
||||
return $this->belongsTo(Order::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* BelongsTo product relation
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function product()
|
||||
{
|
||||
return $this->belongsTo(Product::class);
|
||||
}
|
||||
|
||||
//Formattages
|
||||
/**
|
||||
* Getter for formattedTotalTtc
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function getFormattedTotalTtcAttribute()
|
||||
{
|
||||
return $this->attributes['formattedTotalTtc'] = sprintf('%s €', number_format($this->attributes['total_ttc'], 2, ',', ' '));
|
||||
$this->attributes['formattedTotalTtc'] = sprintf(
|
||||
'%s €',
|
||||
number_format($this->attributes['total_ttc'], 2, ',', ' ')
|
||||
);
|
||||
return $this->attributes['formattedTotalTtc'];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,10 +9,27 @@ class OrdersStatus extends Model
|
|||
{
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* The table associated with the model
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = "orders_status";
|
||||
|
||||
/**
|
||||
* Indicates if the model should be timestamped.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $timestamps = false;
|
||||
|
||||
public function orders() {
|
||||
/**
|
||||
* hasMany orders relation
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function orders()
|
||||
{
|
||||
return $this->hasMany('App\Models\Order', 'status_id');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,17 @@ use Illuminate\Database\Eloquent\Model;
|
|||
|
||||
class PasswordReset extends Model
|
||||
{
|
||||
/**
|
||||
* The table associated with the model
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = "password_resets";
|
||||
|
||||
/**
|
||||
* Indicates if the model should be timestamped.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $timestamps = false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,9 +13,6 @@ use Gloudemans\Shoppingcart\Contracts\Buyable;
|
|||
use Gloudemans\Shoppingcart\CanBeBought;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
/**
|
||||
* @todo : unité de vente/unité de poids devrait être des énums (via table liée ou package enum)
|
||||
*/
|
||||
class Product extends Model implements Buyable
|
||||
{
|
||||
use HasFactory;
|
||||
|
|
@ -36,35 +33,67 @@ class Product extends Model implements Buyable
|
|||
* Store in protected variables instead of attributes
|
||||
* Because those are not set in attributes, Laravel will not try to save it to database
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base Price
|
||||
*
|
||||
* @var float
|
||||
*/
|
||||
protected $priceHt;
|
||||
|
||||
/**
|
||||
* Base Price after discount
|
||||
*
|
||||
* @var float
|
||||
*/
|
||||
protected $discountedPriceHt;
|
||||
|
||||
/**
|
||||
* Price VAT included
|
||||
*
|
||||
* @var float
|
||||
*/
|
||||
protected $priceTtc;
|
||||
|
||||
/**
|
||||
* Price after discount VAT included
|
||||
*
|
||||
* @var float
|
||||
*/
|
||||
protected $discountedPriceTtc;
|
||||
|
||||
/**
|
||||
* Discount amount
|
||||
*
|
||||
* @var float
|
||||
*/
|
||||
protected $discountAmount;
|
||||
|
||||
/**
|
||||
* Dsicount rate
|
||||
*
|
||||
* @var float
|
||||
*/
|
||||
protected $discountRate;
|
||||
|
||||
/**
|
||||
* init prices on boot
|
||||
* Bootstrap the model and its traits.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
//on data retrived from DB
|
||||
// On data retrived from DB.
|
||||
static::retrieved(function ($model) {
|
||||
$model->priceHt = $model->getPriceHtAttribute();
|
||||
$model->priceTtc = $model->getPriceTtcAttribute();
|
||||
$model->discountAmount = $model->getDiscountAmountAttribute();
|
||||
$model->discountRate = $model->getDiscountRateAttribute();
|
||||
$model->discountedPriceHt = $model->getDiscountedPriceHtAttribute();
|
||||
$model->priceHt = $model->getPriceHtAttribute();
|
||||
$model->priceTtc = $model->getPriceTtcAttribute();
|
||||
$model->discountAmount = $model->getDiscountAmountAttribute();
|
||||
$model->discountRate = $model->getDiscountRateAttribute();
|
||||
$model->discountedPriceHt = $model->getDiscountedPriceHtAttribute();
|
||||
$model->discountedPriceTtc = $model->getDiscountedPriceTtcAttribute();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -76,10 +105,13 @@ class Product extends Model implements Buyable
|
|||
* net discounted proice (prix avec taxe et remises)
|
||||
*/
|
||||
|
||||
//Utility to bring prices as a pseudo relation
|
||||
/**
|
||||
* Utility to bring prices as a pseudo relation
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCalcPrices()
|
||||
{
|
||||
//$prices = new Collection();
|
||||
$prices = array(
|
||||
'priceHt' => $this->priceHt,
|
||||
'discountAmount' => $this->discountAmount,
|
||||
|
|
@ -88,15 +120,16 @@ class Product extends Model implements Buyable
|
|||
'priceTtc' => $this->priceTtc,
|
||||
'discountedPriceTtc' => $this->discountedPriceTtc,
|
||||
);
|
||||
//$prices->add($cartextendedItem);
|
||||
return $prices;
|
||||
}
|
||||
|
||||
//gross price
|
||||
/**
|
||||
* Mutator method to set priceHt's value
|
||||
* Mutator method to set priceHt's value gross price
|
||||
*
|
||||
* @param float $value
|
||||
* @return void
|
||||
*/
|
||||
public function setPriceHtAttribute($value)
|
||||
public function setPriceHtAttribute(float $value)
|
||||
{
|
||||
$this->priceHt = $value;
|
||||
}
|
||||
|
|
@ -106,93 +139,135 @@ class Product extends Model implements Buyable
|
|||
* Accessor method for priceHt
|
||||
*
|
||||
* @author Olivier Legat <olivier.legat@ldc.fr>
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getPriceHtAttribute()
|
||||
{
|
||||
if(isset($this->priceHt)) {
|
||||
if (isset($this->priceHt)) {
|
||||
return $this->priceHt;
|
||||
} else {
|
||||
//tenir compte de l'unité de facturation et de l'unité de vente (qui doit être stricte)
|
||||
//si facturation KG et vente piece
|
||||
// prendre le poids, convertir en KG => pre-requis l'unité de poids doit être un enum
|
||||
// multiplier le $this->attributes['price'] par les KG
|
||||
//sinon
|
||||
// value => value
|
||||
/** Tenir compte de l'unité de facturation et de l'unité de vente (qui doit être stricte)
|
||||
* si facturation KG et vente piece
|
||||
* prendre le poids, convertir en KG => pre-requis l'unité de poids doit être un enum
|
||||
* multiplier le $this->attributes['price'] par les KG
|
||||
* sinon
|
||||
* value => value
|
||||
*/
|
||||
if (config('bosettings.sell_unit_management') == "strict") {
|
||||
$calculate = ($this->invoicing_unit == InvoicingUnit::kgm()->value && $this->sell_unit == SellUnit::pce()->value);
|
||||
$calculate = ($this->invoicing_unit == InvoicingUnit::kgm()->value
|
||||
&& $this->sell_unit == SellUnit::pce()->value);
|
||||
} else {
|
||||
$calculate = false;
|
||||
}
|
||||
|
||||
if ($calculate) {
|
||||
//weight converter
|
||||
$weighted_price = $this->attributes['price'] * ($this->weight * WeightUnit::convert()[$this->weight_unit]);
|
||||
return $this->priceHt = round($weighted_price * 1000) / 1000;
|
||||
// Weight converter.
|
||||
$weighted_price = $this->attributes['price']
|
||||
* ($this->weight * WeightUnit::convert()[$this->weight_unit]);
|
||||
$this->priceHt = round($weighted_price * 1000) / 1000;
|
||||
return $this->priceHt;
|
||||
} else {
|
||||
//no calculations, alias of db property
|
||||
return $this->priceHt = $this->attributes['price'];
|
||||
// No calculations, alias of db property.
|
||||
$this->priceHt = $this->attributes['price'];
|
||||
return $this->priceHt;
|
||||
}
|
||||
}
|
||||
}//end if
|
||||
}
|
||||
|
||||
//discounted price
|
||||
public function setDiscountedPriceHtAttribute($value)
|
||||
/**
|
||||
* setter for dicounted price
|
||||
*
|
||||
* @param float $value
|
||||
* @return void
|
||||
*/
|
||||
public function setDiscountedPriceHtAttribute(float $value)
|
||||
{
|
||||
$this->discountedPriceHt = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* getter for discounted price
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getDiscountedPriceHtAttribute()
|
||||
{
|
||||
if (isset($this->discountedPriceHt)) {
|
||||
return $this->discountedPriceHt;
|
||||
} else {
|
||||
$discountedPriceHt = $this->priceHt - $this->discountAmount;
|
||||
$discountedPriceHt = $this->priceHt - $this->discountAmount;
|
||||
$roundingdiscountedPriceHt = round($discountedPriceHt * 1000) / 1000;
|
||||
return $this->discountedPriceHt = $roundingdiscountedPriceHt;
|
||||
$this->discountedPriceHt = $roundingdiscountedPriceHt;
|
||||
return $this->discountedPriceHt;
|
||||
}
|
||||
}
|
||||
|
||||
//net price
|
||||
public function setPriceTtcAttribute($value)
|
||||
/**
|
||||
* setter for net price
|
||||
*
|
||||
* @param float $value
|
||||
* @return void
|
||||
*/
|
||||
public function setPriceTtcAttribute(float $value)
|
||||
{
|
||||
$this->priceTtc = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* getter for net price
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getPriceTtcAttribute()
|
||||
{
|
||||
if (isset($this->priceTtc)) {
|
||||
return $this->priceTtc;
|
||||
} else {
|
||||
$priceTtc = $this->priceHt * ( 1 + ( $this->tax->rate / 100));
|
||||
//on travaille avec des centimes puis on redivise par 100 pour avoir des unités monetaires
|
||||
//on augmente la précision à 3 digits, l'affichage formate les prix sur 2 décimales
|
||||
/**
|
||||
* On travaille avec des centimes puis on redivise par 100 pour avoir des unités monetaires
|
||||
* on augmente la précision à 3 digits, l'affichage formate les prix sur 2 décimales
|
||||
*/
|
||||
$roundingPriceTtc = round($priceTtc * 1000) / 1000;
|
||||
return $this->priceTtc = $roundingPriceTtc;
|
||||
$this->priceTtc = $roundingPriceTtc;
|
||||
return $this->priceTtc;
|
||||
}
|
||||
}
|
||||
|
||||
//net discounted price
|
||||
public function setDiscountedPriceTtcAttribute($value)
|
||||
/**
|
||||
* setter for net dscounted price
|
||||
*
|
||||
* @param float $value
|
||||
* @return void
|
||||
*/
|
||||
public function setDiscountedPriceTtcAttribute(float $value)
|
||||
{
|
||||
$this->discountedPriceTtc = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* getter for net dscounted price
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getDiscountedPriceTtcAttribute()
|
||||
{
|
||||
if (isset($this->discountedPriceTtc)) {
|
||||
$showPrice = $this->discountedPriceTtc;
|
||||
} else {
|
||||
$discountedPriceTtc = $this->discountedPriceHt * ( 1 + ( $this->tax->rate / 100));
|
||||
//on travaille avec des centimes puis on redivise par 100 pour avoir des unités monetaires
|
||||
// On travaille avec des centimes puis on redivise par 100 pour avoir des unités monetaires.
|
||||
$roundingDiscountedPriceTTC = round($discountedPriceTtc * 1000) / 1000;
|
||||
$showPrice = $this->discountedPriceTtc = $roundingDiscountedPriceTTC;
|
||||
$this->discountedPriceTtc = $roundingDiscountedPriceTTC;
|
||||
$showPrice = $this->discountedPriceTtc;
|
||||
}
|
||||
//prix transmis en fonction du setting show_prices
|
||||
// Prix transmis en fonction du setting show_prices.
|
||||
if (config('bosettings.show_prices_authenticated') == "authenticated") {
|
||||
{
|
||||
if (Auth::guard('customer')->check()) {
|
||||
return $showPrice;
|
||||
}
|
||||
if (Auth::guard('customer')->check()) {
|
||||
return $showPrice;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (config('bosettings.show_prices_guest') == "guest") {
|
||||
|
|
@ -202,15 +277,25 @@ class Product extends Model implements Buyable
|
|||
}
|
||||
|
||||
/**
|
||||
* Discount calc
|
||||
* Discount calculators
|
||||
*/
|
||||
|
||||
//montant de remise
|
||||
public function setDiscountAmountAttribute($value)
|
||||
/**
|
||||
* set discoutn amount
|
||||
*
|
||||
* @param float $value
|
||||
* @return void
|
||||
*/
|
||||
public function setDiscountAmountAttribute(float $value)
|
||||
{
|
||||
$this->discountAmount = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for discount amount
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getDiscountAmountAttribute()
|
||||
{
|
||||
if (isset($this->discountAmount)) {
|
||||
|
|
@ -222,23 +307,34 @@ class Product extends Model implements Buyable
|
|||
if ($promo_type == 1) {
|
||||
$discountAmount = $applicablePromotion->discount_value;
|
||||
} else {
|
||||
//on augmente la précision à 3 digits, l'affichage formate les prix sur 2 décimales
|
||||
// On augmente la précision à 3 digits, l'affichage formate les prix sur 2 décimales.
|
||||
$discountAmount = $this->priceHt * ($applicablePromotion->discount_value / 100);
|
||||
$discountAmount = round($discountAmount * 1000) / 1000;
|
||||
}
|
||||
} else {
|
||||
$discountAmount = 0;
|
||||
}
|
||||
return $this->discountAmount = $discountAmount;
|
||||
$this->discountAmount = $discountAmount;
|
||||
return $this->discountAmount;
|
||||
}
|
||||
}
|
||||
|
||||
//taux de remise
|
||||
public function setDiscountRateAttribute($value)
|
||||
/**
|
||||
* set discount rate
|
||||
*
|
||||
* @param float $value
|
||||
* @return void
|
||||
*/
|
||||
public function setDiscountRateAttribute(float $value)
|
||||
{
|
||||
$this->discountRate = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* get discount rate
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getDiscountRateAttribute()
|
||||
{
|
||||
if (isset($this->discountRate)) {
|
||||
|
|
@ -248,7 +344,7 @@ class Product extends Model implements Buyable
|
|||
if (null !== $applicablePromotion) {
|
||||
$promo_type = $applicablePromotion->discount_type_id;
|
||||
if ($promo_type == 1) {
|
||||
//on veut un pourcentage
|
||||
// On veut un pourcentage.
|
||||
$discountRate = ($applicablePromotion->discount_value / $this->priceHt) * 100;
|
||||
} else {
|
||||
$discountRate = $applicablePromotion->discount_value;
|
||||
|
|
@ -256,61 +352,113 @@ class Product extends Model implements Buyable
|
|||
} else {
|
||||
$discountRate = 0;
|
||||
}
|
||||
return $this->discountRate = $discountRate;
|
||||
$this->discountRate = $discountRate;
|
||||
return $this->discountRate;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// //Buyable interface
|
||||
/**
|
||||
* buyablePrice attribute alias
|
||||
*
|
||||
* @param mixed $options
|
||||
* @return float
|
||||
*
|
||||
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
|
||||
*/
|
||||
public function getBuyablePrice($options = null)
|
||||
{
|
||||
// @phpcs:enable
|
||||
return $this->priceHt;
|
||||
}
|
||||
|
||||
//Relations
|
||||
/**
|
||||
* BelongsTo range relation
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function range()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Range', 'range_id');
|
||||
}
|
||||
|
||||
public function old_slugs()
|
||||
/**
|
||||
* hasMany old_slugs relation
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function oldSlugs()
|
||||
{
|
||||
return $this->hasMany('App\Model\OldSlug', 'product_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* hasMany stats relation
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function stats()
|
||||
{
|
||||
return $this->hasMany('App\Models\Stat', 'product_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* belongsToMany orders relation
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
*/
|
||||
public function orders()
|
||||
{
|
||||
return $this->belongsToMany('App\Models\Order', 'orders_products', 'product_id', 'order_id')
|
||||
->withPivot('quantity');
|
||||
}
|
||||
|
||||
//relationship to additionnal product info
|
||||
public function additionnalProductInfo($productType)
|
||||
/**
|
||||
* Pseudo relationship to additionnal product info
|
||||
*
|
||||
* @param string $productType
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasOne
|
||||
*/
|
||||
public function additionnalProductInfo(string $productType)
|
||||
{
|
||||
return $this->$productType;
|
||||
}
|
||||
|
||||
//possible additionnals
|
||||
/**
|
||||
* hasOne foodProduct relation
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasOne
|
||||
*/
|
||||
public function foodProduct()
|
||||
{
|
||||
return $this->hasOne(FoodProduct::class, 'product_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* hasOne anifoodProduct relation
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasOne
|
||||
*/
|
||||
public function anifoodProduct()
|
||||
{
|
||||
return $this->hasOne(AnifoodProduct::class, 'product_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* hasOne toolProduct relation
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasOne
|
||||
*/
|
||||
public function toolProduct()
|
||||
{
|
||||
return $this->hasOne(ToolProduct::class, 'product_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* hasOne garmentProduct relation
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasOne
|
||||
*/
|
||||
public function garmentProduct()
|
||||
{
|
||||
return $this->hasOne(GarmentProduct::class, 'product_id');
|
||||
|
|
@ -318,13 +466,21 @@ class Product extends Model implements Buyable
|
|||
|
||||
|
||||
|
||||
//relationship to associated products
|
||||
/**
|
||||
* belongsToMany products relation
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
*/
|
||||
public function products()
|
||||
{
|
||||
return $this->belongsToMany(Product::class, 'products_products', 'product_id', 'associated_id');
|
||||
}
|
||||
|
||||
//offres speciales
|
||||
/**
|
||||
* belongsToMany promotions relation
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
*/
|
||||
public function promotions()
|
||||
{
|
||||
$now = Carbon::now();
|
||||
|
|
@ -333,13 +489,21 @@ class Product extends Model implements Buyable
|
|||
->whereDate('date_end', '>=', $now);
|
||||
}
|
||||
|
||||
//taxe
|
||||
/**
|
||||
* belongsTo tax relation
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function tax()
|
||||
{
|
||||
return $this->belongsTo(TaxRate::class, 'tax_rate_id');
|
||||
}
|
||||
|
||||
//tags
|
||||
/**
|
||||
* belongsToMany tags relation
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
*/
|
||||
public function tags()
|
||||
{
|
||||
return $this->belongsToMany(Tag::class);
|
||||
|
|
|
|||
|
|
@ -18,7 +18,13 @@ class ProductType extends Model
|
|||
'product_id',
|
||||
];
|
||||
|
||||
public function product() {
|
||||
/**
|
||||
* BelongsTo product relation
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function product()
|
||||
{
|
||||
return $this->belongsTo(Product::class);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,5 +8,6 @@ use Illuminate\Database\Eloquent\Model;
|
|||
class ProductsProducts extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
//useless model it seems
|
||||
|
||||
// Useless model it seems.
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,11 +19,21 @@ class Promotion extends Model
|
|||
'date_end' => 'datetime',
|
||||
];
|
||||
|
||||
/**
|
||||
* BelongsToMany products relation
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
*/
|
||||
public function products()
|
||||
{
|
||||
return $this->belongsToMany(Product::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* BelongsTo discountType relation
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function discountType()
|
||||
{
|
||||
return $this->belongsTo(DiscountType::class, 'discount_type_id');
|
||||
|
|
|
|||
|
|
@ -9,11 +9,23 @@ class Range extends Model
|
|||
{
|
||||
use HasFactory;
|
||||
|
||||
public function products() {
|
||||
/**
|
||||
* hasMany customer relation
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function products()
|
||||
{
|
||||
return $this->hasMany('App\Models\Product', 'range_id');
|
||||
}
|
||||
|
||||
public function old_slugs() {
|
||||
return $this->hasMany('App\Model\OldSlug', 'ranges');
|
||||
/**
|
||||
* hasMany old_slugs relation
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function oldSlugs()
|
||||
{
|
||||
return $this->hasMany('App\Model\OldSlug', 'range_id');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,8 +22,13 @@ class Salarie extends Model
|
|||
'code'
|
||||
];
|
||||
|
||||
|
||||
public function customer() {
|
||||
/**
|
||||
* BelongsTo customer relation
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function customer()
|
||||
{
|
||||
return $this->belongsTo(Customers::class);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,13 @@ class Slide extends Model
|
|||
'date_end' => 'datetime',
|
||||
];
|
||||
|
||||
public function slider() {
|
||||
/**
|
||||
* BelongsTo slider relation
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function slider()
|
||||
{
|
||||
return $this->belongsTo(Slider::class);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,11 +10,21 @@ class Slider extends Model
|
|||
{
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* hasMany slides relation
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function slides()
|
||||
{
|
||||
return $this->hasMany(Slide::class, 'slider_id')->orderBy('order', 'ASC');
|
||||
}
|
||||
|
||||
/**
|
||||
* filtered slides relation by showable date
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function showableSlides()
|
||||
{
|
||||
$now = Carbon::now();
|
||||
|
|
@ -26,6 +36,5 @@ class Slider extends Model
|
|||
$q->whereDate('date_end', '>=', $now)
|
||||
->orWhereNull('date_end');
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,13 @@ class Stat extends Model
|
|||
{
|
||||
use HasFactory;
|
||||
|
||||
public function product() {
|
||||
/**
|
||||
* BelongsTo product relation
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function product()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Product', 'product_id');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,8 +9,18 @@ class Tag extends Model
|
|||
{
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* Indicates if the model should be timestamped.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $timestamps = false;
|
||||
|
||||
/**
|
||||
* belongsToMany products relation
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
*/
|
||||
public function products()
|
||||
{
|
||||
return $this->belongsToMany(Product::class);
|
||||
|
|
|
|||
|
|
@ -9,9 +9,20 @@ class TaxRate extends Model
|
|||
{
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* Indicates if the model should be timestamped.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $timestamps = false;
|
||||
|
||||
public function products() {
|
||||
/**
|
||||
* hasMany products relation
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function products()
|
||||
{
|
||||
return $this->hasMany(Product::class, 'tax_rate_id');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,15 +9,30 @@ class Timeslot extends Model
|
|||
{
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'order_id', 'magasin_id'
|
||||
];
|
||||
|
||||
/**
|
||||
* BelongsTo order relation
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function order()
|
||||
{
|
||||
return $this->belongsTo(Order::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* BelongsTo magasin relation
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function magasin()
|
||||
{
|
||||
return $this->belongsTo(Magasin::class);
|
||||
|
|
|
|||
|
|
@ -9,6 +9,11 @@ class TimeslotSetting extends Model
|
|||
{
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* BelongsTo magasin relation
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function magasin()
|
||||
{
|
||||
return $this->belongsTo(Magasin::class);
|
||||
|
|
|
|||
|
|
@ -2,14 +2,14 @@
|
|||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
use HasFactory, Notifiable;
|
||||
use HasFactory;
|
||||
use Notifiable;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
|
|
@ -44,7 +44,13 @@ class User extends Authenticatable
|
|||
'email_verified_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function orders() {
|
||||
/**
|
||||
* hasMany order relation
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
*/
|
||||
public function orders()
|
||||
{
|
||||
return $this->hasMany('App\Models\Order', 'user_id');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,13 +6,17 @@ use Illuminate\Database\Eloquent\Model;
|
|||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Contracts\Filesystem\Filesystem;
|
||||
use Illuminate\Database\Eloquent\Relations\Relation;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class XmlInco extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'no_art',
|
||||
|
|
@ -33,6 +37,11 @@ class XmlInco extends Model
|
|||
'picture',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'picture' => 'array',
|
||||
'nutritional_values' => 'array',
|
||||
|
|
@ -45,6 +54,11 @@ class XmlInco extends Model
|
|||
*/
|
||||
protected $disk = 'inco';
|
||||
|
||||
/**
|
||||
* Storage path
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $imagesPath = 'images';
|
||||
|
||||
/**
|
||||
|
|
@ -58,10 +72,13 @@ class XmlInco extends Model
|
|||
|
||||
/**
|
||||
* retrieve a collection of medias
|
||||
*
|
||||
* @return Collection
|
||||
*/
|
||||
public function getMediasAttribute() {
|
||||
public function getMediasAttribute()
|
||||
{
|
||||
/** @var Filesystem */
|
||||
$disk = $this->getDisk();
|
||||
$disk = $this->getDisk();
|
||||
$files = $disk->files($this->imagesPath);
|
||||
|
||||
$collFiles = new Collection();
|
||||
|
|
@ -74,7 +91,7 @@ class XmlInco extends Model
|
|||
if (!in_array($pi, array($this->id))) {
|
||||
continue;
|
||||
}
|
||||
$image = base64_encode($disk->get($file));
|
||||
$image = base64_encode($disk->get($file));
|
||||
$element = array(
|
||||
"filename" => $pi,
|
||||
"imgdata" => $image
|
||||
|
|
@ -94,143 +111,183 @@ class XmlInco extends Model
|
|||
return Storage::disk($this->disk);
|
||||
}
|
||||
|
||||
/**
|
||||
* getter
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getNiceStringAttribute()
|
||||
{
|
||||
return sprintf('%s - %s', $this->id, $this->descriptif);
|
||||
}
|
||||
|
||||
/**
|
||||
* update local info
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function updateLocalProductInfo()
|
||||
{
|
||||
$foodProduct = FoodProduct::where('no_art', $this->id)->first();
|
||||
|
||||
if (!empty($foodProduct)) {
|
||||
//info produits à suggerer lors de l'édition
|
||||
// this->descriptif (doit aller dans la table products)
|
||||
// $table->text('preparation')->nullable(); => $this->conseil_prepa
|
||||
// $table->text('selling_argument')->nullable(); => $this->arg_vente
|
||||
|
||||
//infos produit maj automatique
|
||||
/** Info produits à suggerer lors de l'édition
|
||||
* this->descriptif (doit aller dans la table products)
|
||||
* $table->text('preparation')->nullable(); => $this->conseil_prepa
|
||||
* $table->text('selling_argument')->nullable(); => $this->arg_vente
|
||||
* infos produit maj automatique
|
||||
*/
|
||||
$foodProduct->ingredients = $this->lst_ing;
|
||||
$foodProduct->allergens = $this->lib_allergene;
|
||||
//$foodProduct->servings = $this->nb_portion; // problem les types de correspondent pas numeric = string (exemple this->nb_portion = '1/2')
|
||||
|
||||
/** Les types de correspondent pas
|
||||
* numeric ($foodProduct->servings) = string (exemple this->nb_portion = '1/2').
|
||||
*/
|
||||
$nutri_values = $this->nutritional_values;
|
||||
if (!empty($nutri_values)) {
|
||||
//maj des info nutri locales
|
||||
//pour la ref
|
||||
// Maj des info nutri locales.
|
||||
// Pour la ref.
|
||||
$foodProduct->nv_ref_weight_g = $nutri_values["taille_ref"];
|
||||
$foodProduct->nv_kj = $nutri_values["val_energ_kj_r"]; //Energie Kj
|
||||
$foodProduct->nv_kcal = $nutri_values["val_energ_kcal_r"]; //Energie Kcal
|
||||
$foodProduct->nv_fat_g = $nutri_values["mat_grass_r"]; //graisses
|
||||
$foodProduct->nv_sat_fat_g = $nutri_values["ags_r"]; //dont acides gras saturés
|
||||
$foodProduct->nv_carb_g = $nutri_values["glucides_r"]; //Glucides
|
||||
$foodProduct->nv_sugar_g = $nutri_values["sucre_r"]; //dont sucres
|
||||
$foodProduct->nv_fiber_g = $nutri_values["fib_alim_r"]; //fibres alimentaires
|
||||
$foodProduct->nv_protein_g = $nutri_values["proteine_r"]; //protéines
|
||||
$foodProduct->nv_salt_g = $nutri_values["sel_r"]; //sel
|
||||
// Energie Kj.
|
||||
$foodProduct->nv_kj = $nutri_values["val_energ_kj_r"];
|
||||
// Energie Kcal.
|
||||
$foodProduct->nv_kcal = $nutri_values["val_energ_kcal_r"];
|
||||
// Graisses.
|
||||
$foodProduct->nv_fat_g = $nutri_values["mat_grass_r"];
|
||||
// Dont acides gras saturés.
|
||||
$foodProduct->nv_sat_fat_g = $nutri_values["ags_r"];
|
||||
// Glucides.
|
||||
$foodProduct->nv_carb_g = $nutri_values["glucides_r"];
|
||||
// Dont sucres.
|
||||
$foodProduct->nv_sugar_g = $nutri_values["sucre_r"];
|
||||
// Fibres alimentaires.
|
||||
$foodProduct->nv_fiber_g = $nutri_values["fib_alim_r"];
|
||||
// Protéines.
|
||||
$foodProduct->nv_protein_g = $nutri_values["proteine_r"];
|
||||
// Sel.
|
||||
$foodProduct->nv_salt_g = $nutri_values["sel_r"];
|
||||
|
||||
// $foodProduct-> = $nutri_values["sodium_r"];
|
||||
// $foodProduct-> = $nutri_values["ener_e14_r"];
|
||||
// $foodProduct-> = $nutri_values["fruits_r"];
|
||||
// $foodProduct-> = $nutri_values["fruits_coque_sech_r"];
|
||||
// $foodProduct-> = $nutri_values["ener_kjo_r"];
|
||||
// $foodProduct-> = $nutri_values["fatsat_r"];
|
||||
// $foodProduct-> = $nutri_values["choval_r"];
|
||||
// $foodProduct-> = $nutri_values["sugar_r"];
|
||||
// $foodProduct-> = $nutri_values["fibtg_r"];
|
||||
// $foodProduct-> = $nutri_values["pro_r"];
|
||||
// $foodProduct-> = $nutri_values["salteq_r"];
|
||||
/** Autres valeurs dispos
|
||||
* $nutri_values["sodium_r"];
|
||||
* $nutri_values["ener_e14_r"];
|
||||
* $nutri_values["fruits_r"];
|
||||
* $nutri_values["fruits_coque_sech_r"];
|
||||
* $nutri_values["ener_kjo_r"];
|
||||
* $nutri_values["fatsat_r"];
|
||||
* $nutri_values["choval_r"];
|
||||
* $nutri_values["sugar_r"];
|
||||
* $nutri_values["fibtg_r"];
|
||||
* $nutri_values["pro_r"];
|
||||
* $nutri_values["salteq_r"];
|
||||
*/
|
||||
// Valeurs nutritionnelles par portion.
|
||||
// Taille portion en grammes.
|
||||
$foodProduct->nv_serving_size_g = $nutri_values["taille_port"];
|
||||
// Energie Kj.
|
||||
$foodProduct->nv_serving_kj = $nutri_values["val_energ_kj_p"];
|
||||
// Energie Kcal.
|
||||
$foodProduct->nv_serving_kcal = $nutri_values["val_energ_kcal_p"];
|
||||
// Graisses.
|
||||
$foodProduct->nv_serving_fat_g = $nutri_values["mat_grass_p"];
|
||||
// Dont acides gras saturés.
|
||||
$foodProduct->nv_serving_sat_fat_g = $nutri_values["ags_p"];
|
||||
// Glucides.
|
||||
$foodProduct->nv_serving_carb_g = $nutri_values["glucides_p"];
|
||||
// Dont sucres.
|
||||
$foodProduct->nv_serving_sugar_g = $nutri_values["sucre_p"];
|
||||
// Fibres alimentaires.
|
||||
$foodProduct->nv_serving_fiber_g = $nutri_values["fib_alim_p"];
|
||||
// Protéines.
|
||||
$foodProduct->nv_serving_protein_g = $nutri_values["proteine_p"];
|
||||
// Sel.
|
||||
$foodProduct->nv_serving_salt_g = $nutri_values["sel_p"];
|
||||
|
||||
/**
|
||||
* autres valeurs disponibles
|
||||
* $nutri_values["sodium_p"];
|
||||
* $nutri_values["fruits_p"];
|
||||
*/
|
||||
|
||||
//valeurs nutritionnelles par portion
|
||||
$foodProduct->nv_serving_size_g = $nutri_values["taille_port"]; //taille portion en grammes
|
||||
$foodProduct->nv_serving_kj = $nutri_values["val_energ_kj_p"]; //Energie Kj
|
||||
$foodProduct->nv_serving_kcal = $nutri_values["val_energ_kcal_p"]; //Energie Kcal
|
||||
$foodProduct->nv_serving_fat_g = $nutri_values["mat_grass_p"]; //graisses
|
||||
$foodProduct->nv_serving_sat_fat_g = $nutri_values["ags_p"]; //dont acides gras saturés
|
||||
$foodProduct->nv_serving_carb_g = $nutri_values["glucides_p"]; //Glucides
|
||||
$foodProduct->nv_serving_sugar_g = $nutri_values["sucre_p"]; //dont sucres
|
||||
$foodProduct->nv_serving_fiber_g = $nutri_values["fib_alim_p"]; //fibres alimentaires
|
||||
$foodProduct->nv_serving_protein_g = $nutri_values["proteine_p"]; //protéines
|
||||
$foodProduct->nv_serving_salt_g = $nutri_values["sel_p"]; //sel
|
||||
// Apports journaliers.
|
||||
// Energie % recommandé.
|
||||
$foodProduct->nv_daily_energy = $nutri_values["pourcent_apport_ref_kjo_r"];
|
||||
// Graisses.
|
||||
$foodProduct->nv_daily_fat = $nutri_values["pourcent_apport_ref_fat_r"];
|
||||
// Dont acides gras saturés.
|
||||
$foodProduct->nv_daily_sat_fat = $nutri_values["pourcent_apport_ref_fatsat_r"];
|
||||
// Glucides.
|
||||
$foodProduct->nv_daily_carb = $nutri_values["pourcent_apport_ref_choval_r"];
|
||||
// Dont sucres.
|
||||
$foodProduct->nv_daily_sugar = $nutri_values["pourcent_apport_ref_sugar_r"];
|
||||
// Fibres alimentaires.
|
||||
$foodProduct->nv_daily_fiber = $nutri_values["pourcent_apport_ref_fibtg_r"];
|
||||
// Protéines.
|
||||
$foodProduct->nv_daily_protein = $nutri_values["pourcent_apport_ref_pro_r"];
|
||||
// Sel.
|
||||
$foodProduct->nv_daily_salt = $nutri_values["pourcent_apport_ref_salteq_r"];
|
||||
|
||||
// $foodProduct-> = $nutri_values["sodium_p"];
|
||||
// $foodProduct-> = $nutri_values["fruits_p"];
|
||||
|
||||
|
||||
//apports journaliers
|
||||
$foodProduct->nv_daily_energy = $nutri_values["pourcent_apport_ref_kjo_r"]; //Energie % recommandé
|
||||
$foodProduct->nv_daily_fat = $nutri_values["pourcent_apport_ref_fat_r"]; //graisses
|
||||
$foodProduct->nv_daily_sat_fat = $nutri_values["pourcent_apport_ref_fatsat_r"]; //dont acides gras saturés
|
||||
$foodProduct->nv_daily_carb = $nutri_values["pourcent_apport_ref_choval_r"]; //Glucides
|
||||
$foodProduct->nv_daily_sugar = $nutri_values["pourcent_apport_ref_sugar_r"]; //dont sucres
|
||||
$foodProduct->nv_daily_fiber = $nutri_values["pourcent_apport_ref_fibtg_r"]; //fibres alimentaires
|
||||
$foodProduct->nv_daily_protein = $nutri_values["pourcent_apport_ref_pro_r"]; //protéines
|
||||
$foodProduct->nv_daily_salt = $nutri_values["pourcent_apport_ref_salteq_r"]; //sel
|
||||
|
||||
//$foodProduct-> = $nutri_values["pourcent_apport_ref_e14_r"];
|
||||
|
||||
//nutriscore
|
||||
// Autre valeur dispo $nutri_values["pourcent_apport_ref_e14_r"] .
|
||||
// Nutriscore.
|
||||
$foodProduct->nutriscore = $nutri_values["classement"];
|
||||
|
||||
|
||||
//Infos n'ayant pas de mapping
|
||||
// $foodProduct-> = $nutri_values["val_energ_kj_nut"];
|
||||
// $foodProduct-> = $nutri_values["val_energ_kcal_nut"];
|
||||
// $foodProduct-> = $nutri_values["mat_grass_nut"];
|
||||
// $foodProduct-> = $nutri_values["ags_nut"];
|
||||
// $foodProduct-> = $nutri_values["glucides_nut"];
|
||||
// $foodProduct-> = $nutri_values["sucre_nut"];
|
||||
// $foodProduct-> = $nutri_values["sucre_r"];
|
||||
// $foodProduct-> = $nutri_values["fib_alim_nut"];
|
||||
// $foodProduct-> = $nutri_values["proteine_nut"];
|
||||
// $foodProduct-> = $nutri_values["sel_nut"];
|
||||
// $foodProduct-> = $nutri_values["apport_ref"];
|
||||
// $foodProduct-> = $nutri_values["fruits_coque_sech_p"];
|
||||
// $foodProduct-> = $nutri_values["ener_e14_p"];
|
||||
// $foodProduct-> = $nutri_values["pourcent_apport_ref_e14_p"];
|
||||
// $foodProduct-> = $nutri_values["ener_kjo_p"];
|
||||
// $foodProduct-> = $nutri_values["pourcent_apport_ref_kjo_p"];
|
||||
// $foodProduct-> = $nutri_values["fat_p"];
|
||||
// $foodProduct-> = $nutri_values["pourcent_apport_ref_fat_p"];
|
||||
// $foodProduct-> = $nutri_values["fatsat_p"];
|
||||
// $foodProduct-> = $nutri_values["pourcent_apport_ref_fatsat_p"];
|
||||
// $foodProduct-> = $nutri_values["choval_p"];
|
||||
// $foodProduct-> = $nutri_values["pourcent_apport_ref_choval_p"];
|
||||
// $foodProduct-> = $nutri_values["sugar_p"];
|
||||
// $foodProduct-> = $nutri_values["pourcent_apport_ref_sugar_p"];
|
||||
// $foodProduct-> = $nutri_values["fibtg_p"];
|
||||
// $foodProduct-> = $nutri_values["pourcent_apport_ref_fibtg_p"];
|
||||
// $foodProduct-> = $nutri_values["pro_p"];
|
||||
// $foodProduct-> = $nutri_values["pourcent_apport_ref_pro_p"];
|
||||
// $foodProduct-> = $nutri_values["salteq_p"];
|
||||
// $foodProduct-> = $nutri_values["pourcent_apport_ref_salteq_p"];
|
||||
// $foodProduct-> = $nutri_values["apport_port"];
|
||||
// $foodProduct-> = $nutri_values["part_p"];
|
||||
// $foodProduct-> = $nutri_values["part_g"];
|
||||
// $foodProduct-> = $nutri_values["part_l"];
|
||||
// $foodProduct-> = $nutri_values["p_sur_l"];
|
||||
// $foodProduct-> = $nutri_values["pourcent_ags"];
|
||||
// $foodProduct-> = $nutri_values["pourcent_agi"];
|
||||
// $foodProduct-> = $nutri_values["pourcent_ss"];
|
||||
// $foodProduct-> = $nutri_values["pourcent_amidon"];
|
||||
// $foodProduct-> = $nutri_values["composante_n"];
|
||||
// $foodProduct-> = $nutri_values["composante_p"];
|
||||
// $foodProduct-> = $nutri_values["pourcent_fruits"];
|
||||
// $foodProduct-> = $nutri_values["mat_grass_r_prec"];
|
||||
// $foodProduct-> = $nutri_values["ags_r_prec"];
|
||||
// $foodProduct-> = $nutri_values["glucides_r_prec"];
|
||||
// $foodProduct-> = $nutri_values["sucre_r_prec"];
|
||||
// $foodProduct-> = $nutri_values["fib_alim_r_prec"];
|
||||
// $foodProduct-> = $nutri_values["proteine_r_prec"];
|
||||
// $foodProduct-> = $nutri_values["sel_r_prec"];
|
||||
// $foodProduct-> = $nutri_values["sodium_r_prec"];
|
||||
// $foodProduct-> = $nutri_values["fruits_r_prec"];
|
||||
// $foodProduct-> = $nutri_values["fruits_coque_sech_r_prec"];
|
||||
// $foodProduct-> = $nutri_values["score_nutri"];
|
||||
}
|
||||
|
||||
/**
|
||||
* Infos n'ayant pas de mapping
|
||||
*
|
||||
* $nutri_values["val_energ_kj_nut"];
|
||||
* $nutri_values["val_energ_kcal_nut"];
|
||||
* $nutri_values["mat_grass_nut"];
|
||||
* $nutri_values["ags_nut"];
|
||||
* $nutri_values["glucides_nut"];
|
||||
* $nutri_values["sucre_nut"];
|
||||
* $nutri_values["sucre_r"];
|
||||
* $nutri_values["fib_alim_nut"];
|
||||
* $nutri_values["proteine_nut"];
|
||||
* $nutri_values["sel_nut"];
|
||||
* $nutri_values["apport_ref"];
|
||||
* $nutri_values["fruits_coque_sech_p"];
|
||||
* $nutri_values["ener_e14_p"];
|
||||
* $nutri_values["pourcent_apport_ref_e14_p"];
|
||||
* $nutri_values["ener_kjo_p"];
|
||||
* $nutri_values["pourcent_apport_ref_kjo_p"];
|
||||
* $nutri_values["fat_p"];
|
||||
* $nutri_values["pourcent_apport_ref_fat_p"];
|
||||
* $nutri_values["fatsat_p"];
|
||||
* $nutri_values["pourcent_apport_ref_fatsat_p"];
|
||||
* $nutri_values["choval_p"];
|
||||
* $nutri_values["pourcent_apport_ref_choval_p"];
|
||||
* $nutri_values["sugar_p"];
|
||||
* $nutri_values["pourcent_apport_ref_sugar_p"];
|
||||
* $nutri_values["fibtg_p"];
|
||||
* $nutri_values["pourcent_apport_ref_fibtg_p"];
|
||||
* $nutri_values["pro_p"];
|
||||
* $nutri_values["pourcent_apport_ref_pro_p"];
|
||||
* $nutri_values["salteq_p"];
|
||||
* $nutri_values["pourcent_apport_ref_salteq_p"];
|
||||
* $nutri_values["apport_port"];
|
||||
* $nutri_values["part_p"];
|
||||
* $nutri_values["part_g"];
|
||||
* $nutri_values["part_l"];
|
||||
* $nutri_values["p_sur_l"];
|
||||
* $nutri_values["pourcent_ags"];
|
||||
* $nutri_values["pourcent_agi"];
|
||||
* $nutri_values["pourcent_ss"];
|
||||
* $nutri_values["pourcent_amidon"];
|
||||
* $nutri_values["composante_n"];
|
||||
* $nutri_values["composante_p"];
|
||||
* $nutri_values["pourcent_fruits"];
|
||||
* $nutri_values["mat_grass_r_prec"];
|
||||
* $nutri_values["ags_r_prec"];
|
||||
* $nutri_values["glucides_r_prec"];
|
||||
* $nutri_values["sucre_r_prec"];
|
||||
* $nutri_values["fib_alim_r_prec"];
|
||||
* $nutri_values["proteine_r_prec"];
|
||||
* $nutri_values["sel_r_prec"];
|
||||
* $nutri_values["sodium_r_prec"];
|
||||
* $nutri_values["fruits_r_prec"];
|
||||
* $nutri_values["fruits_coque_sech_r_prec"];
|
||||
* $nutri_values["score_nutri"];
|
||||
*/
|
||||
}//end if
|
||||
$foodProduct->save();
|
||||
}
|
||||
}//end if
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,8 +2,6 @@
|
|||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Models\Customers;
|
||||
use App\Models\User;
|
||||
use App\Models\Product;
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
|
|
@ -20,18 +18,23 @@ class ProductPolicy
|
|||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* $user is a App\Models\User or a App\Models\Customers
|
||||
* @param App\Models\User|App\Models\Customers $user
|
||||
* @param \App\Models\Product $product
|
||||
*
|
||||
* @return \Illuminate\Auth\Access\Response
|
||||
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed
|
||||
*/
|
||||
public function addToCart($user = null, Product $product) {
|
||||
public function addToCart($user, Product $product)
|
||||
{
|
||||
// phpcs:enable
|
||||
$now = Carbon::now();
|
||||
if($product->orderable_start === null or $product->orderable_start <= $now) {
|
||||
//on est entré dans la période commandable ou c'est commandable depuis toujours
|
||||
if($product->orderable_end === null or $product->orderable_end >= $now) {
|
||||
//il n'y a pas de limite dans le temps ou elle n'est pas encore passée
|
||||
if ($product->orderable_start === null or $product->orderable_start <= $now) {
|
||||
// On est entré dans la période commandable ou c'est commandable depuis toujours.
|
||||
if ($product->orderable_end === null or $product->orderable_end >= $now) {
|
||||
// Il n'y a pas de limite dans le temps ou elle n'est pas encore passée.
|
||||
return Response::allow();
|
||||
}
|
||||
return Response::deny('Ce produit n\'est pas disponible pour le moment');
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue