<p>We will need to uncomment this line to allow <code>|filter</code> used in condition formulas:</p>
<p><a href="https://github.com/craftcms/commerce/blob/develop/src/services/Formulas.php#L198" rel="nofollow noreferrer">https://github.com/craftcms/commerce/blob/develop/src/services/Formulas.php#L198</a></p>
<p>If you do that manually yourself this formula works:</p>
<p><code>order.lineItems|filter(v =&gt; (v.sku == 'BBB' and v.qty &gt;= 3) )</code></p>
<p>You were missing the <code>v.</code> in front of <code>qty</code>.</p>
<p>Look in the next version of commerce for the <code>|filter</code> being available.</p>

CC BY-SA 4.0
2021-08-26T09:10:17.733Z
2021-08-26T09:10:17.733Z
Luke Holder
<p>In Craft Commerce 3, there is a Order Condition Formula that allow us to condition for the discount. So here is my Case.</p>
<ul>
<li>I have product A and Product B, so I will give a discount to Product A if the costumer buy 3 of Products B.</li>
</ul>
<p>I tried to use this formula</p>
<pre><code>order.lineItems|filter(v =&gt; (v.sku == 'SKU A' and qty &gt;= 3) )
</code></pre>
<p>but the filter is not allowed in this formula, so is there any other way to approach this?</p>

<craft3><plugin-craftcommerce><ecommerce><plugin-craftcommerce3><discounts>
Commerce: Is there any way to give a discount for Product A if the costumer buy 3 Product B?
# Commerce: Is there any way to give a discount for Product A if the costumer buy 3 Product B?

(Asked by: username_0 on 2021-08-26)

In Craft Commerce 3, there is a Order Condition Formula that allow us to condition for the discount. So here is my Case.

I have product A and Product B, so I will give a discount to Product A if the costumer buy 3 of Products B.

I tried to use this formula
order.lineItems|filter(v => (v.sku == 'SKU A' and qty >= 3) )

but the filter is not allowed in this formula, so is there any other way to approach this?

**Tags:** craft3, plugin-craftcommerce, ecommerce, plugin-craftcommerce3, discounts

---

## 1 answers

### Answer by username_1 on 2021-08-26. Score: 2 | Accepted answer

We will need to uncomment this line to allow `|filter` used in condition formulas:

<https://github.com/craftcms/commerce/blob/develop/src/services/Formulas.php#L198>

If you do that manually yourself this formula works:

`order.lineItems|filter(v => (v.sku == 'BBB' and v.qty >= 3) )`

You were missing the `v.` in front of `qty`.

Look in the next version of commerce for the `|filter` being available.


---

