Works for friday & saturday
This commit is contained in:
@@ -9,6 +9,7 @@ use App\Models\Shop\TagGroup;
|
||||
class TagGroupsDataTable extends DataTable
|
||||
{
|
||||
public $model_name = 'tag_groups';
|
||||
public $sortedColumn = 2;
|
||||
|
||||
public function query(TagGroup $model)
|
||||
{
|
||||
@@ -16,10 +17,29 @@ class TagGroupsDataTable extends DataTable
|
||||
return $this->buildQuery($model);
|
||||
}
|
||||
|
||||
public function modifier($datatables)
|
||||
{
|
||||
$datatables
|
||||
->editColumn('visible', function (TagGroup $tag_group) {
|
||||
return view("components.form.toggle", [
|
||||
'name' => 'visible',
|
||||
'value' => $tag_group->visible,
|
||||
'on' => __('oui'),
|
||||
'off' => __('non'),
|
||||
'meta' => 'data-id=' . $tag_group->id,
|
||||
'size' => 'sm',
|
||||
'class' => 'visible',
|
||||
]);
|
||||
})
|
||||
->rawColumns(['visible', 'action']);
|
||||
return parent::modifier($datatables);
|
||||
}
|
||||
|
||||
protected function getColumns()
|
||||
{
|
||||
return [
|
||||
Column::make('code')->title('Code'),
|
||||
Column::make('visible')->title('Visible')->width(60)->searchable(false),
|
||||
Column::make('code')->title('Code')->width(100),
|
||||
Column::make('name')->title('Nom'),
|
||||
Column::make('tags_count')->title('#Tags')->searchable(false)->addClass('text-right')->width(60),
|
||||
$this->makeColumnButtons(),
|
||||
|
||||
@@ -45,4 +45,11 @@ class TagGroupController extends Controller
|
||||
{
|
||||
return TagGroups::destroy($id);
|
||||
}
|
||||
|
||||
public function toggleVisible(Request $request)
|
||||
{
|
||||
$data = TagGroups::toggleVisible($request->input('id'), ($request->input('visible') == 'true') ? 1 : 0);
|
||||
return response()->json(['error' => 0]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,10 +23,16 @@ class CategoryController extends Controller
|
||||
$data = self::init();
|
||||
$data['display_by_rows'] = $by_rows;
|
||||
$data['category'] = Categories::getFull($category_id);
|
||||
$data['articles'] = Articles::getArticlesToSell(['category_id' => $category_id]);
|
||||
$data['tags_selected'] = request()->input('tags') ?? [];
|
||||
$data['articles'] = Articles::getArticlesToSell([
|
||||
'category_id' => $category_id,
|
||||
'tags' => $data['tags_selected'],
|
||||
]);
|
||||
// dump($data['articles']);
|
||||
// exit;
|
||||
$data['tags'] = TagGroups::getWithTagsAndCountOffers();
|
||||
$data['tags'] = TagGroups::getWithTagsAndCountOffers($category_id);
|
||||
// dump($data['tags']);
|
||||
// exit;
|
||||
return view('Shop.Shelves.shelve', $data);
|
||||
}
|
||||
|
||||
|
||||
20
app/Http/Controllers/Shop/SearchController.php
Normal file
20
app/Http/Controllers/Shop/SearchController.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Shop;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
use App\Repositories\Shop\Searches;
|
||||
|
||||
class SearchController extends Controller
|
||||
{
|
||||
public function search(Request $request)
|
||||
{
|
||||
$data = self::init();
|
||||
$data['articles'] = Searches::getResults($request->input());
|
||||
$data['articles_count'] = count($data['articles']);
|
||||
$data['search'] = $request->input();
|
||||
return view('Shop.Search.results', $data);
|
||||
}
|
||||
}
|
||||
@@ -89,6 +89,11 @@ class Article extends Model implements HasMedia
|
||||
return $query->where($this->table . '.name', 'LIKE', "%${str}%");
|
||||
}
|
||||
|
||||
public function scopeSearch($query, $str)
|
||||
{
|
||||
return $query->where($this->table . '.name', 'LIKE', "%${str}%");
|
||||
}
|
||||
|
||||
public function scopeByArticleNature($query, $id)
|
||||
{
|
||||
return $query->where($this->table . '.article_nature_id', $id);
|
||||
@@ -140,6 +145,15 @@ class Article extends Model implements HasMedia
|
||||
}) : $query;
|
||||
}
|
||||
|
||||
public function scopeByTagsSelected($query, $tags)
|
||||
{
|
||||
return $tags ? $query->whereHas('tags', function ($query) use ($tags) {
|
||||
foreach ($tags as $tag) {
|
||||
$query->where('id', $tag);
|
||||
}
|
||||
}) : $query;
|
||||
}
|
||||
|
||||
public function scopeWithOffers($query)
|
||||
{
|
||||
return $query->has('offers');
|
||||
|
||||
@@ -73,4 +73,11 @@ class Tag extends parentTag
|
||||
{
|
||||
return $query->where($this->table . '.tag_group_id', $id);
|
||||
}
|
||||
|
||||
public function scopeWithCountArticlesByCategory($query, $category_id)
|
||||
{
|
||||
return $query->withCount(['articles' => function($query) use ($category_id) {
|
||||
$query->byCategoryParent($category_id);
|
||||
}]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,4 +18,9 @@ class TagGroup extends Model
|
||||
{
|
||||
return $this->belongsTo(ArticleNature::class);
|
||||
}
|
||||
|
||||
public function scopeVisible($query)
|
||||
{
|
||||
return $query->where('visible', 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ class Articles
|
||||
case 'App\Models\Botanic\Variety':
|
||||
$variety = $article->product;
|
||||
$specie = $variety->specie;
|
||||
$description = $specie->description . $variety->description;
|
||||
$description = $specie->description . $variety->description;
|
||||
break;
|
||||
case 'App\Models\Botanic\Specie':
|
||||
$specie = $article->product;
|
||||
@@ -160,6 +160,9 @@ class Articles
|
||||
$data[$article->name][$article_nature_name] = self::getDataPriceForSale($article, $prices);
|
||||
}
|
||||
}
|
||||
if ($data ?? false) {
|
||||
ksort($data);
|
||||
}
|
||||
return $data ?? false;
|
||||
}
|
||||
|
||||
@@ -189,13 +192,9 @@ class Articles
|
||||
|
||||
public static function getArticlesWithOffers($options = false)
|
||||
{
|
||||
$category_id = $options['category_id'] ?? false;
|
||||
$sale_channel_id = $options['sale_channel_id'] ?? SaleChannels::getDefaultID();
|
||||
$tags = $options['tags'] ?? false;
|
||||
$model = ($options['homepage'] ?? false) ? Article::homepage()->visible() : Article::visible();
|
||||
|
||||
// exit;
|
||||
$data = $model->byCategoryParent($category_id)->byTags($tags)->withAvailableOffers($sale_channel_id)->with([
|
||||
$model = self::getModelByOptions($options);
|
||||
$data = $model->withAvailableOffers($sale_channel_id)->with([
|
||||
'image',
|
||||
'product',
|
||||
'article_nature',
|
||||
@@ -214,6 +213,21 @@ class Articles
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function getModelByOptions($options = false)
|
||||
{
|
||||
$category_id = $options['category_id'] ?? false;
|
||||
$search = $options['search'] ?? false;
|
||||
$tags = $options['tags'] ?? false;
|
||||
$article_nature_id = $options['article_nature_id'] ?? false;
|
||||
|
||||
$model = ($options['homepage'] ?? false) ? Article::homepage()->visible() : Article::visible();
|
||||
$model = $category_id ? $model->byCategoryParent($category_id) : $model;
|
||||
$model = $tags ? $model->byTagsSelected($tags) : $model;
|
||||
$model = $search ? $model->search($search) : $model;
|
||||
$model = $article_nature_id ? $model->byArticleNature($article_nature_id) : $model;
|
||||
return $model;
|
||||
}
|
||||
|
||||
public static function getFull($id)
|
||||
{
|
||||
$data['article'] = self::getArticleEdit($id);
|
||||
|
||||
14
app/Repositories/Shop/Searches.php
Normal file
14
app/Repositories/Shop/Searches.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use App\Models\Shop\Article;
|
||||
|
||||
class Searches
|
||||
{
|
||||
public static function getResults($options)
|
||||
{
|
||||
$data = Articles::getArticlesToSell($options);
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
@@ -16,9 +16,7 @@ class TagGroups
|
||||
|
||||
public static function getWithTagsAndCountOffers($category_id = false)
|
||||
{
|
||||
$tags = Tag::withCount(['articles' => function($query) use ($category_id) {
|
||||
$query->byCategory($category_id);
|
||||
}])->get()->toArray();
|
||||
$tags = Tag::withCountArticlesByCategory($category_id)->get()->toArray();
|
||||
$tag_groups = TagGroup::pluck('name', 'id')->toArray();
|
||||
foreach ($tags as $tag) {
|
||||
$data[$tag['tag_group_id']]['name'] = $tag_groups[$tag['tag_group_id']];
|
||||
@@ -82,7 +80,9 @@ class TagGroups
|
||||
{
|
||||
$id = $id ? $id : $data['id'];
|
||||
$model = self::get($id);
|
||||
$data['slug'] = Str::slug($data['name']);
|
||||
if ($data['name'] ?? false) {
|
||||
$data['slug'] = Str::slug($data['name']);
|
||||
}
|
||||
$model->update($data);
|
||||
return $model;
|
||||
}
|
||||
@@ -91,4 +91,9 @@ class TagGroups
|
||||
{
|
||||
return TagGroup::destroy($id);
|
||||
}
|
||||
|
||||
public static function toggleVisible($id, $visible)
|
||||
{
|
||||
return self::update(['visible' => $visible], $id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ class Tags
|
||||
|
||||
public static function getTagHtml($tag)
|
||||
{
|
||||
return '<span class="btn btn-xs btn-secondary pb-2">' . self::getFullnameByTag($tag) . '</span>';
|
||||
return '<span class="btn btn-xs btn-secondary pb-2 mr-2 mb-2">' . self::getFullnameByTag($tag) . '</span>';
|
||||
}
|
||||
|
||||
public static function getOptions()
|
||||
|
||||
Reference in New Issue
Block a user