Answers.Body: <p>The mistake was not reading the docs properly and putting the config values in general.php. Instead, I needed to create a commerce.php config file and put the values in that. As soon as I did, the orders were purged.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-12-21T19:19:44.047Z
Answers.Text: Ahh... that would explain it, too. :)
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-12-21T07:31:24.420Z
Answers.LastActivityDate: 2017-12-21T07:31:24.420Z
Answers.UserDisplayName: Clive Portman
Answers.Body: <blockquote>
    <ol>
    <li>The trigger is time limited, e.g. is only called once a day?</li>
    </ol>
  </blockquote>
  
  <p>Nope.  That logic runs every time the order index page is loaded.</p>
  
  <blockquote>
    <ol start="2">
    <li>There are any known issues with the purging of inactive carts?</li>
    </ol>
  </blockquote>
  
  <p>Nothing I'm aware of.</p>
  
  <blockquote>
    <ol start="3">
    <li>Anything else I could look at?</li>
    </ol>
  </blockquote>
  
  <p>Here's the method and SQL query Commerce uses to determine if there are carts to purge.</p>
  
  <pre><code>private function getCartsIdsToPurge()
  {
      $configInterval = craft()-&gt;config-&gt;get('purgeInactiveCartsDuration', 'commerce');
      $edge = new \DateTime();
      $interval = new \DateInterval($configInterval);
      $interval-&gt;invert = 1;
      $edge-&gt;add($interval);
  
      return Craft::app()-&gt;db-&gt;createCommand()-&gt;select('orders.id')
          -&gt;from('commerce_orders orders')
          -&gt;where('isCompleted=:isCompleted AND dateUpdated &lt;= :edge', [':isCompleted' =&gt; 'not 1','edge' =&gt; $edge-&gt;format('Y-m-d H:i:s')])
          -&gt;queryColumn();
  }
  </code></pre>
  
  <p>Open up the orders table in the database and find a cart you think should be getting purged, but isn't.</p>
  
  <p>Check if it has a 0/null value in the <code>isCompleted</code> column and a <code>dateUpdated</code> column that is (in your case) greater than 1 month old.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-12-21T07:21:45.270Z
Answers.Text: Thanks Brad. Can confirm they have isCompleted set to 0 an the dateUpdated is more than one month ago. While I've been working on this (3 days now) I can see the orders are being purged that are more than 3 months old. So the purging is working, it's just my config setting overriding the duration that isn't. Actually, what I think might be the problem is I've got the value in my general.php file and not created a commerce.php config file. It does say that on https://craftcommerce.com/docs/configuration but I missed it.
Answers.UserDisplayName: Clive Portman
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-12-21T07:32:25.903Z
Answers.Text: Yep. It was the values being in general.php and not commerce.php. Sorry.
Answers.UserDisplayName: Clive Portman
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-12-20T19:26:05.850Z
Answers.LastActivityDate: 2017-12-20T19:26:05.850Z
Answers.UserDisplayName: Brad Bell
Body: <p>I've a Commerce store with orders dating back to September and have the following in my config:</p>
  
  <pre><code>'purgeInactiveCarts' =&gt; true,
  'purgeInactiveCartsDuration' =&gt; 'P1M',
  </code></pre>
  
  <p>The docs say that the purging should be triggered by me visiting the Inactive carts area of the Commerce order section, but it isn't. Does anyone know if:</p>
  
  <ol>
  <li>The trigger is time limited, e.g. is only called once a day?</li>
  <li>There are any known issues with the purging of inactive carts?</li>
  <li>Anything else I could look at?</li>
  </ol>
  
Tags: <plugin-craftcommerce>
Title: Purging inactive carts in Craft Commerce
ThreadText: # Purging inactive carts in Craft Commerce
  
  (Asked by: username_0 on 2017-12-20)
  
  I've a Commerce store with orders dating back to September and have the following in my config:
  
  ```
  'purgeInactiveCarts' => true,
  'purgeInactiveCartsDuration' => 'P1M',
  
  ```
  
  The docs say that the purging should be triggered by me visiting the Inactive carts area of the Commerce order section, but it isn't. Does anyone know if:
  
  1. The trigger is time limited, e.g. is only called once a day?
  2. There are any known issues with the purging of inactive carts?
  3. Anything else I could look at?
  
  **Tags:** plugin-craftcommerce
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_0 on 2017-12-21. Score: 1 | Accepted answer
  
  The mistake was not reading the docs properly and putting the config values in general.php. Instead, I needed to create a commerce.php config file and put the values in that. As soon as I did, the orders were purged.
  
  > **Comments:**
  > **username_1**: Ahh... that would explain it, too. :)  
  
  ---
  
  ### Answer by username_1 on 2017-12-20. Score: 0
  
  > 1. The trigger is time limited, e.g. is only called once a day?
  
  Nope. That logic runs every time the order index page is loaded.
  
  > 2. There are any known issues with the purging of inactive carts?
  
  Nothing I'm aware of.
  
  > 3. Anything else I could look at?
  
  Here's the method and SQL query Commerce uses to determine if there are carts to purge.
  
  ```
  private function getCartsIdsToPurge()
  {
      $configInterval = craft()->config->get('purgeInactiveCartsDuration', 'commerce');
      $edge = new \DateTime();
      $interval = new \DateInterval($configInterval);
      $interval->invert = 1;
      $edge->add($interval);
  
      return Craft::app()->db->createCommand()->select('orders.id')
          ->from('commerce_orders orders')
          ->where('isCompleted=:isCompleted AND dateUpdated <= :edge', [':isCompleted' => 'not 1','edge' => $edge->format('Y-m-d H:i:s')])
          ->queryColumn();
  }
  
  ```
  
  Open up the orders table in the database and find a cart you think should be getting purged, but isn't.
  
  Check if it has a 0/null value in the `isCompleted` column and a `dateUpdated` column that is (in your case) greater than 1 month old.
  
  > **Comments:**
  > **username_0**: Thanks username_1. Can confirm they have isCompleted set to 0 an the dateUpdated is more than one month ago. While I've been working on this (3 days now) I can see the orders are being purged that are more than 3 months old. So the purging is working, it's just my config setting overriding the duration that isn't. Actually, what I think might be the problem is I've got the value in my general.php file and not created a commerce.php config file. It does say that on https://craftcommerce.com/docs/configuration but I missed it.  
  > **username_0**: Yep. It was the values being in general.php and not commerce.php. Sorry.  
  
  ---
  
  