If product has variants, but no main image..
<mvt:foreach iterator="product" array="products">
<mvt:item name="toolkit" param="variantarray|vcount|l.all_settings:product:code" />
<mvt:assign name="counter" value="0" />
<mvt:assign name="hasMain" value="0" />
<mvt:item name="toolkit" param="customimagec|gal_images1|l.all_settings:product:code|" />
<mvt:if expr="g.gal_images1">
<mvt:foreach iterator="image" array="toolkitadditionalimages">
<mvt:if expr="l.settings:image:imagetype:code EQ 'main'">
<mvt:assign name="hasMain" value="1" />
</mvt:if>
</mvt:foreach>
</mvt:if>
<mvt:if expr="g.hasMain EQ 0">
<mvt:foreach iterator="variant" array="variants">
<mvt:assign name="counter" value="g.counter + 1" />
<mvt:if expr="g.counter EQ 1">
<mvt:item name="toolkit" param="customimagec|gal_images|l.all_settings:variant:variant_code|" />
<mvt:if expr="g.gal_images">
<mvt:foreach iterator="image" array="toolkitadditionalimages">
<mvt:if expr="l.settings:image:imagetype:code EQ 'main'">
<ProductImage_Add product_code="&mvt:product:code;" filepath="&mvte:image:image:image;" imagetype_code="main" /><br />
</mvt:if>
</mvt:foreach>
</mvt:if>
</mvt:if>
</mvt:foreach>
</mvt:if>
</mvt:foreach>