Answers.Body: <p>Based on some research, I believe a custom <a href="https://craftcommerce.com/docs/adjusters" rel="nofollow noreferrer">Adjuster</a> is the way to solve this problem.</p>
  
  <p>I created an adjuster with the following:</p>
  
  <p><code>craft/plugins/myplugin/MypluginPlugin.php</code></p>
  
  <pre class="lang-php prettyprint-override"><code>public function commerce_registerOrderAdjusters()
  {
    return [
      401 =&gt; new \Commerce\Adjusters\Myplugin_TenpercentDiscount
    ];
  }
  </code></pre>
  
  <p><code>craft/plugins/myplugin/Adjusters/Myplugin_TenPercentDiscount.php</code></p>
  
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  
  namespace Commerce\Adjusters;
  use Craft\Commerce_LineItemModel;
  use Craft\Commerce_OrderAdjustmentModel;
  use Craft\Commerce_OrderModel;
  
  class Myplugin_TenPercentDiscount implements Commerce_AdjusterInterface {
  
  public function adjust(Commerce_OrderModel &amp;$order, array $lineItems = []){
  
      if (empty($lineItems))
      {
          return [];
      }
  
      if ($order-&gt;totalQty &gt;= 10)
      {
          $adjuster = new Commerce_OrderAdjustmentModel();
  
          $adjuster-&gt;type        = 'Item Discount';
          $adjuster-&gt;name        = '10% Off Items';
          $adjuster-&gt;description = 'Your order qualifies for a 10% discount on all non sale items because you are purchasing at least 10 products.';
          $adjuster-&gt;orderId     = $order-&gt;id;
  
          $amountOff = 0;
          foreach ($lineItems as $item)
          {
              if (empty($item-&gt;onSale))
              {
                  $amountOff += ($item-&gt;subtotal + $item-&gt;discount) * .1;
              }
          }
          $amountOff = $amountOff * -1;
  
          $adjuster-&gt;amount      = $amountOff;
          $adjuster-&gt;optionsJson = ['lineItemsAffected' =&gt; null];
          $order-&gt;baseDiscount  += $amountOff;
  
          $adjuster-&gt;included = false;
  
          return [$adjuster];
      }
      return[];
  }
  
  }
  </code></pre>
  
  <p>Does anyone see any flaws with this approach?</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-03-03T15:42:01.907Z
Answers.Text: Hi peter, I am struggling onto where I'd have to put this code. I've tried to put it under craft->plugins->Commerce->Adjusters and named it Myplugin_TenPercentDiscount.php. But that does not seem to work. Sorry, I am a bit lost in all of this.
Answers.UserDisplayName: outline4
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-03-23T21:09:58.033Z
Answers.Text: Hi @outline4 -- You're close. You'll need to create your own plugin. I suggest using Plugin Factory for the scaffolding: https://pluginfactory.io/ and then you'll want the adjuster in the path: `craft/plugins/yourplugin/Adjusters/Yourplugin_Adjustername.php`
Answers.UserDisplayName: Peter Tell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-03-23T21:10:38.963Z
Answers.Text: Forgot to add, you also need to register the adjuster, I updated my code above to show that
Answers.UserDisplayName: Peter Tell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-05-09T19:02:03.390Z
Answers.LastActivityDate: 2018-03-23T21:13:15.190Z
Answers.LastEditDate: 2018-03-23T21:13:15.190Z
Answers.UserDisplayName: Peter Tell
Body: <p>What I would like is for a 10% discount to be applied to non sale items after the total cart quantity reaches 10 total items. I would ONLY like this discount on non sale items. Is that possible?</p>
  
  <p>So, say I have 2 Products in my cart:</p>
  
  <ul>
  <li>Item A - $20 on sale for $10, qty 9</li>
  <li>Item B - $20, qty 1</li>
  </ul>
  
  <p>This makes my total in cart quantity 10 line items even though 9 of them are sale items.</p>
  
  <p>What I would like is for <code>Item B</code> to be discounted 10% making my cart total <code>$108</code></p>
  
  <pre><code>( (10*9) + (20 * .9) ) = 108
  </code></pre>
  
  <p>As it currently stands, if I toggle <code>Exclude this discount for products that are already on sale</code> it doesn't count the sales items towards the total.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-05-08T16:37:33.120Z
Comments.Text: So 1) cart needs to reach 10 items. 2) Then 10% off on any item not already on sale.
Comments.UserDisplayName: RitterKnight
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-05-08T17:28:57.877Z
Comments.Text: Correct. You're much more succinct than I ;-)
Comments.UserDisplayName: Peter Tell
Tags: <plugin-craftcommerce>
Title: Craft Commerce - For a discount, can we include all products in the product count but not include the sale items that receive the discount?
ThreadText: # Craft Commerce - For a discount, can we include all products in the product count but not include the sale items that receive the discount?
  
  (Asked by: username_0 on 2017-05-03)
  
  What I would like is for a 10% discount to be applied to non sale items after the total cart quantity reaches 10 total items. I would ONLY like this discount on non sale items. Is that possible?
  
  So, say I have 2 Products in my cart:
  
  * Item A - $20 on sale for $10, qty 9
  * Item B - $20, qty 1
  
  This makes my total in cart quantity 10 line items even though 9 of them are sale items.
  
  What I would like is for `Item B` to be discounted 10% making my cart total `$108`
  
  ```
  ( (10*9) + (20 * .9) ) = 108
  
  ```
  
  As it currently stands, if I toggle `Exclude this discount for products that are already on sale` it doesn't count the sales items towards the total.
  
  **Tags:** plugin-craftcommerce
  
  > **Comments:**
  > **username_1**: So 1) cart needs to reach 10 items. 2) Then 10% off on any item not already on sale.  
  > **username_0**: Correct. You're much more succinct than I ;-)  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2017-05-09. Score: 3 | Accepted answer
  
  Based on some research, I believe a custom [Adjuster](https://craftcommerce.com/docs/adjusters) is the way to solve this problem.
  
  I created an adjuster with the following:
  
  `craft/plugins/myplugin/MypluginPlugin.php`
  
  ```php
  public function commerce_registerOrderAdjusters()
  {
    return [
      401 => new \Commerce\Adjusters\Myplugin_TenpercentDiscount
    ];
  }
  
  ```
  
  `craft/plugins/myplugin/Adjusters/Myplugin_TenPercentDiscount.php`
  
  ```php
  <?php
  
  namespace Commerce\Adjusters;
  use Craft\Commerce_LineItemModel;
  use Craft\Commerce_OrderAdjustmentModel;
  use Craft\Commerce_OrderModel;
  
  class Myplugin_TenPercentDiscount implements Commerce_AdjusterInterface {
  
  public function adjust(Commerce_OrderModel &$order, array $lineItems = []){
  
      if (empty($lineItems))
      {
          return [];
      }
  
      if ($order->totalQty >= 10)
      {
          $adjuster = new Commerce_OrderAdjustmentModel();
  
          $adjuster->type        = 'Item Discount';
          $adjuster->name        = '10% Off Items';
          $adjuster->description = 'Your order qualifies for a 10% discount on all non sale items because you are purchasing at least 10 products.';
          $adjuster->orderId     = $order->id;
  
          $amountOff = 0;
          foreach ($lineItems as $item)
          {
              if (empty($item->onSale))
              {
                  $amountOff += ($item->subtotal + $item->discount) * .1;
              }
          }
          $amountOff = $amountOff * -1;
  
          $adjuster->amount      = $amountOff;
          $adjuster->optionsJson = ['lineItemsAffected' => null];
          $order->baseDiscount  += $amountOff;
  
          $adjuster->included = false;
  
          return [$adjuster];
      }
      return[];
  }
  
  }
  
  ```
  
  Does anyone see any flaws with this approach?
  
  > **Comments:**
  > **username_2**: Hi username_0, I am struggling onto where I'd have to put this code. I've tried to put it under craft->plugins->Commerce->Adjusters and named it Myplugin_TenPercentDiscount.php. But that does not seem to work. Sorry, I am a bit lost in all of this.  
  > **username_0**: Hi @username_2 -- You're close. You'll need to create your own plugin. I suggest using Plugin Factory for the scaffolding: https://pluginfactory.io/ and then you'll want the adjuster in the path: `craft/plugins/yourplugin/Adjusters/Yourplugin_Adjustername.php`  
  > **username_0**: Forgot to add, you also need to register the adjuster, I updated my code above to show that  
  
  ---
  
  