HOSTCMS v.6
ФИЛЬТР ТОВАРОВ
Быстрый фильтр товаров. Производители
Вывод производителей в фильтре в виде checkbox.
Редактируем <xsl:template match="shop_producer"> показа производителей в коде XSL шаблона фильтра:
XSL
<div class="filter-item">
<div class="caption">Производитель</div>
<ul>
<xsl:apply-templates select="/shop/producers/shop_producer" />
</ul>
</div>
<!-- Шаблон показа производителей -->
<xsl:template match="shop_producer">
<xsl:variable name="id" select="@id" />
<xsl:variable name="name">
<xsl:choose>
<xsl:when test="/shop/filter_mode = 0">
<xsl:value-of select="name" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="path" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:if test="position() = 4">
<xsl:text disable-output-escaping="yes"><div class="hidden"></xsl:text>
</xsl:if>
<li>
<input type="checkbox" value="{@id}" name="producer_id[]" id="producer_id_{@id}" data-property="producer_id" data-value="{$name}">
<xsl:if test="/shop/producer_id = @id">
<xsl:attribute name="checked">checked</xsl:attribute>
</xsl:if>
<label for="producer_id_{@id}">
<xsl:value-of select="name"/>
<!--<xsl:if test="count/node()">
<xsl:text> (</xsl:text><xsl:value-of select="count"/><xsl:text>)</xsl:text>
</xsl:if>-->
</label>
</input>
</li>
<xsl:if test="position() >= 4 and position() = last()">
<xsl:text disable-output-escaping="yes"></div></xsl:text>
<a href="javascript:;" class="show-all js-show-all" data-on="Скрыть" data-off="Показать все"><span>Показать все</span></a>
</xsl:if>
</xsl:template>
Сортировка товаров и товары со скидкой
1. Дорабатываем Сортировку товаров на сайте на HostCMS
2. Отбираем в базе данных все товары со скидкой
1. Сортировка товаров

Блок кода ТДС "Интернет-магазин" дорабатываем, чтобы добавить сортировки и выводить товары со скидками. Здесь же в коде кусок кода, который будет нам отбирать товары со скидкой
if (Core_Array::getGet('filter') || Core_Array::getGet('sorting'))
{
$Shop_Controller_Show->addEntity(
Core::factory('Core_Xml_Entity')
->name('filter')->value(1)
);
// отбираем товары со скидкой
if(intval(Core_Array::getGet('filter')) && intval(Core_Array::getGet('is_sale'))) {
$current_date = date('Y-m-d H:i:s');
$Shop_Controller_Show->shopItems()
->queryBuilder()
->join('shop_item_discounts', 'shop_items.id', '=', 'shop_item_discounts.shop_item_id')
->join('shop_discounts', 'shop_item_discounts.shop_discount_id', '=', 'shop_discounts.id', array(
array('AND (' => array('shop_discounts.end_datetime', '>=', $current_date)),
array('OR' => array('shop_discounts.end_datetime', '=', '0000-00-00 00:00:00')),
array('AND' => array('shop_discounts.start_datetime', '<=', $current_date)),
array(')' => NULL)
));
}
// Sorting
$sorting = intval(Core_Array::getGet('sorting'));
($sorting == 1 || $sorting == 2)
&& $Shop_Controller_Show->orderBy('absolute_price', $sorting == 1 ? 'ASC' : 'DESC');
$sorting == 3 && $Shop_Controller_Show->orderBy('shop_items.name', 'ASC');
$sorting == 4 && $Shop_Controller_Show->orderBy('shop_items.name', 'DESC');
$sorting == 5 && $Shop_Controller_Show
->shopItems()
->queryBuilder()
->clearOrderBy()
->orderBy('shop_items.datetime', 'DESC');
$sorting == 6 && $Shop_Controller_Show
->shopItems()
->queryBuilder()
->clearOrderBy()
->orderBy('shop_items.datetime', 'ASC');
$Shop_Controller_Show->addEntity(
Core::factory('Core_Xml_Entity')
->name('sorting')->value($sorting)
);
// Prices
$Shop_Controller_Show->setFilterPricesConditions($_GET);
// Additional properties
$Shop_Controller_Show->setFilterPropertiesConditions($_GET);
}
В XSL-шаблоне фильтра менем select на этот
<select class="form-select" name="sorting" onchange="$(this).parents('form:first').submit()" placeholder="Сортировать">
<option value="0" selected="selected">Порядок: по умолчанию</option>
<option value="1">
<xsl:if test="sorting = 1"><xsl:attribute name="selected">selected</xsl:attribute></xsl:if>
По возрастанию цены
</option>
<option value="2">
<xsl:if test="sorting = 2"><xsl:attribute name="selected">selected</xsl:attribute></xsl:if>
По убыванию цены
</option>
<option value="3">
<xsl:if test="sorting = 3"><xsl:attribute name="selected">selected</xsl:attribute></xsl:if>
Название: А-Я
</option>
<option value="4">
<xsl:if test="sorting = 4"><xsl:attribute name="selected">selected</xsl:attribute></xsl:if>
Название: Я-А
</option>
<option value="5">
<xsl:if test="sorting = 5"><xsl:attribute name="selected">selected</xsl:attribute></xsl:if>
Сперва новые
</option>
<option value="6">
<xsl:if test="sorting = 6"><xsl:attribute name="selected">selected</xsl:attribute></xsl:if>
Сперва старые
</option>
</select>
2. Товары со скидкой
В меню сайта или в любое другое место макета добавляем кнопку, например "РАСПРОДАЖА", с такой ссылкой
<a href="/shop/?filter=1&is_sale=1"> Распродажа </a>
В код ТДС Интернет-магазина добавляем строки (куда добавить показано выше)
// отбираем товары со скидкой
if(intval(Core_Array::getGet('filter')) && intval(Core_Array::getGet('is_sale'))) {
$current_date = date('Y-m-d H:i:s');
$Shop_Controller_Show->shopItems()
->queryBuilder()
->join('shop_item_discounts', 'shop_items.id', '=', 'shop_item_discounts.shop_item_id')
->join('shop_discounts', 'shop_item_discounts.shop_discount_id', '=', 'shop_discounts.id', array(
array('AND (' => array('shop_discounts.end_datetime', '>=', $current_date)),
array('OR' => array('shop_discounts.end_datetime', '=', '0000-00-00 00:00:00')),
array('AND' => array('shop_discounts.start_datetime', '<=', $current_date)),
array(')' => NULL)
));
}
В итоге, при клике на кнопку РАСПРОДАЖА, будут отобраны в базе и показаны на странице каталога все товары, к которым применены скидки