Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery Arrays - $inArray
    primarykey
    data
    text
    <p>I am throwing an error message if more than one SKU is in a shopping cart, but I need to make one exception to my rule. Below is my code.</p> <p>Basically what is going on here is that JNL758 is the only SKU that can also be in the cart along with any of the SKUs from customizedProductIDs and customizedProductIDs2.</p> <p>I need some rule that won't display the error message if 1 SKU from customizedProductIDs or customizedProductIDs2 along with JNL758 is in the cart, but that would be it then - the user can't have an additional SKU in the cart.</p> <p>Let's say @JNL0500, JNL758, and JNL123 is in the cart - I need to display the error message. No error message would display if only @JNL0500 and JNL758 is in the cart.</p> <pre><code>var customizedProductIDs = ["@JNL0500", "@JNL0501", "@JNL0502", "@JNL0503", "@JNL0504"]; var customizedProductIDs2 = ["@JNL0408", "@JNL1036", "@JNL1735", "JNL1005", "@JNL0222", "@JNL0221"]; var cardsku = ["JNL758"]; function cartItemCountError() { if ($451 &amp;&amp; $451.OrderDetails &amp;&amp; $451.OrderDetails.lineItems) { var cartItemCount = $451.OrderDetails.lineItems.length; var errors = false; if (cartItemCount &gt; 1) { for (var i = 0; i &lt; cartItemCount; i++) { var currItem = $451.OrderDetails.lineItems[i]; // If cart has a customized item in it (See customizedProductIDs array.), it may not have any other item in the cart.) if ($.inArray(currItem.productID, customizedProductIDs) != -1) { errors = true; } else if ($.inArray(currItem.productID, customizedProductIDs2) != -1) { errors = true; } if ($.inArray(currItem.productID, customizedProductIDs2) &amp;&amp; ($.inArray(currItem.productID, cardsku)) != -1) { errors = false; } } } return errors; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload