Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steveosoule/76c5c3e56e0205b431118c6cc1b8e366 to your computer and use it in GitHub Desktop.
Save steveosoule/76c5c3e56e0205b431118c6cc1b8e366 to your computer and use it in GitHub Desktop.
Miva - Nested Category URI 301 Redirects
<mvt:comment>
## About
Given a store with a category/sub-category structure like this:
- appliances
- kitchen
- refrigerators
It will generate Miva XML Provisioning for a category URI like this:
/appliances/kitchen/refrigerators.html
## Directions
1. Assign the `sitemap` item to a page and replace the Sitemap template content with this Gist.
2. Visit the front-end of the site and save the output in an XML file.
3. Import the file through Data Management.
## Similar Gist
https://gist.github.com/steveosoule/b70d431e7434b49831524de605059924
</mvt:comment>
<mvt:foreach iterator="category" array="categories">
<mvt:do file="g.Module_Root $ '/modules/component/cmp-mv-prodctgy-meta.mvc'" name="l.settings:category:CategoryCascadeList_Load_Category_Result" value="CategoryCascadeList_Load_Category( l.settings:category, l.settings:category:list )" />
<mvt:foreach iterator="item" array="category:list">
<mvt:item name="customfields" param="Read_Category_ID( l.settings:item:id, 'uri_slug', l.settings:item:customfield_values:customfields:uri_slug )" />
<mvt:if expr="ISNULL l.settings:item:customfield_values:customfields:uri_slug">
<mvt:assign name="l.settings:item:customfield_values:customfields:uri_slug" value="l.settings:item:code" />
</mvt:if>
<mvt:assign name="l.settings:category:uri" value="l.settings:category:uri $ '/' $ l.settings:item:customfield_values:customfields:uri_slug" />
</mvt:foreach>
<mvt:assign name="l.settings:category:uri" value="l.settings:category:uri $ '.html'" />
<mvt:assign name="l.settings:category:uri_xml" value="'<uri_add category_code=\"' $ l.settings:category:code $ '\" status=\"301\" uri=\"' $ l.settings:category:uri $ '\" />'" />
&mvt:category:uri_xml;
</mvt:foreach>
<mvt:foreach iterator="product" array="products">
<mvt:do file="g.Module_Library_DB" name="l.success" value="CategoryList_Load_Offset_Product_Assigned( l.settings:product:id, 0, '', '', 999, l.settings:product:categories_nextoffset, l.settings:product:categories )" />
<mvt:foreach iterator="category" array="product:categories">
<mvt:do file="g.Module_Root $ '/modules/component/cmp-mv-prodctgy-meta.mvc'" name="l.settings:category:CategoryCascadeList_Load_Category_Result" value="CategoryCascadeList_Load_Category( l.settings:category, l.settings:category:list )" />
<mvt:foreach iterator="item" array="category:list">
<mvt:item name="customfields" param="Read_Category_ID( l.settings:item:id, 'uri_slug', l.settings:item:customfield_values:customfields:uri_slug )" />
<mvt:if expr="ISNULL l.settings:item:customfield_values:customfields:uri_slug">
<mvt:assign name="l.settings:item:customfield_values:customfields:uri_slug" value="l.settings:item:code" />
</mvt:if>
<mvt:assign name="l.settings:category:uri" value="l.settings:category:uri $ '/' $ l.settings:item:customfield_values:customfields:uri_slug" />
</mvt:foreach>
<mvt:assign name="l.settings:category:uri" value="l.settings:category:uri $ '/' $ l.settings:product:code $ '.html'" />
<mvt:assign name="l.settings:category:uri_xml" value="'<uri_add product_code=\"' $ l.settings:product:code $ '\" status=\"301\" uri=\"' $ l.settings:category:uri $ '\" />'" />
&mvt:category:uri_xml;
</mvt:foreach>
</mvt:foreach>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment