Detect if two SKU's are on any line in BigCommerce Order Feed and return TRUE/FALSE for Checkbox
We offer customized products on BigCommerce that enter our Netsuite system with a different process. Several scripts/workflows check a checkbox on the Sales Order "Order Contains Embroidery"
After a lot of testing, and a lot of unfamiliarity with handlebars, I'm unable to check this box if ONE OR BOTH Products appear within the order. These two Products are EMB-TEXT and EMB-LOGO. (note: they are different products/parents
The closest I came was with this string in the export field of the order flow:
{{#each products}}{{#compare name '==' 'EMB-TEXT'}}TRUE{{/compare}}{{/each}}
But attempting to expand it to the other sku, or if the sku occured multiple times either wouldn't import at all, or import correctly.
I thought I was maybe getting closer with something like this, but getting it to check a checkbox, leads me to believe some sort of OR statement might be needed:
{{#each products}}{{#compare name '==' 'EMB-TEXT'}}TRUE{{/compare}}{{else}}{{#compare name '==' 'EMB-LOGO'}}TRUE{{/compare}}{{/each}}
The order data is standard coming out of BigCommerce, but I attempted to abbreviate it here:
products: [
{
id: 50624,
order_id: 2000393212,
product_id: 4456,
order_address_id: 3922,
name: "EMB-TEXT",
}
]
Any help is greatly appreciated.
- nick
-
Hi, Nick Cirocco.
As written, the second handlebars statement is invalid, because the {{else}} statement is outside of the first #compare block. (That's not caught by the editor as an error, which I'll try to look into.)
The correct syntax would be (whitespace for readability here only)...
{{#each products}}
{{#compare name '==' 'EMB-TEXT'}}true
{{else}}
{{#compare name '==' 'EMB-LOGO'}}true{{/compare}}
{{/compare}}
{{/each}}The logical problem that I'm struggling with is on subsequent iterations of {{#each products}}. You wouldn't want to pass "truetrue" to the checkbox, which is how this statement will evaluate, assuming the customer had selected both EMB-TEXT and EMB-LOGO on two different products.
Getting a single value for the checkbox might be best accomplished in a JavaScript hook, where you can loop through the records and add a new field to your data if either EMB- condition is true.
0 -
Scratch that, on second thought. It's much simpler, since there couldn't be a case when a product had both name '==' 'EMB-TEXT' and name '==' 'EMB-LOGO'. You would just need this statement, without the {{else}}, for a single product:
{{#compare name '==' 'EMB-TEXT'}}true{{/compare}}{{#compare name '==' 'EMB-LOGO'}}true{{/compare}}
0 -
Hi Nick Cirocco,
I also received this suggestion from one of our senior engineers:
"each" will not work if both the products can appear within the order. This should do the trick -{{#contains (jsonSerialize products) "EMB-TEXT"}}true{{else}}{{#contains (jsonSerialize products) "EMB-LOGO"}}true{{/contains}}{{/contains}}
0
Please sign in to leave a comment.
Comments
3 comments