Instantly share code, notes, and snippets.
Last active
August 23, 2017 00:38
-
Save steveosoule/ebb1f0e136402eea69335d70d0fc0297 to your computer and use it in GitHub Desktop.
Miva - Related Products Based on Breadcrumbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<mvt:comment> | |
<!-- | |
Instructions: | |
1. Create a "related_breadcrumbs" ReadyTheme Content Section | |
2. Put the following code within that content section. | |
3. Add the <mvt:item name="readytheme" param="contentsection( 'related_breadcrumbs' )" /> item to the PROD page where you want them to display. | |
--> | |
</mvt:comment> | |
<mvt:comment> | |
<!-- | |
| Initialization & Settings | |
--> | |
</mvt:comment> | |
<mvt:assign name="l.settings:related_breadcrumbs:max_product_count" value="8" /> | |
<mvt:assign name="l.settings:related_breadcrumbs:image:width" value="150" /> | |
<mvt:assign name="l.settings:related_breadcrumbs:image:height" value="150" /> | |
<mvt:do file="g.Module_Library_DB" name="l.result" value="ImageType_Load_Code( 'main', l.settings:related_breadcrumbs:image:type )" /> | |
<mvt:comment> | |
<!-- | |
| Prepare Data From Breadcrumbs | |
--> | |
</mvt:comment> | |
<mvt:foreach array="breadcrumbs:links" iterator="link"> | |
<mvt:do file="g.Module_Library_DB" name="l.success" value="Category_Load_Code( l.settings:link:code, l.settings:link:category )" /> | |
<mvt:if expr="l.settings:link:category:id"> | |
<mvt:do file="g.Module_Feature_URI_UT" name="l.settings:link:category:link" value="Store_Category_URL( l.settings:link:category, NULL )" /> | |
<mvt:assign name="l.result" value="miva_array_insert( l.settings:related_breadcrumbs:categories, l.settings:link:category, 1 )" /> | |
</mvt:if> | |
</mvt:foreach> | |
<mvt:comment> | |
<!-- | |
| Load Products on Breadcrumb Categories | |
--> | |
</mvt:comment> | |
<mvt:foreach array="related_breadcrumbs:categories" iterator="related_category"> | |
<mvt:do file="g.Module_Library_DB" name="l.success" value="ProductList_Load_Offset_Category_Assigned( l.settings:related_category:id, 0, '1', 'active', l.settings:related_breadcrumbs:max_product_count, l.settings:related_category:productlist:next_offset, l.settings:related_category:productlist:products )" /> | |
<mvt:foreach array="related_category:productlist:products" iterator="category_product"> | |
<mvt:comment> | |
Load Resized `main` Image | |
</mvt:comment> | |
<mvt:do file="g.Module_Library_DB" name="l.result" value="ProductImage_Load_Type(l.settings:category_product:id, l.settings:related_breadcrumbs:image:type:id, l.settings:category_product:imagetypes_data:type)" /> | |
<mvt:do file="g.Module_Library_DB" name="l.result" value="Image_Load_ID( l.settings:category_product:imagetypes_data:type:image_id, l.settings:category_product:imagetypes_data:image )" /> | |
<mvt:do file="g.Module_Library_DB" name="l.result" value="GeneratedImage_FindOrInsert_Image_Dimensions( l.settings:category_product:imagetypes_data:image, l.settings:related_breadcrumbs:image:width, l.settings:related_breadcrumbs:image:height, l.settings:category_product:imagetypes_data:generated )" /> | |
<mvt:if expr="l.settings:category_product:imagetypes_data:generated:id"> | |
<mvt:assign name="l.settings:category_product:src" value="l.settings:category_product:imagetypes_data:generated:image" /> | |
<mvt:else> | |
<mvt:assign name="l.settings:category_product:src" value="g.theme_path $ '/images/img_no_thumb.jpg'" /> | |
</mvt:if> | |
<mvt:comment> | |
Load other product data (URI, Currency Formatting) | |
</mvt:comment> | |
<mvt:do file="g.Module_Feature_URI_UT" name="l.settings:category_product:link" value="Store_Product_URL( l.settings:category_product, NULL )" /> | |
<mvt:do file="g.Module_Store_Module_Currency" name="l.settings:category_product:formatted_price" value="CurrencyModule_AddFormatting( g.Store:currncy_mod, l.settings:category_product:price )" /> | |
</mvt:foreach> | |
<mvt:do file="g.Module_Feature_TUI_UT" name="l.result" value="CommonComponentFields_Initialize_Product_Discounts_Runtime(l.settings:related_category:products, miva_array_elements(l.settings:related_category:products))" /> | |
</mvt:foreach> | |
<mvt:if expr="NOT miva_array_elements( l.settings:related_breadcrumbs:categories )"> | |
<mvt:exit/> | |
</mvt:if> | |
<h2>Related Breadcrumbs</h2> | |
<mvt:foreach array="related_breadcrumbs:categories" iterator="related_category"> | |
<h2 class="carousel-products-heading">&mvt:related_category:name;</h2> | |
<div class="carousel-products carousel-products row"> | |
<mvt:foreach array="related_category:productlist:products" iterator="category_product"> | |
<div class="carousel-product column half medium-one-fourth align-center" style="width: 24%; display: inline-block;"> | |
<a href="&mvt:category_product:link;"> | |
<img class="carousel-product-image" src="&mvt:category_product:src;" alt="&mvt:category_product:name;"> | |
</a> | |
<div class="carousel-product-price">&mvt:category_product:formatted_price;</div> | |
<div class="carousel-product-name"> | |
<a href="&mvt:category_product:link;"> | |
&mvt:category_product:name; | |
</a> | |
</div> | |
</div> | |
</mvt:foreach> | |
</div> | |
</mvt:foreach> | |
<mvt:if expr="g.debug"> | |
<mvt:eval expr="glosub(miva_array_serialize(l.settings:related_breadcrumbs), ',', '<br>')" /> | |
</mvt:if> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment