Pizzeria Arcobaleno
Indische vegetarische Gerichte
Indische Hähnchengerichte
getLanguageCode() ?? 'en')
);
$businessData = is_array($business ?? null)
? $business
: [];
$businessId = (int) ($businessData['id'] ?? 0);
$homeProducts = [];
$categoryCodes = [];
/*
|--------------------------------------------------------------------------
| DATABASE
|--------------------------------------------------------------------------
|
| KEEP THIS ENTIRE SECTION UNCHANGED.
|
| DO NOT MODIFY THE QUERY.
|
*/
if ($businessId > 0) {
$db = db_connect();
$language = $db->table('languages')
->where('language_code', $lang)
->where('is_active', 1)
->get()
->getRowArray();
if ($language === null) {
$language = $db->table('languages')
->where('language_code', 'de')
->where('is_active', 1)
->get()
->getRowArray();
}
$languageId = (int) ($language['id'] ?? 0);
$products = $db->table('products p')
->select(
'p.id,
p.product_code,
p.sku,
p.food_type,
p.spice_level,
p.is_bestseller,
p.is_new,
p.is_today_special,
p.is_offer,
p.is_combo,
p.is_dessert,
p.is_drink,
p.is_chef_special,
p.is_recommended,
pt.name,
pt.slug,
c.category_code,
ct.category_name'
)
->join(
'product_translations pt',
'pt.product_id = p.id
AND pt.language_id = ' . $languageId,
'left'
)
->join(
'categories c',
'c.id = p.category_id',
'left'
)
->join(
'category_translations ct',
'ct.category_id = c.id
AND ct.language_id = ' . $languageId,
'left'
)
->where('p.business_id', $businessId)
->where('p.is_active', 1)
->where('p.is_available', 1)
->where('p.deleted_at', null)
->orderBy(
'CAST(p.sku AS UNSIGNED)',
'ASC',
false
)
->orderBy('p.id')
->get()
->getResultArray();
if ($products !== []) {
$productIds = array_map(
static fn(array $product): int => (int) $product['id'],
$products
);
$productVariants = [];
$variantRows = $db->table('product_variants pv')
->select(
'
pv.id,
pv.product_id,
pv.variant_value_id,
pv.price,
pv.sort_order,
vv.value_code,
vvt.name
'
)
->join(
'variant_values vv',
'vv.id = pv.variant_value_id',
'left'
)
->join(
'variant_value_translations vvt',
'vvt.variant_value_id = vv.id
AND vvt.language_id = ' . $languageId,
'left'
)
->whereIn('pv.product_id', $productIds)
->where('pv.is_active', 1)
->orderBy('pv.product_id')
->orderBy('pv.sort_order')
->get()
->getResultArray();
foreach ($variantRows as $row) {
$productVariants[$row['product_id']][] = [
'variant_id' => (int) $row['id'],
'variant_value_id' => (int) $row['variant_value_id'],
'price' => (float) $row['price'],
'sort_order' => (int) $row['sort_order'],
'code' => $row['value_code'],
'name' => !empty($row['name'])
? $row['name']
: $row['value_code'],
];
}
/*
|--------------------------------------------------------------------------
| PRODUCT VARIANTS
|--------------------------------------------------------------------------
|
| Minimum price
| Number of variants
|
*/
$variantRows = $db->table('product_variants')
->select(
'product_id,
MIN(price) AS minimum_price,
COUNT(id) AS variant_count',
false
)
->whereIn('product_id', $productIds)
->where('is_active', 1)
->where('deleted_at', null)
->groupBy('product_id')
->get()
->getResultArray();
$variantData = [];
foreach ($variantRows as $variantRow) {
$variantData[(int) $variantRow['product_id']] = [
'price' => isset($variantRow['minimum_price'])
? (float) $variantRow['minimum_price']
: null,
'count' => (int) ($variantRow['variant_count'] ?? 0),
];
}
/*
|--------------------------------------------------------------------------
| PRODUCT IMAGES
|--------------------------------------------------------------------------
*/
$mediaRows = $db->table('media_links ml')
->select(
'ml.record_id,
ml.is_primary,
ml.display_order,
ml.id AS link_id,
m.public_url,
m.relative_path,
m.thumbnail_path'
)
->join(
'media m',
'm.id = ml.media_id',
'inner'
)
->where('ml.module_name', 'products')
->whereIn('ml.record_id', $productIds)
->where('ml.is_active', 1)
->where('ml.deleted_at', null)
->where('m.is_active', 1)
->where('m.is_public', 1)
->where('m.deleted_at', null)
->orderBy('ml.record_id', 'ASC')
->orderBy('ml.is_primary', 'DESC')
->orderBy('ml.display_order', 'ASC')
->orderBy('ml.id', 'ASC')
->get()
->getResultArray();
$mediaByProduct = [];
foreach ($mediaRows as $mediaRow) {
$productId = (int) $mediaRow['record_id'];
if (!isset($mediaByProduct[$productId])) {
$mediaByProduct[$productId] = $mediaRow;
}
}
/*
|--------------------------------------------------------------------------
| BUILD HOME PRODUCT ARRAY
|--------------------------------------------------------------------------
*/
foreach ($products as $product) {
$productId = (int) $product['id'];
$media = $mediaByProduct[$productId] ?? [];
$categoryCode = trim(
(string) ($product['category_code'] ?? '')
);
$categoryName = trim(
(string) (
$product['category_name']
?? $categoryCode
)
);
/*
|--------------------------------------------------------------------------
| CATEGORY LIST
|--------------------------------------------------------------------------
*/
if ($categoryCode !== '') {
$categoryCodes[$categoryCode] = $categoryName;
}
/*
|--------------------------------------------------------------------------
| PRODUCT IMAGE
|--------------------------------------------------------------------------
*/
$imagePath = trim((string)(
$media['thumbnail_path']
?? $media['public_url']
?? $media['relative_path']
?? ''
));
/*
|--------------------------------------------------------------------------
| PRODUCT RECORD
|--------------------------------------------------------------------------
*/
$homeProducts[] = [
'id' => $productId,
'menu_code' => trim(
(string) ($product['sku'] ?? '')
),
'product_code' => trim(
(string) ($product['product_code'] ?? '')
),
'name' => trim(
(string) (
$product['name']
?? $product['product_code']
?? ''
)
),
'slug' => trim(
(string) ($product['slug'] ?? '')
),
'category_code' => $categoryCode,
'category_name' => $categoryName,
/*
|--------------------------------------------------------------------------
| PRODUCT ATTRIBUTES
|--------------------------------------------------------------------------
*/
'food_type' => trim(
(string) ($product['food_type'] ?? 'non_veg')
),
'spice_level' => trim(
(string) ($product['spice_level'] ?? 'none')
),
'is_bestseller' => (int) ($product['is_bestseller'] ?? 0),
'is_new' => (int) ($product['is_new'] ?? 0),
'is_today_special' => (int) ($product['is_today_special'] ?? 0),
'is_offer' => (int) ($product['is_offer'] ?? 0),
'is_combo' => (int) ($product['is_combo'] ?? 0),
'is_dessert' => (int) ($product['is_dessert'] ?? 0),
'is_drink' => (int) ($product['is_drink'] ?? 0),
'is_chef_special' => (int) ($product['is_chef_special'] ?? 0),
'is_recommended' => (int) ($product['is_recommended'] ?? 0),
/*
|--------------------------------------------------------------------------
| PRICE
|--------------------------------------------------------------------------
*/
'price' =>
$variantData[$productId]['price']
?? null,
/*
|--------------------------------------------------------------------------
| VARIANTS
|--------------------------------------------------------------------------
*/
'variant_count' =>
(int) (
$variantData[$productId]['count']
?? 0
),
'variants' =>
$productVariants[$productId]
?? [],
/*
|--------------------------------------------------------------------------
| PRODUCT IMAGE
|--------------------------------------------------------------------------
*/
'image' =>
$imagePath !== ''
? base_url(ltrim($imagePath, '/'))
: '',
];
}
}
}
/*
|--------------------------------------------------------------------------
| SORT CATEGORIES
|--------------------------------------------------------------------------
*/
asort(
$categoryCodes,
SORT_NATURAL | SORT_FLAG_CASE
);
/*
|--------------------------------------------------------------------------
| PRODUCT COUNT
|--------------------------------------------------------------------------
*/
$productCount = count($homeProducts);
?>