При экспорте в YML не выгружается фото товара (тэг picture)
Материал из Umicms
Версия от 08:52, 4 июня 2013; Mad grant (обсуждение | вклад)
Если при экспорте в YML не выгружается фото товара, следует проверить тип данных товара, который выгружается. По умолчанию, фото для тега picture берётся из поля photo. Если такого поля нет в типе данных, то в файл ~/xsl/export/custom/YML.xsl можно скопировать шаблон экспорта объекта и добавить туда нужное поле. Например, если для изображения требуется использовать поле izobrajenie, то нужно заменить в шаблоне поле photo на izobrajenie. Пример содержимого файла ~/xsl/export/custom/YML.xsl для данного случая:
<?xml version="1.0" encoding="UTF-8"?>
<!--
TODO: // Write here your own templates
-->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:php="http://php.net/xsl"
xmlns:udt="http://umi-cms.ru/2007/UData/templates"
extension-element-prefixes="php"
exclude-result-prefixes="xsl php udt">
<xsl:template match="page[basetype/@method = 'object']">
<xsl:param name="price" select="number(.//property[@name = 'price']/value)" />
<xsl:if test="$price > 0">
<offer id="{@id}">
<xsl:choose>
<xsl:when test=".//property[@name = $vendor]/value != '' and .//property[@name = $model]/value != ''">
<xsl:attribute name="type">vendor.model</xsl:attribute>
</xsl:when>
<xsl:when test=".//property[@name = $isbn]/value != ''">
<xsl:attribute name="type">book</xsl:attribute>
</xsl:when>
<xsl:when test=".//property[@name = $title]/value != ''">
<xsl:attribute name="type">artist.title</xsl:attribute>
</xsl:when>
<xsl:when test=".//property[@name = $place]/value != ''">
<xsl:attribute name="type">event-ticket</xsl:attribute>
</xsl:when>
<xsl:when test=".//property[@name = $transport]/value != ''">
<xsl:attribute name="type">tour</xsl:attribute>
</xsl:when>
</xsl:choose>
<xsl:attribute name="available">
<xsl:choose>
<xsl:when test=".//property[@name = 'common_quantity']/value > 0"><xsl:text>true</xsl:text></xsl:when>
<xsl:otherwise><xsl:text>false</xsl:text></xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<url><xsl:value-of select="concat('http://', /umidump/meta/domain, @link)" /></url>
<price><xsl:value-of select="$price"/></price>
<currencyId>
<xsl:choose>
<xsl:when test="string-length($default-currency)"><xsl:value-of select="$default-currency" /></xsl:when>
<xsl:otherwise>RUR</xsl:otherwise>
</xsl:choose>
</currencyId>
<categoryId><xsl:value-of select="@parentId"/></categoryId>
<xsl:if test=".//property[@name = 'izobrajenie']/value != ''">
<picture>
<xsl:value-of select="concat('http://', /umidump/meta/domain, //property[@name = 'izobrajenie']/value)"/>
</picture>
</xsl:if>
<!--
<delivery>!!!delivery(true|false)!!!</delivery>
-->
<xsl:choose>
<!-- vendor.model -->
<xsl:when test="(.//property[@name = $vendor]/value != '') and (.//property[@name = $model]/value != '')">
<xsl:if test=".//property[@name = $typePrefix]/value != ''">
<typePrefix><xsl:value-of select=".//property[@name = $typePrefix]/value"/></typePrefix>
</xsl:if>
<vendor><xsl:value-of select=".//property[@name = $vendor]/value"/></vendor>
<model><xsl:value-of select=".//property[@name = $model]/value"/></model>
</xsl:when>
<!-- book -->
<xsl:when test=".//property[@name = $isbn]/value != ''">
<xsl:if test=".//property[@name = $author]/value != ''">
<author><xsl:value-of select=".//property[@name = $author]/value"/></author>
</xsl:if>
<name><xsl:value-of select="name"/></name>
<xsl:if test=".//property[@name = $publisher]/value != ''">
<publisher><xsl:value-of select=".//property[@name = $publisher]/value"/></publisher>
</xsl:if>
<xsl:if test=".//property[@name = $series]/value != ''">
<series><xsl:value-of select=".//property[@name = $series]/value"/></series>
</xsl:if>
<xsl:if test=".//property[@name = $year]/value != ''">
<year><xsl:value-of select=".//property[@name = $year]/value"/></year>
</xsl:if>
<xsl:if test=".//property[@name = $isbn]/value != ''">
<ISBN><xsl:value-of select=".//property[@name = $isbn]/value"/></ISBN>
</xsl:if>
</xsl:when>
<!-- artist.title -->
<xsl:when test=".//property[@name = $title]/value != ''">
<xsl:if test=".//property[@name = $artist]/value != ''">
<artist><xsl:value-of select=".//property[@name = $artist]/value"/></artist>
</xsl:if>
<title><xsl:value-of select=".//property[@name = $title]/value"/></title>
<xsl:if test=".//property[@name = $year]/value != ''">
<year><xsl:value-of select=".//property[@name = $year]/value"/></year>
</xsl:if>
<xsl:if test=".//property[@name = $media]/value != ''">
<media><xsl:value-of select=".//property[@name = $media]/value"/></media>
</xsl:if>
<xsl:if test=".//property[@name = $starring]/value != ''">
<starring><xsl:value-of select=".//property[@name = $starring]/value"/></starring>
</xsl:if>
<xsl:if test=".//property[@name = $director]/value != ''">
<director><xsl:value-of select=".//property[@name = $director]/value"/></director>
</xsl:if>
<xsl:if test=".//property[@name = $originalName]/value != ''">
<originalName><xsl:value-of select=".//property[@name = $originalName]/value"/></originalName>
</xsl:if>
<xsl:if test=".//property[@name = $country]/value != ''">
<country><xsl:value-of select=".//property[@name = $country]/value"/></country>
</xsl:if>
</xsl:when>
<!-- event-ticket -->
<xsl:when test=".//property[@name = $place]/value != ''">
<name><xsl:value-of select="name"/></name>
<place><xsl:value-of select=".//property[@name = $place]/value"/></place>
<xsl:if test="(.//property[@name = $hall]/value != '') and (.//property[@name = $hall-plan]/value != '')">
<hall plan="{.//property[@name = $hall-plan]/value}"><xsl:value-of select=".//property[@name = $hall]/value"/></hall>
</xsl:if>
<xsl:if test=".//property[@name = $hall_part]/value != ''">
<hall_part><xsl:value-of select=".//property[@name = $hall_part]/value"/></hall_part>
</xsl:if>
<xsl:if test=".//property[@name = $date]/value != ''">
<date><xsl:value-of select=".//property[@name = $date]/value"/></date>
</xsl:if>
<xsl:if test=".//property[@name = $is_premiere]/value != ''">
<is_premiere><xsl:value-of select=".//property[@name = $is_premiere]/value"/></is_premiere>
</xsl:if>
<xsl:if test=".//property[@name = $is_kids]/value != ''">
<is_kids><xsl:value-of select=".//property[@name = $is_kids]/value"/></is_kids>
</xsl:if>
</xsl:when>
<!-- tour -->
<xsl:when test=".//property[@name = $transport]/value != ''">
<xsl:if test=".//property[@name = $worldRegion]/value != ''">
<worldRegion><xsl:value-of select=".//property[@name = $worldRegion]/value"/></worldRegion>
</xsl:if>
<xsl:if test=".//property[@name = $country]/value != ''">
<country><xsl:value-of select=".//property[@name = $country]/value"/></country>
</xsl:if>
<xsl:if test=".//property[@name = $region]/value != ''">
<region><xsl:value-of select=".//property[@name = $region]/value"/></region>
</xsl:if>
<xsl:if test=".//property[@name = $days]/value != ''">
<days><xsl:value-of select=".//property[@name = $days]/value"/></days>
</xsl:if>
<xsl:if test=".//property[@name = $dataTour]/value != ''">
<dataTour><xsl:value-of select=".//property[@name = $dataTour]/value"/></dataTour>
</xsl:if>
<name><xsl:value-of select="name"/></name>
<xsl:if test=".//property[@name = $hotel_stars]/value != ''">
<hotel_stars><xsl:value-of select=".//property[@name = $hotel_stars]/value"/></hotel_stars>
</xsl:if>
<xsl:if test=".//property[@name = $room]/value != ''">
<room><xsl:value-of select=".//property[@name = $room]/value"/></room>
</xsl:if>
<xsl:if test=".//property[@name = $meal]/value != ''">
<meal><xsl:value-of select=".//property[@name = $meal]/value"/></meal>
</xsl:if>
<xsl:if test=".//property[@name = $included]/value != ''">
<included><xsl:value-of select=".//property[@name = $included]/value"/></included>
</xsl:if>
<xsl:if test=".//property[@name = $transport]/value != ''">
<transport><xsl:value-of select=".//property[@name = $transport]/value"/></transport>
</xsl:if>
<xsl:if test=".//property[@name = 'price_min']/value != ''">
<price_min><xsl:value-of select=".//property[@name = 'price_min']/value"/></price_min>
</xsl:if>
<xsl:if test=".//property[@name = 'price_max']/value != ''">
<price_max><xsl:value-of select=".//property[@name = 'price_max']/value"/></price_max>
</xsl:if>
</xsl:when>
<xsl:otherwise>
<name><xsl:value-of select="name"/></name>
</xsl:otherwise>
</xsl:choose>
<xsl:if test=".//property[@name = 'description']/value != ''">
<description><xsl:value-of select=".//property[@name = 'description']/value"/></description>
</xsl:if>
<xsl:if test=".//property[@name = 'bar_code']/value != '' and string-length(.//property[@name = 'bar_code']/value) < 13">
<barcode><xsl:value-of select=".//property[@name = 'bar_code']/value"/></barcode>
</xsl:if>
<xsl:variable name="type_id" select="@type-id" />
<xsl:variable name="page_id" select="@id" />
<xsl:apply-templates select="../../types/type[@id = $type_id]" mode="filterable">
<xsl:with-param name="page_id" select="$page_id" />
</xsl:apply-templates>
</offer>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
где izobrajenie - id поля, из которого нужно извлечь фотографию.