invert query from offers->articles to articles->offers

This commit is contained in:
Ludovic CANDELLIER
2022-01-05 22:05:30 +01:00
parent a3c6fc6ebe
commit 95ca3c6404
17 changed files with 121 additions and 93 deletions

View File

@@ -20,6 +20,8 @@ class HomeController extends Controller
{
$data = self::init();
$data['offers'] = Offers::getLast()->toArray();
dump($data);
exit;
return view('Shop.home', $data);
}
}

View File

@@ -0,0 +1,17 @@
<?php
namespace App\Http\Controllers\Shop;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Repositories\Shop\Offers;
class OfferController extends Controller
{
public function show($id)
{
$offer = Offers::getFull($id);
dump($offer);
}
}

View File

@@ -86,6 +86,13 @@ class Article extends Model implements HasMedia
public function scopeWithOffers($query)
{
return $query->has('Offers');
return $query->has('offers');
}
public function scopeWithCurrentOffers($query)
{
return $query->whereHas('offers', function ($query) {
$query->where('status_id', 1);
});
}
}

View File

@@ -14,9 +14,11 @@ use Spatie\Translatable\HasTranslations;
use Rinvex\Tags\Traits\Taggable;
use Wildside\Userstamps\Userstamps;
use Kalnoy\Nestedset\NodeTrait;
class Category extends Model
{
use HasTranslations, InteractsWithMedia, SoftDeletes, Taggable, Userstamps;
use HasTranslations, InteractsWithMedia, NodeTrait, SoftDeletes, Taggable, Userstamps;
protected $guarded = ['id'];
protected $table = 'categories';
@@ -41,4 +43,9 @@ class Category extends Model
{
return $query->where('category_id', $category_id);
}
public function scopeVisible($query)
{
return $query->where('visible', 1);
}
}

View File

@@ -38,6 +38,11 @@ class Offer extends Model
return $this->belongsTo(Variation::class);
}
public function scopeActive($query)
{
return $query->where('status_id', 1);
}
public function scopeByArticle($query, $id)
{
return $query->where('article_id', $id);

View File

@@ -6,11 +6,6 @@ use App\Repositories\Core\Arrays;
class Categories
{
public static function getTree($withFolder = false)
{
$categories = self::getCategoryTree()->toArray();
return self::getChildren($categories[0]['children'], $withFolder);
}
public static function getFancyTree()
{
@@ -20,6 +15,12 @@ class Categories
return $categories;
}
public static function getTree($withFolder = false)
{
$categories = self::getCategoryTree()->toArray();
return self::getChildren($categories[0]['children'], $withFolder);
}
public static function getCategoryTree()
{
return self::getModel()->defaultOrder()->get()->toTree();

View File

@@ -59,6 +59,11 @@ class Articles
return $data;
}
public static function getArticlesWithOffers()
{
return Article::withCurrentOffers()->with('offers')->get();
}
public static function getFull($id)
{
$data['article'] = self::getArticleEdit($id);

View File

@@ -38,6 +38,11 @@ class Categories
return $category->tags->pluck('name', 'id')->toArray();
}
public static function getTreeVisibles()
{
$tree = Category::get()->toTree();
}
public static function getTree()
{
return CategoryTrees::getTree();

View File

@@ -19,7 +19,7 @@ class Offers
public static function getLast()
{
return Offer::with(['article.image'])->orderByDesc('updated_at')->get();
return Offer::with(['article.image'])->active()->orderByDesc('updated_at')->get();
}
public static function getByCategoryWithTags($category_id)

View File

@@ -0,0 +1,25 @@
<a href="{{ route('Shop.Offers.show', ['id' => $offer['id']]) }}">
<div class="card">
<img src="{{ App\Repositories\Shop\Articles::getPreviewSrc($offer['article']['image'] ?? false) }}" class="card-img-top" alt="...">
<div class="card-body">
<span class="card-title">{{ $offer['article']['name'] }}</span>
<span class="pull-right">
<i class="fa fa-heart"></i>
</span>
<p class="card-text">
<div class="row">
<div class="col-6">
3.50 <br>
Semence
</div>
<div class="col-6">
1.65 <br>
Plant
</div>
</div>
</p>
</div>
</div>
</a>

View File

@@ -0,0 +1,25 @@
<a href="{{ route('Shop.Offers.show', ['id' => $offer['id']]) }}">
<div class="card">
<img src="{{ App\Repositories\Shop\Articles::getPreviewSrc($offer['article']['image'] ?? false) }}" class="card-img-top" alt="...">
<div class="card-body">
<span class="card-title">{{ $offer['article']['name'] }}</span>
<span class="pull-right">
<i class="fa fa-heart"></i>
</span>
<p class="card-text">
<div class="row">
<div class="col-6">
3.50 <br>
Semence
</div>
<div class="col-6">
1.65 <br>
Plant
</div>
</div>
</p>
</div>
</div>
</a>

View File

@@ -1,55 +0,0 @@
<!doctype html>
<html lang="fr">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>OpenSemis</title>
<meta name="description" content="Boutique propulsée par HumaN.E.T">
<meta name="keywords" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/vnd.microsoft.icon" href="img/favicon.ico?1528709483">
<link rel="shortcut icon" type="image/x-icon" href="img/favicon.ico?1528709483">
<link rel="stylesheet" href="theme.css" type="text/css" media="all">
</head>
<body id="index">
<main>
{{ include("Shop.layout.partials.header") }}
{{ include("Shop._partials.notifications") }}
<div id="top_home">
<div id="spin-wrapper"></div>
<div id="siteloader">
<div class="loader"></div>
</div>
{{ include("Shop._partials.slider") }}
{{ include("Shop._partials.block-banner") }}
{{ include("Shop._partials.block-products") }}
{{ include("Shop._partials.block-breadcrumb") }}
{{ include("Shop._partials.wrapper") }}
{{ include("Shop._partials.block-bottom")}}
{{ include("Shop._partials.footer")}}
</div>
</main>
<a id="slidetop" href="#" >&nbsp;</a>
<script type="text/javascript" src="theme.js" ></script>
</body>
</html>

View File

@@ -1,23 +0,0 @@
<div class="card">
<img src="{{ App\Repositories\Shop\Articles::getPreviewSrc($offer['article']['image'] ?? false) }}" class="card-img-top" alt="...">
<div class="card-body">
<span class="card-title">{{ $offer['article']['name'] }}</span>
<span class="pull-right">
<i class="fa fa-heart"></i>
</span>
<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>
</div>
</p>
</div>
</div>

View File

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

View File

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

6
routes/Shop/Offers.php Normal file
View File

@@ -0,0 +1,6 @@
<?php
Route::prefix('Offers')->name('Offers.')->group(function () {
Route::get('show/{id}', 'OfferController@show')->name('show');
});

View File

@@ -1,9 +1,10 @@
<?php
Route::prefix('Shop')->namespace('Shop')->name('Shop.')->group(function () {
include( __DIR__ . '/Articles.php');
include( __DIR__ . '/Categories.php');
include( __DIR__ . '/Customers.php');
include( __DIR__ . '/Invoices.php');
include( __DIR__ . '/Orders.php');
include( __DIR__ . '/Articles.php');
include( __DIR__ . '/Categories.php');
include( __DIR__ . '/Customers.php');
include( __DIR__ . '/Invoices.php');
include( __DIR__ . '/Offers.php');
include( __DIR__ . '/Orders.php');
});