FH // XML for Product Kits & Default Variants // Update Templates & attributes
<mvt:comment><!-- Auth code check --></mvt:comment>
<mvt:if expr="g.auth NE '2dMo1MTgbigNtV6a'">
Access Denied
<mvt:exit/>
</mvt:if>
<mvt:assign name="l.break" value="asciichar( 10 )" />
<mvt:assign name="l.double_quote" value="asciichar( 34 )" />
<mvt:assign name="g.File_Path" value="'/xml_prodkits/'" />
<mvt:assign name="g.File_Name" value="'provisioning.xml'" />
<mvt:assign name="g.Final_File_Path" value="g.File_Path $ g.File_Name" />
<mvt:assign name="g.Full_File_Path" value="g.domain:name $ g.File_Path $ g.File_Name" />
<mvt:assign name="g.temp_file" value="g.File_Path $ 'temp_' $ g.File_Name" />
<mvt:if expr="l.settings:all_products:page_links:last_page GT 1">
<mvt:if expr="ISNULL g.start">
<a href="&mvt:global:sessionurl;Screen=&mvt:global:Screen;&start=1&auth=&mvt:global:auth;">Start</a><br />
</mvt:if>
</mvt:if>
<mvt:if expr="g.start">
<mvt:if expr="ISNULL g.Per_Page">
<mvt:assign name="g.Per_Page" value="150" />
</mvt:if>
<mvt:if expr="ISNULL g.Offset">
<mvt:assign name="g.Offset" value="0" />
</mvt:if>
<mvt:if expr="l.settings:all_products:page_links:current_page EQ l.settings:all_products:page_links:last_page">
COMPLETE<br/><br/>
</mvt:if>
<mvt:foreach iterator="product" array="all_products:products">
<mvt:assign name="l.settings:getOptions:query" value="'SELECT DISTINCT option_1, option_2, miva_sku FROM prodkit_export WHERE miva_sku = ?'" />
<mvt:assign name="l.settings:getOptions:bind_parameters[1]" value="l.settings:product:code" />
<mvt:item name="mvdo" param="l.settings:getOptions" />
<mvt:if expr="l.settings:getOptions:results[1]:option_1">
<mvt:comment><!-- Product Kit! --></mvt:comment>
<mvt:assign name="g.xml" value="g.xml $ '
<ProductKit_Delete_All product_code=\"' $ l.settings:product:code $ '\" />'" />
<mvt:foreach iterator="option" array="getOptions:results">
<mvt:assign name="l.settings:getParts:query" value="'SELECT part_sku, qty FROM prodkit_export WHERE option_1 = ? AND option_2 = ? AND miva_sku = ?'" />
<mvt:assign name="l.settings:getParts:bind_parameters[1]" value="l.settings:option:option_1" />
<mvt:assign name="l.settings:getParts:bind_parameters[2]" value="l.settings:option:option_2" />
<mvt:assign name="l.settings:getParts:bind_parameters[3]" value="l.settings:product:code" />
<mvt:item name="mvdo" param="l.settings:getParts" />
<mvt:assign name="l.settings:loadOption1:query" value="'SELECT a.code as attribute_code, o.code as option_code, a.attemp_id as template FROM s01_Attributes as a LEFT JOIN s01_Options as o ON a.id = o.attr_id WHERE o.code LIKE ? AND a.product_id = ?'" />
<mvt:assign name="l.settings:loadOption1:bind_parameters[1]" value="l.settings:option:option_1 $ ':%'" />
<mvt:assign name="l.settings:loadOption1:bind_parameters[2]" value="l.settings:product:id" />
<mvt:item name="mvdo" param="l.settings:loadOption1" />
<mvt:assign name="l.settings:loadOption2:query" value="'SELECT a.code as attribute_code, o.code as option_code, a.attemp_id as template FROM s01_Attributes as a LEFT JOIN s01_Options as o ON a.id = o.attr_id WHERE o.code LIKE ? AND a.product_id = ?'" />
<mvt:assign name="l.settings:loadOption2:bind_parameters[1]" value="l.settings:option:option_2 $ ':%'" />
<mvt:assign name="l.settings:loadOption2:bind_parameters[2]" value="l.settings:product:id" />
<mvt:item name="mvdo" param="l.settings:loadOption2" />
<mvt:if expr="ISNULL l.settings:loadOption1:results[1]:option_code">
<mvt:assign name="l.settings:checkOption1:query" value="'SELECT a.code as attribute_code, o.code as option_code, a.attemp_id as template FROM s01_Attributes as a LEFT JOIN s01_AttributeTemplateOptions as o ON a.attemp_id = o.attemp_id WHERE o.code LIKE ? AND a.product_id = ?'" />
<mvt:assign name="l.settings:checkOption1:bind_parameters[1]" value="l.settings:option:option_1 $ ':%'" />
<mvt:assign name="l.settings:checkOption1:bind_parameters[2]" value="l.settings:product:id" />
<mvt:item name="mvdo" param="l.settings:checkOption1" />
</mvt:if>
<mvt:comment> <!-- Update Product Attribute/ Templates [1] --></mvt:comment>
<mvt:if expr="l.settings:checkOption1:results[1]:template GT 0">
<mvt:assign name="l.settings:optionTemplate1:query" value="'SELECT code FROM s01_AttributeTemplateAttrs WHERE attemp_id = ?'" />
<mvt:assign name="l.settings:optionTemplate1:bind_parameters[1]" value="l.settings:checkOption1:results[1]:template" />
<mvt:item name="mvdo" param="l.settings:optionTemplate1" />
<mvt:assign name="g.xml" value="g.xml $ '
<AttributeTemplateAttribute_Update template_code=\"' $ l.settings:checkOption1:results[1]:attribute_code $ '\" attribute_code=\"' $ l.settings:optionTemplate1:results[1]:code $ '\">
<Inventory>Yes</Inventory>
</AttributeTemplateAttribute_Update>'" />
<mvt:elseif expr="l.settings:loadOption1:results[1]:attribute_code">
<mvt:assign name="g.xml" value="g.xml $ '
<ProductAttribute_Update product_code=\"' $ l.settings:product:code $ '\" attribute_code=\"' $ l.settings:loadOption1:results[1]:attribute_code $ '\">
<Inventory>Yes</Inventory>
</ProductAttribute_Update>'" />
</mvt:if>
<mvt:if expr="ISNULL l.settings:loadOption2:results[1]:option_code">
<mvt:assign name="l.settings:checkOption2:query" value="'SELECT a.code as attribute_code, o.code as option_code, a.attemp_id as template FROM s01_Attributes as a LEFT JOIN s01_AttributeTemplateOptions as o ON a.attemp_id = o.attemp_id WHERE o.code LIKE ? AND a.product_id = ?'" />
<mvt:assign name="l.settings:checkOption2:bind_parameters[1]" value="l.settings:option:option_2 $ ':%'" />
<mvt:assign name="l.settings:checkOption2:bind_parameters[2]" value="l.settings:product:id" />
<mvt:item name="mvdo" param="l.settings:checkOption2" />
</mvt:if>
<mvt:comment> <!-- Update Product Attribute/ Templates [2] --></mvt:comment>
<mvt:if expr="l.settings:checkOption2:results[1]:template GT 0">
<mvt:assign name="l.settings:optionTemplate2:query" value="'SELECT code FROM s01_AttributeTemplateAttrs WHERE attemp_id = ?'" />
<mvt:assign name="l.settings:optionTemplate2:bind_parameters[1]" value="l.settings:checkOption2:results[1]:template" />
<mvt:item name="mvdo" param="l.settings:optionTemplate2" />
<mvt:assign name="g.xml" value="g.xml $ '
<AttributeTemplateAttribute_Update template_code=\"' $ l.settings:checkOption2:results[1]:attribute_code $ '\" attribute_code=\"' $ l.settings:optionTemplate2:results[1]:code $ '\">
<Inventory>Yes</Inventory>
</AttributeTemplateAttribute_Update>'" />
<mvt:elseif expr="l.settings:loadOption2:results[1]:attribute_code">
<mvt:assign name="g.xml" value="g.xml $ '
<ProductAttribute_Update product_code=\"' $ l.settings:product:code $ '\" attribute_code=\"' $ l.settings:loadOption2:results[1]:attribute_code $ '\">
<Inventory>Yes</Inventory>
</ProductAttribute_Update>'" />
</mvt:if>
<mvt:assign name="g.xml" value="g.xml $ '
<ProductVariant_Add product_code=\"' $ l.settings:product:code $ '\">'" />
<mvt:assign name="g.xml" value="g.xml $ '
<Options>'" />
<mvt:if expr="l.settings:checkOption1:results[1]:template GT 0">
<mvt:assign name="l.settings:optionTemplate1:query" value="'SELECT code FROM s01_AttributeTemplateAttrs WHERE attemp_id = ?'" />
<mvt:assign name="l.settings:optionTemplate1:bind_parameters[1]" value="l.settings:checkOption1:results[1]:template" />
<mvt:item name="mvdo" param="l.settings:optionTemplate1" />
<mvt:assign name="g.xml" value="g.xml $ '
<AttributeTemplateAttribute_Option attribute_code=\"' $ l.settings:checkOption1:results[1]:attribute_code $ '\" attributetemplateattribute_code=\"' $ l.settings:optionTemplate1:results[1]:code $ '\" option_code=\"' $ l.settings:checkOption1:results[1]:option_code $ '\" />'" />
<mvt:else>
<mvt:assign name="g.xml" value="g.xml $ '
<Attribute_Option attribute_code=\"' $ l.settings:loadOption1:results[1]:attribute_code $ '\" option_code=\"' $ l.settings:loadOption1:results[1]:option_code $ '\" />'" />
</mvt:if>
<mvt:if expr="l.settings:option:option_2">
<mvt:if expr="l.settings:checkOption2:results[1]:template GT 0">
<mvt:assign name="l.settings:optionTemplate2:query" value="'SELECT code FROM s01_AttributeTemplateAttrs WHERE attemp_id = ?'" />
<mvt:assign name="l.settings:optionTemplate2:bind_parameters[1]" value="l.settings:checkOption2:results[1]:template" />
<mvt:item name="mvdo" param="l.settings:optionTemplate2" />
<mvt:assign name="g.xml" value="g.xml $ '
<AttributeTemplateAttribute_Option attribute_code=\"' $ l.settings:checkOption2:results[1]:attribute_code $ '\" attributetemplateattribute_code=\"' $ l.settings:optionTemplate2:results[1]:code $ '\" option_code=\"' $ l.settings:checkOption2:results[1]:option_code $ '\" />'" />
<mvt:elseif expr="l.settings:loadOption2:results[1]:option_code">
<mvt:assign name="g.xml" value="g.xml $ '
<Attribute_Option attribute_code=\"' $ l.settings:loadOption2:results[1]:attribute_code $ '\" option_code=\"' $ l.settings:loadOption2:results[1]:option_code $ '\" />'" />
</mvt:if>
</mvt:if>
<mvt:assign name="g.xml" value="g.xml $ '
</Options>
<Parts>'" />
<mvt:foreach iterator="part" array="getParts:results">
<mvt:assign name="g.xml" value="g.xml $ '
<Part product_code=\"' $ l.settings:part:part_sku $ '\" quantity=\"' $ l.settings:part:qty $ '\" />' "/>
</mvt:foreach>
<mvt:assign name="g.xml" value="g.xml $ '
</Parts>
<ProductVariantPricing>
<Method>Master</Method>
</ProductVariantPricing>
</ProductVariant_Add>'" />
</mvt:foreach>
<mvt:else>
<mvt:comment><!-- Default --></mvt:comment>
<mvt:assign name="l.settings:defaultVariants:query" value="'SELECT part_sku, qty FROM prodkit_export WHERE miva_sku = ?'" />
<mvt:assign name="l.settings:defaultVariants:bind_parameters[1]" value="l.settings:product:code" />
<mvt:item name="mvdo" param="l.settings:defaultVariants" />
<mvt:if expr="l.settings:defaultVariants:results[1]:part_sku">
<mvt:assign name="g.xml" value="g.xml $ '
<ProductVariant_Update_Default product_code=\"' $ l.settings:product:code $ '\">
<Parts>'" />
<mvt:foreach iterator="part" array="defaultVariants:results">
<mvt:assign name="g.xml" value="g.xml $ '
<Part product_code=\"' $ l.settings:part:part_sku $ '\" quantity=\"' $ l.settings:part:qty $ '\" />'" />
</mvt:foreach>
<mvt:assign name="g.xml" value="g.xml $ '
</Parts>
<ProductVariantPricing>
<Method>Master</Method>
</ProductVariantPricing>
</ProductVariant_Update_Default>'" />
</mvt:if>
</mvt:if>
</mvt:foreach>
<mvt:if expr="l.settings:all_products:page_links:current_page EQ 1">
<mvt:assign name="l.file_exists" value="sexists( g.temp_file )" />
<mvt:if expr="l.file_exists EQ 1">
<mvt:assign name="l.file_deleted" value="sdelete( g.temp_file )" />
<mvt:if expr="l.file_deleted EQ 1">
<mvt:assign name="l.file_created" value="file_create( g.temp_file, 'SCRIPT', g.xml )" />
</mvt:if>
<mvt:else>
<mvt:assign name="l.file_created" value="file_create( g.temp_file, 'SCRIPT', g.xml )" />
</mvt:if>
</mvt:if>
<mvt:if expr="g.xml">
<mvt:assign name="l.write_line" value="file_append( g.temp_file, 'script', g.xml )" />
</mvt:if>
<mvt:if expr="l.settings:all_products:page_links:current_page EQ l.settings:all_products:page_links:last_page">
</mvt:if>
<mvt:if expr="l.settings:all_products:page_links:current_page NE l.settings:all_products:page_links:last_page">
<a href="&mvt:all_products:page_links:next_link;&auth=&mvt:global:auth;&start=&mvt:global:start;" id="page-links-next">next</a>
</mvt:if>
</mvt:if>
<mvt:if expr="g.start AND l.settings:all_products:page_links:current_page NE l.settings:all_products:page_links:last_page">
<script>
document.addEventListener("DOMContentLoaded", function(event) {
var next = document.getElementById('page-links-next').getAttribute('href');
if (next) {
window.location.href = next;
}
});
</script>
</mvt:if>