SELECT
SQL_CALC_FOUND_ROWS products.product_id,
IF(
shared_descr.product_id IS NOT NULL,
shared_descr.product, descr1.product
) as product,
IF(
products.age_verification = 'Y',
'Y',
IF(
cscart_categories.age_verification = 'Y',
'Y', cscart_categories.parent_age_verification
)
) as need_age_verification,
IF(
products.age_limit > cscart_categories.age_limit,
IF(
products.age_limit > cscart_categories.parent_age_limit,
products.age_limit, cscart_categories.parent_age_limit
),
IF(
cscart_categories.age_limit > cscart_categories.parent_age_limit,
cscart_categories.age_limit, cscart_categories.parent_age_limit
)
) as age_limit
FROM
cscart_products as products
LEFT JOIN cscart_product_descriptions as descr1 ON descr1.product_id = products.product_id
AND descr1.lang_code = 'de'
LEFT JOIN cscart_product_prices as prices ON prices.product_id = products.product_id
AND prices.lower_limit = 1
INNER JOIN cscart_products_categories as products_categories ON products_categories.product_id = products.product_id
INNER JOIN cscart_categories ON cscart_categories.category_id = products_categories.category_id
AND (
cscart_categories.usergroup_ids = ''
OR FIND_IN_SET(
0, cscart_categories.usergroup_ids
)
OR FIND_IN_SET(
1, cscart_categories.usergroup_ids
)
)
AND cscart_categories.status IN ('A', 'H')
LEFT JOIN cscart_ult_product_descriptions shared_descr ON shared_descr.product_id = products.product_id
AND shared_descr.company_id = 1
AND shared_descr.lang_code = 'de'
LEFT JOIN cscart_product_required_products ON products.product_id = cscart_product_required_products.required_id
WHERE
1
AND cscart_categories.company_id = 1
AND (
products.usergroup_ids = ''
OR FIND_IN_SET(0, products.usergroup_ids)
OR FIND_IN_SET(1, products.usergroup_ids)
)
AND products.status IN ('A')
AND prices.usergroup_id IN (0, 0, 1)
AND cscart_product_required_products.product_id = 1554
GROUP BY
products.product_id
ORDER BY
product asc,
products.product_id ASC