add methods to detect distinct product type et article nature on shelve
This commit is contained in:
@@ -62,6 +62,12 @@ class CategoryController extends Controller
|
|||||||
'display_by_rows' => $request->input('display_by_rows') ?? false,
|
'display_by_rows' => $request->input('display_by_rows') ?? false,
|
||||||
'product_type' => $product_type,
|
'product_type' => $product_type,
|
||||||
'article_nature' => $article_nature,
|
'article_nature' => $article_nature,
|
||||||
|
'article_natures' => Articles::getArticleNaturesWithOffers([
|
||||||
|
'category_id' => $category_id,
|
||||||
|
]),
|
||||||
|
'product_types' => Articles::getProductTypesWithOffers([
|
||||||
|
'category_id' => $category_id,
|
||||||
|
]),
|
||||||
'tags_selected' => $request->input('tags') ?? [],
|
'tags_selected' => $request->input('tags') ?? [],
|
||||||
'articles' => Articles::getArticlesToSell([
|
'articles' => Articles::getArticlesToSell([
|
||||||
'category_id' => $category_id,
|
'category_id' => $category_id,
|
||||||
@@ -71,8 +77,6 @@ class CategoryController extends Controller
|
|||||||
]),
|
]),
|
||||||
'tags' => TagGroups::getWithTagsAndCountOffers($category_id),
|
'tags' => TagGroups::getWithTagsAndCountOffers($category_id),
|
||||||
];
|
];
|
||||||
// dump($data);
|
|
||||||
// exit;
|
|
||||||
return view('Shop.Shelves.shelve', $data);
|
return view('Shop.Shelves.shelve', $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,4 +39,9 @@ class ArticleNature extends Model
|
|||||||
{
|
{
|
||||||
return $query->where($this->table . '.product_type', $type);
|
return $query->where($this->table . '.product_type', $type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function scopeByIds($query, $ids)
|
||||||
|
{
|
||||||
|
return $query->whereIn($this->table . '.id', $ids);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,11 @@ class ArticleNatures
|
|||||||
return $type ? self::getProductTypes()[$type] : false;
|
return $type ? self::getProductTypes()[$type] : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getProductTypeNameByClass($model)
|
||||||
|
{
|
||||||
|
return self::getProductTypeName(self::getProductTypeByModel($model));
|
||||||
|
}
|
||||||
|
|
||||||
public static function getProductTypeName($type)
|
public static function getProductTypeName($type)
|
||||||
{
|
{
|
||||||
return self::getProductTypes()[$type] ?? false;
|
return self::getProductTypes()[$type] ?? false;
|
||||||
@@ -30,16 +35,12 @@ class ArticleNatures
|
|||||||
{
|
{
|
||||||
switch ($model) {
|
switch ($model) {
|
||||||
case Specie::class:
|
case Specie::class:
|
||||||
$type = 1;
|
|
||||||
break;
|
|
||||||
case Variety::class:
|
case Variety::class:
|
||||||
$type = 1;
|
return 1;
|
||||||
break;
|
|
||||||
case Merchandise::class:
|
case Merchandise::class:
|
||||||
$type = 2;
|
return 2;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
return $type ?? false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getProductTypes()
|
public static function getProductTypes()
|
||||||
@@ -83,6 +84,12 @@ class ArticleNatures
|
|||||||
return ArticleNature::orderBy('name', 'asc')->get();
|
return ArticleNature::orderBy('name', 'asc')->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getNamesByIds($ids)
|
||||||
|
{
|
||||||
|
$names = ArticleNature::byIds($ids)->pluck('name')->toArray();
|
||||||
|
return array_map('strtolower', $names);
|
||||||
|
}
|
||||||
|
|
||||||
public static function get($id)
|
public static function get($id)
|
||||||
{
|
{
|
||||||
return ArticleNature::find($id);
|
return ArticleNature::find($id);
|
||||||
|
|||||||
@@ -194,7 +194,8 @@ class Articles
|
|||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'id' => $article->id,
|
'id' => $article->id,
|
||||||
'description' => (!empty($article->description)) ? $article->description : $article->product->description,
|
'article_nature_id' => $article->article_nature_id,
|
||||||
|
'description' => $article->description ? $article->description : $article->product->description,
|
||||||
'image' => self::getFullImageByArticle($article),
|
'image' => self::getFullImageByArticle($article),
|
||||||
'product_type' => $article->product_type,
|
'product_type' => $article->product_type,
|
||||||
'product_id' => $article->product_id,
|
'product_id' => $article->product_id,
|
||||||
@@ -238,6 +239,38 @@ class Articles
|
|||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getArticleNaturesWithOffers($options = false)
|
||||||
|
{
|
||||||
|
return ArticleNatures::getNamesByIds(self::getArticleNaturesIdsWithOffers($options));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getArticleNaturesIdsWithOffers($options = false)
|
||||||
|
{
|
||||||
|
$sale_channel_id = $options['sale_channel_id'] ?? SaleChannels::getDefaultID();
|
||||||
|
$model = self::getModelByOptions($options);
|
||||||
|
$data = $model->withAvailableOffers($sale_channel_id)->get()->pluck('article_nature_id')->unique();
|
||||||
|
return array_values($data->toArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getProductTypesWithOffers($options = false)
|
||||||
|
{
|
||||||
|
$data = [];
|
||||||
|
$classes = self::getProductTypesClassesWithOffers($options);
|
||||||
|
foreach ($classes as $class) {
|
||||||
|
$type = ArticleNatures::getProductTypeNameByClass($class);
|
||||||
|
$data[$type] = true;
|
||||||
|
}
|
||||||
|
return array_keys($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getProductTypesClassesWithOffers($options = false)
|
||||||
|
{
|
||||||
|
$sale_channel_id = $options['sale_channel_id'] ?? SaleChannels::getDefaultID();
|
||||||
|
$model = self::getModelByOptions($options);
|
||||||
|
$data = $model->withAvailableOffers($sale_channel_id)->get()->pluck('product_type')->unique();
|
||||||
|
return $data->toArray();
|
||||||
|
}
|
||||||
|
|
||||||
public static function getModelByOptions($options = false)
|
public static function getModelByOptions($options = false)
|
||||||
{
|
{
|
||||||
$category_id = $options['category_id'] ?? false;
|
$category_id = $options['category_id'] ?? false;
|
||||||
|
|||||||
Reference in New Issue
Block a user