Skip to main content

Detect if two SKU's are on any line in BigCommerce Order Feed and return TRUE/FALSE for Checkbox

Comments

3 comments

  • Stephen Brandt Documentation Manager Community moderator
    Engaged
    Great Answer
    Top Contributor
    Celigo University Level 3: Master

    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
  • Stephen Brandt Documentation Manager Community moderator
    Engaged
    Great Answer
    Top Contributor
    Celigo University Level 3: Master

    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
  • Kate Larson Community moderator Principal Technical Writer
    Celigo University Level 3: Master

    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.