Files
opensem/app/Repositories/Shop/Shelves.php
2023-12-09 21:02:28 +01:00

48 lines
1.7 KiB
PHP

<?php
namespace App\Repositories\Shop;
class Shelves
{
public static function getOffersByCategoryAndNature($categoryId, $articleNatureId = false, $tags = [], $articleNature = false, $displayByRows = false)
{
$productTypes = Articles::getProductTypesWithOffers([
'category_id' => $categoryId,
]);
$articleNatures = Articles::getArticleNaturesWithOffers([
'category_id' => $categoryId,
]);
if ($articleNatureId) {
$productType = ArticleNatures::getProductType($articleNatureId);
} else {
if (! $articleNature) {
if (count($articleNatures)) {
$articleNature = $articleNatures[0];
}
}
$productType = ArticleNatures::getProductTypeBySlug($articleNature);
$articleNatureId = ArticleNatures::getIdBySlug($articleNature);
}
return [
'category' => Categories::getFull($categoryId),
'breadcrumb' => Categories::getAncestorsByCategory($categoryId),
'display_by_rows' => $displayByRows,
'product_type' => $productType,
'article_nature' => $articleNature,
'article_natures' => $articleNatures ?? [],
'product_types' => $productTypes ?? [],
'tags_selected' => $tags,
'articles' => Articles::getArticlesToSell([
'category_id' => $categoryId,
'tags' => $tags,
'product_type' => $productType ?? false,
'article_nature_id' => $articleNatureId ?? false,
]),
'tags' => TagGroups::getWithTagsAndCountOffers($categoryId),
];
}
}