Нужна таблица товаров
Здравствуйте! Подскажите, пожалуйста, каким образом можно вывести таблицу товаров магазина с дополнительными свойствами. Если делать как в корзине, то будет выведен только определенный набор свойств. Для разных разделов каталогов в нашем интернет-магазине набор дополнительных свойств разный.
Можете ознакомится с документацией по выводу
«Не выходи из комнаты, не совершай ошибку…»
Скажите, каким образом можно сформировать заголовки столбцов в таблице? Наверное, для Вас это очевидно, но пока не для меня. Я начал именно с документации. Ответ не пришел. Скорее всего, я еще плохо ориентируюсь в ядре HostCMS и XSLT.
Наверное я глуповат, но не знаю как пристроить решение. Каким образом можно вывести отдельную строку с названиями дополнительных и основных свойств товара. Вы бы не могли предоставить пример для стандартного дело магазина? Как выводятся свойства для каждого товара – это совершенно ясно. Как вывести названия свойств для заголовка не знаю. Пожалуйста, помогите. Клиент ждет. Я не могу доделать только это.
Пример:
Сначала в шаблоне XSL пишем:
<!-- Выводим товары магазина -->
<div class="row products-grid">
<xsl:apply-templates select="header" /> <!-- Заголовок таблицы -->
<xsl:apply-templates select="shop_item" /> <!-- Товары магазина -->
</div>
Потом идет
<!-- Шаблон для товара -->
<xsl:template match="shop_item">
<!-- Вывод дополнительных свойств товара -->
<xsl:variable name="myItem" select="." />
<div class="col-xs-12 col-sm-6 hidden-md hidden-lg item">
<div class="grid_wrap">
<xsl:if test="discount != 0">
<div class="ribbon-wrapper">
<div class="ribbon bg-color2">HOT</div>
</div>
</xsl:if>
<div class="product-image">
<a href="{url}" title="{name}">
<xsl:choose>
<xsl:when test="image_small != ''">
<img src="{dir}{image_small}" alt="{name}" />
</xsl:when>
<xsl:otherwise>
<i class="fa fa-camera"></i>
</xsl:otherwise>
</xsl:choose>
</a>
</div>
<div class="product-name">
<a href="{url}" title="{name}">
<xsl:value-of disable-output-escaping="yes" select="name"/>
</a>
</div>
<xsl:for-each select="/shop/shop_item_properties//property">
<xsl:variable name="propertyId" select="@id" />
<xsl:choose>
<xsl:when test="count($myItem/property_value[property_id = $propertyId])">
<xsl:apply-templates select="$myItem/property_value[property_id = $propertyId]"/>
</xsl:when>
<xsl:otherwise></xsl:otherwise>
</xsl:choose>
</xsl:for-each>
<div class="price-box">
<span id="product-price-12-new" class="regular-price">
<span class="price">
<xsl:value-of select="format-number(price, '### ##0,00', 'my')"/><xsl:text> </xsl:text><xsl:value-of disable-output-escaping="yes" select="currency"/><xsl:text> </xsl:text>
</span>
<xsl:if test="discount != 0">
<br/>
<span class="old-price">
<xsl:value-of select="format-number(price+discount+mark-up, '### ##0,00', 'my')"/><xsl:text> </xsl:text><xsl:value-of disable-output-escaping="yes" select="currency"/><xsl:text> </xsl:text>
</span>
</xsl:if>
</span>
<!-- Бонусы для товара -->
<xsl:if test="count(shop_bonuses/shop_bonus)">
<div class="product-bonuses">
+<xsl:value-of select="shop_bonuses/total" /> бонусов
</div>
</xsl:if>
</div>
<div class="product-shop">
<div class="actions">
<button class="button btn-cart" onclick="return $.bootstrapAddIntoCart('{/shop/url}cart/', {@id}, 1)" title="Add to Cart" type="button">
<i class="fa fa-shopping-cart bg-color5">
<b></b>
</i>
<span class="bg-color3">
<span>В корзину</span>
</span>
</button>
<xsl:variable name="shop_item_id" select="@id" />
<ul class="add-to-links">
<li>
<xsl:if test="/shop/favorite/shop_item[@id = $shop_item_id]/node()">
<xsl:attribute name="class">link-wishlist-current</xsl:attribute>
</xsl:if>
<a class="link-wishlist" onclick="return $.addFavorite('{/shop/url}', {@id}, this)"><i class="fa fa-heart-o"></i>Избранное</a>
</li>
<li>
<xsl:if test="/shop/comparing/shop_item[@id = $shop_item_id]/node()">
<xsl:attribute name="class">link-compare-current</xsl:attribute>
</xsl:if>
<span class="separator">|</span>
<a class="link-compare" onclick="return $.addCompare('{/shop/url}', {@id}, this)"><i class="fa fa-bar-chart"></i>Сравнить</a>
</li>
</ul>
</div>
</div>
</div>
</div>
<div class="hidden-xs hidden-sm">
<div class="col-md-5 col-lg-5">
<!-- <a href="{url}" title="{name}">
<xsl:choose>
<xsl:when test="image_small != ''">
<img src="{dir}{image_small}" alt="{name}" />
</xsl:when>
<xsl:when test="default-img != ''">
<img src="{dir}{default-img}" alt="{name}" />
</xsl:when>
<xsl:otherwise>
<i class="fa fa-camera"></i>
</xsl:otherwise>
</xsl:choose>
</a> -->
<a href="{url}" title="{name}">
<xsl:value-of disable-output-escaping="yes" select="name"/>
</a>
</div>
<div class="col-md-4 col-lg-4 property-row">
<xsl:for-each select="/shop/shop_item_properties//property">
<xsl:variable name="propertyId" select="@id" />
<xsl:choose>
<xsl:when test="count($myItem/property_value[property_id = $propertyId])">
<!--Вывод всех свойств кроме минимального количества для заказа ($propertyId = 80)-->
<xsl:if test="$propertyId != 80">
<!--<xsl:value-of disable-output-escaping="yes" select="$propertyId"/>-->
<xsl:apply-templates select="$myItem/property_value[property_id = $propertyId]"/>
</xsl:if>
</xsl:when>
<xsl:otherwise></xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</div>
<xsl:choose>
<xsl:when test="currency > 0.1">
<div class="price-box col-xs-1 col-sm-1 col-md-1 col-lg-1">
<xsl:value-of select="format-number(price, '### ##0,00', 'my')"/><xsl:text> </xsl:text><xsl:value-of disable-output-escaping="yes" select="currency"/><xsl:text> </xsl:text>
<xsl:if test="discount != 0">
<span class="old-price">
<xsl:value-of select="format-number(price+discount+mark-up, '### ##0,00', 'my')"/><xsl:text> </xsl:text><xsl:value-of disable-output-escaping="yes" select="currency"/><xsl:text> </xsl:text>
</span>
</xsl:if>
<!-- Бонусы для товара -->
<xsl:if test="count(shop_bonuses/shop_bonus)">
<div class="product-bonuses">
+<xsl:value-of select="shop_bonuses/total" /> бонусов
</div>
</xsl:if>
</div>
</xsl:when>
<xsl:otherwise>
<div class="price-box col-xs-1 col-sm-1 col-md-1 col-lg-1">
<xsl:value-of select="format-number(price, '### ##0,00', 'my')"/><xsl:text> </xsl:text><xsl:value-of disable-output-escaping="yes" select="currency"/><xsl:text> </xsl:text>
<xsl:if test="discount != 0">
<span class="old-price">
<xsl:value-of select="format-number(price+discount+mark-up, '### ##0,00', 'my')"/><xsl:text> </xsl:text><xsl:value-of disable-output-escaping="yes" select="currency"/><xsl:text> </xsl:text>
</span>
</xsl:if>
<!-- Бонусы для товара -->
<xsl:if test="count(shop_bonuses/shop_bonus)">
<div class="product-bonuses">
+<xsl:value-of select="shop_bonuses/total" /> бонусов
</div>
</xsl:if>
</div>
</xsl:otherwise>
</xsl:choose>
<div class="actions col-xs-1 col-sm-1 col-md-2 col-lg-2">
<button class="button btn-cart" onclick="return $.bootstrapAddIntoCart('{/shop/url}cart/', {@id}, 1)" title="Add to Cart" type="button">
<i class="fa fa-shopping-cart bg-color5">
</i>
</button>
<!--</div>-->
<xsl:variable name="shop_item_id" select="@id" />
<div style="display:inline-block;">
<xsl:if test="/shop/favorite/shop_item[@id = $shop_item_id]/node()">
<xsl:attribute name="class">link-wishlist-current</xsl:attribute>
</xsl:if>
<a class="link-wishlist" onclick="return $.addFavorite('{/shop/url}', {@id}, this)"><i class="fa fa-heart-o"></i></a>
</div>
<div style="display: inline-block;">
<xsl:if test="/shop/comparing/shop_item[@id = $shop_item_id]/node()">
<xsl:attribute name="class">link-compare-current</xsl:attribute>
</xsl:if>
<span class="separator">|</span>
<a class="link-compare" onclick="return $.addCompare('{/shop/url}', {@id}, this)"><i class="fa fa-bar-chart"></i></a>
</div>
</div>
</div>
</xsl:template>
Но что написать внутри тэгов:
<!-- Заголовок таблицы -->
<xsl:template match="header">
</xsl:template>
Я уже все перепробовал. Поэтому внутри тэгов ничего нет.
Пример:
Сначала в шаблоне XSL пишем:
<!-- Выводим товары магазина -->
<div class="row products-grid">
<xsl:apply-templates select="header" /> <!-- Заголовок таблицы -->
<xsl:apply-templates select="shop_item" /> <!-- Товары магазина -->
</div>
Потом идет
<!-- Шаблон для товара -->
<xsl:template match="shop_item">
<!-- Вывод дополнительных свойств товара -->
<xsl:variable name="myItem" select="." />
<div class="col-xs-12 col-sm-6 hidden-md hidden-lg item">
<div class="grid_wrap">
<xsl:if test="discount != 0">
<div class="ribbon-wrapper">
<div class="ribbon bg-color2">HOT</div>
</div>
</xsl:if>
<div class="product-image">
<a href="{url}" title="{name}">
<xsl:choose>
<xsl:when test="image_small != ''">
<img src="{dir}{image_small}" alt="{name}" />
</xsl:when>
<xsl:otherwise>
<i class="fa fa-camera"></i>
</xsl:otherwise>
</xsl:choose>
</a>
</div>
<div class="product-name">
<a href="{url}" title="{name}">
<xsl:value-of disable-output-escaping="yes" select="name"/>
</a>
</div>
<xsl:for-each select="/shop/shop_item_properties//property">
<xsl:variable name="propertyId" select="@id" />
<xsl:choose>
<xsl:when test="count($myItem/property_value[property_id = $propertyId])">
<xsl:apply-templates select="$myItem/property_value[property_id = $propertyId]"/>
</xsl:when>
<xsl:otherwise></xsl:otherwise>
</xsl:choose>
</xsl:for-each>
<div class="price-box">
<span id="product-price-12-new" class="regular-price">
<span class="price">
<xsl:value-of select="format-number(price, '### ##0,00', 'my')"/><xsl:text> </xsl:text><xsl:value-of disable-output-escaping="yes" select="currency"/><xsl:text> </xsl:text>
</span>
<xsl:if test="discount != 0">
<br/>
<span class="old-price">
<xsl:value-of select="format-number(price+discount+mark-up, '### ##0,00', 'my')"/><xsl:text> </xsl:text><xsl:value-of disable-output-escaping="yes" select="currency"/><xsl:text> </xsl:text>
</span>
</xsl:if>
</span>
<!-- Бонусы для товара -->
<xsl:if test="count(shop_bonuses/shop_bonus)">
<div class="product-bonuses">
+<xsl:value-of select="shop_bonuses/total" /> бонусов
</div>
</xsl:if>
</div>
<div class="product-shop">
<div class="actions">
<button class="button btn-cart" onclick="return $.bootstrapAddIntoCart('{/shop/url}cart/', {@id}, 1)" title="Add to Cart" type="button">
<i class="fa fa-shopping-cart bg-color5">
<b></b>
</i>
<span class="bg-color3">
<span>В корзину</span>
</span>
</button>
<xsl:variable name="shop_item_id" select="@id" />
<ul class="add-to-links">
<li>
<xsl:if test="/shop/favorite/shop_item[@id = $shop_item_id]/node()">
<xsl:attribute name="class">link-wishlist-current</xsl:attribute>
</xsl:if>
<a class="link-wishlist" onclick="return $.addFavorite('{/shop/url}', {@id}, this)"><i class="fa fa-heart-o"></i>Избранное</a>
</li>
<li>
<xsl:if test="/shop/comparing/shop_item[@id = $shop_item_id]/node()">
<xsl:attribute name="class">link-compare-current</xsl:attribute>
</xsl:if>
<span class="separator">|</span>
<a class="link-compare" onclick="return $.addCompare('{/shop/url}', {@id}, this)"><i class="fa fa-bar-chart"></i>Сравнить</a>
</li>
</ul>
</div>
</div>
</div>
</div>
<div class="hidden-xs hidden-sm">
<div class="col-md-5 col-lg-5">
<!-- <a href="{url}" title="{name}">
<xsl:choose>
<xsl:when test="image_small != ''">
<img src="{dir}{image_small}" alt="{name}" />
</xsl:when>
<xsl:when test="default-img != ''">
<img src="{dir}{default-img}" alt="{name}" />
</xsl:when>
<xsl:otherwise>
<i class="fa fa-camera"></i>
</xsl:otherwise>
</xsl:choose>
</a> -->
<a href="{url}" title="{name}">
<xsl:value-of disable-output-escaping="yes" select="name"/>
</a>
</div>
<div class="col-md-4 col-lg-4 property-row">
<xsl:for-each select="/shop/shop_item_properties//property">
<xsl:variable name="propertyId" select="@id" />
<xsl:choose>
<xsl:when test="count($myItem/property_value[property_id = $propertyId])">
<!--Вывод всех свойств кроме минимального количества для заказа ($propertyId = 80)-->
<xsl:if test="$propertyId != 80">
<!--<xsl:value-of disable-output-escaping="yes" select="$propertyId"/>-->
<xsl:apply-templates select="$myItem/property_value[property_id = $propertyId]"/>
</xsl:if>
</xsl:when>
<xsl:otherwise></xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</div>
<xsl:choose>
<xsl:when test="currency > 0.1">
<div class="price-box col-xs-1 col-sm-1 col-md-1 col-lg-1">
<xsl:value-of select="format-number(price, '### ##0,00', 'my')"/><xsl:text> </xsl:text><xsl:value-of disable-output-escaping="yes" select="currency"/><xsl:text> </xsl:text>
<xsl:if test="discount != 0">
<span class="old-price">
<xsl:value-of select="format-number(price+discount+mark-up, '### ##0,00', 'my')"/><xsl:text> </xsl:text><xsl:value-of disable-output-escaping="yes" select="currency"/><xsl:text> </xsl:text>
</span>
</xsl:if>
<!-- Бонусы для товара -->
<xsl:if test="count(shop_bonuses/shop_bonus)">
<div class="product-bonuses">
+<xsl:value-of select="shop_bonuses/total" /> бонусов
</div>
</xsl:if>
</div>
</xsl:when>
<xsl:otherwise>
<div class="price-box col-xs-1 col-sm-1 col-md-1 col-lg-1">
<xsl:value-of select="format-number(price, '### ##0,00', 'my')"/><xsl:text> </xsl:text><xsl:value-of disable-output-escaping="yes" select="currency"/><xsl:text> </xsl:text>
<xsl:if test="discount != 0">
<span class="old-price">
<xsl:value-of select="format-number(price+discount+mark-up, '### ##0,00', 'my')"/><xsl:text> </xsl:text><xsl:value-of disable-output-escaping="yes" select="currency"/><xsl:text> </xsl:text>
</span>
</xsl:if>
<!-- Бонусы для товара -->
<xsl:if test="count(shop_bonuses/shop_bonus)">
<div class="product-bonuses">
+<xsl:value-of select="shop_bonuses/total" /> бонусов
</div>
</xsl:if>
</div>
</xsl:otherwise>
</xsl:choose>
<div class="actions col-xs-1 col-sm-1 col-md-2 col-lg-2">
<button class="button btn-cart" onclick="return $.bootstrapAddIntoCart('{/shop/url}cart/', {@id}, 1)" title="Add to Cart" type="button">
<i class="fa fa-shopping-cart bg-color5">
</i>
</button>
<!--</div>-->
<xsl:variable name="shop_item_id" select="@id" />
<div style="display:inline-block;">
<xsl:if test="/shop/favorite/shop_item[@id = $shop_item_id]/node()">
<xsl:attribute name="class">link-wishlist-current</xsl:attribute>
</xsl:if>
<a class="link-wishlist" onclick="return $.addFavorite('{/shop/url}', {@id}, this)"><i class="fa fa-heart-o"></i></a>
</div>
<div style="display: inline-block;">
<xsl:if test="/shop/comparing/shop_item[@id = $shop_item_id]/node()">
<xsl:attribute name="class">link-compare-current</xsl:attribute>
</xsl:if>
<span class="separator">|</span>
<a class="link-compare" onclick="return $.addCompare('{/shop/url}', {@id}, this)"><i class="fa fa-bar-chart"></i></a>
</div>
</div>
</div>
</xsl:template>
Но что написать внутри тэгов:
<!-- Заголовок таблицы -->
<xsl:template match="header">
</xsl:template>
Я уже все перепробовал. Поэтому внутри тэгов ничего нет.
Авторизация