Skip to content

Instantly share code, notes, and snippets.

@bheyde
Created September 7, 2017 15:38
Show Gist options
  • Save bheyde/ab5a70bdd092824dad41cd956390ed37 to your computer and use it in GitHub Desktop.
Save bheyde/ab5a70bdd092824dad41cd956390ed37 to your computer and use it in GitHub Desktop.
bronto
<mvt:comment>Bronto JSON Integration - Cart Data => only run after first item is added to cart or on invoicee page</mvt:comment>
<mvt:if expr="l.settings:global_minibasket:basketitemsonly_count GT 0 OR l.settings:page:code EQ 'INVC'">
<mvt:comment><!-- Variable setup --></mvt:comment>
<mvt:if expr="l.settings:page:code NE 'INVC'">
<mvt:comment><!-- Order item data --></mvt:comment>
<mvt:assign name="l.settings:orderData:subtotal" value="0" />
<mvt:assign name="l.settings:orderData:discounts" value="0" />
<mvt:assign name="l.settings:orderData:tax" value="0" />
<mvt:foreach iterator="item" array="global_minibasket:items">
<mvt:comment><!-- Order subtotal --></mvt:comment>
<mvt:assign name="l.settings:orderData:subtotal" value="l.settings:orderData:subtotal + l.settings:item:subtotal" />
<mvt:comment><!-- Order discounts --></mvt:comment>
<mvt:foreach iterator="item_discount" array="item:discounts">
<mvt:assign name="l.settings:orderData:discounts" value="l.settings:orderData:discounts + l.settings:item_discount:discount" />
</mvt:foreach>
</mvt:foreach>
<mvt:comment><!-- Order total --></mvt:comment>
<mvt:assign name="l.settings:orderData:total" value="glosub( l.settings:global_minibasket:formatted_total, '$', '' )" />
<mvt:elseif expr="l.settings:page:code EQ 'INVC'">
<mvt:comment><!-- Order total --></mvt:comment>
<mvt:assign name="l.settings:orderData:total" value="rnd( l.settings:order:total, 2 )" />
<mvt:comment><!-- Order subtotal --></mvt:comment>
<mvt:assign name="l.settings:orderData:subtotal" value="rnd( l.settings:order:subtotal, 2 )" />
<mvt:foreach iterator="type" array="order:charges">
<mvt:if expr="l.settings:order:charges:type EQ 'TAX'">
<mvt:assign name="l.settings:orderData:tax" value="l.settings:orderData:tax + l.settings:order:charges:amount" />
</mvt:if>
</mvt:foreach>
</mvt:if>
<mvt:comment><!-- Set cart phase based on checkout step --></mvt:comment>
<mvt:if expr="l.settings:page:code EQ 'ORDL'">
<mvt:assign name="l.settings:orderData:phase" value="'CUSTOMER_LOGIN'" />
</mvt:if>
<mvt:if expr="l.settings:page:code EQ 'OCST'">
<mvt:assign name="l.settings:orderData:phase" value="'BILLING'" />
</mvt:if>
<mvt:if expr="l.settings:page:code EQ 'OSEL'">
<mvt:assign name="l.settings:orderData:phase" value="'SHIPPING_METHOD'" />
</mvt:if>
<mvt:if expr="l.settings:page:code EQ 'OPAY'">
<mvt:assign name="l.settings:orderData:phase" value="'PAYMENT'" />
</mvt:if>
<mvt:if expr="l.settings:page:code EQ 'INVC'">
<mvt:assign name="l.settings:orderData:phase" value="'ORDER_COMPLETE'" />
</mvt:if>
<mvt:comment> Load imagetype data & settings </mvt:comment>
<mvt:do name="l.success" file="g.Module_Library_DB" value="ImageType_Load_Code( 'Default', l.settings:imagetype_loaded )" />
<mvt:assign name="l.width" value="144" />
<mvt:assign name="l.height" value="144" />
<!-- Start: Bronto JSON Integration -->
<script type="text/javascript">
var orderData = {
<mvt:if expr="NOT ISNULL l.settings:orderData:phase">
"cartPhase": "&mvt:orderData:phase;",
</mvt:if>
"currency": "USD",
"subtotal": <mvt:eval expr="rnd(l.settings:orderData:subtotal, 2)" />,
"discountAmount": <mvt:eval expr="rnd(l.settings:orderData:discounts, 2)" />,
"taxAmount": <mvt:eval expr="rnd(l.settings:orderData:tax, 2)" />,
"grandTotal": &mvt:orderData:total;,
<mvt:if expr="l.settings:order:id">
"orderId": "&mvt:order:id;",
<mvt:elseif expr="g.order:id">
"orderId": "&mvt:global:order:id;",
</mvt:if>
<mvt:if expr="NOT ISNULL g.customer:pw_email">
"emailAddress": "&mvte:global:customer:pw_email;",
<mvt:elseif expr="NOT ISNULL g.customer:bill_email">
"emailAddress": "&mvte:global:customer:bill_email;",
<mvt:elseif expr="NOT ISNULL g.customer:ship_email">
"emailAddress": "&mvte:global:customer:ship_email;",
<mvt:elseif expr="NOT ISNULL g.basket:bill_email">
"emailAddress": "&mvte:global:basket:bill_email;",
<mvt:elseif expr="NOT ISNULL g.basket:ship_email">
"emailAddress": "&mvte:global:basket:ship_email;",
</mvt:if>
"cartUrl": "&mvt:urls:bask:secure;",
<mvt:if expr="l.settings:page:code EQ 'INVC'">
"lineItems": [
<mvt:assign name="l.items_count" value="miva_array_elements( l.settings:order:items )" />
<mvt:foreach iterator="item" array="order:items">
<mvt:comment> Set custom imagetype dimensions </mvt:comment>
<mvt:do name="l.success" file="g.Module_Library_DB" value="ProductImage_Load_Type(l.settings:item:product:id, l.settings:imagetype_loaded:id, l.settings:item:imagetype)" />
<mvt:do name="l.success" file="g.Module_Library_DB" value="Image_Load_ID(l.settings:item:imagetype:image_id, l.settings:item:imagedata)" />
<mvt:do name="l.image_loaded" file="g.Module_Library_DB" value="Image_Load_File( l.settings:item:imagedata:image, l.image )" />
<mvt:if expr="l.image_loaded">
<mvt:do file="g.Module_Library_DB" name="l.generated_image_loaded" value="GeneratedImage_FindOrInsert_Image_Dimensions( l.image, l.width, l.height, l.settings:item:generated_image )" />
</mvt:if>
<mvt:assign name="l.settings:item:new_cropped_image" value="l.settings:item:generated_image:image" />
{
"sku": "&mvtj:item:product:sku;",
"name": "&mvtj:item:product:name;",
<mvt:if expr="NOT ISNULL l.settings:item:product:descrip">
<mvt:item name="toolkit" param="nohtml|clean_desc|l.all_settings:item:product:descrip" />
<mvt:assign name="g.clean_desc" value="trim(g.clean_desc)" />
"description": "&mvte:global:clean_desc;",
</mvt:if>
<mvt:comment>"category": "Shirts > T-Shirts > Blue",</mvt:comment>
"unitPrice": <mvt:eval expr="glosub( l.settings:item:formatted_base_price, '$', '' )" />,
"salePrice": <mvt:eval expr="glosub( l.settings:item:formatted_price, '$', '' )" />,
"quantity": &mvt:item:quantity;,
"totalPrice": <mvt:eval expr="glosub( l.settings:item:formatted_subtotal, '$', '' )" />,
<mvt:if expr="NOT ISNULL l.settings:item:new_cropped_image">
"imageUrl": "&mvt:global:basehref;&mvt:item:new_cropped_image;",
</mvt:if>
"productUrl": "https://&mvt:global:domain:name;&mvt:item:link;"
<mvt:if expr="POS1 EQ l.items_count">
}
<mvt:else>
},
</mvt:if>
</mvt:foreach>
]
<mvt:else>
"lineItems": [
<mvt:assign name="l.items_count" value="miva_array_elements( l.settings:global_minibasket:items )" />
<mvt:foreach iterator="item" array="global_minibasket:items">
<mvt:comment> Set custom imagetype dimensions </mvt:comment>
<mvt:do name="l.success" file="g.Module_Library_DB" value="ProductImage_Load_Type(l.settings:item:product:id, l.settings:imagetype_loaded:id, l.settings:item:imagetype)" />
<mvt:do name="l.success" file="g.Module_Library_DB" value="Image_Load_ID(l.settings:item:imagetype:image_id, l.settings:item:imagedata)" />
<mvt:do name="l.image_loaded" file="g.Module_Library_DB" value="Image_Load_File( l.settings:item:imagedata:image, l.image )" />
<mvt:if expr="l.image_loaded">
<mvt:do file="g.Module_Library_DB" name="l.generated_image_loaded" value="GeneratedImage_FindOrInsert_Image_Dimensions( l.image, l.width, l.height, l.settings:item:generated_image )" />
</mvt:if>
<mvt:assign name="l.settings:item:new_cropped_image" value="l.settings:item:generated_image:image" />
{
"sku": "&mvt:item:product:sku;",
"name": "&mvte:item:product:name;",
<mvt:if expr="NOT ISNULL l.settings:item:product:descrip">
<mvt:item name="toolkit" param="nohtml|clean_desc|l.all_settings:item:product:descrip" />
<mvt:assign name="g.clean_desc" value="trim(g.clean_desc)" />
"description": "&mvtj:global:clean_desc;",
</mvt:if>
<mvt:comment>"category": "Shirts > T-Shirts > Blue",</mvt:comment>
"unitPrice": <mvt:eval expr="glosub( l.settings:item:formatted_base_price, '$', '' )" />,
"salePrice": <mvt:eval expr="glosub( l.settings:item:formatted_price, '$', '' )" />,
"quantity": &mvt:item:quantity;,
"totalPrice": <mvt:eval expr="glosub( l.settings:item:formatted_subtotal, '$', '' )" />,
<mvt:if expr="NOT ISNULL l.settings:item:new_cropped_image">
"imageUrl": "&mvt:global:basehref;&mvt:item:new_cropped_image;",
</mvt:if>
"productUrl": "https://&mvt:global:domain:name;&mvt:item:link;"
<mvt:if expr="POS1 EQ l.items_count">
}
<mvt:else>
},
</mvt:if>
</mvt:foreach>
]
</mvt:if>
};
</script>
<!-- End: Bronto JSON Integration -->
</mvt:if>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment