Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Maybe this will help you:</p> <p>Example deal: Buy 4 of <strong>PRODUCT_A</strong> get 2 of <strong>PRODUCT_B</strong> free</p> <p>Variables:</p> <ul> <li><code>numSkuRequired</code>: number of products required for deal to work(in this case 4)</li> <li><code>skuRequired</code>: the product required for deal to work(in this case <strong>PRODUCT_A</strong>'s identifier, sku/id or something)</li> <li><code>numSkuFree</code>: number of products to be given as free(in this case 2)</li> <li><code>skuFree</code>: the product that is given away for free(in this case <strong>PRODUCT_B</strong>'s identifier, sku/id or something)</li> <li><code>quantityLookupRequired</code>: <strong>PRODUCT_A</strong>'s summed quantity in cart, default <code>false</code></li> <li><code>quantityLookupFree</code>: <strong>PRODUCT_B</strong>'s summed quantity in cart, default <code>false</code></li> <li><code>quantityFree</code>: final result that we're looking for to calculate the total amount, number of free products(<strong>PRODUCT_B</strong>), default <code>0</code></li> <li><code>price</code>: price of <strong>PRODUCT_B</strong>, default <code>0</code></li> <li><code>discount</code>: total discount amount, default <code>0</code></li> </ul> <p>Steps</p> <ol> <li>find sum of PRODUCT_A in cart, save in variable <code>quantityLookupRequired</code></li> <li>ensure that <code>quantityLookupRequired</code> is <code>&gt;=</code> <code>numSkuRequired</code></li> <li>find sum of PRODUCT_B in cart, save in variable <code>quantityLookupFree</code></li> <li>ensure that <code>quantityLookupFree</code> is <code>&gt;=</code> <code>numSkuFree</code></li> <li>find price of PRODUCT_B and save in variable <code>price</code></li> <li>loop(see below) to find <code>quantityFree</code> (the editor isn't allowing me to make this look much better sorry).</li> <li><p><code>discount</code> will be <code>quantityFree * price</code></p> <p>for(int i = 0; i &lt; numSkuRequired + numSkuFree; i &lt;= quantityLookupRequired + quantityLookupFree; i += (numSkuRequired + numSkuFree)) { quantityFree += numSkuFree; } while(quantityFree % numSkuFree != 0)/* don't allow partial discounts */ { quantityFree--; } discount = quantityFree * price;</p></li> </ol> <p>Note: a slightly different approach is taken when the deal only includes 1 product(Buy 4 of <strong>PRODUCT_A</strong> get 2 of <strong>PRODUCT_A</strong> free)</p>
    singulars
    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.
    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