Add display articles & categories, raw mode

This commit is contained in:
Ludovic CANDELLIER
2020-08-20 23:55:42 +02:00
parent 12aff23e00
commit 77a239fce9
15 changed files with 102 additions and 88 deletions

View File

@@ -28,9 +28,9 @@ class HomeController extends Controller
public function index()
{
$data['categories'] = Categories::getTree();
$data['category'] = Categories::get(15)->toArray();
$data['articles'] = Articles::getByCategory(0)->toArray();
dump($data);
exit;
// dump($data);
return view('Shop.home', $data);
}
}

12
app/Models/Core/Media.php Normal file
View File

@@ -0,0 +1,12 @@
<?php
namespace App\Models\Core;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Media extends Model
{
protected $table = 'media';
}

View File

@@ -26,9 +26,14 @@ class Article extends Model implements HasMedia
return $this->hasMany('App\Models\Shop\ArticleAttribute');
}
public function prices()
public function images()
{
return $this->hasManyThrough('App\Models\Shop\ArticlePrice','App\Models\Shop\ArticleAttribute');
return $this->hasMany('App\Models\Core\Media','model_id')->where('model_type','App\Models\Shop\Article');
}
public function image()
{
return $this->hasOne('App\Models\Core\Media','model_id')->where('model_type','App\Models\Shop\Article');
}
public function inventories()
@@ -41,6 +46,11 @@ class Article extends Model implements HasMedia
return $this->hasMany('App\Models\Shop\InvoiceItem');
}
public function prices()
{
return $this->hasManyThrough('App\Models\Shop\ArticlePrice','App\Models\Shop\ArticleAttribute');
}
public function product()
{
return $this->morphTo();

View File

@@ -49,7 +49,7 @@ class Articles
public static function getByCategory($category_id)
{
return Article::with(['prices.article_attribute.attribute_value'])->get();
return Article::with(['prices.article_attribute.attribute_value','product','image'])->get();
}
public static function getCategoriesByArticle($article)
@@ -92,7 +92,7 @@ class Articles
self::storeCategories($article, $categories);
self::storeTags($article, $tags);
self::storePrices($article, $prices);
return $article_id;
return $article->id;
}
public static function store($data)
@@ -175,6 +175,17 @@ class Articles
}
}
public static function getThumbSrc($image)
{
$id = $image['id'];
$images = json_decode($image['responsive_images'], true);
$urls = $images['medialibrary_original']['urls'];
$img = $urls[count($urls)-1];
$src = "storage/$id/responsive-images/$img";
return $src;
}
public static function deleteImage($id, $index)
{

View File

@@ -8,11 +8,11 @@
</div>
<div class="col-4">
{{ Form::label('model', 'Familles de produit') }}<br>
@include('components.select', ['name' => 'model', 'id_name' => 'model', 'list' => $models_options, 'value' => isset($model) ? $model : null, 'class' => 'select2 form-control'])
@include('components.select', ['name' => 'product_type', 'id_name' => 'product_type', 'list' => $models_options, 'value' => isset($product_type) ? $product_type : null, 'class' => 'select2 form-control'])
</div>
<div class="col-6">
{{ Form::label('model_id', 'Produit') }}<br>
@include('components.select2', ['name' => 'model_id', 'id_name' => 'model_id', 'value' => isset($model_id) ? $model_id : null, 'class' => 'select2 form-control'])
@include('components.select2', ['name' => 'product_id', 'id_name' => 'product_id', 'value' => isset($product_id) ? $product_id : null, 'class' => 'select2 form-control'])
</div>
</div>
@@ -57,13 +57,13 @@
@push('js')
<script>
$("#model_id").change( function(e) {
var model = $('#model_id').select2('data');
var name = model[0]['text'];
$("#product_id").change( function(e) {
var product = $('#product_id').select2('data');
var name = product[0]['text'];
$('input[name="name"]').val(name);
});
$('#model').change( function() {
$('#product_type').change( function() {
loadVarieties();
});
@@ -71,10 +71,10 @@
$.ajax({
url : '{{ route('Botanic.Admin.Varieties.getSelect') }}',
method : 'POST',
data: {model: $('#model').val()},
data: {model: $('#product_type').val()},
success : function(data) {
$("#model_id").select2({data: data});
$("#model_id").val({{ $model_id }}).trigger('change');
$("#product_id").select2({data: data});
$("#product_id").trigger('change');
}
});
}

View File

@@ -5,7 +5,6 @@
@section('content')
@include("Shop.layout.partials.block-breadcrumb")
@include("Shop.layout.partials.block-products")
@include("Shop.layout.partials.category")
@endsection

View File

@@ -10,7 +10,7 @@
<meta name="csrf-token" content="{{ csrf_token() }}">
<title>OpenSemis</title>
<meta name="description" content="Boutique propulsée par HumaN.E.T">
<meta name="description" content="Vente de semences, variété anciennes">
<meta name="keywords" content="">
<link rel="icon" type="image/vnd.microsoft.icon" href="img/favicon.ico">
@@ -36,7 +36,7 @@
</section>
</div>
@include("Shop._partials.footer")
@include("Shop.layout.partials.footer")
</main>
</div>

View File

@@ -1,23 +1,23 @@
<div class="article">
<div class="row">
<div class="col-12">
<img src="{{ $article['img'] ?? '/img/logo'}}" class="img-responsive">
{{ $article['name'] }}
<span class="pull-right">
<i class="fa fa-heart"></i>
</span>
</div>
</div>
<div class="card" style="width: 18rem;">
<img src="{{ App\Repositories\Shop\Articles::getThumbSrc($article['image']) }}" class="card-img-top" alt="...">
<div class="card-body">
<span class="card-title">{{ $article['name'] }}</span>
<span class="pull-right">
<i class="fa fa-heart"></i>
</span>
<div class="row">
<div class="col-6">
3.10 <br>
Semence
</div>
<p class="card-text">
<div class="row">
<div class="col-6">
3.10 <br>
Semence
</div>
<div class="col-6">
1.65 <br>
Plant
<div class="col-6">
1.65 <br>
Plant
</div>
</div>
</div>
</p>
</div>
</div>

View File

@@ -0,0 +1,7 @@
<div class="row">
@foreach ($articles as $article)
<div class="col-3">
@include('Shop.layout.partials.article')
</div>
@endforeach
</div>

View File

@@ -1,40 +0,0 @@
<div id="ishiproductsblock" class="container clearfix">
<div class="ishiproductsblock-container">
<h2 class="home-title">Meilleurs produits</h2>
<ul id="ishiproductstab" class="nav nav-tabs clearfix">
<li class="nav-item first_item">
<a class="nav-link active" href="#featured-products-block" data-toggle="tab">En vedette</a>
</li>
<li class="nav-item ">
<a class="nav-link " href="#new-products-block" data-toggle="tab">Dernier</a>
</li>
<li class="nav-item last_item">
<a class="nav-link " href="#bestseller-products-block" data-toggle="tab">Meilleures ventes</a>
</li>
</ul>
<div class="product_content ">
<div class="tab-content">
<div id="featured-products-block" class="tab-pane active">
<div class="block_content row">
<div id="ishi-featured-products" class="owl-carousel">
{{ include("Shop._partials.product", {index:1}) }}
{{ include("Shop._partials.product", {index:2}) }}
{{ include("Shop._partials.product", {index:3}) }}
{{ include("Shop._partials.product", {index:4}) }}
{{ include("Shop._partials.product", {index:5}) }}
{{ include("Shop._partials.product", {index:6}) }}
{{ include("Shop._partials.product", {index:7}) }}
{{ include("Shop._partials.product", {index:8}) }}
</div>
</div>
</div>
<div id="new-products-block">
</div>
<div id="bestseller-products-block">
</div>
</div>
</div>
</div>
</div>

View File

@@ -1,7 +1,7 @@
<div class="row">
<div class="col-8">
<h1>{{ $category['name'] }}</h1>
<h3>{{ $category['description'] }}</h3>
<h1 style="font-size: 2em;">{{ $category['name'] }}</h1>
<h3 style="font-size: 1.2em;">{!! $category['description'] !!}</h3>
</div>
<div class="col-4">
@include('Shop.layout.partials.category_add')

View File

@@ -1,9 +1,14 @@
<div class="row">
<div class="col-6">
Ajouter au panier la liste des semences
<button type="button" class="btn btn-success">
<i class="fa fa-seedling"></i>
Ajouter au panier la liste des <strong>semences</strong>
</button>
</div>
<div class="col-6">
Ajouter au panier la liste des plants
<button type="button" class="btn btn-warning">
Ajouter au panier la liste des <strong>plants</strong>
</button>
</div>
</div>
@@ -12,7 +17,7 @@
Il y a {{ $nb ?? 0 }} article(s) dans la liste
<form name="product_sorting">
<label>Trier par</label>
@include('components.select', ['name' => ])
@include('components.select', ['name' => 'sorting', 'list' => ['Pertinence']])
</form>
</div>
</div>

View File

@@ -1,3 +1,7 @@
@foreach ($articles as $article)
@include('Shop.layout.partials.article')
@endforeach
<div class="row">
@foreach ($articles as $article)
<div class="col-3">
@include('Shop.layout.partials.article')
</div>
@endforeach
</div>

View File

@@ -0,0 +1,6 @@
<footer id="footer">
@include("Shop._partials.footer-after")
</footer>

View File

@@ -3,7 +3,7 @@
@if (isset($id_name))id="{{ $id_name }}"@endif
class="form-control @if (isset($class)){{ $class }} @endif"
@if (isset($style))style="{{ $style }}" @endif
@if (isset($required))required="required"@endif
@if (isset($required) && $required)required="required"@endif
@if (isset($multiple))multiple="multiple"@endif
>
@if (isset($with_empty))