Jump to content

Условие в шаблоне products.tpl на присутствие\отсутствие акционных товаров


Recommended Posts

Добрый день. Очень нужна ваша помощь.

Вывожу акционные товары в шаблоне 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 by Enhill
Link to post
Share on other sites

Мне подсказали вот такое решение:

 

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 by Enhill
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...