Skip to content

Instantly share code, notes, and snippets.

@crswll
Last active December 14, 2015 00:39
Show Gist options
  • Save crswll/5000244 to your computer and use it in GitHub Desktop.
Save crswll/5000244 to your computer and use it in GitHub Desktop.
SSML for getting ProStores product data into a JS object.
<ss:if test="$request.getParameter('no')">
<ss:set name="product" value="$store.products.getProductWithNumber($request.getParameter('no'))"/>
<ss:if test="$product">
<script>
var product = {
name: "<ss:value source="$product.name" escape="javastring"/>",
price: [
<ss:foreach item="price" within="$product.finalPriceList">
<ss:value source="$price" format="none"/><ss:if test="$counter.isLast() == false">,</ss:if>
</ss:foreach>
],
sku: "<ss:value source="$product.sku" escape="javastring"/>",
upc: "<ss:value source="$product.upc" escape="javastring"/>",
isbn: "<ss:value source="$product.isbn" escape="javastring"/>",
quantity: <ss:value source="$product.quantityInStock"/>,
brief: "<ss:value source="$product.brief" escape="javastring"/>",
description: "<ss:value source="$product.description" escape="javastring"/>",
images: [
<ss:foreach item="media" within="$product.images">
<ss:set name="mediaCounter" value="$counter"/>
<ss:set name="item" value="$media.storeMediaItem"/>
{
type: "<ss:value source="$item.type"/>",
name: "<ss:value source="$item.name" escape="javastring"/>",
title: "<ss:value source="$item.title" escape="javastring"/>",
small: "<ss:value source="$item.small"/>",
medium: "<ss:value source="$item.medium"/>",
large: "<ss:value source="$item.large"/>",
tags: [
<ss:foreach item="tag" within="$item.tags">
"<ss:value source="$tag.value" escape="javastring"/>"<ss:if test="$counter.isLast == false">,</ss:if>
</ss:foreach>
]
}<ss:if test="$mediaCounter.isLast == false">,</ss:if>
</ss:foreach>
],
attributes: [
<ss:foreach item="attribute" within="$product.attributes">
<ss:set name="attributeCounter" value="$counter"/>
{
attributeText: "<ss:value source="$attribute.attributeText" escape="javastring"/>",
price: [
<ss:foreach item="price" within="$attribute.finalPriceList">
<ss:value source="$price" format="none"/><ss:if test="$counter.isLast() == false">,</ss:if>
</ss:foreach>
],
sku: "<ss:value source="$attribute.sku" escape="javastring"/>",
upc: "<ss:value source="$attribute.upc"/>",
isbn: "<ss:value source="$attribute.isbn"/>",
quantity: <ss:value source="$attribute.quantity"/>,
externalQuantity: <ss:value source="$attribute.externalQuantity"/>,
size: {
length: <ss:value source="$attribute.length" format="none" default="0"/>,
height: <ss:value source="$attribute.height" format="none" default="0"/>,
width: <ss:value source="$attribute.width" format="none" default="0"/>,
weight: <ss:value source="$attribute.weight" format="none" default="0"/>
}
}<ss:if test="$attributeCounter.isLast() == false">,</ss:if>
</ss:foreach>
],
promotions: [
<ss:foreach item="promotion" within="$product.activePromotions">
<ss:set name="promotionCounter" value="$counter"/>
{
activeInd: <ss:value source="$promotion.activeInd"/>,
applyToAttributesEnabled: <ss:value source="$promotion.applyToAttributesEnabled"/>,
exclusiveInd: <ss:value source="$promotion.exclusiveInd"/>,
prefix: <ss:value source="$string.wrapInQuotes($promotion.prefix)"/>,
endDate: <ss:value source="$string.wrapInQuotes($promotion.endDate)" default="false"/>,
startDate: "<ss:value source="$promotion.startDate" escape="javastring" default="false"/>",
properties: {
discountAmount: <ss:value source="$promotion.getPropertyValue('discount.amount')" default="false"/>,
discountType: <ss:value source="$string.wrapInQuotes($promotion.getPropertyValue('discount.type'))" default="false"/>,
limitMaxUse: <ss:value source="$promotion.getPropertyValue('limit.maxuse')" default="false"/>,
limitMaxUseCount: <ss:value source="$promotion.getPropertyValue('limit.maxuse.count')" default="false"/>,
orderMinimum: <ss:value source="$promotion.getPropertyValue('order.minimum')" default="false"/>,
orderMaximum: <ss:value source="$promotion.getPropertyValue('order.maximum')" default="false"/>,
quantityMinimum: <ss:value source="$promotion.getPropertyValue('quantity.minimum')" default="false"/>,
quantityMaximum: <ss:value source="$promotion.getPropertyValue('quantity.maximum')" default="99999"/>
}
}<ss:if test="$promotionCounter.isLast() == false">,</ss:if>
</ss:foreach>
]
};
</script>
</ss:if>
</ss:if>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment