Показ схожих информационных элементов на основе меток

#
Re: Показ схожих информационных элементов на основе меток
Всё равно не получается. Может я в XSL-шаблоне что-то не так делаю?

<?xml version="1.0" encoding="utf-8"?><!DOCTYPE xsl:stylesheet>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:hostcms="http://www.hostcms.ru/" exclude-result-prefixes="hostcms">
<xsl:output xmlns="http://www.w3.org/TR/xhtml1/strict" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" encoding="utf-8" indent="yes" method="html" omit-xml-declaration="no" version="1.0" media-type="text/xml"/>
<xsl:decimal-format name="my" decimal-separator="," grouping-separator=" "/>
<xsl:template match="/shop">
<xsl:apply-templates select="shop_item"/>
<xsl:apply-templates select="/shop/samenews/shop_item"/>

<div class="col-xs-6 col-sm-4 col-md-3">
<a rel="tag" href="{dir}{image_large}" title="Увеличить фото"><xsl:choose><xsl:when test="image_small != ''">
<img src="{dir}{image_small}" alt="{name}" class="img-thumbnail" /></xsl:when></xsl:choose></a>
<h5 class="bold"><xsl:value-of select="format-number(price, '### ##0', 'my')"/><xsl:text> </xsl:text><xsl:value-of select="currency" /><xsl:text> </xsl:text></h5>
<a href="{url}" title="Перейти в проект" hostcms:id="{@id}" hostcms:field="name" hostcms:entity="shop_item">
<xsl:value-of disable-output-escaping="yes" select="name"/></a></div>

</xsl:template>
<xsl:template match="shop_item">
<xsl:variable name="prev_item" select="/shop/neighboring_items/prev_item"/>
<xsl:variable name="next_item" select="/shop/neighboring_items/next_item"/>
<xsl:variable name="link_path" select="/shop/shop_group/url"/>

<ul class="pager">
<xsl:choose><xsl:when test="$prev_item != ''">
<li><a href="../{$prev_item}/">← Предыдущая</a></li></xsl:when><xsl:otherwise></xsl:otherwise></xsl:choose>
<xsl:choose><xsl:when test="$next_item != ''">
<li><a href="../{$next_item}/">Следующая →</a></li></xsl:when><xsl:otherwise></xsl:otherwise></xsl:choose>
<!--<div class="clearfix"></div>-->
</ul>

<h1 hostcms:id="{@id}" hostcms:field="name" hostcms:entity="shop_item"><xsl:value-of disable-output-escaping="yes" select="name"/></h1>
<xsl:variable name="group" select="/shop/group"/>
<xsl:if test="/shop/message/node()">
<xsl:value-of disable-output-escaping="yes" select="/shop/message"/>
</xsl:if>
<!-- Цена товара -->
<h5 class="bold"><xsl:if test="price != 0">Цена:
<xsl:value-of select="format-number(price, '### ##0', 'my')"/><xsl:text> </xsl:text><xsl:value-of select="currency" /><xsl:text> </xsl:text>
<!-- Если цена со скидкой - выводим её -->
<xsl:if test="price_tax != price"><span class="oldPrice">
<xsl:value-of select="format-number(price_tax, '### ##0', 'my')"/><xsl:text> </xsl:text><xsl:value-of select="currency" />
</span><xsl:text> </xsl:text></xsl:if>
</xsl:if></h5>
<!-- Изображение для товара, если есть
<div class="gallery">
<div class="col-xs-6 col-sm-4 col-md-3">
<a rel="tag" href="{dir}{image_large}" title="{name}" class="img_box">
<img src="{dir}{image_small}" alt="{name}" class="img-thumbnail" /></a>
</div>
</div>
-->
<!-- Описание товара -->
<xsl:if test="description != ''">
<!--<div hostcms:id="{@id}" hostcms:field="description" hostcms:entity="shop_item" hostcms:type="wysiwyg">-->
<xsl:value-of disable-output-escaping="yes" select="description" />
<!--</div>-->
</xsl:if>
<!-- Текст товара -->
<xsl:if test="text != ''">
<div hostcms:id="{@id}" hostcms:field="text" hostcms:entity="shop_item" hostcms:type="wysiwyg"><xsl:value-of disable-output-escaping="yes" select="text"/></div>
</xsl:if>
<!-- Если указано отображать комментарии -->
<xsl:if test="/shop/show_comments/node() and /shop/show_comments = 1">
<!-- Отображение комментариев  -->
<xsl:if test="count(comment) &gt; 0">
<p class="h1"><a name="comments"></a>Комментарии</p>
<xsl:apply-templates select="comment"/>
</xsl:if>
</xsl:if>

<p class="both h3 bg-prim m-b">Похожие изделия - проекты</p>

<!--
<xsl:template match="/shop">
<xsl:apply-templates select="shop_item"/>
<xsl:apply-templates select="/shop/samenews/shop_item"/>
<div class="gallery"><xsl:template match="shop_item"></div>


<div class="col-xs-6 col-sm-4 col-md-3">
<a rel="tag" href="{dir}{image_large}" title="Увеличить фото"><xsl:choose><xsl:when test="image_small != ''">
<img src="{dir}{image_small}" alt="{name}" class="img-thumbnail" /></xsl:when></xsl:choose></a>
<h5 class="bold"><xsl:value-of select="format-number(price, '### ##0', 'my')"/><xsl:text> </xsl:text><xsl:value-of select="currency" /><xsl:text> </xsl:text></h5>
<a href="{url}" title="Перейти в проект" hostcms:id="{@id}" hostcms:field="name" hostcms:entity="shop_item">
<xsl:value-of disable-output-escaping="yes" select="name"/></a></div>
</xsl:template>
-->

<!-- Тэги для информационного элемента -->
<p class="tags both">
<xsl:if test="count(tag) &gt; 0">
<span class="octicon octicon-tag"></span><span><xsl:apply-templates select="tag"/></span>
</xsl:if>
</p>

</xsl:template>
<!-- Вывод строки со значением свойства -->
<xsl:template match="property_value">
<xsl:if test="value/node() and value != '' or file/node() and file != ''">
<div class="shop_property">
<xsl:variable name="property_id" select="property_id" />
<xsl:variable name="property" select="/shop/shop_item_properties//property[@id=$property_id]" />
<xsl:value-of disable-output-escaping="yes" select="$property/name"/><xsl:text>: </xsl:text>
<span><xsl:choose>
<xsl:when test="$property/type = 2">
<a href="{../dir}{file}" target="_blank"><xsl:value-of disable-output-escaping="yes" select="file_name"/></a>
</xsl:when>
<xsl:when test="$property/type = 7">
<input type="checkbox" disabled="disabled">
<xsl:if test="value = 1">
<xsl:attribute name="checked">checked</xsl:attribute>
</xsl:if>
</input>
</xsl:when>
<xsl:otherwise>
<xsl:value-of disable-output-escaping="yes" select="value"/>
</xsl:otherwise>
</xsl:choose></span>
</div>
</xsl:if>
</xsl:template>

<!-- Метки -->
<xsl:template match="tag"><a href="{/shop/url}tag/{urlencode}/" class="tag"><xsl:value-of select="name"/></a>
<xsl:if test="position() != last()"><xsl:text>, </xsl:text></xsl:if>
</xsl:template>
<!-- Шаблон для модификаций -->
<xsl:template match="modifications/shop_item">
<li>
<!-- Название модификации -->
<a href="{url}"><xsl:value-of disable-output-escaping="yes" select="name"/></a>,
<!-- Цена модификации -->
<xsl:value-of select="price"/><xsl:text> </xsl:text><xsl:value-of disable-output-escaping="yes" select="currency"/>
</li>
</xsl:template>
<!-- Шаблон для сопутствующих товаров -->
<xsl:template match="associated/shop_item">
<li>
<!-- Название сопутствующего товара -->
<a href="{url}"><xsl:value-of disable-output-escaping="yes" select="name"/></a>,
<!-- Цена сопутствующего товара -->
<xsl:value-of select="price"/><xsl:text> </xsl:text><xsl:value-of disable-output-escaping="yes" select="currency"/>
</li>
</xsl:template>
<!-- Вывод рейтинга -->
<xsl:template name="show_average_grade">
<xsl:param name="grade" select="0"/>
<xsl:param name="const_grade" select="0"/>
<!-- Чтобы избежать зацикливания -->
<xsl:variable name="current_grade" select="$grade * 1"/>
<xsl:choose>
<!-- Если число целое -->
<xsl:when test="floor($current_grade) = $current_grade and not($const_grade &gt; ceiling($current_grade))">
<xsl:if test="$current_grade - 1 &gt; 0">
<xsl:call-template name="show_average_grade">
<xsl:with-param name="grade" select="$current_grade - 1"/>
<xsl:with-param name="const_grade" select="$const_grade - 1"/>
</xsl:call-template>
</xsl:if>
<xsl:if test="$current_grade != 0">
<img src="/images/star-full.png"/>
</xsl:if>
</xsl:when>
<xsl:when test="$current_grade != 0 and not($const_grade &gt; ceiling($current_grade))">
<xsl:if test="$current_grade - 0.5 &gt; 0">
<xsl:call-template name="show_average_grade">
<xsl:with-param name="grade" select="$current_grade - 0.5"/>
<xsl:with-param name="const_grade" select="$const_grade - 1"/>
</xsl:call-template>
</xsl:if>
<img src="/images/star-half.png"/>
</xsl:when>
<!-- Выводим серые звездочки, пока текущая позиция не дойдет то значения, увеличенного до целого -->
<xsl:otherwise>
<xsl:call-template name="show_average_grade">
<xsl:with-param name="grade" select="$current_grade"/>
<xsl:with-param name="const_grade" select="$const_grade - 1"/>
</xsl:call-template>
<img src="/images/star-empty.png"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- Шаблон для вывода звездочек (оценки) -->
<xsl:template name="for">
<xsl:param name="i" select="0"/>
<xsl:param name="n"/>
<input type="radio" name="shop_grade" value="{$i}" id="id_shop_grade_{$i}">
<xsl:if test="/shop/shop_grade = $i">
<xsl:attribute name="checked"></xsl:attribute>
</xsl:if>
</input><xsl:text> </xsl:text>
<label for="id_shop_grade_{$i}">
<xsl:call-template name="show_average_grade">
<xsl:with-param name="grade" select="$i"/>
<xsl:with-param name="const_grade" select="5"/>
</xsl:call-template>
</label>
<br/>
<xsl:if test="$n &gt; $i and $n &gt; 1">
<xsl:call-template name="for">
<xsl:with-param name="i" select="$i + 1"/>
<xsl:with-param name="n" select="$n"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
<!-- Отображение комментариев -->
<xsl:template match="comment">
<!-- Отображаем комментарий, если задан текст или тема комментария -->
<xsl:if test="text != '' or subject != ''">
<a name="comment{@id}"></a>
<div class="comment" id="comment{@id}">
<xsl:if test="subject != ''">
<div class="subject" hostcms:id="{@id}" hostcms:field="subject" hostcms:entity="comment"><xsl:value-of select="subject"/></div>
</xsl:if>
<div hostcms:id="{@id}" hostcms:field="text" hostcms:entity="comment" hostcms:type="wysiwyg"><xsl:value-of select="text" disable-output-escaping="yes"/></div>
<p class="tags">
<!-- Оценка комментария -->
<xsl:if test="grade != 0">
<span><xsl:call-template name="show_average_grade">
<xsl:with-param name="grade" select="grade"/>
<xsl:with-param name="const_grade" select="5"/>
</xsl:call-template></span>
</xsl:if>
<img src="/images/user.png" />
<xsl:choose>
<!-- Комментарий добавил авторизированный пользователь -->
<xsl:when test="count(siteuser) &gt; 0">
<span><a href="/users/info/{siteuser/login}/"><xsl:value-of select="siteuser/login"/></a></span>
</xsl:when>
<!-- Комментарй добавил неавторизированный пользователь -->
<xsl:otherwise>
<span><xsl:value-of select="author" /></span>
</xsl:otherwise>
</xsl:choose>
<img src="/images/calendar.png" /> <span><xsl:value-of select="datetime"/></span>
<xsl:if test="/shop/show_add_comments/node()
and ((/shop/show_add_comments = 1 and /shop/siteuser_id > 0)
or /shop/show_add_comments = 2)">
<span class="red" onclick="$('.comment_reply').hide('slow');$('#cr_{@id}').toggle('slow')">ответить</span></xsl:if>
<span class="red"><a href="{/shop/shop_item/url}#comment{@id}" title="Ссылка на комментарий">#</a></span>
</p>
</div>
<!-- Отображаем только авторизированным пользователям -->
<xsl:if test="/shop/show_add_comments/node() and ((/shop/show_add_comments = 1 and /shop/siteuser_id > 0) or /shop/show_add_comments = 2)">
<div class="comment_reply" id="cr_{@id}">
<xsl:call-template name="AddCommentForm">
<xsl:with-param name="id" select="@id"/>
</xsl:call-template>
</div>
</xsl:if>
<!-- Выбираем дочерние комментарии -->
<xsl:if test="count(comment)">
<div class="comment_sub">
<xsl:apply-templates select="comment"/>
</div>
</xsl:if>
</xsl:if>
</xsl:template>
<!-- Шаблон вывода добавления комментария -->
<xsl:template match="shop_discount"><div class="shop_discount"><xsl:value-of disable-output-escaping="yes" select="name"/><xsl:text> </xsl:text><span><xsl:value-of select="percent"/>%</span></div></xsl:template><xsl:template match="shop_group" mode="breadCrumbs"><xsl:variable name="parent_id" select="parent_id"/><xsl:apply-templates select="//shop_group[@id=$parent_id]" mode="breadCrumbs"/><xsl:if test="parent_id=0"><a href="{/shop/url}" hostcms:id="{/shop/@id}" hostcms:field="name" hostcms:entity="shop"><xsl:value-of select="/shop/name"/></a></xsl:if><span><xsl:text> → </xsl:text></span><a href="{url}" hostcms:id="{@id}" hostcms:field="name" hostcms:entity="shop_group"><xsl:value-of select="name"/></a></xsl:template><xsl:template name="declension"><xsl:param name="number" select="number"/><xsl:variable name="nominative">

</xsl:variable><xsl:variable name="genitive_singular"></xsl:variable><xsl:variable name="genitive_plural"></xsl:variable><xsl:variable name="last_digit"><xsl:value-of select="$number mod 10"/></xsl:variable><xsl:variable name="last_two_digits"><xsl:value-of select="$number mod 100"/></xsl:variable><xsl:choose><xsl:when test="$last_digit = 1 and $last_two_digits != 11"><xsl:value-of select="$nominative"/></xsl:when><xsl:when test="$last_digit = 2 and $last_two_digits != 12or $last_digit = 3 and $last_two_digits != 13or $last_digit = 4 and $last_two_digits != 14"><xsl:value-of select="$genitive_singular"/></xsl:when><xsl:otherwise><xsl:value-of select="$genitive_plural"/></xsl:otherwise></xsl:choose></xsl:template></xsl:stylesheet>
#
Re: Показ схожих информационных элементов на основе меток
kamardindg,
1. посмотрите попадает ли вообще у вас в XML что то
2. если нет сделайте кол-во совпадений по тэгу 1
3. снова посмотрите, попадает или нет
4. если не попадает значит нет совпадений или делаете что то не так
5. если попадает значит правьте xsl шаблон и в нем что то не так
www.morozovpimnev.ru - создание, поддержка и продвижение сайтов | Наш канал https://asmp.su/channel
#
Re: Показ схожих информационных элементов на основе меток
Посмотрите, пожалуйста - туда ли я код вставил?
Типовые динамические страницы → Интернет-магазин (Код страницы):


<?php
$Shop_Controller_Show = Core_Page::instance()->object;
$xslName = $Shop_Controller_Show->item
? Core_Array::get(Core_Page::instance()->libParams, 'shopItemXsl')
: Core_Array::get(Core_Page::instance()->libParams, 'shopXsl');
$Shop_Controller_Show->addEntity(Core::factory('Core_Xml_Entity')
->name('ТекущаяГруппа')->value($Shop_Controller_Show->group))
->addEntity(Core::factory('Core_Xml_Entity')
->name('show_comments')->value(Core_Array::get(Core_Page::instance()->libParams, 'showComments', 1)))
->addEntity(Core::factory('Core_Xml_Entity')
->name('show_add_comments')->value(Core_Array::get(Core_Page::instance()->libParams, 'showAddComment', 2))
);
$Shop_Controller_Show
->tags(TRUE)
->comments(TRUE)
->associatedItems(TRUE)
->modifications(TRUE);
if ($Shop_Controller_Show->item == 0) {
$Shop_Controller_Show->itemsForbiddenTags(array('text'));
if (Core_Array::getGet('filter') || Core_Array::getGet('sorting')) {
$Shop_Controller_Show->addEntity(Core::factory('Core_Xml_Entity')
->name('filter')
->value(1)
);
$oShop = $Shop_Controller_Show->getEntity();
$sorting = intval(Core_Array::getGet('sorting'));
$Shop_Controller_Show->addEntity(Core::factory('Core_Xml_Entity')
->name('sorting')
->value($sorting)
);
$Shop_Controller_Show->addCacheSignature('sorting=' . $sorting);
// Цены
$price_from = intval(Core_Array::getGet('price_from'));
$price_to = intval(Core_Array::getGet('price_to'));
if ($price_from || $price_to || $sorting == 1 || $sorting == 2) {
// Получаем список валют магазина
$aShop_Currencies = Core_Entity::factory('Shop_Currency')->findAll();
$query_currency_switch = 'price';
foreach ($aShop_Currencies as $oShop_Currency) {
// Получаем коэффициент пересчета для каждой валюты
$currency_coefficient = Shop_Controller::instance()->getCurrencyCoefficientInShopCurrency(
$oShop_Currency, $oShop->Shop_Currency
);
$query_currency_switch = "IF (`shop_items`.`shop_currency_id` = '{$oShop_Currency->id}', IF (shop_discounts.percent, price * (100 - shop_discounts.percent) * {$currency_coefficient} / 100, shop_items.price * {$currency_coefficient}), {$query_currency_switch})";
}
$current_date = date('Y-m-d H:i:s');
$Shop_Controller_Show->shopItems()
->queryBuilder()
->select(array(Core_QueryBuilder::expression($query_currency_switch), 'absolute_price'))
->leftJoin('shop_item_discounts', 'shop_items.id', '=', 'shop_item_discounts.shop_item_id')
->leftJoin('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)
));
if ($price_from) {
$Shop_Controller_Show->shopItems()->queryBuilder()->having('absolute_price', '>=', $price_from) && $Shop_Controller_Show->addEntity(Core::factory('Core_Xml_Entity')
->name('price_from')->value($price_from)
);
$Shop_Controller_Show->addCacheSignature('price_from=' . $price_from); }
if ($price_to) {
$Shop_Controller_Show->shopItems()->queryBuilder()->having('absolute_price', '<=', $price_to);
$Shop_Controller_Show->addEntity(Core::factory('Core_Xml_Entity')
->name('price_to')->value($price_to)
);
$Shop_Controller_Show->addCacheSignature('price_to=' . $price_to); }
$Shop_Controller_Show->shopItems()->queryBuilder()
->clearOrderBy()
->orderBy('absolute_price', $sorting == 1 ? 'ASC' : 'DESC');
}
$sorting == 3 && $Shop_Controller_Show->shopItems()->queryBuilder()
->clearOrderBy()
->orderBy('shop_items.name', 'ASC');
// Дополнительные свойства
$oShop_Item_Property_List = Core_Entity::factory('Shop_Item_Property_List', $oShop->id);
$aProperties = $Shop_Controller_Show->group !== FALSE && is_null($Shop_Controller_Show->tag)
? $oShop_Item_Property_List->getPropertiesForGroup($Shop_Controller_Show->group)
: $oShop_Item_Property_List->Properties->findAll();
$aTmpProperties = array();
$havingCount = 0;
foreach ($aProperties as $oProperty) {
// Св-во может иметь несколько значений
$aPropertiesValue = Core_Array::getGet('property_' . $oProperty->id);
if ($aPropertiesValue) {
!is_array($aPropertiesValue) && $aPropertiesValue = array($aPropertiesValue);
foreach ($aPropertiesValue as $sPropertyValue) {
$aTmpProperties[] = array($oProperty, strval($sPropertyValue));
}
$havingCount++;
}
elseif (!is_null(Core_Array::getGet('property_' . $oProperty->id . '_from'))) {
// From ... to ...
$aTmpProperties[] = array($oProperty, array(
'from' => intval(Core_Array::getGet('property_' . $oProperty->id . '_from')),
'to' => intval(Core_Array::getGet('property_' . $oProperty->id . '_to'))
));
$havingCount++;
}}
if (count($aTmpProperties)) {
$aTableNames = array();
$Shop_Controller_Show->shopItems()->queryBuilder()
->leftJoin('shop_item_properties', 'shop_items.shop_id', '=', 'shop_item_properties.shop_id')
->setAnd()
->open();
reset($aTmpProperties);
while(list(, list($oProperty, $propertyValue)) = each($aTmpProperties)) {
$tableName = $oProperty->createNewValue(0)->getTableName();
!in_array($tableName, $aTableNames) && $aTableNames[] = $tableName;
$Shop_Controller_Show->shopItems()->queryBuilder()
->where('shop_item_properties.property_id', '=', $oProperty->id);
if (!is_array($propertyValue)) {
// Для строк фильтр LIKE %...%
if ($oProperty->type == 1) {
$Shop_Controller_Show->shopItems()->queryBuilder()
->where($tableName . '.value', 'LIKE', "%{$propertyValue}%");
}
else {
// Checkbox
$oProperty->type == 7 && $propertyValue != '' && $propertyValue = 1;
$Shop_Controller_Show->shopItems()->queryBuilder()
->where($tableName . '.value', '=', $propertyValue);
}
$Shop_Controller_Show->shopItems()->queryBuilder()
->setOr();
$Shop_Controller_Show->addEntity(Core::factory('Core_Xml_Entity')
->name('property_' . $oProperty->id)->value($propertyValue)
);
$Shop_Controller_Show->addCacheSignature("property{$oProperty->id}={$propertyValue}");
}
else {
$from = trim(strval(Core_Array::get($propertyValue, 'from')));
$from && $Shop_Controller_Show->shopItems()->queryBuilder()
->where($tableName . '.value', '>=', $from)
->setAnd();
$to = trim(strval(Core_Array::get($propertyValue, 'to')));
$to && $Shop_Controller_Show->shopItems()->queryBuilder()
->where($tableName . '.value', '<=', $to);
$Shop_Controller_Show->shopItems()->queryBuilder()
->setOr();
$Shop_Controller_Show->addEntity(Core::factory('Core_Xml_Entity')
->name('property_' . $oProperty->id . '_from')
->value($from)
)->addEntity(Core::factory('Core_Xml_Entity')
->name('property_' . $oProperty->id . '_to')->value($to)
);
$Shop_Controller_Show
->addCacheSignature("property{$oProperty->id}_from={$from}")
->addCacheSignature("property{$oProperty->id}_to={$to}");
}}
$Shop_Controller_Show->shopItems()->queryBuilder()
->close()
->groupBy('shop_items.id')
->having(Core_Querybuilder::expression('COUNT(DISTINCT `shop_item_properties`.`property_id`)'), '=', $havingCount);
foreach ($aTableNames as $tableName) {
$Shop_Controller_Show->shopItems()->queryBuilder()
->leftJoin($tableName, 'shop_items.id', '=', $tableName . '.entity_id',
array(
array('AND' => array('shop_item_properties.property_id', '=', Core_QueryBuilder::expression($tableName . '.property_id')))
)
);
}}}}
else {
if (Core_Array::getPost('add_comment') && Core_Array::get(Core_Page::instance()->libParams, 'showComments', 1)) {
$oShop = $Shop_Controller_Show->getEntity();
$Shop_Controller_Show->cache(FALSE);
$oLastComment = Core_Entity::factory('Comment')->getLastCommentByIp(Core_Array::get($_SERVER, 'REMOTE_ADDR')
);
$oXmlCommentTag = Core::factory('Core_Xml_Entity')
->name('document');
$siteuser_id = 0;
if (Core::moduleIsActive('siteuser')) {
$oSiteuser = Core_Entity::factory('Siteuser')->getCurrent();
if ($oSiteuser) {
$siteuser_id = $oSiteuser->id;
}}
$oComment = Core_Entity::factory('Comment');
$allowable_tags = '<b><strong><i><em><br><p><u><strike><ul><ol><li>';
$oComment->parent_id = intval(Core_Array::getPost('parent_id', 0));
$oComment->active = $oShop->comment_active;
$oComment->author = Core_Str::stripTags(Core_Array::getPost('author'));
$oComment->email = Core_Str::stripTags(Core_Array::getPost('email'));
$oComment->phone = Core_Str::stripTags(Core_Array::getPost('phone'));
$oComment->grade = intval(Core_Array::getPost('grade', 0));
$oComment->subject = Core_Str::stripTags(Core_Array::getPost('subject'));
$oComment->text = nl2br(Core_Str::stripTags(Core_Array::getPost('text'), $allowable_tags));
$oComment->siteuser_id = $siteuser_id;
$oShop_Item = Core_Entity::factory('Shop_Item', $Shop_Controller_Show->item);
$oXmlCommentTag
->addEntity($oComment)
->addEntity($oShop_Item);
if (is_null($oLastComment) || time() > Core_Date::sql2timestamp($oLastComment->datetime) + ADD_COMMENT_DELAY) {
if ($oShop->use_captcha == 0 || $siteuser_id > 0 || Core_Captcha::valid(Core_Array::getPost('captcha_id'), Core_Array::getPost('captcha'))) {
$oComment->save();
$oShop_Item->add($oComment);
$oXmlCommentTag->addEntity($oShop);
// Отправка письма администратору
$sText = Xsl_Processor::instance()
->xml($oXmlCommentTag->getXml())
->xsl(Core_Entity::factory('Xsl')->getByName(Core_Array::get(Core_Page::instance()->libParams, 'addCommentAdminMailXsl')))
->process();
Core_Mail::instance()
->to(EMAIL_TO)
->from(Core_Valid::email($oComment->email)
? $oComment->email
: EMAIL_TO
)
->subject(Core::_('Shop.comment_mail_subject'))
->message(trim($sText))
->contentType(Core_Array::get(Core_Page::instance()->libParams, 'commentMailNoticeType', 0) == 0
? 'text/plain'
: 'text/html'
)
->send();
}
else {
$oXmlCommentTag->addEntity(Core::factory('Core_Xml_Entity')
->name('error_captcha')->value(1)
);
$oComment->text = Core_Str::br2nl($oComment->text);
$Shop_Controller_Show->addEntity($oComment);
}}
else {
$oXmlCommentTag->addEntity(Core::factory('Core_Xml_Entity')
->name('error_time')->value(1)
);
$oComment->text = Core_Str::br2nl($oComment->text);
$Shop_Controller_Show->addEntity($oComment);
}
// Результат добавления комментария
$xsl_result = Xsl_Processor::instance()
->xml($oXmlCommentTag->getXml())
->xsl(Core_Entity::factory('Xsl')->getByName(Core_Array::get(Core_Page::instance()->libParams, 'addCommentNoticeXsl')))
->process();
$Shop_Controller_Show->addEntity(Core::factory('Core_Xml_Entity')
->name('message')->value($xsl_result)
);
}}
// В корне выводим из всех групп
/*if ($Shop_Controller_Show->group == 0) {
$Shop_Controller_Show->group(FALSE);}*/


$oShop_Item = Core_Entity::factory('Shop_Item', $Shop_Controller_Show->item);
$oTag_Shop_Items = $oShop_Item->Tag_Shop_Items->findAll();
// Минимальное количество тегов для совпадения.
$iSameTags = 3;
$aTagIds = array();
foreach($oTag_Shop_Items as $oTag_Shop_Item) {
$aTagIds[] = $oTag_Shop_Item->tag_id;
} if (count($aTagIds)) {
$oSameTag_Shop_Items = Core_Entity::factory('Tag_Shop_Item');
$oSameTag_Shop_Items->queryBuilder()
->select('tag_shop_items.*')
->where('tag_id', 'IN', $aTagIds)
->where('tag_shop_items.shop_item_id', '!=', $oShop_Item->id)
->join('shop_items', 'tag_shop_items.shop_item_id', '=', 'shop_items.id')
->join('shops', 'shop_items.shop_id', '=', 'shops.id')
->where('shops.site_id', '=', CURRENT_SITE)
->groupBy('shop_items.id')
->having('COUNT(tag_id)', '>=', $iSameTags)
->clearOrderBy()
->orderBy('RAND()')
->limit(4);
$aSameTag_Shop_Items = $oSameTag_Shop_Items->findAll();
$oXmlSamenews = Core::factory('Core_Xml_Entity')->name('samenews');
$Shop_Controller_Show->addEntity($oXmlSamenews);
foreach($aSameTag_Shop_Items as $oSameTag_Shop_Item) {
$oXmlSamenews->addEntity($oSameTag_Shop_Item->Shop_Item->clearEntities());
}}


$Shop_Controller_Show
->xsl( Core_Entity::factory('Xsl')->getByName($xslName) )
->itemsProperties(TRUE)
->show();
#
Re: Показ схожих информационных элементов на основе меток
Alexpimnev, Вы гений!
С утра разобрался, на свежую голову – всё получилось великолепно!
Огромное спасибо!
Все разделы интернет-магазина «Мебель на заказ по индивидуальным проектам» работают.
#
Re: Показ схожих информационных элементов на основе меток
Подскажите, пожалуйста, как в код ТДС  для показа схожих элементов передать дополнительные свойства?
iNikSite - дизайн и фронтенд разработка
Авторизация