КАРТОЧКА ТОВАРА / МИКРОРАЗМЕТКА В КАРТОЧКЕ ТОВАРА (для HostCMS)

Заметка создана: 30 июля 2024 г.
Микроразметка в Хлебных крошках в XSL шаблоне "Карточка товара"
<!-- Путь к группе -->
     <div class="d-none d-sm-block breadcrumbs" xmlns:v="http://rdf.data-vocabulary.org/#">

            <xsl:if test="$group = 0">
                <span typeof="v:Breadcrumb">
                    <a title="{/shop/name}" href="{/shop/url}" hostcms:id="{/shop/@id}" hostcms:field="name" hostcms:entity="shop" property="v:title" rel="v:url">
                        <xsl:value-of disable-output-escaping="yes" select="/shop/name"/>
                    </a>
                </span>
            </xsl:if>

            <xsl:apply-templates select="/shop//shop_group[@id=$group]" mode="breadCrumbs"/>

            <!-- Если модификация, выводим в пути родительский товар -->
            <xsl:if test="shop_item/node()">
                <i class="fa fa-angle-right"></i>

                <span typeof="v:Breadcrumb">
                    <a title="{shop_item/name}" href="{shop_item/url}" property="v:title" rel="v:url">
                        <xsl:value-of disable-output-escaping="yes" select="shop_item/name"/>
                    </a>
                </span>
            </xsl:if>

            <i class="fa fa-angle-right"></i>

            <span typeof="v:Breadcrumb">
                <a href="{url}" hostcms:id="{@id}" hostcms:field="name" hostcms:entity="shop_item" property="v:title" rel="v:url"><xsl:value-of disable-output-escaping="yes" select="name"/></a>
            </span>
        </div>
<!-- Шаблон выводит рекурсивно ссылки на группы магазина -->
<xsl:template match="shop_group" mode="breadCrumbs">
    <xsl:param name="parent_id" select="parent_id"/>

    <!-- Получаем ID родительской группы и записываем в переменную $group -->
    <xsl:param name="group" select="/shop/shop_group"/>

    <xsl:apply-templates select="//shop_group[@id=$parent_id]" mode="breadCrumbs"/>

    <xsl:if test="parent_id=0">
        <span typeof="v:Breadcrumb">
            <a title="{/shop/name}" href="{/shop/url}" hostcms:id="{/shop/@id}" hostcms:field="name" hostcms:entity="shop" class="root" property="v:title" rel="v:url">
                <xsl:value-of select="/shop/name"/>
            </a>
        </span>
    </xsl:if>

    <i class="fa fa-angle-right"></i>

    <span typeof="v:Breadcrumb">
        <a title="{name}" href="{url}" hostcms:id="{@id}" hostcms:field="name" hostcms:entity="shop_group" property="v:title" rel="v:url">
            <xsl:value-of disable-output-escaping="yes" select="name"/>
        </a>
    </span>

</xsl:template>

Микроразметка карточки товара

<div itemscope="itemscope" itemtype="http://schema.org/Product">

                   <!-- Название товара -->
                   <h1><span itemprop="name"><xsl:value-of select="name"/></span></h1>


                    <!-- Изображение для товара, если есть -->
                    <xsl:if test="image_small != ''">
                        <div id="gallery" class="photo">
                            <a href="{dir}{image_large}" ><img src="{dir}{image_small}" alt="" itemprop="image"/></a>
                        </div>

                        <ul class="margin-top-10">
                        <li><a href="{dir}{image_large}"><img src="{dir}{image_small}" alt=""  height="100"/></a></li>
                            <xsl:for-each select="property_value[tag_name='xml_foto'][file !='']">
                            <li><a href="{../dir}{file}"><img src="{../dir}{file_small}" height="100" itemprop="image"/></a></li>
                            </xsl:for-each>
                        </ul>
                    </xsl:if>


                    <!-- Цена товара -->
                    <xsl:if test="price != 0">
                        <div class="price" itemprop="offers" itemscope="" itemtype="http://schema.org/Offer">
                        <span itemprop="price" content="{price}"><xsl:value-of select="format-number(price, '### ##0', 'my')"/></span><xsl:text> </xsl:text>
                            <span itemprop="priceCurrency" content="RUB"><xsl:value-of select="currency"/></span>

                            <!-- Если цена со скидкой - выводим ее -->
                            <xsl:if test="discount != 0">
                                <p class="item-old-price">
                                    <xsl:value-of select="format-number(price + discount, '### ##0', 'my')"/><xsl:text> </xsl:text><xsl:value-of select="currency" />
                                </p>
                            </xsl:if>
                        </div>
                    </xsl:if>


                    <!-- Описание товара -->
                    <xsl:if test="description != ''">
                        <div itemprop="description"><xsl:value-of disable-output-escaping="yes" select="description" /></div>
                    </xsl:if>

   </div>

<div itemscope itemtype="http://schema.org/Product">
            <img src="/img/img.jpg" itemprop="image">
            <div itemprop="name"><strong>товар</strong></div>
            <div itemprop="description">Какое-то описание</div>
            <div itemprop="offers" itemscope itemtype="http://schema.org/Offer"> 
            <span itemprop="price">25356</span> <span itemprop="priceCurrency">RUB</span>
            </div>
</div>