Fix on data for article, problem with id on polymorphic
This commit is contained in:
@@ -20,10 +20,10 @@ class HomeController extends Controller
|
||||
{
|
||||
$data = self::init();
|
||||
// $data['offers'] = Offers::getLast()->toArray();
|
||||
$data['articles'] = Articles::getArticlesWithOffers()->toArray();
|
||||
$data['articles'] = Articles::getArticlesToSell();
|
||||
// $data['prices'] = $data['articles']['offers'][0]['tariff']['price_lists'][0]['price_list_values'][0];
|
||||
dump($data);
|
||||
exit;
|
||||
// dump($data);
|
||||
// exit;
|
||||
return view('Shop.home', $data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,17 +62,42 @@ class Articles
|
||||
public static function getArticlesToSell()
|
||||
{
|
||||
$articles = self::getArticlesWithOffers();
|
||||
// dump($articles->toArray());
|
||||
foreach ($articles as $article) {
|
||||
$data[$article->article_nature->name][$article->name][] = [
|
||||
'description' => $article->description,
|
||||
];
|
||||
$price_lists = $article->offers[0]->tariff->price_lists->toArray();
|
||||
// dump($price_lists);
|
||||
if (count($price_lists)) {
|
||||
$data[$article->name] = [
|
||||
'description' => (!empty($article->description)) ? $article->description : $article->product->description,
|
||||
'image' => $article->image,
|
||||
'product_type' => $article->product_type,
|
||||
'product_id' => $article->product_id,
|
||||
];
|
||||
$prices = $price_lists[0]['price_list_values'][0];
|
||||
$article_nature_name = strtolower($article->article_nature->name);
|
||||
// dump($prices);
|
||||
$data[$article->name][$article_nature_name] = [
|
||||
'article_id' => $article->id,
|
||||
'offer_id' => $article->offers[0]->id,
|
||||
'quantity' => $prices['quantity'],
|
||||
'price' => $prices['price_taxed'],
|
||||
];
|
||||
}
|
||||
}
|
||||
// dump($data);
|
||||
// exit;
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function getArticlesWithOffers()
|
||||
{
|
||||
return Article::visible()->withAvailableOffers()->with(['image', 'article_nature', 'offers.tariff.price_lists.price_list_values'])->get();
|
||||
return Article::visible()->withAvailableOffers()->with([
|
||||
'image',
|
||||
'product',
|
||||
'article_nature',
|
||||
'offers.variation',
|
||||
'offers.tariff.price_lists.price_list_values',
|
||||
])->get();
|
||||
}
|
||||
|
||||
public static function getFull($id)
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateStatsTables extends Migration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
Schema::create('stats_events', function (Blueprint $table) {
|
||||
$table->id();
|
||||
|
||||
$table->string('name');
|
||||
$table->string('type');
|
||||
$table->bigInteger('value');
|
||||
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
<a href="{{ route('Shop.Articles.show', ['id' => $article['id']]) }}">
|
||||
<a href="{{ route('Shop.Articles.show', ['id' => $article['semences']['article_id'] ?? false ]) }}">
|
||||
<div class="card">
|
||||
<img src="{{ App\Repositories\Shop\Articles::getPreviewSrc($article['image'] ?? false) }}" class="card-img-top" alt="...">
|
||||
<div class="card-body">
|
||||
<span class="card-title">{{ $article['name'] }}</span>
|
||||
<span class="card-title">{{ $product_name }}</span>
|
||||
<span class="pull-right">
|
||||
<i class="fa fa-heart"></i>
|
||||
</span>
|
||||
@@ -10,14 +10,15 @@
|
||||
<p class="card-text">
|
||||
<div class="row">
|
||||
<div class="col-6">
|
||||
3.50 €<br>
|
||||
{{ $article['semences']['price'] ?? null }}<br>
|
||||
Semence
|
||||
</div>
|
||||
|
||||
<div class="col-6">
|
||||
1.65 €<br>
|
||||
Plant
|
||||
</div>
|
||||
@if ($article['plants'] ?? false)
|
||||
<div class="col-6">
|
||||
{{ $article['plants']['price'] }}<br>
|
||||
Plant
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<div class="row">
|
||||
@foreach ($articles as $article)
|
||||
@foreach ($articles as $product_name => $article)
|
||||
<div class="col-sm-3 col-lg-2">
|
||||
@include('Shop.Articles.partials.article')
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user