Summarize RAL Upsells
by karlovac
HTML
<div id="output">
</div>
CSS
#output {
font-size: 24px;
}
table, th, td {
border: 1px solid black;
}
JavaScript
var dtgRecipeId = '61411982'; // DTG
var cyoRecipeId = '75059882'; // CYO
var dtgBasePrice = 1299; // DTG This needs to come from the server
var cyoBasePrice = 1399; // CYO
var currency = 'RMB';
function isDtg(vendorId) {
return vendorId.indexOf('dtg') > -1;
}
function getCategory(av) {
var category = 'embroidery';
// console.log('attribute', av.name);
var customizationTypeFacet = av.facets.filter(function(f) {return f.name === 'Customization Type'});
if (av.name === 'Add Numbers') {
category = 'patch';
}
if (customizationTypeFacet.length > 0) {
var customizationType = customizationTypeFacet[0].values[0].name;
if (customizationType.indexOf('Flag') > -1) {
category = 'patch';
}
}
return category;
}
function checkPrice(recipeId, basePrice, callback) {
var recipeUrl = 'https://api.fluidretail.net/recipe/'+recipeId+'?api-key=R8lp7_l6U7en-K1C4XrWRYgdjY4bPzVlk&locale=en_us&include=localized_configuration,extended_attributes';
// Remember that within China, the recipe URL will be:
// http://cdn-prod.fluidconfigure.cn/api/recipe/91002197?api-key=R8lp7_l6U7en-K1C4XrWRYgdjY4bPzVlk&locale=en_us&include=localized_configuration,extended_attributes
$.ajax({
url: recipeUrl,
beforeSend: function( xhr ) {
xhr.overrideMimeType( 'text/plain; charset=x-user-defined' );
}
})
.done(function( data ) {
var recipe = JSON.parse(data);
var upsells = [];
if (!isDtg(recipe.product.vendor_id)) {
// CYO Products - calculate total price based on upsells
for (var alias in recipe.extended_attributes) {
var attribute = recipe.extended_attributes[alias];
var valueVendorId = attribute.value !== false ? attribute.value.info.vendorIds : '-';
// Skip the size because that is where the SKU lives, and it has a hard-coded "$1" price, whereas in the actual calculation we use the SKU price
if (alias !== 'size' && attribute.value !== false &&...