<p>I made a simple mistake by defining the array with the setting value.
I wrote <code>array('currentInvoiceNumber', $newInvoiceNumber)</code> instead of <code>array('currentInvoiceNumber' =&gt; $newInvoiceNumber)</code>.</p>

CC BY-SA 3.0
2017-08-23T07:20:07.647Z
2017-08-23T17:35:35.910Z
2017-08-23T17:35:35.910Z
phaetons
<p>I want to update programatically a plugin's setting:</p>

<pre><code>public function init()
{   
     craft()-&gt;on('commerce_orders.onBeforeOrderComplete', function($event){
        // Set InvoiceNumber
        $newInvoiceNumber = $this-&gt;getSettings()-&gt;currentInvoiceNumber + 1;
        $myPlugin = craft()-&gt;plugins-&gt;getPlugin( 'Ultraschall' );
        craft()-&gt;plugins-&gt;savePluginSettings( $myPlugin, 
                                              array('currentInvoiceNumber', $newInvoiceNumber ));
    });
}
</code></pre>

<p>But I get this error:</p>

<pre><code>PHP warning
array_key_exists() expects parameter 2 to be array, null given
/mnt/web209/c2/98/5363898/htdocs/dev.ultraschall-leinwand.de/craft/app/models/BaseModel.php(418)

417  // Is this the first time this extra attribute has been set?
418  else if (!array_key_exists($name, $this-&gt;_extraAttributeNames))
419  {
420     $this-&gt;_extraAttributeNames[] = $name;
421  }
422 
423  $this-&gt;_attributes[$name] = $value;
424  return true;
</code></pre>

<p>I have added defineSettings() and getSettingsHtml() to the Plugin and can change values via CP without problems.</p>

<p>Why do I get this error?</p>

CC BY-SA 3.0
2017-08-03T06:17:29.867Z
Can you post a bit more of the stack trace leading up to that error?  Have you ever used xDebug?  Great for figuring out stuff like this.
Brad Bell
<plugin-craftcommerce><settings>
Error updating programmatically a plugin's setting
# Error updating programmatically a plugin's setting

(Asked by: username_0 on 2017-08-02)

I want to update programatically a plugin's setting:
public function init()
{   
     craft()->on('commerce_orders.onBeforeOrderComplete', function($event){
        // Set InvoiceNumber
        $newInvoiceNumber = $this->getSettings()->currentInvoiceNumber + 1;
        $myPlugin = craft()->plugins->getPlugin( 'Ultraschall' );
        craft()->plugins->savePluginSettings( $myPlugin, 
                                              array('currentInvoiceNumber', $newInvoiceNumber ));
    });
}

But I get this error:
PHP warning
array_key_exists() expects parameter 2 to be array, null given
/mnt/web209/c2/98/5363898/htdocs/dev.ultraschall-leinwand.de/craft/app/models/BaseModel.php(418)

417  // Is this the first time this extra attribute has been set?
418  else if (!array_key_exists($name, $this->_extraAttributeNames))
419  {
420     $this->_extraAttributeNames[] = $name;
421  }
422 
423  $this->_attributes[$name] = $value;
424  return true;

I have added defineSettings() and getSettingsHtml() to the Plugin and can change values via CP without problems.
Why do I get this error?

**Tags:** plugin-craftcommerce, settings
> **Comments:**
> **username_1**: Can you post a bit more of the stack trace leading up to that error?  Have you ever used xDebug?  Great for figuring out stuff like this.  

---

## 1 answers

### Answer by username_0 on 2017-08-23. Score: 2 | Accepted answer

I made a simple mistake by defining the array with the setting value.
I wrote `array('currentInvoiceNumber', $newInvoiceNumber)` instead of `array('currentInvoiceNumber' => $newInvoiceNumber)`.


---

