change icons, css, add routing to merchandise, add mail templater, fixes
This commit is contained in:
45
app/Repositories/Core/Export/HelperExcel.php
Normal file
45
app/Repositories/Core/Export/HelperExcel.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core\Export;
|
||||
|
||||
class HelperExcel
|
||||
{
|
||||
public static function getHeaderStyle($color = 'ffffff', $bgcolor = '00a3cb')
|
||||
{
|
||||
return [
|
||||
'fill' => self::setFill($bgcolor),
|
||||
'borders' => self::setBorders($bgcolor),
|
||||
'font' => self::setFont($color, 14, true),
|
||||
];
|
||||
}
|
||||
|
||||
public static function setFill($color)
|
||||
{
|
||||
return [
|
||||
'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID,
|
||||
'startColor' => [
|
||||
'rgb' => $color,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public static function setBorders($color)
|
||||
{
|
||||
return [
|
||||
'outline' => [
|
||||
'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THICK,
|
||||
'color' => ['argb' => $color],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public static function setFont($color, $size = 12, $bold = false, $font = 'Calibri')
|
||||
{
|
||||
return [
|
||||
'name' => $font,
|
||||
'size' => $size,
|
||||
'bold' => $bold,
|
||||
'color' => ['argb' => $color],
|
||||
];
|
||||
}
|
||||
}
|
||||
26
app/Repositories/Core/Mail/MailLogs.php
Normal file
26
app/Repositories/Core/Mail/MailLogs.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core\Mail;
|
||||
|
||||
use App\Models\Core\Mail\MailLog;
|
||||
use App\Traits\Model\Basic;
|
||||
|
||||
class MailLogs
|
||||
{
|
||||
use Basic;
|
||||
|
||||
public static function getSubject($id)
|
||||
{
|
||||
return MailParser::getSubject(self::get($id)->event);
|
||||
}
|
||||
|
||||
public static function getParsed($id)
|
||||
{
|
||||
return MailParser::getParsed(self::get($id)->event);
|
||||
}
|
||||
|
||||
public static function getModel()
|
||||
{
|
||||
return MailLog::query();
|
||||
}
|
||||
}
|
||||
89
app/Repositories/Core/Mail/MailParser.php
Normal file
89
app/Repositories/Core/Mail/MailParser.php
Normal file
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core\Mail;
|
||||
|
||||
use ZBateson\MailMimeParser\Header\HeaderConsts;
|
||||
use ZBateson\MailMimeParser\MailMimeParser;
|
||||
|
||||
class MailParser
|
||||
{
|
||||
public static function getParsed($mail)
|
||||
{
|
||||
$model = self::getModel($mail);
|
||||
|
||||
return [
|
||||
'from' => self::getFromByModel($model),
|
||||
'subject' => self::getSubjectByModel($model),
|
||||
'content' => self::getHtmlByModel($model),
|
||||
'to_name' => self::getToNameByModel($model),
|
||||
'to_email' => self::getToEmailByModel($model),
|
||||
];
|
||||
}
|
||||
|
||||
public static function getSubject($mail)
|
||||
{
|
||||
return self::getSubjectByModel(self::getModel($mail));
|
||||
}
|
||||
|
||||
public static function getText($mail)
|
||||
{
|
||||
return self::getTextByModel(self::getModel($mail));
|
||||
}
|
||||
|
||||
public static function getHtml($mail)
|
||||
{
|
||||
return self::getHtmlByModel(self::getModel($mail));
|
||||
}
|
||||
|
||||
public static function getFrom($mail)
|
||||
{
|
||||
return self::getFromByModel(self::getModel($mail));
|
||||
}
|
||||
|
||||
public static function getToName($mail)
|
||||
{
|
||||
return self::getToNameByModel(self::getModel($mail));
|
||||
}
|
||||
|
||||
public static function getToEmail($mail)
|
||||
{
|
||||
return self::getToEmailByModel(self::getModel($mail));
|
||||
}
|
||||
|
||||
public static function getSubjectByModel($model)
|
||||
{
|
||||
return $model->getHeaderValue(HeaderConsts::SUBJECT);
|
||||
}
|
||||
|
||||
public static function getTextByModel($model)
|
||||
{
|
||||
return $model->getTextContent();
|
||||
}
|
||||
|
||||
public static function getFromByModel($model)
|
||||
{
|
||||
return $model->getHeader(HeaderConsts::FROM)->getPersonName();
|
||||
}
|
||||
|
||||
public static function getToNameByModel($model)
|
||||
{
|
||||
return $model->getHeader(HeaderConsts::TO)->getAddresses()[0]->getName();
|
||||
}
|
||||
|
||||
public static function getToEmailByModel($model)
|
||||
{
|
||||
return $model->getHeader(HeaderConsts::TO)->getAddresses()[0]->getEmail();
|
||||
}
|
||||
|
||||
public static function getHtmlByModel($model)
|
||||
{
|
||||
return $model->getHtmlContent();
|
||||
}
|
||||
|
||||
public static function getModel($mail)
|
||||
{
|
||||
$mailParser = new MailMimeParser();
|
||||
|
||||
return $mailParser->parse($mail, false);
|
||||
}
|
||||
}
|
||||
64
app/Repositories/Core/Mail/MailTemplates.php
Normal file
64
app/Repositories/Core/Mail/MailTemplates.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core\Mail;
|
||||
|
||||
use App\Models\Core\Mail\MailTemplate;
|
||||
use App\Traits\Model\Basic;
|
||||
use Mustache_Engine;
|
||||
|
||||
class MailTemplates
|
||||
{
|
||||
use Basic;
|
||||
|
||||
public static function init()
|
||||
{
|
||||
return [
|
||||
'mailables' => Mailables::getList(),
|
||||
];
|
||||
}
|
||||
|
||||
public static function edit($id)
|
||||
{
|
||||
$data = self::get($id)->toArray();
|
||||
$mailable = $data['mailable'];
|
||||
$data['vars'] = $mailable::getVariables();
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function getVarsByMailable($mailable)
|
||||
{
|
||||
return $mailable::getVariables();
|
||||
}
|
||||
|
||||
public static function getDataFormodalPreview($id)
|
||||
{
|
||||
$template = self::get($id);
|
||||
$mailable = $template->mailable;
|
||||
|
||||
return [
|
||||
'id' => $id,
|
||||
'users' => $mailable::getUsers(),
|
||||
];
|
||||
}
|
||||
|
||||
public static function preview($id, $user_id)
|
||||
{
|
||||
$template = self::get($id);
|
||||
$mailable = $template->mailable;
|
||||
$data = $mailable::getDataByUser($user_id);
|
||||
$html_template = $template->toArray()['html_template_translations'][$data['lang']] ?? false;
|
||||
if ($html_template) {
|
||||
$m = new Mustache_Engine();
|
||||
|
||||
return $m->render($html_template, $data);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function getModel()
|
||||
{
|
||||
return MailTemplate::query();
|
||||
}
|
||||
}
|
||||
18
app/Repositories/Core/Mail/Mailables.php
Normal file
18
app/Repositories/Core/Mail/Mailables.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core\Mail;
|
||||
|
||||
class Mailables
|
||||
{
|
||||
public static function getList()
|
||||
{
|
||||
$data = [];
|
||||
$files = glob(app_path('Mail').'/*.php');
|
||||
foreach ($files as $file) {
|
||||
$class = basename($file, '.php');
|
||||
$data['App\Mail\\'.$class] = $class;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
18
app/Repositories/Core/Mail/Mailer.php
Normal file
18
app/Repositories/Core/Mail/Mailer.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Core\Mail;
|
||||
|
||||
class Mailer
|
||||
{
|
||||
public static function getTemplates()
|
||||
{
|
||||
return MailTemplates::getOptions();
|
||||
}
|
||||
|
||||
public static function getTemplate($template_id)
|
||||
{
|
||||
$templates = self::getTemplates();
|
||||
|
||||
return $templates[$template_id];
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,10 @@
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use App\Models\Shop\ArticleNature;
|
||||
use App\Models\Shop\Article;
|
||||
use App\Models\Botanic\Specie;
|
||||
use App\Models\Botanic\Variety;
|
||||
use App\Models\Shop\Merchandise;
|
||||
|
||||
class ArticleNatures
|
||||
{
|
||||
@@ -11,9 +15,36 @@ class ArticleNatures
|
||||
return ArticleNature::get()->pluck('name', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function getOptionsByMerchandise()
|
||||
public static function getProductType($id)
|
||||
{
|
||||
return self::getOptionsByProductType(2);
|
||||
$type = self::get($id)->product_type ?? false;
|
||||
return $type ? self::getProductTypes()[$type] : false;
|
||||
}
|
||||
|
||||
public static function getProductTypeName($type)
|
||||
{
|
||||
return self::getProductTypes()[$type] ?? false;
|
||||
}
|
||||
|
||||
public static function getProductTypeByModel($model)
|
||||
{
|
||||
switch ($model) {
|
||||
case Specie::class:
|
||||
$type = 1;
|
||||
break;
|
||||
case Variety::class:
|
||||
$type = 1;
|
||||
break;
|
||||
case Merchandise::class:
|
||||
$type = 2;
|
||||
break;
|
||||
}
|
||||
return $type ?? false;
|
||||
}
|
||||
|
||||
public static function getProductTypes()
|
||||
{
|
||||
return ['', 'botanic', 'merchandise'];
|
||||
}
|
||||
|
||||
public static function getOptionsByBotanic()
|
||||
@@ -21,9 +52,30 @@ class ArticleNatures
|
||||
return self::getOptionsByProductType(1);
|
||||
}
|
||||
|
||||
public static function getOptionsByMerchandise()
|
||||
{
|
||||
return self::getOptionsByProductType(2);
|
||||
}
|
||||
|
||||
public static function getOptionsByProductTypeModel($model)
|
||||
{
|
||||
$type = self::getProductTypeByModel($model);
|
||||
return self::getOptionsByProductType($type);
|
||||
}
|
||||
|
||||
public static function getOptionsByProductType($type)
|
||||
{
|
||||
return ArticleNature::byProductType($type)->get()->pluck('name', 'id')->toArray();
|
||||
return self::getByProductType($type)->pluck('name', 'id')->toArray();
|
||||
}
|
||||
|
||||
public static function getByProductType($type)
|
||||
{
|
||||
return ArticleNature::byProductType($type)->get();
|
||||
}
|
||||
|
||||
public static function getByCategory($category_id)
|
||||
{
|
||||
return Article::byCategory($category_id)->select('article_nature_id')->distinct()->get();
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
|
||||
@@ -10,6 +10,7 @@ use App\Repositories\Core\Comments;
|
||||
use App\Repositories\Botanic\Species;
|
||||
use App\Repositories\Botanic\Varieties;
|
||||
use App\Models\Shop\Article;
|
||||
use App\Models\Shop\Merchandise;
|
||||
|
||||
use App\Traits\Repository\Imageable;
|
||||
|
||||
@@ -106,7 +107,7 @@ class Articles
|
||||
$data['description'] = self::getFullDescriptionByArticle($article);
|
||||
$images = self::getFullImagesByArticle($article);
|
||||
$data['image'] = self::getPreviewSrc($images[0] ?? false);
|
||||
$data['images'] = $images;
|
||||
$data['images'] = count($images) ? $images : false;
|
||||
$data['image_big'] = self::getImageSrc($images[0] ?? false);
|
||||
$data['inherited'] = self::getInherited($id);
|
||||
$data['categories'] = self::getCategoriesNameByArticle($article);
|
||||
@@ -376,6 +377,22 @@ class Articles
|
||||
return $article->categories->pluck('id')->toArray();
|
||||
}
|
||||
|
||||
public static function getProductTypeByCategory($category_id)
|
||||
{
|
||||
$models = self::getProductTypesModelsByCategory($category_id);
|
||||
return (($models[0] ?? false) == Merchandise::class) ? 'merchandise' : 'botanic';
|
||||
}
|
||||
|
||||
public static function getProductTypesModelsByCategory($category_id)
|
||||
{
|
||||
return Article::byCategory($category_id)->select('product_type')->distinct()->get();
|
||||
}
|
||||
|
||||
public static function countProductTypesByCategory($category_id)
|
||||
{
|
||||
return Article::byCategory($category_id)->select('product_type')->distinct()->count();
|
||||
}
|
||||
|
||||
public static function getCategoriesNameByArticle($article)
|
||||
{
|
||||
return $article->categories->pluck('name', 'id')->toArray();
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\Repositories\Shop;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use App\Models\Shop\Order;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class Orders
|
||||
{
|
||||
@@ -70,6 +71,8 @@ class Orders
|
||||
public static function create($data)
|
||||
{
|
||||
OrderStats::increase();
|
||||
$data['uuid'] = Str::uuid()->toString();
|
||||
$data['ref'] = self::getNewRef();
|
||||
return Order::create($data);
|
||||
}
|
||||
|
||||
@@ -111,4 +114,12 @@ class Orders
|
||||
{
|
||||
return ['', 'CARTE BANCAIRE', 'CHEQUE', 'VIREMENT BANCAIRE'];
|
||||
}
|
||||
|
||||
public static function getNewRef()
|
||||
{
|
||||
$ref = date('ym') . '00000';
|
||||
$last_ref = Order::orderBy('ref', 'desc')->where('ref', '>', $ref)->first();
|
||||
return $last_ref ? $last_ref->ref + 1 : $ref + 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user