Skip to content

Instantly share code, notes, and snippets.

@bheyde
Last active November 17, 2016 00:26
Show Gist options
  • Save bheyde/a61b54f85130fdb87c5a9cb5759829e2 to your computer and use it in GitHub Desktop.
Save bheyde/a61b54f85130fdb87c5a9cb5759829e2 to your computer and use it in GitHub Desktop.
Load Variant Data
MivaEvents.SubscribeToEvent('variant_changed', function (product_data) {
var master_code = product_data.product_code;
var variant_id = product_data.variant_id;
var url = "/load-variant-data.html?product_code=" + master_code + "&variant_id=" + variant_id;
$.get( url, function( data ) {
//Data Bindings
$("#product_code").html(data.sku);
$("#product_name").html(data.name);
});
});
<mvt:if expr="NOT ISNULL g.product_code AND NOT ISNULL g.variant_id">
<mvt:do file="g.Module_Library_DB" name="l.success" value="Product_Load_Code(g.product_code, l.product)" />
<mvt:do file="g.Module_Library_DB" name="l.success" value="ProductList_Load_Variant(l.product:id, g.variant_id, l.productvariants)" />
<mvt:comment>Load Variant Product To Get Description</mvt:comment>
<mvt:do file="g.Module_Library_DB" name="l.success" value="Product_Load_Code(l.productvariants[1]:code, l.product)" />
<mvt:assign name="l.productvariants[1]:descrip" value="l.product:descrip" />
<mvt:assign name="l.settings:variant" value="l.productvariants[1]" />
{
"sku": "&mvtj:variant:sku;",
"code": "&mvtj:variant:code;",
"name": "&mvtj:variant:name",
"weight": "&mvtj:variant:weight",
"description": "&mvtj:variant:descrip",
<mvt:item name="customfields" param="Read_Product_Code(l.settings:variant:code,'')" />
<mvt:assign name="g.custom_field_count" value="miva_array_elements( l.settings:customfields )" />
<mvt:foreach iterator="custom_field" array="customfields">
"&mvte:custom_field:code;": "&mvtj:custom_field:value;" <mvt:if expr="pos1 LT g.custom_field_count">,</mvt:if>
</mvt:foreach>
}
</mvt:if>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment