Add method to get offers by articles with siblings, enhance display
This commit is contained in:
@@ -53,13 +53,13 @@ var jsCoreInclude = [
|
||||
'build/js/include/form/upload.js',
|
||||
'build/js/include/form/validator.js',
|
||||
'build/js/include/layout/animate.js',
|
||||
'build/js/include/layout/message.js',
|
||||
// 'build/js/include/layout/message.js',
|
||||
// 'build/js/include/layout/modal.js',
|
||||
'build/js/include/layout/scroll.js',
|
||||
'build/js/include/layout/tooltip.js',
|
||||
// 'build/js/include/datatable.js',
|
||||
'build/js/include/file.js',
|
||||
'build/js/include/uploader.js',
|
||||
// 'build/js/include/file.js',
|
||||
// 'build/js/include/uploader.js',
|
||||
]
|
||||
|
||||
var jsBundle = [
|
||||
|
||||
@@ -13,9 +13,9 @@ class ArticleController extends Controller
|
||||
public function show($id)
|
||||
{
|
||||
$data = self::init();
|
||||
$data['article'] = Articles::getArticle($id);
|
||||
// dump($data);
|
||||
// exit;
|
||||
$data['article'] = Articles::getArticleToSell($id);
|
||||
dump($data);
|
||||
exit;
|
||||
return view('Shop.Articles.show', $data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,6 +50,11 @@ class Article extends Model implements HasMedia
|
||||
return $this->morphTo();
|
||||
}
|
||||
|
||||
public function siblings()
|
||||
{
|
||||
return $this->hasMany(Article::class, 'name', 'name');
|
||||
}
|
||||
|
||||
public function tags()
|
||||
{
|
||||
return $this->morphToMany(Tag::class, 'taggable');
|
||||
|
||||
@@ -4,11 +4,12 @@ namespace App\Models\Shop;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
use Znck\Eloquent\Traits\BelongsToThrough;
|
||||
use App\Traits\Model\HasComments;
|
||||
|
||||
class Offer extends Model
|
||||
{
|
||||
use HasComments;
|
||||
use BelongsToThrough, HasComments;
|
||||
|
||||
protected $guarded = ['id'];
|
||||
protected $table = 'shop_offers';
|
||||
@@ -18,6 +19,14 @@ class Offer extends Model
|
||||
return $this->belongsTo(Article::class);
|
||||
}
|
||||
|
||||
public function article_nature()
|
||||
{
|
||||
return $this->belongsToThrough(ArticleNature::class, Article::class, null, '', [
|
||||
'App\Models\Shop\Article' => 'article_id',
|
||||
'App\Models\Shop\ArticleNature' => 'article_nature_id',
|
||||
]);
|
||||
}
|
||||
|
||||
public function tariff()
|
||||
{
|
||||
return $this->belongsTo(Tariff::class);
|
||||
@@ -63,6 +72,11 @@ class Offer extends Model
|
||||
return $query->where($this->table . '.article_id', $id);
|
||||
}
|
||||
|
||||
public function scopeByArticles($query, $ids)
|
||||
{
|
||||
return $query->whereIn($this->table . '.article_id', $ids);
|
||||
}
|
||||
|
||||
public function scopeByOffer($query, $id)
|
||||
{
|
||||
return $query->where($this->table . '.id', $id);
|
||||
|
||||
@@ -27,6 +27,35 @@ class Articles
|
||||
return $export;
|
||||
}
|
||||
|
||||
public static function getOffersGroupedByNature($id)
|
||||
{
|
||||
$article_ids = self::getSiblingsIds($id);
|
||||
$offers = Offers::getOffersByArticles($article_ids);
|
||||
dump($offers->toArray());
|
||||
foreach ($offers as $offer) {
|
||||
$data[$offer->article_nature->name][] = [
|
||||
'name' => $offer->variation->name,
|
||||
'tariff' => $offer->tariff,
|
||||
];
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function getSiblingsIDs($id)
|
||||
{
|
||||
return self::getSiblings($id)->pluck('id')->toArray();
|
||||
}
|
||||
|
||||
public static function getSiblings($id)
|
||||
{
|
||||
return Article::with('siblings')->find($id)->siblings;
|
||||
}
|
||||
|
||||
public static function getOffersById($id)
|
||||
{
|
||||
return Offers::getOffersByArticle($id);
|
||||
}
|
||||
|
||||
public static function getOptions()
|
||||
{
|
||||
return Article::orderBy('name', 'asc')->pluck('name', 'id')->toArray();
|
||||
@@ -47,6 +76,20 @@ class Articles
|
||||
return Article::orderBy('name', 'asc')->get();
|
||||
}
|
||||
|
||||
public static function getArticleToSell($id)
|
||||
{
|
||||
$article = self::get($id);
|
||||
$data = $article->toArray();
|
||||
$data['description'] = (!empty($article->description)) ? $article->description : $article->product->description;
|
||||
$data['image'] = self::getPreview($article->image);
|
||||
$data['image_big'] = self::getImage($article->image);
|
||||
$data['inherited'] = self::getInherited($id);
|
||||
$data['categories'] = self::getCategoriesNameByArticle($article);
|
||||
$data['tags'] = self::getTagsSlugByArticle($article);
|
||||
$data['offers'] = self::getOffersById($id)->toArray();
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function getArticle($id)
|
||||
{
|
||||
$article = self::get($id);
|
||||
|
||||
@@ -7,6 +7,16 @@ use App\Models\Shop\Offer;
|
||||
class Offers
|
||||
{
|
||||
|
||||
public static function getOffersByArticles($articles_id)
|
||||
{
|
||||
return Offer::active()->with(['article_nature', 'tariff.price_lists.price_list_values', 'variation'])->byArticles($articles_id)->get();
|
||||
}
|
||||
|
||||
public static function getOffersByArticle($article_id)
|
||||
{
|
||||
return Offer::active()->with('variation')->byArticle($article_id)->get();
|
||||
}
|
||||
|
||||
public static function getThumbSrcById($id)
|
||||
{
|
||||
return self::getThumbSrc(self::get($id));
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
"alexisgeneau/mailvalidate": "dev-master",
|
||||
"arcanedev/log-viewer": "^8.1",
|
||||
"arrilot/laravel-widgets": "^3.13",
|
||||
"awobaz/compoships": "^2.1",
|
||||
"barryvdh/laravel-dompdf": "^0.9",
|
||||
"barryvdh/laravel-snappy": "^0.4.7",
|
||||
"bencoderus/min-auth": "^1.0",
|
||||
|
||||
@@ -54,5 +54,7 @@
|
||||
"cancel": "Annuler",
|
||||
"save": "Sauver",
|
||||
"comments": "Notes internes",
|
||||
"comment_add": "Ajout de Note interne"
|
||||
"comment_add": "Ajout de Note interne",
|
||||
"apply": "Appliquer",
|
||||
"close": "Fermer"
|
||||
}
|
||||
@@ -8,7 +8,7 @@
|
||||
<div class="card-body">
|
||||
<div class="row card-title">
|
||||
<div class="col-10" style="font-weight: bold; color: green;">
|
||||
<h2 style="font-size: 1.4em;">{{ $article['parent_name'] }}</h2>
|
||||
<h2 style="font-size: 1.3em;">{{ $article['parent_name'] }}</h2>
|
||||
{{ $article['product_name'] }}
|
||||
</div>
|
||||
<div class="col-2 p-0 text-right" style="font-size: 2em; color: red;">
|
||||
|
||||
@@ -1,55 +1,49 @@
|
||||
<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 class="row pb-3" style="background-color: #CCC;">
|
||||
<div class="col-8">
|
||||
<div class="row pt-2">
|
||||
<div class="col-10">
|
||||
<a href="{{ route('Shop.Articles.show', ['id' => $article['semences']['article_id'] ?? false ]) }}" class="text-decoration-none">
|
||||
<div style="font-weight: bold; color: green; font-size: 1.5em;">{{ $product_name }}</div>
|
||||
</a>
|
||||
</div>
|
||||
<div class="col-2 text-right">
|
||||
<span style="font-size: 2em; color: red;">
|
||||
<i class="fa fa-heart"></i>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-12">
|
||||
<a href="{{ route('Shop.Articles.show', ['id' => $article['semences']['article_id'] ?? false ]) }}" class="text-decoration-none">
|
||||
<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 class="col-2">
|
||||
<img src="{{ App\Repositories\Shop\Articles::getPreviewSrc($article['image'] ?? false) }}" class="card-img-top" alt="...">
|
||||
</div>
|
||||
<div class="col-10">
|
||||
{!! $article['description'] !!}
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
<div class="col-4">
|
||||
<div class="row h-100" style="color: green; display: flex;">
|
||||
<div class="col-6 text-center" style="background-color: rgba(0,128,0,0.3); margin: auto;">
|
||||
@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>
|
||||
</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>
|
||||
@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>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
<div class="row">
|
||||
<div class="col-6">
|
||||
<button type="button" class="btn btn-success">
|
||||
<i class="fa fa-2x fa-seedling"></i>
|
||||
<i class="fa fa-3x fa-seedling float-left"></i>
|
||||
Ajouter au panier la liste des <strong>semences</strong>
|
||||
</button>
|
||||
</div>
|
||||
<div class="col-6">
|
||||
<button type="button" class="btn btn-warning">
|
||||
<i class="fab fa-2x fa-pagelines"></i>
|
||||
<i class="fab fa-3x fa-pagelines float-left"></i>
|
||||
Ajouter au panier la liste des <strong>plants</strong>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user