Last active
February 17, 2021 20:29
-
-
Save mbahar/73a7395df1747d74b7c9d76eb4658ca4 to your computer and use it in GitHub Desktop.
Product desciption builder
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
// type your code here | |
/* | |
sample condition array: | |
['minor',['rubs','stains'],'lining'] | |
['minor',['rubs'],'lining'] | |
['minor',['rubs','stains','dirt'],'lining'] | |
*/ | |
/* | |
Conditon specs | |
*/ | |
// Conditions for Bags | |
["rubs", "stains", "cracks", "tear", "discoloration", "spots", "darkening", "peeling","stickiness","pen marks"] | |
if ( {{ u_type.value == "Handbags" || u_type.value == "Accessories" }} ) { | |
return {'primary' : { 'name' :'Exterior Parts', 'specs' : ["edges", "corners", "leather parts", "leather trim", "handles", "strap", "surface", "canvas", "zipper pull","stitches","pocket" ] }, | |
'secondary': | |
{'name' :'Interior Parts', 'specs' : ["lining", "inside pocket", "pouch", "stitches","bottom"] } | |
} | |
} | |
if ( {{ u_type.value }} == "Watches" ) { | |
return { 'primary' : | |
{ 'name' :'Face and Body', 'specs' : ["edges", "a corner","corners", "bottom surface", "bottom corners", "upper leather parts", "leather trim", "handle", "strap", "surface", "canvas", "zipper pool","stitch","pocket" ] }, | |
'secondary' : { 'name' :'Bracelet', 'specs' : ["lining", "inside pocket", "pouch", "upper parts"] } | |
} | |
} | |
return {} | |
function buildSentence (words, type) { | |
if (! words.length >0 ) { | |
return "" | |
} | |
var sentence = "" | |
for (item in words) { | |
sentence += words[item] + ", " | |
} | |
sentence = sentence.slice(0, -2) | |
var count = (sentence.match(/,/g) || []).length; | |
if (count > 0) { | |
var n = sentence.lastIndexOf(", ") | |
sentence = sentence.substr(0, n ) + ' and '+ sentence.substr(n+2) | |
} | |
sentence += type + ". " | |
return sentence.charAt(0).toUpperCase() + sentence.slice(1) | |
} | |
function mergeStr (a,b, endS = "") { | |
if (b) { | |
return a+b+endS | |
} | |
return "" | |
} | |
function buildPhrase (subj, words, type) { | |
if (! words.length >0 ) { | |
return "" | |
} | |
var sentence = "" | |
for (item in words) { | |
sentence += words[item] + ", " | |
} | |
sentence = sentence.slice(0, -2) | |
var count = (sentence.match(/,/g) || []).length; | |
if (count > 0) { | |
var n = sentence.lastIndexOf(", ") | |
sentence = sentence.substr(0, n ) + ' and '+ sentence.substr(n+2) | |
} | |
sentence += type + ". " | |
sentence = subj + " " + sentence | |
return sentence.charAt(0).toUpperCase() + sentence.slice(1) | |
} | |
var str_ext="" | |
for (var item in cond_ext_details_arr.value) { | |
var str_item = (cond_ext_details_arr.value[item]) | |
str_ext += buildPhrase( str_item[0] , str_item[1] , " on the " + str_item[2] ) | |
} | |
var str_int="" | |
for (var item in cond_int_details_arr.value) { | |
var str_item = (cond_int_details_arr.value[item]) | |
str_int += buildPhrase( str_item[0] , str_item[1] , " on the " + str_item[2] ) | |
} | |
return ( "Item Condition:<br/>" + lookup_condition.value + " condition. Perfect for daily use. <br/>" + | |
"<br/>Exterior: " + str_ext + mergeStr (" Zipper ", lookup_hb_zipper.value, ".") + | |
"<br/>Interior: " + str_int + buildSentence ([ lookup_odor.value], "") + mergeStr( " <br/>Comes with: ", buildSentence ( lookup_hb_acces.value, "") ) | |
+ "<br/>Please see pictures for more details." | |
) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment