Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save andrew-serrano/9e59429ef3f06f8a7c96caa18195eae1 to your computer and use it in GitHub Desktop.
Save andrew-serrano/9e59429ef3f06f8a7c96caa18195eae1 to your computer and use it in GitHub Desktop.
Used to delete google image type photos on products.
<mvt:comment> Redirect URL </mvt:comment>
<mvt:assign name="g.url" value="glosub( g.domain:base_surl, 'mm5/', '' ) $ 'delete-product-images'" />
<mvt:comment>
***
Image Deleter - Start
***
Image Deleter is being used for google product feed form.
</mvt:comment>
<mvt:if expr="ISNULL g.offset">
<mvt:comment> Set offset to 0 </mvt:comment>
<mvt:assign name="g.offset" value="0" />
<mvt:else>
<mvt:comment> Else continue </mvt:comment>
<mvt:assign name="g.offset" value="g.offset" />
</mvt:if>
<mvt:comment> Load all products </mvt:comment>
<mvt:do file="g.Module_Library_DB" name="l.success" value="ProductList_Load_Offset(g.offset ,'', '', 200 , g.nextOffset , l.settings:products )" />
<mvt:comment> Iterate over products </mvt:comment>
<mvt:foreach iterator="product" array="products">
<mvt:comment> Defualt Vars </mvt:comment>
<mvt:assign name="l.google_image_type_delete" value="NULL" />
<mvt:assign name="l.google_image_delete" value="NULL" />
<mvt:comment> Load image type </mvt:comment>
<mvt:do file="g.Module_Library_DB" name="l.success" value="ImageType_Load_Code('google_product_feed', l.google_image_type_delete)" />
<mvt:comment> Load Product image that is related to the type </mvt:comment>
<mvt:do file="g.Module_Library_DB" name="l.success" value="ProductImage_Load_Type(l.settings:product:id, l.google_image_type_delete:id, l.google_image_delete )" />
<mvt:comment> Create variable to delete image from product and image table </mvt:comment>
<mvt:assign name="l.productimage:id" value="l.google_image_delete:id" />
<mvt:assign name="l.productimage:image_id" value="l.google_image_delete:image_id" />
<mvt:comment> Delete image from product </mvt:comment>
<mvt:do file="g.Module_Library_DB" name="l.product_table" value="ProductImage_Delete(l.productimage)" />
<mvt:comment> Delete image from image table </mvt:comment>
<mvt:do file="g.Module_Library_DB" name="l.image_table" value="Image_Delete_LowLevel(l.productimage:image_id)" />
<mvt:comment> Delete image from server </mvt:comment>
<mvt:do file="g.Module_Library_DB" name="l.server" value="Image_Delete(l.productimage:image_id)" />
</mvt:foreach>
<mvt:if expr="g.nextOffset EQ 0">
Finished!
<mvt:exit/>
<mvt:else>
<mvt:comment>Refresh Page</mvt:comment>
<mvt:assign name="g.redirect_url" value="g.url $ '?continue=' $ g.continue $ '&offset=' $ g.nextOffset" />
<mvt:if expr="g.continue EQ 'refresh'">
<meta http-equiv="refresh" content="0;url=&mvt:global:redirect_url;"/>
<mvt:elseif expr="g.continue EQ 'cron'">
<mvt:eval expr="miva_output_header( 'Status', '301 Moved Permanently')" />
<mvt:eval expr="miva_output_header( 'Location', g.redirect_url )" />
</mvt:if>
</mvt:if>
<mvt:comment>
***
Image Resizer - End
***
</mvt:comment>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment