Enhill Posted June 3, 2019 Report Share Posted June 3, 2019 (edited) Добрый день. Очень нужна ваша помощь.Вывожу акционные товары в шаблоне products.tpl с помощью GET параметра: if (!empty($type) && !$brand) { $query = $this->db->placehold(" SELECT c.name, count(pc.product_id) as products_count, c.parent_id, c.id, c.url FROM __products_categories pc LEFT JOIN __categories c ON c.id=pc.category_id INNER JOIN __products p ON p.id=pc.product_id AND pc.position=(SELECT MIN(pc2.position) FROM __products_categories pc2 WHERE pc.product_id=pc2.product_id) WHERE 1 AND p.visible=1 AND (SELECT 1 FROM __variants pv WHERE pv.product_id=p.id AND pv.compare_price>0 LIMIT 1) = 1 AND (SELECT count(*)>0 FROM __variants pv WHERE pv.product_id=p.id AND pv.price>0 AND (pv.stock IS NULL OR pv.stock>0) LIMIT 1) = 1 GROUP BY pc.category_id ORDER BY products_count DESC"); $this->db->query($query); $results_categories = $this->db->results(); foreach($results_categories as &$u) { $u->url .= '?type=actions'; } https://site.ru/category_name?type=actions Как сделать условие в шаблоне products.tpl на присутствие\отсутствие акционных товаров?Цель: показывать ссылку на акционные товары, только в тех категориях, где они есть. Edited June 3, 2019 by Enhill Quote Link to post Share on other sites
Noxter Posted June 3, 2019 Report Share Posted June 3, 2019 Если я правильно Вас понял, то вам понадобиться фильтр $filter['discounted']: $products = $this->products->get_products(array('discounted'=>true)); Quote Link to post Share on other sites
Enhill Posted June 3, 2019 Author Report Share Posted June 3, 2019 (edited) Мне подсказали вот такое решение: ProductsView $discounted = new stdClass(); if ($this->request->get('discounted', 'integer')) { $discounted->disabled = false; $discounted->count = 0; } else { $temp_filter = $filter; $temp_filter['discounted'] = 1; $discounted->count = $this->products->count_products($temp_filter); if((int)$discounted->count > 0) { $discounted->disabled = false; } else { $discounted->disabled = true; $discounted->count = 0; } unset($temp_filter); } $this->design->assign('discounted', $discounted); В шаблоне products.tpl {if !$discounted->disabled} Показываем, когда в категории есть товары со скидкой {/if} Работает отлично. Но есть вопрос к профессионалам: не избыточно ли? Edited June 3, 2019 by Enhill Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.