Add display articles by rows, and display article in full mode

This commit is contained in:
Ludovic CANDELLIER
2022-01-18 23:39:27 +01:00
parent 3641bd7d68
commit cefe956bc4
11 changed files with 147 additions and 84 deletions

View File

@@ -9,79 +9,14 @@ use App\Repositories\Shop\Articles;
class ArticleController extends Controller class ArticleController extends Controller
{ {
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*
* @param \App\Article $article
* @return \Illuminate\Http\Response
*/
public function show($id) public function show($id)
{ {
// $data = self::init();
$data['article'] = Articles::getArticle($id);
// dump($data);
// exit;
return view('Shop.Articles.show', $data);
} }
/**
* Show the form for editing the specified resource.
*
* @param \App\Article $article
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Article $article
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param \App\Article $article
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
} }

View File

@@ -74,6 +74,17 @@ class Medias
return '.' . pathinfo($filename, PATHINFO_EXTENSION); return '.' . pathinfo($filename, PATHINFO_EXTENSION);
} }
public static function getImageSrc($image)
{
if (!$image) {
return null;
}
$id = $image['id'];
$filename = $image['name'] . self::getExtension($image['file_name']);
return "/storage/$id/$filename";
}
public static function getThumbSrc($image) public static function getThumbSrc($image)
{ {
if (!$image) { if (!$image) {

View File

@@ -51,7 +51,9 @@ class Articles
{ {
$article = self::get($id); $article = self::get($id);
$data = $article->toArray(); $data = $article->toArray();
$data['description'] = (!empty($article->description)) ? $article->description : $article->product->description;
$data['image'] = Articles::getPreview($article->image); $data['image'] = Articles::getPreview($article->image);
$data['image_big'] = Articles::getImage($article->image);
$data['inherited'] = self::getInherited($id); $data['inherited'] = self::getInherited($id);
$data['categories'] = self::getCategoriesNameByArticle($article); $data['categories'] = self::getCategoriesNameByArticle($article);
$data['tags'] = self::getTagsNameByArticle($article); $data['tags'] = self::getTagsNameByArticle($article);
@@ -63,6 +65,7 @@ class Articles
{ {
$articles = self::getArticlesWithOffers(); $articles = self::getArticlesWithOffers();
// dump($articles->toArray()); // dump($articles->toArray());
// exit;
foreach ($articles as $article) { foreach ($articles as $article) {
$price_lists = $article->offers[0]->tariff->price_lists->toArray(); $price_lists = $article->offers[0]->tariff->price_lists->toArray();
// dump($price_lists); // dump($price_lists);
@@ -81,6 +84,7 @@ class Articles
'offer_id' => $article->offers[0]->id, 'offer_id' => $article->offers[0]->id,
'quantity' => $prices['quantity'], 'quantity' => $prices['quantity'],
'price' => $prices['price_taxed'], 'price' => $prices['price_taxed'],
'variation' => $article->offers[0]->variation->name,
]; ];
} }
} }
@@ -95,7 +99,7 @@ class Articles
'image', 'image',
'product', 'product',
'article_nature', 'article_nature',
'offers.variation', 'offers.variation.package',
'offers.tariff.price_lists.price_list_values', 'offers.tariff.price_lists.price_list_values',
])->get(); ])->get();
} }

View File

@@ -36,6 +36,16 @@ trait Imageable
return $image ? Medias::getPreviewSrc($image) : null; return $image ? Medias::getPreviewSrc($image) : null;
} }
public static function getImage($image)
{
return '<img src="' . self::getImageSrc($image) . '" class="img-fluid">';
}
public static function getImageSrc($image)
{
return $image ? Medias::getImageSrc($image) : null;
}
public static function deleteImage($id, $index) public static function deleteImage($id, $index)
{ {
return Medias::deleteImage(self::get($id), $index); return Medias::deleteImage(self::get($id), $index);

View File

@@ -2,23 +2,29 @@
<div class="card"> <div class="card">
<img src="{{ App\Repositories\Shop\Articles::getPreviewSrc($article['image'] ?? false) }}" class="card-img-top" alt="..."> <img src="{{ App\Repositories\Shop\Articles::getPreviewSrc($article['image'] ?? false) }}" class="card-img-top" alt="...">
<div class="card-body"> <div class="card-body">
<span class="card-title">{{ $product_name }}</span> <span class="card-title" style="font-weight: bold; color: green;">{{ $product_name }}</span>
<span class="pull-right"> <span class="float-right" style="font-size: 2em; color: red;">
<i class="fa fa-heart"></i> <i class="fa fa-heart"></i>
</span> </span>
<p class="card-text"> <p class="card-text">
<div class="row"> <div class="row" style="color: green;">
<div class="col-6"> <div class="col-6">
{{ $article['semences']['price'] ?? null }}<br> @if ($article['semences'] ?? false)
<span style="font-size: 1.4em; font-weight: bold;">{{ $article['semences']['price'] ?? null }}</span> <br>
@else
Indisponible
@endif
Semence Semence
</div> </div>
@if ($article['plants'] ?? false)
<div class="col-6"> <div class="col-6">
{{ $article['plants']['price'] }}<br> @if ($article['plants'] ?? false)
<span style="font-size: 1.4em; font-weight: bold;">{{ $article['plants']['price'] }}</span> <br>
@else
Indisponible
@endif
Plant Plant
</div> </div>
@endif
</div> </div>
</p> </p>
</div> </div>

View File

@@ -0,0 +1,55 @@
<a href="{{ route('Shop.Articles.show', ['id' => $article['semences']['article_id'] ?? false ]) }}">
<div class="row pb-3">
<div class="col-12">
<div class="card-title" style="font-weight: bold; color: green;">{{ $product_name }}</div>
</div>
<div class="col-12">
<div class="row">
<div class="col-8">
<div class="row">
<div class="col-2">
<div class="row">
<div class="col-9">
<img src="{{ App\Repositories\Shop\Articles::getPreviewSrc($article['image'] ?? false) }}" class="card-img-top" alt="...">
</div>
<div class="col-3 text-center">
<span style="font-size: 2em; color: red;">
<i class="fa fa-heart"></i>
</span>
</div>
</div>
</div>
<div class="col-10">
{!! $article['description'] !!}
</div>
</div>
</div>
<div class="col-4">
<p class="card-text">
<div class="row" style="color: green;">
<div class="col-6 text-center">
@if ($article['semences'] ?? false)
<span style="font-size: 1.4em; font-weight: bold;">{{ $article['semences']['price'] ?? null }}</span> <br>
{{ $article['semences']['variation'] }}
<div>
Quantité :
</div>
@include('components.form.button', [
'class' => 'btn-success basket semences',
'txt' => 'Ajouter au panier',
])
@endif
</div>
<div class="col-6 text-center">
@if ($article['plants'] ?? false)
<span style="font-size: 1.4em; font-weight: bold;">{{ $article['plants']['price'] }}</span> <br>
{{ $article['plants']['variation'] }}
@endif
</div>
</div>
</p>
</div>
</div>
</div>
</div>
</a>

View File

@@ -0,0 +1,33 @@
@extends('Shop.layout.layout', [
'title' => __('home.title'),
])
@section('content')
<div class="row">
<div class="col-1">
</div>
<div class="col-4">
{!! $article['image_big'] !!}
</div>
<div class="col-4">
<h1>{{ $article['name'] }}</h1>
{!! $article['description'] !!}
</div>
<div class="col-3">
@component('components.card', [
'title' => 'Semence',
'class' => 'mb-3',
])
@include('components.form.button', [
'class' => 'btn-success basket semences',
'txt' => 'Ajouter au panier',
])
@endcomponent
@component('components.card', [
'title' => 'Plant',
])
@endcomponent
</div>
</div>
@endsection

View File

@@ -3,5 +3,9 @@
]) ])
@section('content') @section('content')
@if ($display_by_rows ?? true)
@include('Shop.layout.partials.category_articles_rows')
@else
@include('Shop.layout.partials.category_articles') @include('Shop.layout.partials.category_articles')
@endif
@endsection @endsection

View File

@@ -0,0 +1,3 @@
@foreach ($articles as $product_name => $article)
@include('Shop.Articles.partials.article_rows')
@endforeach

View File

@@ -4,7 +4,7 @@
@isset($header) @isset($header)
{{ $header }} {{ $header }}
@else @else
<h3 class="card-title">{{ $title }}</h3> <h3 class="card-title">{{ $title ?? false }}</h3>
@isset($tools) @isset($tools)
<div class="card-tools"> <div class="card-tools">
{!! $tools !!} {!! $tools !!}

View File

@@ -1,4 +1,6 @@
<button type="{{ $type ?? 'button' }}" class="btn {{ $class ?? ''}}" @if (isset($id)) id="{{ $id }}"@endif> <button type="{{ $type ?? 'button' }}" class="btn {{ $class ?? ''}}" @if (isset($id)) id="{{ $id }}"@endif>
@if ($icon ?? false)
<i class="fa fa-fw {{ $icon ?? '' }}"></i> <i class="fa fa-fw {{ $icon ?? '' }}"></i>
@endif
{{ $txt ?? '' }} {{ $txt ?? '' }}
</button> </button>