xml 具有变体的自定义数据馈送

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了xml 具有变体的自定义数据馈送相关的知识,希望对你有一定的参考价值。

<mvt:comment>
	<!--
	Custom Data Feed
	File Output: /feeds/output/google.txt & /feeds/output/data-feed.txt
	date; curl -o NUL --location --max-redirs 1000 --data "auth=o8syU567D88o94yh&redirect=1" http://www.example.com/data-feed.html; date; echo -e "\a";
	-->
</mvt:comment>

<mvt:if expr="g.auth NE 'o8syU567D88o94yh'">
	Access Denied
	<mvt:exit/>
</mvt:if>

<mvt:assign name="g.tab" value="asciichar(9)"/>
<mvt:assign name="g.newline" value="asciichar(10)"/>
<mvt:assign name="g.return" value="asciichar(13)"/>
<mvt:assign name="g.pipe" value="asciichar(124)"/>
<mvt:assign name="g.comma" value="asciichar(44)"/>
<mvt:assign name="g.quote" value="asciichar(34)"/>
<mvt:assign name="g.period" value="asciichar(46)"/>
<mvt:assign name="g.delimiter" value="asciichar(9)"/>

<mvt:assign name="g.file_folder" value="'/feeds/output/'"/>

<mvt:comment><!-- File Config Variables --></mvt:comment>
	<mvt:if expr="ISNULL g.temp_file_name">
		<mvt:assign name="g.temp_file_name" value="'data-feed.temp'"/>
	</mvt:if>
	<mvt:assign name="g.temp_file_path" value="g.file_folder $ g.temp_file_name"/>
	<mvt:assign name="g.final_file_path" value="glosub( g.temp_file_path, '.temp', '.txt' )"/>


<mvt:assign name="g.header_row" value="
	'id'								$ g.delimiter $
	'item_group_id'						$ g.delimiter $
	'code'								$ g.delimiter $
	'title'								$ g.delimiter $
	'description'						$ g.delimiter $
	'google_product_category'			$ g.delimiter $
	'product_type'						$ g.delimiter $
	'general_product_type'				$ g.delimiter $
	'departments'						$ g.delimiter $
	'link'								$ g.delimiter $
	'image_link'						$ g.delimiter $
	'condition'							$ g.delimiter $
	'availability'						$ g.delimiter $
	'count_onhand'						$ g.delimiter $
	'flag'								$ g.delimiter $
	'price'								$ g.delimiter $
	'brand'								$ g.delimiter $
	'gender'							$ g.delimiter $
	'age_group'							$ g.delimiter $
	'color'								$ g.delimiter $
	'size'								$ g.delimiter $
	'master_flag'						$ g.delimiter $
	'expiration_date'					$
	g.newline
"/>


<mvt:comment><!-- Delete File if it exists, create new file with header row --></mvt:comment>
	<mvt:if expr="ISNULL g.Per_Page">
		<mvt:assign name="g.Per_Page" value="100" />
	</mvt:if>
	<mvt:if expr="ISNULL g.AllOffset">
		<mvt:assign name="g.AllOffset" value="0" />
	</mvt:if>
	<mvt:if expr="g.output EQ 'screen'">
		&mvt:global:header_row;
	<mvt:else>
		<mvt:comment><!-- Create/Delete File --></mvt:comment>
			<mvt:if expr="g.AllOffset LT g.Per_Page">
				<mvt:assign name="g.file_exists" value="sexists(g.temp_file_path)"/>
				<mvt:if expr="g.file_exists EQ 1">
					<mvt:assign name="g.file_deleted" value="sdelete(g.temp_file_path)"/>
					<mvt:if expr="g.file_deleted EQ 1">
						<mvt:assign name="g.file_created" value="file_create(g.temp_file_path, 'script', g.header_row)"/>
					</mvt:if>
				<mvt:else>
					<mvt:assign name="g.file_created" value="file_create(g.temp_file_path, 'script', g.header_row)"/>
				</mvt:if>
			</mvt:if>
	</mvt:if>

<mvt:comment><!-- Loop over all of the products --></mvt:comment>
	<mvt:foreach iterator="product" array="all_products:products">

		<mvt:comment><!-- Clean Description --></mvt:comment>
			<mvt:item name="toolkit" param="nohtml|l.all_settings:product:descrip|l.all_settings:product:descrip" />
			<mvt:assign name="l.settings:product:descrip" value="glosub( l.settings:product:descrip, g.newline, '' )" />
			<mvt:assign name="l.settings:product:descrip" value="glosub( l.settings:product:descrip, g.tab, '' )" />
			<mvt:assign name="l.settings:product:descrip" value="glosub( l.settings:product:descrip, g.return, '' )" />
			<mvt:assign name="l.settings:product:descrip" value="trim(glosub( l.settings:product:descrip, '&nbsp;', ' ' ))" />

		<mvt:comment><!-- Misc. Product Details --></mvt:comment>
			<mvt:assign name="l.settings:product:item_group_id" value="l.settings:product:id" />
			<mvt:assign name="l.settings:product:link" value="'http://www.btosports.com/p/' $ l.settings:product:code" />
			<mvt:if expr="l.settings:product:customfield_values:productimagecustomfields:main">
				<mvt:assign name="l.settings:product:image" value="'http://www.btosports.com/mm5/' $ l.settings:product:customfield_values:productimagecustomfields:main" />
			</mvt:if>
			<mvt:assign name="l.settings:product:condition" value="'new'" />
			<mvt:assign name="l.settings:product:count_onhand" value="0" />

		<mvt:comment><!-- Loop Over Variants OR Attributes --></mvt:comment>
			<mvt:assign name="l.settings:product:total_quantity" value="0"/>
			<mvt:item name="toolkit" param="variantarray|l.all_settings:product:vcount|l.all_settings:product:code" />

			<mvt:comment><!-- Loop Over Variants (New Inventory Method) --></mvt:comment>
			<mvt:foreach iterator="variant" array="variants">

				<mvt:assign name="l.settings:variant:size" value="''" />
				<mvt:assign name="l.settings:variant:color" value="''" />
				<mvt:assign name="l.settings:variant:link" value="l.settings:product:link" />

				<mvt:comment><!-- Availability --></mvt:comment>
					<mvt:assign name="l.settings:product:count_onhand" value="l.settings:product:count_onhand + l.settings:variant:count_onhand" />
					<mvt:if expr="l.settings:variant:count_onhand GT 0">
						<mvt:assign name="l.settings:variant:availability" value="'in stock'" />
					<mvt:else>
						<mvt:assign name="l.settings:variant:availability" value="'out of stock'" />
					</mvt:if>

				<mvt:comment><!-- Misc. Variant Details --></mvt:comment>
					<mvt:item name="toolkit" param="customimagec|l.all_settings:variant:image|l.all_settings:variant:variant_code|main" />
					<mvt:if expr="l.settings:variant:image">
						<mvt:assign name="l.settings:variant:image" value="'http://' $ g.domain:name $ '/mm5/' $ l.settings:variant:image" />
					</mvt:if>
					<mvt:if expr="ISNULL l.settings:variant:price">
						<mvt:assign name="l.settings:variant:price" value="l.settings:product:price" />
					</mvt:if>
					<mvt:assign name="l.settings:variant:id" value="l.settings:variant:variant_id" />
					<mvt:assign name="l.settings:variant:code" value="gettoken(l.settings:variant:variant_code, '*', 1)" />

				<mvt:comment><!-- Write Variant File Row --></mvt:comment>
					<mvt:assign name="g.file_row" value="
						l.settings:variant:code													$ g.delimiter $
						l.settings:product:code													$ g.delimiter $
						l.settings:variant:code													$ g.delimiter $
						l.settings:product:name													$ g.delimiter $
						l.settings:product:descrip												$ g.delimiter $
						l.settings:product:customfield_values:customfields:google_category		$ g.delimiter $
						l.settings:product:product_type											$ g.delimiter $
						l.settings:product:general_product_type:trump							$ g.delimiter $
						l.settings:product:departments											$ g.delimiter $
						l.settings:variant:link													$ g.delimiter $
						l.settings:variant:image												$ g.delimiter $
						l.settings:product:condition											$ g.delimiter $
						l.settings:variant:availability											$ g.delimiter $
						l.settings:variant:count_onhand											$ g.delimiter $
						l.settings:product:customfield_values:customfields:flag					$ g.delimiter $
						l.settings:variant:price												$ g.delimiter $
						l.settings:product:brand												$ g.delimiter $
						l.settings:product:gender												$ g.delimiter $
						l.settings:product:age_group											$ g.delimiter $
						l.settings:variant:color												$ g.delimiter $
						l.settings:variant:size													$ g.delimiter $
						'v'																		$ g.delimiter $
						g.expiration_date														$
						g.newline
					"/>

					<mvt:if expr="g.output EQ 'screen'">
						&mvt:global:file_row;
					 <mvt:else>
						<mvt:assign name="g.write_line" value="file_append( g.temp_file_path, 'script', g.file_row )"/>
					</mvt:if>

			</mvt:foreach>

			<mvt:assign name="l.settings:product:variants" value="l.settings:variants" />

	</mvt:foreach>

	<mvt:if expr="g.output EQ 'debug'">
		<mvt:eval expr="decodeattribute(glosub(miva_array_serialize(l.settings:all_products:products), ',', '<br>'))" />
		<mvt:exit/>
	</mvt:if>

<mvt:comment><!-- Pagination/Response --></mvt:comment>
	<mvt:assign name="g.next_url" value="'http://' $ g.domain:name $ '/data-feed.html?redirect=' $ g.redirect $ '&auth=' $ g.auth $ '&Output=' $ g.output $ '&AllOffset=' $ g.AllNextOffset $ '&Per_Page=' $ g.Per_Page $ '&Product_Code=' $ g.Product_Code" />
	<mtt:if expr="l.settings:all_products:page_links:current_page EQ l.settings:all_products:page_links:last_page">
		Complete
		<mvt:comment><!-- Rename Final File --></mvt:comment>
			<mvt:assign name="g.file_exists" value="sexists(g.temp_file_path)"/>
			<mvt:if expr="g.file_exists EQ 1">
				<mvt:assign name="g.file_renamed" value="srename(g.temp_file_path, g.final_file_path)"/>
			</mvt:if>
	<mvt:else>
		Continue|&mvt:global:AllNextOffset;
		<mvt:if expr="g.output EQ 'redirect'">
			<mvt:assign name="l.header" value="miva_output_header( 'Status', '301 Moved Permanently' )" />
			<mvt:assign name="l.header" value="miva_output_header( 'Location', g.next_url )" />
		</mvt:if>
	</mvt:if>

以上是关于xml 具有变体的自定义数据馈送的主要内容,如果未能解决你的问题,请参考以下文章

WooCommerce 中特定产品变体的自定义后缀

PHP卷曲?阿贾克斯?将 XML 数据馈送作为动态下拉菜单导入

具有 Spring Security 和 Java Config 的自定义身份验证提供程序

Android API中的自定义字体低于16?

xml 生成自定义变体URL(Acme)

xml 生成自定义变体URL(Acme)